Back to Arangodb

Lambda and Non-Metafunction Templates

3rdParty/boost/1.78.0/libs/mpl/doc/tutorial/lambda-and-non.html

3.12.9.11.6 KB
Original Source

| Prev Next | Back Along | Up Home | Full TOC | Front Page / Tutorial: Metafunctions and Higher-Order Metaprogramming / Lambda Details / Lambda and Non-Metafunction Templates |

Lambda and Non-Metafunction Templates

There is just one detail of placeholder expressions that we haven't discussed yet. MPL uses a special rule to make it easier to integrate ordinary templates into metaprograms: After all of the placeholders have been replaced with actual arguments, if the resulting template specialization X doesn't have a nested ::type, the result is just X itself.

For example, mpl::apply<std::vector<_>, T> is always just std::vector<T>. If it weren't for this behavior, we would have to build trivial metafunctions to create ordinary template specializations in lambda expressions:

// trivial std::vector generator
template<class U> 
struct make_vector { typedef std::vector<U> type; };

typedef mpl::apply< **make\_vector\<\_\>** , T>::type vector_of_t;

Instead, we can simply write:

typedef mpl::apply< **std::vector\<\_\>** , T>::type vector_of_t;

| Prev Next | Back Along | Up Home | Full TOC |