Boost has recently become available on the project on which I'm working, and I don't have much experience with it. The library has so many parts and features that it's hard to know where to get started in learning it - especially since I'll be trying to learn it while making production code (so it can't slow me down too much).

I would greatly appreciate it if someone could list around 3 to 5 features which are very useful in general, every-day programming and state why they're useful. Then I can start to learn those and use them - it'll at least give me a foothold in the library and a friendly place to start learning it/applying it :)

Thanks in advance!

  • I don't understand the phrase 'foothold in the library' in this context. What's wrong with books? There are a few on the subject from the usual vendors, having them on your teams bookshelf should be a must. – aquaherd Oct 4 '11 at 23:08
  • I read all the time for programming - I don't have the time to read a book or reference guide on boost back to front to know everything it has and whether or not its useful right this minute. I'd like to start using it here and there and slowly pick it up while working, and I wanted a few core examples of really useful boost components. For example, Effective C++ by Scott Meyers talks about shared_ptr non stop (and very little else) because it's so good. What else is unusually helpful in boost? – John Humphreys - w00te Oct 4 '11 at 23:14
  • I personally very much liked the BOOST_FOREACH macros, the observer/subscriber patterns, the regular expressions, the date/time parsers (facets), but I either encountered them by chance while modifying existing boost using code or as DeadMG outlined. I have only scratched the tip of the iceberg that is boost, but it felt like a natural continuation of the STL. – aquaherd Oct 4 '11 at 23:44

If you are using a pre TR1 compiler then smart pointers



If your compiler already has smart pointers use them.
The reason is obvious C++ without smart pointers is basically not C++

The boost ptr_contaier libraries.

All the STL containers re-implemented specifically to hold pointers. Not only do the containers take ownership of the pointers so that when the container is destroyed it automatically destroys all the pointers. BUT it also provides accesses to elements as normal object references (not pointers) this makes it easy to use the objects in standard algorithms without wrapper functors.

The boost lambda libraries. (see comment below)

The STL functors and binders are OK for simple things. But boost::lambda took it the next step and makes things a lot simpler when using the standard algorithms.

boost::any and boost::variant

When you need to hold objects without wanting to know their exact type.

multi Index Containers

Containers that allow multiple different ways to access the elements.
Gone are the days when you have a vector of objects and a separate map for quick searching vector. This cuts down on the boilerplate you need to write to maintain the two containers when inserting/deleting elements into the containers.


Probably the least useful in real life but a lot of fun to play with is boost::lexical_cast. It converts any object to/from a string (as long as that type has the appropriate << and >> operators defined). Very useful for dumping error messages when de-bugging.

  • 1
    Boost.Phoenix has officially replaced Boost.Lambda, which is now considered deprecated. Please recommend the former rather than the latter for new code. :-] – ildjarn Oct 5 '11 at 0:59

Boost isn't a framework, nor a library. It is a quality-controlled, peer-reviewed library collection. You don't learn Boost. The libraries are individual- when you need something, you check to see if it's in Boost, if it is, then you learn that library. That's it. You can't get a grasp on boost::optional from getting a grasp on boost::variant.

  • 4
    You could say that boost is a quality label and a distribution set. – Klaim Oct 4 '11 at 22:36

Boost is a collections of libraries. Next time you do a code kata, pick a library in Boost that you think may help you and use it. The documentation is very good and you should not no problems picking up simple usages. More complex ones will come when you try to do more clever things.

Example: a thread safe singleton with boost::thread call_once.

Example: read a configuration file of key:value using tokenizer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.