Click here to Skip to main content
Click here to Skip to main content

An Introduction to Boost

By , 6 Jul 2003
 

Contents

  1. Introduction
  2. Installation
  3. Why Boost?
  4. What Does Boost Provide?
  5. What Else?
  6. References
  7. Version History

Introduction

Boost is a free library which is aimed at providing quality software components to developers, whilst using the styles of the Standard Template Library. Some of the components within the library may be put forward as future extensions to the Standard Library.

The Boost main page
The Boost libraries index
CUJ Descriptions of the boost components

The Boost homepage contains extensive documentation on all of the individual components. This article is intended to be an overview of why you should consider using Boost, and the Boost components in preference to other libraries, and to provide a location on CodeProject which can offer links to related documentation.

Installation

Boost installation is simple because most of the components within the library reside in their own header files, which should not require modification. The BoostJam build tool is available for the components which do require compilation.

You can download the source zip from SourceForge.

Unzip the entire archive into a directory of your choosing. To start using the components add the Boost directory which includes version numbers to your include path. For the current version of Boost, boost_1_30_0.

Most of the components come with test suites and examples of use.

Why Boost?

  • Boost is namespace aware. All components within the library are packaged in the "boost" namespace, or a sub-namespace thereof.
  • Regular updates. Boost is a library which is growing all the time, the home page and the Boost Announcements Lists show some of the changes in the last few releases.
  • Developer support. Questions related to the components can be directed to the Boost users mailing group, or found on the Boost Mail Archives or on one of the specific lists for a particular component.
  • Boost supports a variety of compilers, operating systems and standard libraries. It provides workarounds for the broken features of many compilers, perhaps the most significant being the workarounds for problems with templates, including partial template specialisation and member template friends.
  • Regression testing. Each update to Boost is heavily regression tested, and the status of the library for all compilers is freely available.
  • Many of the people involved with the development of the C++ standard are involved with Boost.
  • Simple to install and upgrade. In most cases, installation and upgrading only requires the addition or change of one include path.
  • Easy to configure. Compilation options can be specified by changing directives in one or two header files.

What Does Boost Provide?

What follows is a minimal listing of components. There are about 50 major sub-components in Boost at the moment. The following components were those that I felt logically progressed from the components in the STL, were easy to integrate, or were especially significant to most programmers.

Smart Pointers

Smart pointers are tools that prevent resource leaks (especially in the presence of exceptions), promote the concept of 'Initialisation is Resource Acquisition'. They emulate, to a certain extent, garbage collection like behaviour.

Most of the limitation of std::auto_ptr are relatively well known:
  • std::auto_ptr's cannot be stored within a standard containers.
  • std::auto_ptr's cannot (easily) be used to implement the pImpl (pointer-to-implementation) idiom.
  • std::auto_ptr does not work with arrays.
The 5 types of Boost smart pointers overcome these flaws and provide many extra features.
  • Custom delete functions can be supplied.
  • Detection of incomplete template types.
Boost smart pointer index
Comparison of Boost and Loki Smart Pointers The New C++: Smart(er) Pointers - Herb Sutter
Introduction to uses of the Boost smart pointers Conversations: Getting to the Point - Herb Sutter and Jim Hyslop

Composers

Functors and binders have become a common part of using the STL, but using most standard library implementations it can still be difficult to combine multiple functions. Composers allow functors to be combined in several ways, minimising the amount of times that users have to write their own loops.

Boost::compose index
The C++ Standard Library - A Tutorial and Reference (Nicolai M. Josuttis)

Any

A component which provides a type safe way to move any type of component, without having to rely upon void pointers or unions. The design principles for this component is at least as significant as the component itself (derivation of a template class from a non template base class). Something similar to boost::any appears in Alexandrescu’s Modern C++ Design in the guise of Functors and Functor Implementations.

boost::any main page
boost::any Theory
Introduction to uses of Boost Any Conversations: I'd Hold Anything for You - Herb Sutter

Bind and Function

Bind and Function are specified as two separate components, but they are extensions (any number of arguments) of binders and functors concept which are currently in place in the Standard Library.

boost::function main page
boost::bind main page

The Lambda Library

The lambda library provides a shortcut for producing binders, functors and composers using expression templates. My personal opinion on the library is that developers would need some practice to recognise it’s use. Libraries like the Lambda library are probably the way of the future for C++, but at the moment, I think I’m prepared to have slower uglier code that I know the next guy can understand.

The Boost Lambda Library Index
Further information on the basics of expression templates was published in the March issue of the C/C++ users journal (C++ Expression Templates – Angelika Langer and Klaus Kreft)

The Boost Graph Library (The BGL)

The BGL is a huge library, with a large amount of support material and good sample programs. “The Boost Graph Library, The: User Guide and Reference Manual” has been published by Addison-Wesley in the C++ In Depth Series (The same fantastic series that includes 'Exceptional C++', 'More Exceptional C++' and 'Modern C++ Design'), which I believe is testament to the quality of the library.

Boost Graph Library Table of Contents
The Boost Graph Library, The: User Guide and Reference Manual Book Review

Thread

Developed by Code Project regular William E. Kempf, the threads library makes it seem almost as easy to do threads in C++ as it is in Java. It requires linking to an additional library, built with BoostJam.

boost::threads index
William E. Kempf on boost::thread

Spirit parser generator framework

Jonathan de Halleux has written an excellent introduction to the Spirit Parser Generator Framework with comprehensive links to relevant material

What Else?

  • Regular Expressions
  • Traits
  • File System (Directory Iteration)
  • Iterator Adaptors
  • Maths and Matrices
  • A Template metaprogramming framework
  • Tuples
  • Python

References

Many of the references in this article come from the C / C++ Users journal website, which is an excellent resource for up to date information on uses, and techniques for using STL and Boost.

Additional information about Boost can be found at Boost Consulting

This article was inspired by an item in the 'Article Requests and Ideas' Forum by John M. Drescher

Version history

30. 6. 2003 Initial Posting

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Andrew Walker
Web Developer
Australia Australia
Member
Andrew is a PhD student at Swinburne University in Melbourne Australia, investigating the control systems of UUV's - Unmanned Underwater Vehicles. He graduated from Swinburne with a Bachelor of Engineering (Robotics and Mechatronics) and a Bachelor of Science(Computer Science & Software Engineering)
 
His practical experience includes a year developing an industrial computer vision system from scratch, and working as the software architect for the 2004 Swinburne Robocup team (f180 league).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberVirendra Kulkarni16 Sep '09 - 0:24 
Very basic info is provided a comparison with some other library would really add some value.
GeneralProblem while using string.hppmembertonyaim8327 Aug '07 - 19:45 
Boost library provide string.hpp for performing various operation on string.
When im trying to include this file i m getting following error messages.:-
/* code
#include"boost/algorithm/string.hpp"
*/
 
Error :- :c:\boost\algorithm\string\yes_no_type.hpp(22) : error C2265: '' : reference to a zero-sized array is illegal
c:\boost\algorithm\string\yes_no_type.hpp(23) : see reference to class template instantiation 'boost::algorithm::size_descriptor' being compiled
c:\boost_1_34_0\boost\mpl\bool.hpp(37) : fatal error C1506: unrecoverable block scoping error..
 
What can be the reason for this..
 

 

 
tony

GeneralRe: Problem while using string.hppmemberfoxconn8 Apr '08 - 4:08 
it may be VC6 compiler bugs.
Please use VC7.0 or above,
 
"We especially recommend this method if you use Microsoft Visual Studio .NET 2003 or Microsoft Visual Studio 2005"
--from http://www.boost.org/doc/libs/1_35_0/more/getting_started/windows.html[^]
QuestionHow to use this library?memberbreak;12 Oct '06 - 3:17 
Hello,
i try to use boost in my projects, regular expressions for example, but i recive only an error!
This is my first try with boost, an example from boost homepage:
boost::tregex r(__T("(?:\\A|.*\\\\)([^\\\\]+)"));
boost::tmatch what;
 
Error Message:
error C2039: 'tregex' : is not a member of 'boost'
error C2065: 'tregex' : undeclared identifier

 
how to use now this regular expressions in vc6 projects??
 
thanks in advance
break;
Questionn-ary tree?memberAnthony_Yio13 Apr '04 - 22:14 
Does boost come with n-ary tree container?

 
Sonork 100.41263:Anthony_Yio
 
Life is about experiencing ...

AnswerRe: n-ary tree?memberAndrew Walker13 Apr '04 - 22:56 
No it's one of the few things that boost doesn't have - the experts still argue about how tree classes should be written.
 
Boost does however have the Boost Graph Library, which is a superset of all trees, and can be used to construct trees - some of the examples do this. I found the learning curve for the BGL to be very steep, one of the very few parts of boost that is like that.
 

 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: n-ary tree?memberAnthony_Yio14 Apr '04 - 1:43 
Using Boost would be my primary choice, but since Boost doesn't have it (N-Ary tree) at the moment. I will use STL n-ary tree by Kasper Peeters instead.
 
thanks, nice intro to Boost.
 
Sonork 100.41263:Anthony_Yio
GeneralRe: n-ary tree?memberunjedai22 May '07 - 16:50 
Peeters' tree looks really cool, but he is using the GNU General Public License, so you can't use it in proprietary software.
GeneralIntroductory Boost PresentationmemberMattyT18 Nov '03 - 12:41 
Heya Everyone,
 
I recently gave a presentation to my colleagues here at work on the wonders of the Boost library. It gives a gentle introduction to Boost and nine of the libraries.
 
It was well received and went for about an hour. I thought that others may be able to use it so I've made it available here[^].
 
Feel free to use/abuse modify, whatever!
 
Cheers,
Matt
GeneralRe: Introductory Boost PresentationmembertheCPkid16 Apr '09 - 21:58 
the link is not working.. Sigh | :sigh:
GeneralBoost Submitted librariesmemberJonathan de Halleux15 Jul '03 - 0:34 
Boost contains a lot of libraries... but it contains even more hidden goodies if you start looking into the "not yet" accepted libraries.
 
To find them, go to the boost mailing list on yahoo and look into the files sections. After crawling a bit, I found (I'm giving only a few):
 
  • The Relational Templated Library: this project is to SQL as Spirit is for parsers
  • hashed containers (hash_map, hash_set, ...)
  • socket streams
  • filtered stream buffers
  • a lot of format libraries
  • etc...
 

 
Jonathan de Halleux.

GeneralRe: Boost Submitted librariesmemberAndrew Walker15 Jul '03 - 2:01 
Thanks for the response, good luck with IoBind and it's proposal for inclusion into Boost.
 
If you've got any additional links and / or material that you think needs to be added, or other components which you consider essential I'd appreciate any advice you could give.
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneraluBLASmemberJonathan de Halleux16 Jul '03 - 4:01 
uBLAS is a C++ wrapper around the BLAS (Basic Linear Algebra Subroutines). It also contains bindings to LAPACK (Linear Algebra Package).
 
I think this package maybe deserves some attention. In fact, it would to time to put a good tutorial on CP about Numerical Algebra: When it comes to matrix computation, there are basically to solution:
 

Home made

I see people implementing their own matrix classes and therefore implementing their own +, -, *, etc... and worse inversion operator (usually a cut and paste from Numerical Recipies): you should always avoid this solution when it comes to matrix computation:
  • personnal implementations are error-prone. Moreover, error are difficult to track down.
  • Algorithms are usually not the "top of the notch". Matrix computation is not a still science and algorithms haved evolved a lot in the past few years
  • You can do what you want, your implementation will be slower than LAPACK counter part
  • It takes a lot of time and code to write to get a decent matrix class
You can add many things to this list...
 

LAPACK

On the other you have the BLAS and LAPACK who are optimized Fortran routines written by numerical algebra gurus:
  • It's free
  • Algorithms are error free!
  • Algorithms are fast
  • You can solve all the classical problems: eigen values, LU, Choleski, etc... You don't need to type it again

 
One thing that makes LAPACK difficult to use is that it's basically a Fortran library, you need the right memory alignment and function calls tend to be long and tedious. This is where uBLAS comes into the play:
  • uBLAS has bindings to LAPACK
  • uBLAS is a template wrapper, minimum function overhead (all methods are inline and optimized away by the compiler)
 
Smile | :)

 
Jonathan de Halleux.

GeneralAt lastmemberJonathan de Halleux15 Jul '03 - 0:30 
Nice, a good boost intro. was really missing in CP.
 
Maybe this article belongs to tutorials ?
 
Jonathan de Halleux.

Generalauto_ptrsmemberAdi Shavit7 Jul '03 - 23:05 
Hi,
 
Good introduction.
The more introductions and articles about boost we have the more people will learn how to use these amazing libraries.
 
Just a note, though, regarding auto_pts.
auto_ptrs, were never meant as smart pointers per se, so the limitations and faults you mention aren't really limitations and faults (but can actually be considered features). auto_ptrs are meant as an exception safe mechanism for memory management. People have gone to great trouble to get the feature of not allowing them to be stored in containers to work.
 
I think that adding them to the STL before other real smart-pointers may arguably be confusing, but real smart-pointers are one of the most probable candidaes for the next STL release, indeed, mostly based on the boost smart pointers.
 
Anyway, I think every C++ user should be familiar with the Boost smart pointers and I hope your article spurs people to go and explore more.
 
Thanks,
Adi
 

GeneralRe: auto_ptrssussMårten R9 Jul '03 - 4:34 
I agree with you in general, however I think std::auto_ptr should not be copy-constructible or assignable (albeit with a non-const reference). IMO ownership should be transferred using swap and/or attach/detach.
 
However, std::auto_ptr is the way it is and it's a very valueable piece of code if used as intended.
 

 
/Mårten
GeneralRe: auto_ptrsmemberAdi Shavit9 Jul '03 - 10:15 
Making auto_ptrs copy-constructible and assignable is what gives them their power as bare pointer replacements in the case of returning a pointer from a function.
 
It removes the age old dilemma of who'll deallocate the pointer.
Now the allocating function can trust the auto_ptr to take care of cleaning up.
 
But I agree: "it's a very valueable piece of code if used as intended".
 
Adi
 

GeneralThank YoumemberJohn M. Drescher7 Jul '03 - 11:31 
Thanks. Just wondering do you plan any more articles on this subject? I have been looking for an intro for BOOST for over a year because I can not understand the provided documentation.
 
John
GeneralRe: Thank YoumemberAndrew Walker7 Jul '03 - 15:03 
I'm more than willing to add to this article or write additional material, I don't claim to be a Boost expert, but I've been working with it for a little while. I think that most of the documentation is OK, but sometimes it can be a bit hard to find what you're looking for - the standard of documentation varies significantly across components.
 
What type of things were you looking for in particular? Any particular components?
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: Thank YoumemberJohn M. Drescher8 Jul '03 - 9:20 
I was generally looking for more examples on how and where to use the library. I have looked into using boost code for a long time but when I read the examples I either don't understand what is happening or where someone would use it in a real world example. When I look at the pointers stuff. WOW there are so many types! I am not sure where to start. I use the smart pointer from the following article http://www.codeproject.com/cpp/smartptr.asp[^]
 
Does boost offer a better solution?
 
Also, is there any use for the threads library in a win32 application? To me it looks like you sacrifice performance and functionality for portability.
 
Thanks in advance,

 
John
GeneralRe: Thank YoumemberAndrew Walker8 Jul '03 - 16:04 
John M. Drescher wrote:
I use the smart pointer from the following article http://www.codeproject.com/cpp/smartptr.asp
 
Stefan Chekanov's SmartPointer that you've been using is just different to the Boost Smart Pointers.
 
boost::shared_ptr and boost::shared_array offer reference counting, similar to Chekanov's 'RefCountPtr', the boost approach to thread safety varies away from the design in Chekanov's work.
 
The number of classes involved with the Boost smart pointers is probably less than you would expect, they are just spread around in lots of header files.
 
I haven't worked with Chekanov's classes so the following comments are from the short look that I've just had.
 
1/ It is likely that the class will not be able to uphold an exception safety guarantee. I'm not going to cite a specific example, nothing was glaring obvious, but proving exception guarantees is hard, very hard.
 
2/ The constructor which accepts a SmartPtrBase, which can be used to convert pointer types is likely to be risky if used inappropriately to convert the types of pointers (threaded -> non-threaded), which could allow incorrect access to a resource.
 
3/ The Boost Smart pointers reference counts will be safe in the presence of threads, however they do not aquire criticle sections (see the CSyncAccessRep class) so the contained object will not be safeguarded in multiple threads. This is perhaps the biggest difference, if you decide to change Smart Pointer implementations.
 
4/ Parameterization: Chekanov states that to avoid having to supply additional template parameters he provides the additional classes. All of the boost smart pointers have been designed to only take a single parameter (the type of the pointer).
But Greg Colvin and Jerry Schwarz argued that "parameterization will discourage users", and in the end we choose to supply only the direct implementation
See: http://www.boost.org/libs/smart_ptr/smart_ptr.htm[^] for more information.
If you are looking for a full blown parameterization capable smart pointer, Loki (from 'Modern C++ Design' fame) has now received a large ammount of testing, and may be appropriate.
 
My personal opinion on smart pointers is that they are a must-have tool, but I'm only going to use something I know isn't going to fail in unexpected ways. Also, if I decide to change platforms, my code should require as little work as possible to port. Smart pointer code is one of the areas where I know that tiny changes can have a massive effect in the presence of exceptions, and proving that a solution is exception safe is a time consuming job. I'm willing to cede to the known experts in the field, Colvin, Abrahams, Dawes and Dimov along with all the other users and library writers that the boost smart pointers will 'just work' - no matter what.
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: Thank YoumemberJohn M. Drescher8 Jul '03 - 16:10 
Thanks for taking the time to write a very detailed reply...
 
John
GeneralRe: Thank YoumemberAndrew Walker8 Jul '03 - 16:25 
John M. Drescher wrote:
Also, is there any use for the threads library in a win32 application? To me it looks like you sacrifice performance and functionality for portability.
 
I'm not sure where functionality and performance losses could come from, but my knowledge of threading isn't the greatest. To me it looks like all the overhead is at construction / destruction of a thread object. I'm more than willing to trade that for being able to pass parameters into my function in a typesafe way (using function objects and binders), rather than attempting to cast void pointers.
 
I guess it's another example of 'adding an extra level of indirection' to solve a problem. If you can work easily with win32 threads then use that, it's the beauty of boost, you can pick and choose which bits you want,
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: Thank YoumemberJohn M. Drescher25 Jul '03 - 7:02 
How about Boost.function? Recently a article http://www.codeproject.com/cpp/CallbackDemo.asp[^] there was a suggestion to use Boost.function instead. I looked at the documentation and examples and have absolutly no idea about the usefulness of Boost.function and how I could use it to replace a callback mechanism.
 
John
GeneralBoost Function (long)memberAndrew Walker25 Jul '03 - 18:47 
John M. Drescher wrote:
Recently a article http://www.codeproject.com/cpp/CallbackDemo.asp
 
Just a couple of comments on that particular article:
- The way the sample app is written makes it relatively hard to see what callbacks are doing
- Big chunks of the code aren't type safe (void pointers) - big mental alarm bells start ringing in my head, getting all the louder when I see C-style casts.
- Some of the functions should really be using standard library elements, without even considering boost.
 
In the cases where you're writing the code, it's generally easiest to specify that anything with function call semantics is acceptable. The simplest way to do that is to templatize all of the functions. STL does this, that's why all the STL algorithms are templatized. Function objects in the standard are meant to be light-weight, so the types shouldn't really be significant. The consequence of that is that it's hard to exchange global functions for member function pointers.
 
The following code, which is a rewrite of the mentioned article's sample code uses boost::bind. If the callback does not support a conversion to a string type, the build will fail.
 
The basic idea to remember is that a callback (for a member function) needs to have two things: first an object pointer (or reference) and second the member function pointer. Binding like this allows you to attach the object to the member function pointer, in this case most if not all of this should be possible without using boost, by just using standard library elements (the second part of my response isn't). What makes boost bind/function/mem_fn outstanding in this area is that you can have any number of arguments.
#include <iostream>
#include <sstream>
#include <boost/bind.hpp>
 
using namespace std;
 
template<class T>
void globalCallback(T callback)
{
    ostringstream oss;
    oss << "From a global callback" << endl;
    callback(oss.str());
}
 
class Add
{
public:
    // generated ctor & dtor ok.

    template<class T>
    bool addNumbers(int num1, int num2, T callback)
    {
        ostringstream oss;
        oss << "Adding    " << num1 << " + " << num2 << " = " << (num1+num2) << endl;
        callback(oss.str());
        return true;
    }
};
 
class Multiply
{
public:
    // generated ctor & dtor ok.

    template<class T>
    bool multiplyNumbers(int num1, int num2, T callback)
    {
        ostringstream oss;
        oss << "Adding    " << num1 << " * " << num2 << " = " << (num1*num2) << endl;
        callback(oss.str());
        return true;
    }
};
 
class Test  
{
public:
 
    // generated ctor & dtor ok.

    void testStart()
    {
        cout << "Start" << endl;
 
        Add add;   // local instances
        Multiply multi;
 
        // -------------- Demo 1 : normal callback ----------------------
        cout << "\n> Setting CallbackOutputStars !\n";
        add.addNumbers       (120, 30, boost::bind(&Test::callbackOutputStars,this,_1));
	    multi.multiplyNumbers(3,   22, boost::bind(&Test::callbackOutputStars,this,_1));
 
        // -------------- Demo 2 : changing the callback ----------------
        cout << "\n> Setting CallbackOutputDollar !\n";
        add.addNumbers       (33, 66, boost::bind(&Test::callbackOutputStars,this,_1));
        multi.multiplyNumbers(5,  10, boost::bind(&Test::callbackOutputStars,this,_1));
 
        // -------------- Demo 3 : global callback ----------------------

        cout << ("\n> Finally the callback from a global function :\n");
        globalCallback(boost::bind(&Test::callbackOutputStars,this,_1));
 
        cout << "Done" << endl;
    }
 
private:
    void callbackOutputStars(const std::string& str)
    {
        ostringstream oss;
        oss << "  ***** Some stars *****  " << str << endl;
        cout << oss.str();
    }
 
    void callbackOutputDollar(const std::string& str)
    {
        ostringstream oss;
        oss << "  $$$ Now with Dollar $$$ " << str << endl;
        cout << oss.str();
    }
};
 
int main()
{
    Test t;
    t.testStart();
    return 0;
}
 
However, if you need a callback facility are you going to know the types involved? Most of the time the answer to that question is yes. [Slightly OT: As a student, that one concept took me months to get my head around, especially with so many templates whizzing around].
 
boost::function does this by letting you restrict the incoming types a bit better. Think of it as a flag to other programmers about what you are doing.
 
#include <boost/function.hpp> // added from the last sample
// changed from last sample
void globalCallback(boost::function1<void,std::string> callback)
{
    ostringstream oss;
    oss << "From a global callback" << endl;
    callback(oss.str());
}
// changed from last sample
class Add
{
public:
    // generated ctor & dtor ok.

    bool addNumbers(int num1, int num2, boost::function1<void,std::string> callback)
    {
        ostringstream oss;
        oss << "Adding    " << num1 << " + " << num2 << " = " << (num1+num2) << endl;
        callback(oss.str());
        return true;
    }
};
// changed from last sample
class Multiply
{
public:
    // generated ctor & dtor ok.

    bool multiplyNumbers(int num1, int num2, boost::function1<void,std::string> callback)
    {
        ostringstream oss;
        oss << "Adding    " << num1 << " * " << num2 << " = " << (num1*num2) << endl;
        callback(oss.str());
        return true;
    }
};
 
I built both samples under MSVC6, and noticed a degradation in compile time performance using boost::function.
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: Boost Function (long)memberJohn M. Drescher25 Jul '03 - 18:53 
Thank You very much for your time to write such a long and informative answer...
 
John
GeneralRe: Thank YoumemberMattyT7 Jul '03 - 21:13 
I've been considering writing an article about some Boost features myself - this is a great start Andrew, thanks! Smile | :)
 
It's always surprising to me that many of my colleagues don't know or use Boost as it's a terrific resource.
 
If anyone would like more information about some of the specific functionality that Boost provides then I also extend the safe offer as Andrew - let us know what is of interest to you and we'll try and provide...
 

On a separate issue, it's always good to see Aussies contributing - particularly Victorians! It's just a shame that you chose Swinburne Andrew... (coming from a former RMIT'er) Wink | ;)
GeneralRe: Thank YoumemberKevin McFarlane8 Jul '03 - 0:37 
MattyT wrote:
It's always surprising to me that many of my colleagues don't know or use Boost as it's a terrific resource
 
I know of it but haven't used it yet. I think more people will use it over time as it becomes better known and documented. It was the same with STL. I knew of it a long time before I started using it - mainly because it took me a while before I understood how to use it.
 
Also, we must reckon with the following stages when encountering new technolgy (or, at least, they're common stages for me!)
 
1. Bafflement.
2. Understanding but then asking: but what's the point?
3. Encountering a problem(s) for which the new technology provides a tailor-made solution.
 
Kevin
GeneralRe: Thank YoumemberAndrew Walker8 Jul '03 - 0:48 
Boost is becoming increasingly important, especially considering the upcoming Standards review:
 
On comp.std.c++ Beman Dawes wrote:
Of the 12 proposals accepted so far, 10 grew out of the Boost libraries.
 
With momentum like that behind the Boost, it seems to me like it can't be ignored - developers need to be aware that many of these components are, in addition to being 'top notch', likely to be adopted into the c++ Standard.
 
http://std.dkuug.dk/jtc1/sc22/wg21/docs/library_technical_report.html[^]
 

If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
 
Rudyard Kipling

GeneralRe: Thank YoumemberKevin McFarlane8 Jul '03 - 1:11 
The key thing for me is usually point 3 in my post. I need to encounter a problem for which I can use the new technique (once I've understood how to use it). I don't usually use new stuff just for the sake of it. Especially, as others may have to maintain my code.
 
I think there just always will be some lag between what the average developer uses it and what's new. Even now many developers shy away from STL and stick to unnecessarily low-level, error-prone code. I know this from having done lots of maintenance programming recently, and not on really old code.
 
However, my main problem at the moment is finding any kind of work at all in the current market, having been out of work for most of the past couple of years. So Boost doesn't get me too excited just at the moment. Not to mention that, in the UK, C++ is bottom of the skills table and bottom of the rates table too!Cry | :(( Not much of an incentive to invest time in learning quite demanding stuff.
 
Kevin
GeneralRe: Thank YoumemberMattyT8 Jul '03 - 17:40 
Much like when I read Andrei Alexandrescu's book I found that being aware of new features and techniques really changed the way that you approach and solve problems. Suddenly you find your tools (the language) more flexible and solutions become more natural. I think I can smell an article about effective use of the Boost and Loki libraries coming up... Wink | ;)
 
I can understand the job issues - we're facing similar problems here in Australia. Frown | :( But adding Boost knowledge to your repertoire can't hurt can it? Wink | ;) It would certainly make me more likely to hire someone for a C++ role...
GeneralRe: Thank YoumemberKevin McFarlane8 Jul '03 - 23:22 

MattyT wrote:
I found that being aware of new features and techniques really changed the way that you approach and solve problems. Suddenly you find your tools (the language) more flexible and solutions become more natural.
 
I certainly like to be aware of the latest ideas on a subject, even if I don't use them straight away (otherwise I wouldn't have read this article!). But new ideas aren't always easy to grasp. For example, STL seemed mysterious and complicated to me for some time.
 
There's also the fact that if you use something obscure you will baffle the majority of other developers who may have to maintain your code. Of course, at some point we've all got to move on. It's a question of striking a balance. I started using STL heavily after it had been around for some time and there were books on the subject. At that point I expected conscientious C++ developers to be using it, even if they weren't. And a lot of C++ developers still aren't!
 
MattyT wrote:
But adding Boost knowledge to your repertoire can't hurt can it?
 
The problem is that, looking at adverts for C++ jobs, things such as Boost are not requested. All of the complementary technolgies seem to have higher importance - ATL, COM, SQL Server, .NET.
 
MattyT wrote:
would certainly make me more likely to hire someone for a C++ role...
 
There are all sorts of things I could add to my repertoire but it's a question of priorities. I think it's better to focus on things that are in demand in the marketplace which, from the way things are going in the UK, might soon be something other than programming!
 

 

 

 
Kevin

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 7 Jul 2003
Article Copyright 2003 by Andrew Walker
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid