Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Obtaining the same types and reducing symbol length
PrevUpHomeNext

The flexible option specification mechanism used by Boost.Intrusive for hooks and containers has also a couple of downsides:

  • If a user specifies the same options in different order or specifies some options and lefts the rest as defaults the type of the created container/hook will be different. Sometimes this is annoying, because two programmers specifying the same options might end with incompatible types. For example, the following two lists, although they're using the same options, have not the same type:

#include <boost/intrusive/list.hpp>

using namespace boost::intrusive;

//Explicitly specify constant-time size and size type
typedef list<T, constant_time_size<true>, size_type<std::size_t> List1;

//Implicitly specify constant-time size and size type
typedef list<T> List2;
  • Option specifiers lead to long template symbols for classes and functions. Option specifiers themselves are verbose and without variadic templates, several default template parameters are assigned for non-specified options. Object and debugging information files can grow and compilation times might suffer a bit if long names are produced.

To solve these issues Boost.Intrusive offers some helper metafunctions that that reduce symbol lengths and create the same type if the same options (either explicitly or implicitly) are used. This also improves compilation times. All containers and hooks have their respective make_xxx versions. Previous shown example can be rewritten like this to obtain the same list type:

#include <boost/intrusive/list.hpp>

 using namespace boost::intrusive;

 #include <boost/intrusive/list.hpp>

 using namespace boost::intrusive;

 //Explicitly specify constant-time size and size type
 typedef make_list<T, constant_time_size<true>, size_type<std::size_t>::type List1;

 //Implicitly specify constant-time size and size type
 typedef make_list<T>::type List2;

Produced symbol lengths and compilation times are usually shorter and object/debug files are smaller. If you are a programmer concerned with file sizes and compilation times, this option is your choice.


PrevUpHomeNext