]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) --> | |
7 | <head> | |
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: Handling Placeholders</title> | |
11 | <link rel="stylesheet" href="../style.css" type="text/css" /> | |
12 | </head> | |
13 | <body class="docframe"> | |
14 | <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./higher-order.html" class="navigation-link">Prev</a> <a href="./the-lambda-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./higher-order.html" class="navigation-link">Back</a> <a href="./more-lambda-capabilities.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial-metafunctions.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="./handling-placeholders.html" class="navigation-link">Handling Placeholders</a></td> | |
16 | </tr></table><div class="header-separator"></div> | |
17 | <div class="section" id="handling-placeholders"> | |
18 | <h1><a class="toc-backref" href="./tutorial-metafunctions.html#id48" name="handling-placeholders">Handling Placeholders</a></h1> | |
19 | <p>Our implementation of <tt class="literal"><span class="pre">twice</span></tt> already works with metafunction | |
20 | classes. Ideally, we would | |
21 | like it to work with placeholder expressions too, much the same as | |
22 | <tt class="literal"><span class="pre">mpl::transform</span></tt> allows us to pass either form. For example, we | |
23 | would like to be able to write:</p> | |
24 | <pre class="literal-block"> | |
25 | template <class X> | |
26 | struct two_pointers | |
27 | : twice<<strong>boost::add_pointer<_1></strong>, X> | |
28 | {}; | |
29 | </pre> | |
30 | <!-- @ example.append('typedef two_pointers<int>::type intstar2;') | |
31 | compile('all', pop = 1, expect_error = True) --> | |
32 | <p>But when we look at the implementation of <tt class="literal"><span class="pre">boost::add_pointer</span></tt>, | |
33 | it becomes clear that the current definition of <tt class="literal"><span class="pre">twice</span></tt> can't | |
34 | work that way.</p> | |
35 | <pre class="literal-block"> | |
36 | template <class T> | |
37 | struct add_pointer | |
38 | { | |
39 | typedef T* type; | |
40 | }; | |
41 | </pre> | |
42 | <!-- @ compile() --> | |
43 | <p>To be invokable by <tt class="literal"><span class="pre">twice</span></tt>, <tt class="literal"><span class="pre">boost::add_pointer<_1></span></tt> would have | |
44 | to be a metafunction class, along the lines of <tt class="literal"><span class="pre">add_pointer_f</span></tt>. | |
45 | Instead, it's just a nullary metafunction returning the almost | |
46 | senseless type <tt class="literal"><span class="pre">_1*</span></tt>. Any attempt to use <tt class="literal"><span class="pre">two_pointers</span></tt> will | |
47 | fail when <tt class="literal"><span class="pre">apply1</span></tt> reaches for a nested <tt class="literal"><span class="pre">::apply</span></tt> | |
48 | metafunction in <tt class="literal"><span class="pre">boost::add_pointer<_1></span></tt> and finds that it | |
49 | doesn't exist.</p> | |
50 | <p>We've determined that we don't get the behavior we want | |
51 | automatically, so what next? Since <tt class="literal"><span class="pre">mpl::transform</span></tt> can do this | |
52 | sort of thing, there ought to be a way for us to do it too — and | |
53 | so there is.</p> | |
54 | <ul class="toc simple" id="outline"> | |
55 | <li><a class="reference" href="./the-lambda-metafunction.html" id="id49" name="id49">The <tt class="literal"><span class="pre">lambda</span></tt> Metafunction</a></li> | |
56 | <li><a class="reference" href="./the-apply-metafunction.html" id="id50" name="id50">The <tt class="literal"><span class="pre">apply</span></tt> Metafunction</a></li> | |
57 | </ul> | |
58 | </div> | |
59 | ||
60 | <div class="footer-separator"></div> | |
61 | <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./higher-order.html" class="navigation-link">Prev</a> <a href="./the-lambda-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./higher-order.html" class="navigation-link">Back</a> <a href="./more-lambda-capabilities.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial-metafunctions.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> | |
62 | </tr></table></body> | |
63 | </html> |