Boost.Flyweight Tutorial Annex: MPL lambda expressions

This short introduction to lambda expressions is meant for readers unfamiliar
with the Boost MPL Library who
want to rapidly acquire a working knowledge of the basic concepts for the purposes
of using them in Boost.Flyweight. Please refer to the Boost.MPL documentation
for further information beyond these introductory notes.

The specifiers defined by Boost.Flyweight rely heavily on the
Lambda
Expression concept defined by the
Boost MPL Library. A lambda
expression can be thought of as a compile-time "type function", an entity (a
concrete type, actually) that can be invoked with a list of types and returns
some associated type in its turn. Consider for instance an arbitrary class
template:

template<typenameT,typenameQ>classfoo{...};

and suppose we want to have a lambda expression that, when invoked
with some generic types Arg1 and Arg2,
returns foo<Arg1,Arg2>. Such a lambda expression
can be implemented in two ways

Note that, in this case, foo_specifier is a concrete type, much
as int or std::set<std::string> are; yet,
MPL internal mechanisms are able to detect that this type has been gotten
from instantiating a class template with placeholders boost::mpl::_1
and boost::mpl::_2 and take these placeholders as slots to
be substituted for actual types (the first and second type supplied,
respectively) when foo_specifier is
invoked. So, an instantiation of foo can be used
to refer back to the foo class template itself! The net
effect is the same as with metafunctions, but placeholder expressions spare
us the need to write boilerplate metafunction classes
--and the kind of metaprogramming magic they depend on has an undeniable
beauty to it.

So far the examples shown just forward the arguments Arg1 and
Arg2 directly to a class template without further elaboration,
but there is nothing preventing us from doing some argument manipulation,
like, for instance, switching their places: