1 <?xml version=
"1.0" encoding=
"utf-8" ?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
4 <!-- Copyright Aleksey Gurtovoy 2006. Distributed under the Boost -->
5 <!-- Software License, Version 1.0. (See accompanying -->
6 <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
8 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
9 <meta name=
"generator" content=
"Docutils 0.3.6: http://docutils.sourceforge.net/" />
10 <title>THE BOOST MPL LIBRARY: Lambda and Non-Metafunction Templates
</title>
11 <link rel=
"stylesheet" href=
"../style.css" type=
"text/css" />
13 <body class=
"docframe">
14 <table class=
"header"><tr class=
"header"><td class=
"header-group navigation-bar"><span class=
"navigation-group"><a href=
"./placeholder-expression.html" class=
"navigation-link">Prev
</a> <a href=
"./the-importance-of-being.html" class=
"navigation-link">Next
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./placeholder-expression.html" class=
"navigation-link">Back
</a> <a href=
"./the-importance-of-being.html" class=
"navigation-link">Along
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./lambda-details.html" class=
"navigation-link">Up
</a> <a href=
"../index.html" class=
"navigation-link">Home
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./tutorial_toc.html" class=
"navigation-link">Full TOC
</a></span></td>
15 <td class=
"header-group page-location"><a href=
"../index.html" class=
"navigation-link">Front Page
</a> /
<a href=
"./tutorial-metafunctions.html" class=
"navigation-link">Tutorial: Metafunctions and Higher-Order Metaprogramming
</a> /
<a href=
"./lambda-details.html" class=
"navigation-link">Lambda Details
</a> /
<a href=
"./lambda-and-non.html" class=
"navigation-link">Lambda and Non-Metafunction Templates
</a></td>
16 </tr></table><div class=
"header-separator"></div>
17 <div class=
"section" id=
"lambda-and-non">
18 <h1><a class=
"toc-backref" href=
"./lambda-details.html#id57" name=
"lambda-and-non">Lambda and Non-Metafunction Templates
</a></h1>
19 <p>There is just one detail of placeholder expressions that we haven't
20 discussed yet. MPL uses a special rule to make it easier to
21 integrate ordinary templates into metaprograms: After all of the
22 placeholders have been replaced with actual
23 arguments, if the resulting template specialization
<em>X
</em> doesn't
24 have a nested
<tt class=
"literal"><span class=
"pre">::type
</span></tt>, the result is just
25 <em>X
</em> itself.
</p>
26 <p>For example,
<tt class=
"literal"><span class=
"pre">mpl::apply
<std::vector
<_
>,
</span> <span class=
"pre">T
></span></tt> is always just
27 <tt class=
"literal"><span class=
"pre">std::vector
<T
></span></tt>. If it weren't for this behavior, we would
28 have to build trivial metafunctions to create ordinary template
29 specializations in lambda expressions:
</p>
30 <pre class=
"literal-block">
31 // trivial std::vector generator
32 template
<class U
>
33 struct make_vector { typedef std::vector
<U
> type; };
35 typedef mpl::apply
<<strong>make_vector
<_
></strong>, T
>::type vector_of_t;
37 <p>Instead, we can simply write:
</p>
38 <pre class=
"literal-block">
39 typedef mpl::apply
<<strong>std::vector
<_
></strong>, T
>::type vector_of_t;
41 <!-- @ # ensure indentation works. The ReST parser will push the 2nd line left
43 stack[-1].prepend('#include <vector>\ntypedef int T;')
47 <div class=
"footer-separator"></div>
48 <table class=
"footer"><tr class=
"footer"><td class=
"header-group navigation-bar"><span class=
"navigation-group"><a href=
"./placeholder-expression.html" class=
"navigation-link">Prev
</a> <a href=
"./the-importance-of-being.html" class=
"navigation-link">Next
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./placeholder-expression.html" class=
"navigation-link">Back
</a> <a href=
"./the-importance-of-being.html" class=
"navigation-link">Along
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./lambda-details.html" class=
"navigation-link">Up
</a> <a href=
"../index.html" class=
"navigation-link">Home
</a></span><span class=
"navigation-group-separator"> |
</span><span class=
"navigation-group"><a href=
"./tutorial_toc.html" class=
"navigation-link">Full TOC
</a></span></td>