views:

1315

answers:

12

I've been browsing revision 1.38.0 of the Boost libraries, in an attempt to decide if there are enough jewels there to justify negotiating my company's external software approval process. In the course of writing test programs and reading the documents, I've reached a couple conclusions

  • of course, not everything in Boost will ever be of use in my engineering group
  • more importantly, some of these libraries seem more polished than others

In fact, some libraries seem a bit toy-like to me.

There are a number of fairly accessible libraries that I can see putting to use after only a short period of investigation, such as boost::variant (I really like the visitor component and the fact that the compiler barfs if a visitor lacks an operator for one of the variant types). I'd use *boost::shared_ptr* except for the fact that our group already has a set of smart pointer types.

So based on the broad experience of Stack Overflow users, which Boost libraries

  • have high quality?
  • are more than toys?
  • are there any which have a high entry barrier but which are well worth learning?

Note that this is a somewhat different question than that posed in Boost considered harmful?

P.S. - Has one of the answers (from litb) been deleted? I can't see it here, and only an excerpt on my user page...

+4  A: 

Boost::lambda is somewhat helpful if you use STL. It enables you to create predicates in place, like this:

for_each(a.begin(), a.end(), std::cout << _1 << ' ');

This code outputs all elements from container separated by spaces.

Pavel Dogurevich
like this? are you saying that the inclusion of boost would support that: for_each(a.begin(), a.end(), std::cout << _1 << ' '); ?
Boost lambda allows exactly that.
Richard
Boost::Lambda is too annoying to use for anything much more complicated than that though, at least for me.
Head Geek
+4  A: 

Many of the additions to the C++0x standard library were first created as part of the Boost libraries.

They are not perfect (is any software) but the engineering process used is pretty robust (far more than most free software). If you do need help, you will find plenty on the mailing list.

Richard
+4  A: 

I often use boost::filesystem. It does all necessary for simple file management

thrantir
+4  A: 

Boost interprocess is definitely worth it if you are doing things w/ shared memory & the like.

Jason S
+4  A: 

I'd say the valuable libraries are:

  • Metaprogramming (MPL, enable_if, type/function_traits)
  • Preprocessor - if you need it, it may come handy
  • variant, optional - as you already noted
  • Math - quaternions, extra math functions (although they might not be useful to you)
  • lambda: although the syntax is hairy, it's pretty addictive
  • operators/iterators: they are really handy when constructing your own types

Maybe Python (never tried, but some eg. KDE programs use it)

jpalecek
+4  A: 

I personally think you should take a look at libraries that hides platform specific stuff like threading, ipc, memory mapped files, file system, asynchronous IO etc.

These can save you lots of time and trouble in multi platform projects and tends to be focused on exposing functionality rather than exercises in fancy C++ features.

Laserallan
As a general comment, I think you are spot on. But like smart pointers, my group has a mature framework which includes hardware and filesystem abstraction, cross-network data portability, etc. Hence the interest in higher-level concepts.
Don Wakefield
+9  A: 

I found boost to be an uncontested must-have when designing cross-platform (e.g. *nix and win32) multi-threaded apps (boost::thread, boost::interprocess.) This alone has been justification enough in at least one instance for adopting boost as part of my employers' projects.

The rest (containers, generic programming and meta-programming, memory) followed as freebies.

vladr
+3  A: 

If you need to parse text files that are more complex that simple key/value pairs, I highly recommend Boost::spirit. It has a high learning curve, but once you figure it out, it lets you easily embed EBNF grammers right in the code. Its much more robust than writing your own parser. I also find myself creating file formats that are designed more for the ease of the writer of the file than the writer of the parsing code.

KeithB
+1  A: 

Not exactly the same question but should help answer yours : http://stackoverflow.com/questions/325906/most-used-parts-of-boost/325915#325915

Klaim
Favorited. Thanks!
Don Wakefield
+2  A: 

I have found boost.thread and boost.asio indispensable for writing client/server applications. The smart pointer library makes it easy to write code that uses exception handling without leaking memory.

On a side note, a set of PDF files documenting some of the more common boost libraries has been released recently. You can download them from SourceForge.

Ferruccio
I downloaded it, and skimming some of the libs I've already written toy programs for, it seems these are just PDFs of the documentation that ships with the Boost libraries? Is this not so for some of them?
Don Wakefield
Nope, that's all it is, so far as I know.
Head Geek
+10  A: 

I use quite frequently (and it makes my life simpler):

  • smart pointers (shared_ptr, scoped_ptr, weak_ptr, interprocess unique_ptr):

    • scoped_ptr for basic RAII (without shared ownership and ownership transfer), at no cost.
    • shared_ptr for more complex operations - when shared ownership is needed. However there is some cost.
    • unique_ptr - there is active work at boost on unifying various approaches (present at Boost) to unique_ptr with move emulation.
    • They are really simple to use (header only), easy to learn and very well tested (well, except maybe the unique_ptr)
  • Boost Thread - actively developed (threads are now movable) library for working with threads. Hides the complexity of thread implementation on a given platform.

  • Boost MPL and Fusion - these are more difficult to explain. For long time I didn't use compile time power, but after some reading and learning it turned out that some of my code can be nicely simplified. Still, beware of the compilation time...

  • Boost Asio

    • Contrary to the first impression (at least some time ago) it is not only the networking library. It provides asynchronous I/O model that can be used for virtually anything.
  • Boost Format (powerful output formatting, but very heavy)

  • Boost Spirit2x (Karma and Qi used both for parsing and generating output based on a given grammar). Really powerful, can create a parser without resorting to external tools. Yet the compilation time might be a problem. Also version 2x is being actively developed and the documentation is rather scarce (the spirit-devel mailing list is very helpful though)

  • Boost Bind, Function and Lambda to make your life easier and Boost Phoenix - just to experiment

  • lexical_cast (something similar might be born soon as boost::string)

  • Regex/Xpressive - regular expressions

  • Type traits and concept checks - once again to make your life easier

  • Math:

    • various random number generators
    • various statistical distributions
    • ublas - for using LAPACK/BLAS bindings in C++ like way
    • some mathematical functions, normally not available in C++
    • some tools for controlling the conversions between numreric types
    • interval arithmetics
  • Boost Iterator (specialized adaptors for iterators and facade for creating your own)

  • Boost Unit Testing framework

And still there are some parts that I'd barely touched in Boost. Probably I also forgot to mention few obvious ones.

Remember to use right tools (hammers) for right problems (nails). Remember to keep the solutions simple. Remember about the cost of received functionality (for example shared_ptr or boost::format runtime overhead or MPL/Fusion/Spirit/Phoenix compile time costs and executable sizes). But experiment and learn - it's where the fun is.

And when it comes to convincing the management to use the new libraries - you don't have to start with all the libraries. Start with the simple things (probably the ones that have a long and stable Boost history, broad compiler support, are planned for inclusion in TR2/C++1x, etc) and simple examples that show the benefits.

Anonymous
+1  A: 

I've read the other answers and I need to add Boost.Graph (BGL) and its friend Boost.Property_map. These two literally changed my everyday work.

It is extremely well designed, but most people are put off at first because there is quite a high price to pay before actually understanding the purpose of all concepts. But once you get a grip on this library, it becomes hard to go without !

Benoît