Front Page / Tutorial: Metafunctions and Higher-Order Metaprogramming / Details |
By now you should have a fairly complete view of the fundamental concepts and language of both template metaprogramming in general and of the Boost Metaprogramming Library. This section reviews the highlights.
Most of this book's examples will use the Boost Metaprogramming Library. Like the Boost type traits headers, MPL headers follow a simple convention:
#include <boost/mpl/component-name.hpp>
If the component's name ends in an underscore, however, the corresponding MPL header name does not include the trailing underscore. For example, mpl::bool_ can be found in <boost/mpl/bool.hpp>. Where the library deviates from this convention, we'll be sure to point it out to you.
A kind of lambda expression that, through the use of placeholders, enables in-place partial metafunction application and metafunction composition. As you will see throughout this book, these features give us the truly amazing ability to build up almost any kind of complex type computation from more primitive metafunctions, right at its point of use:
// find the position of a type x in some_sequence such that: // x is convertible to 'int' // && x is not 'char' // && x is not a floating type typedef mpl::find_if< some_sequence , mpl::and_< boost::is_convertible<_1,int> , mpl::not_<boost::is_same<_1,char> > , mpl::not_<boost::is_float<_1> > > >::type iter;
Placeholder expressions make good on the promise of algorithm reuse without forcing us to write new metafunction classes. The corresponding capability is often sorely missed in the runtime world of the STL, since it is often much easier to write a loop by hand than it is to use standard algorithms, despite their correctness and efficiency advantages.