Search code examples
c++boost

Should we prefer Boost or standard lib?


I'm reading Boost array documentation and I see this line :

If you are using C++11, you should consider using std::array instead of boost::array

I was under the impression that Boost, for its major libs, was always preferable to standard lib because :

  • boost will never perform worse than the standard lib
  • boost may provide more features
  • boost is at last of equal quality than standard lib (people writing the C++ standard are active boost developpers/supervisors)
  • major boost features end up in the standard lib a few years later

So am I right to prefer boost over stdlib ?

If not / more complicated, which of my assumptions are to be corrected ?


Solution

  • I think you should use standard lib when available because... it's standard and comes with the compiler. Besides, if you use boost you need an annoying external dependency.

    So, my advice is: use std when possible. If you're writing portable code, that must also be compiled with old compilers, you can consider to use your own namespace (e.g.: cxx0x) that embeds std or boost namespace according to the compiler you're using (this is called namespace alias):

    #ifdef COMPILER_HAS_CXX0X
        #include <memory>
        namespace cxx0x = std;
    #else
        #include <boost/shared_ptr.hpp>
        namespace cxx0x = boost;
    #endif
    
    ...
    
    cxx0x::shared_ptr<MyClass> = ...