Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/mpl/doc/tutorial/placeholder-expression.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 5.1 KB
Line 
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<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
7<title>THE BOOST MPL LIBRARY: Placeholder Expression Definition</title>
8<link rel="stylesheet" href="../style.css" type="text/css" />
9</head>
10<body class="docframe">
11<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Prev</a>&nbsp;<a href="./lambda-and-non.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Back</a>&nbsp;<a href="./lambda-and-non.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
12<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="./placeholder-expression.html" class="navigation-link">Placeholder Expression Definition</a></td>
13</tr></table><div class="header-separator"></div>
14<div class="section" id="placeholder-expression">
15<h1><a class="toc-backref" href="./lambda-details.html#id56" name="placeholder-expression">Placeholder Expression Definition</a></h1>
16<p>Now that you know just what <em>placeholder</em> means, we can define
17<em>placeholder expression</em>:</p>
18<div class="admonition-definition admonition">
19<p class="admonition-title first">Definition</p>
20<p>A placeholder expression is either:</p>
21<blockquote>
22<blockquote>
23<ul class="simple">
24<li>a placeholder</li>
25</ul>
26</blockquote>
27<p><em>or</em></p>
28<blockquote>
29<ul class="simple">
30<li>a template specialization with at least one argument that
31is a placeholder expression.</li>
32</ul>
33</blockquote>
34</blockquote>
35</div>
36<p>In other words, a placeholder expression always involves a
37placeholder.</p>
38<!-- DWA: I'm still not sure we shouldn't be at least mentioning the
39pitfall, but for now it's commented out.
40
41Lambda and Nullary Metafunctions
42- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43
44The definition of *placeholder expression* above has an interesting
45implication: an ordinary nullary metafunction is never a placeholder
46expression.  In other words, even though ``add_pointer<int>`` is a
47nullary metafunction, it won't be invoked in the expression below;
48the assertion will always fail:
49
50.. parsed-literal::
51
52   BOOST_STATIC_ASSERT((
53       mpl::apply<
54           boost::is_same<**boost::add_pointer<int>**,_1>
55         , int\*
56       >::type::value
57   ));
58
59In order to allow a nullary metafunction to be used as a lambda
60expression, MPL provides this definition of ``arg``:
61
62.. parsed-literal::
63
64    // primary template definition (not a specialization)
65    template <class F>
66    struct arg
67    {
68        template <class A1 = void\_, class A2 = void\_, ... class *Am* = void\_>
69        struct apply : F
70        {
71        };
72    };
73
74When applied to a lambda expression's actual arguments, ``arg<F>``
75ignores them and simply returns ``F::type``.  In other words, if
76``F`` is a nullary metafunction, ``arg<F>`` is a metafunction class
77that invokes ``F`` and returns the result.  So we can transform
78add_pointer<int> into a placeholder and get the desired result
79with:
80
81.. parsed-literal::
82
83   BOOST_STATIC_ASSERT((
84       mpl::apply<
85           boost::is_same<
86                **mpl::arg<boost::add_pointer<int> >**
87              , _1
88           >
89         , int\*
90       >::type::value
91   )); -->
92</div>
93
94<div class="footer-separator"></div>
95<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Prev</a>&nbsp;<a href="./lambda-and-non.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Back</a>&nbsp;<a href="./lambda-and-non.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
96</tr></table></body>
97</html>
Note: See TracBrowser for help on using the repository browser.