new MPL docs
[SVN r26212]
This commit is contained in:
1 parent
d5e241cd2a
commit
54a5f8f55f
306 files changed
+27492
-7633
No files matched your search
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Acknowledgements</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./resources.html" class="navigation-link">Prev</a> Next</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./resources.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./acknowledgements.html" class="navigation-link">Acknowledgements</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="acknowledgements">
|
||||
<h1><a class="toc-backref" href="../index.html#id78" name="acknowledgements">Acknowledgements</a></h1>
|
||||
<p>Many, many people in one or another way contributed to the library development. The
|
||||
list below is known to be incomplete and needs updating! We sincerely promise to
|
||||
fix it in the near feature.</p>
|
||||
<p>For bug reports, patches, suggestions and insightful discussions, our thanks go to:</p>
|
||||
<ul class="simple">
|
||||
<li>John Bandela</li>
|
||||
<li>Fernando Cacciola</li>
|
||||
<li>Peter Dimov</li>
|
||||
<li>Eric Friedman</li>
|
||||
<li>Arnaldur Gylfason</li>
|
||||
<li>David B. Held</li>
|
||||
<li>Vesa Karvonen</li>
|
||||
<li>Mat Marcus</li>
|
||||
<li>Hamish Mackenzie</li>
|
||||
<li>Paul Mensonides</li>
|
||||
<li>Emily Winch</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./resources.html" class="navigation-link">Prev</a> Next</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./resources.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: apply/lambda Semantics</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./changes-in-boost-1-32-0.html" class="navigation-link">Prev</a> <a href="./iterator-protocol.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./iterator-protocol.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./apply-lambda-semantics.html" class="navigation-link">apply/lambda Semantics</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="apply-lambda-semantics">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id64" name="apply-lambda-semantics"><tt class="literal"><span class="pre">apply</span></tt>/<tt class="literal"><span class="pre">lambda</span></tt> Semantics</a></h1>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">Nullary metafunction classes are now consistent with all other
|
||||
metafunction classes, rather than being identical to nullary
|
||||
metafunctions:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="37%" />
|
||||
<col width="22%" />
|
||||
<col width="40%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th><p class="first last">Nullary...</p>
|
||||
</th>
|
||||
<th><p class="first last">Before</p>
|
||||
</th>
|
||||
<th><p class="first last">Now</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last">Metafunction</p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">f::type</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">f::type</span></tt></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td><p class="first last">Metafunction class</p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">c::type</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">c::apply<>::type</span></tt> or
|
||||
<tt class="literal"><span class="pre">c::apply::type</span></tt> <a class="footnote-reference" href="#id21" id="id20" name="id20">[7]</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>This fixes a flaw in the metafunction class/metafunction algebra
|
||||
that long has been a major source of other inconsistencies throughout
|
||||
the library.</p>
|
||||
</li>
|
||||
<li><p class="first">The <tt class="literal"><span class="pre">apply</span></tt> metafunction now automatically invokes <tt class="literal"><span class="pre">lambda</span></tt>
|
||||
on its first argument. For example, the following is well-formed now:</p>
|
||||
<pre class="literal-block">
|
||||
typedef apply< plus<_1,_1>, int_<2> >::type four;
|
||||
</pre>
|
||||
<p><tt class="literal"><span class="pre">apply_wrap</span></tt><em>n</em> auxiliary metafunctions are available for rare cases
|
||||
when it's crucial to eliminate the small overhead associated with lambda
|
||||
expressions while still avoiding various compiler bugs known to
|
||||
cause problems with
|
||||
the obvious <tt class="literal"><span class="pre">f::template</span> <span class="pre">apply<...>::type</span></tt> syntax.</p>
|
||||
</li>
|
||||
<li><p class="first">The <tt class="literal"><span class="pre">lambda</span></tt> implementation for broken compilers has been
|
||||
reworked to emulate the semantics of the full-fledged version
|
||||
as closely as possible; consequently, any code out there that
|
||||
was taking advantage of the semantic quirks of less complete
|
||||
emulation in the previous release may stop working with the new
|
||||
one.</p>
|
||||
</li>
|
||||
</ol>
|
||||
<p>To get a detailed picture of the new apply/lambda semantics, please
|
||||
see the test case at
|
||||
<a class="reference" href="http://cvs.sourceforge.net/viewcvs.py/boost/boost/libs/mpl/test/apply.cpp?view=markup" target="_top">http://cvs.sourceforge.net/viewcvs.py/boost/boost/libs/mpl/test/apply.cpp?view=markup</a>
|
||||
and the corresponding sections of the MPL <a class="reference" href="./reference-manual.html">reference manual</a>.</p>
|
||||
<table class="footnote" frame="void" id="id21" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id20" name="id21">[7]</a></td><td>The second form is available only on fully conforming compilers.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./changes-in-boost-1-32-0.html" class="navigation-link">Prev</a> <a href="./iterator-protocol.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./iterator-protocol.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Broken Integral Constant Expressions</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./portability.html" class="navigation-link">Prev</a> <a href="./incomplete-support-for.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./incomplete-support-for.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./portability.html" class="navigation-link">Portability</a> / <a href="./broken-integral-constant.html" class="navigation-link">Broken Integral Constant Expressions</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="broken-integral-constant">
|
||||
<h1><a class="toc-backref" href="./portability.html#id74" name="broken-integral-constant">Broken Integral Constant Expressions</a></h1>
|
||||
<p>This is probably the most surprising of the portability issues
|
||||
we're going to discuss, not least because for many C++ programmers, their everyday
|
||||
experience seems to indicate no problems in this area whatsoever. After all,
|
||||
integer compile-time computations along the lines of:</p>
|
||||
<pre class="literal-block">
|
||||
enum flags {
|
||||
flag1 = (1 << 0)
|
||||
, flag2 = (1 << 1)
|
||||
, flag3 = (1 << 2)
|
||||
...
|
||||
};
|
||||
</pre>
|
||||
<p>are <em>very</em> commonplace in C++, and there is hardly a compiler out
|
||||
there that cannot handle this correctly. While arithmetic by
|
||||
itself is indeed rarely problematic, when you are trying to mix it
|
||||
with templates on certain deficient compilers, all kinds of new
|
||||
issues arise. Fortunately, as with the rest of the portability
|
||||
issues we're discussing here, the problem fades into past as new
|
||||
compiler versions are released. The majority of most recent
|
||||
compilers of many vendors are already free from these issues.</p>
|
||||
<div class="section" id="the-problem">
|
||||
<h2><a name="the-problem">The Problem</a></h2>
|
||||
<p>The problem is in fact multi-faceted; there are a number of
|
||||
different subissues. Some are present in one set of compilers,
|
||||
some are in another, and it's not uncommon for a code that works
|
||||
for one compiler to break another one and vice-versa. If this
|
||||
sounds like a maintenance nightmare to you, it is! If you are
|
||||
interested in the specific list of issues, please refer to John
|
||||
Maddock's excellent "<a class="reference" href="../../../../more/int_const_guidelines.htm" target="_top">Coding Guidelines for Integral Constant
|
||||
Expressions</a>" summary. For the purpose of our discission here, it
|
||||
is sufficient to say that if your code has to work on one of the
|
||||
compilers listed as problematic in this area, you can safely assume
|
||||
that if you decide to fight them on a case-by-case basis, chances
|
||||
are that you won't be able to maintain your sanity for very long.</p>
|
||||
</div>
|
||||
<div class="section" id="the-symptoms">
|
||||
<h2><a name="the-symptoms">The Symptoms</a></h2>
|
||||
<p>On the positive side, when you have an issue with integral
|
||||
arithmetic, the diagnostics are almost always straightforward:
|
||||
usually the error message refers you to the exact place in the code
|
||||
that is causing problems, and the essence of issue is obvious from
|
||||
the error's text, or it becomes obvious once you've encountered the
|
||||
same error a couple of times. For instance, if we throw this
|
||||
well-formed fragment at MSVC 7.1 (otherwise an excellent compiler!)</p>
|
||||
<pre class="literal-block">
|
||||
void value();
|
||||
|
||||
// compares two Integral Constants
|
||||
template< typename N1, typename N2 > struct less
|
||||
: bool_< (N1::value < N2::value) > // line #8
|
||||
{
|
||||
};
|
||||
</pre>
|
||||
<p>we get:</p>
|
||||
<pre class="literal-block">
|
||||
portability.cpp(8) : warning C4346: 'N2::value' : dependent name is not a type
|
||||
prefix with 'typename' to indicate a type
|
||||
portability.cpp(10) : see reference to class template instantiation 'less<N1,N2>' being compiled
|
||||
portability.cpp(8) : error C2143: syntax error : missing ',' before ')'
|
||||
portability.cpp(9) : error C2143: syntax error : missing ';' before '{'
|
||||
portability.cpp(10) : error C2143: syntax error : missing ';' before '}'
|
||||
portability.cpp(10) : fatal error C1004: unexpected end of file found
|
||||
</pre>
|
||||
<p>The errors themselves are far from being ideal, but at least we are
|
||||
pointed at the correct line and even the correct part of the
|
||||
line. The above basically reads as "something's wrong between the
|
||||
parentheses", and that plus the "syntax error" part is usually
|
||||
enough of the clue.</p>
|
||||
</div>
|
||||
<div class="section" id="the-solution">
|
||||
<h2><a name="the-solution">The Solution</a></h2>
|
||||
<p>Despite the fact the problems are so numerous and multi-faceted and
|
||||
the workarounds are conflicting, the problems can be hidden
|
||||
reliably beneath a library abstraction layer. The underlaying idea
|
||||
is very simple: we can always wrap the constants in types and pass
|
||||
those around. Then all that is left is to implement algebraic
|
||||
metafunctions that operate on such wrappers, once, and we are home
|
||||
safe.</p>
|
||||
<p>If this sounds familiar to you, probably it's because you have
|
||||
already took a look at the MPL and know that the approach we just
|
||||
described is in fact <em>the</em> standard way of doing arithmetic in the
|
||||
library. Although it's motivated by more general observations,
|
||||
this fact comes very handy for the library users that care about
|
||||
portability of their numerically-heavy metaprograms. The MPL
|
||||
primitives are already there, and more importantly, they already
|
||||
implement the necessary workarounds, so your numeric code just
|
||||
works. In fact, if you stay within the library's type-wrapper
|
||||
idioms, these particular problems never "leak" out of its
|
||||
abstraction layer.</p>
|
||||
<p>On a final note, there is a price of avoiding built-in arithmetics
|
||||
altogether, namely decreased readability and, on some compilers,
|
||||
increased compile-time overhead. Still, in majority of cases, the
|
||||
benefits of type-based arithmetics overweight its small
|
||||
shortcomings.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./portability.html" class="navigation-link">Prev</a> <a href="./incomplete-support-for.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./incomplete-support-for.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Changelog & History</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./reference-manual.html" class="navigation-link">Prev</a> <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./reference-manual.html" class="navigation-link">Back</a> <a href="./technical-details.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="changelog-history">
|
||||
<h1><a class="toc-backref" href="../index.html#id62" name="changelog-history">Changelog & History</a></h1>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./changes-in-boost-1-32-0.html" id="id63" name="id63">Changes in Boost 1.32.0 Release</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./reference-manual.html" class="navigation-link">Prev</a> <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./reference-manual.html" class="navigation-link">Back</a> <a href="./technical-details.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Changes in Boost 1.32.0 Release</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./changelog-history.html" class="navigation-link">Prev</a> <a href="./apply-lambda-semantics.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changelog-history.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="changes-in-boost-1-32-0">
|
||||
<h1><a class="toc-backref" href="./changelog-history.html#id63" name="changes-in-boost-1-32-0">Changes in Boost 1.32.0 Release</a></h1>
|
||||
<p>The following summarizes major changes in the library interface and
|
||||
implementation from the previous release. Note that this is <em>not</em> a
|
||||
comprehensive list of all changes (yet).</p>
|
||||
<!-- DWA - "with the accent on backward compatibility" didn't have any
|
||||
obvious meaning to me. -->
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./apply-lambda-semantics.html" id="id64" name="id64"><tt class="literal"><span class="pre">apply</span></tt>/<tt class="literal"><span class="pre">lambda</span></tt> Semantics</a></li>
|
||||
<li><a class="reference" href="./iterator-protocol.html" id="id65" name="id65">Iterator Protocol</a></li>
|
||||
<li><a class="reference" href="./tag-dispatching-protocol.html" id="id66" name="id66">Tag Dispatching Protocol</a></li>
|
||||
<li><a class="reference" href="./numeric-metafunction.html" id="id67" name="id67">Numeric Metafunction Protocol/Infrastructure</a></li>
|
||||
<li><a class="reference" href="./renaming-cleanup.html" id="id68" name="id68">Renaming/Cleanup</a></li>
|
||||
<li><a class="reference" href="./miscellaneous.html" id="id69" name="id69">Miscellaneous</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./changelog-history.html" class="navigation-link">Prev</a> <a href="./apply-lambda-semantics.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changelog-history.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Dependencies</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./physical-structure.html" class="navigation-link">Prev</a> <a href="./portability.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./physical-structure.html" class="navigation-link">Back</a> <a href="./portability.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./dependencies.html" class="navigation-link">Dependencies</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="dependencies">
|
||||
<h1><a class="toc-backref" href="./technical-details.html#id72" name="dependencies">Dependencies</a></h1>
|
||||
<p>Besides <a class="reference" href="../../../config/index.html" target="_top">Boost.Config</a> headers, the MPL relies on three other header-only
|
||||
libraries:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../../../preprocessor/index.html" target="_top">Boost.Preprocessor</a></li>
|
||||
<li><a class="reference" href="../../../type_traits/index.html" target="_top">Boost.Type Traits</a></li>
|
||||
<li><a class="reference" href="../../../static_assert/index.html" target="_top">Boost.Static Assert</a></li>
|
||||
</ul>
|
||||
<p>These dependencies are essential and cannot be eliminated. The
|
||||
library's <em>tests and examples</em> may depend on some additional Boost
|
||||
libraries such as <a class="reference" href="../../../bind/index.html" target="_top">Boost.Bind</a>; unless you are interested in actually
|
||||
compiling these files, you can safely ignore those dependencies.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./physical-structure.html" class="navigation-link">Prev</a> <a href="./portability.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./physical-structure.html" class="navigation-link">Back</a> <a href="./portability.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Details</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-importance-of-being.html" class="navigation-link">Prev</a> <a href="./exercises.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Back</a> <a href="./exercises.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>
|
||||
<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="./details.html" class="navigation-link">Details</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="details">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id59" name="details">Details</a></h1>
|
||||
<p>By now you should have a fairly complete view of the fundamental
|
||||
concepts and language of both template metaprogramming in general
|
||||
and of the Boost Metaprogramming Library. This section
|
||||
reviews the highlights.</p>
|
||||
<dl>
|
||||
<dt>Metafunction forwarding.</dt>
|
||||
<dd>The technique of using public derivation to
|
||||
supply the nested <tt class="literal"><span class="pre">type</span></tt> of a metafunction by accessing the one
|
||||
provided by its base class.</dd>
|
||||
<dt>Metafunction class.</dt>
|
||||
<dd>The most basic way to formulate a compile-time
|
||||
function so that it can be treated as polymorphic metadata; that
|
||||
is, as a type. A metafunction class is a class with a nested
|
||||
metafunction called <tt class="literal"><span class="pre">apply</span></tt>.</dd>
|
||||
<dt>MPL.</dt>
|
||||
<dd><p class="first">Most of this book's examples will use the Boost
|
||||
Metaprogramming Library. Like the Boost type traits headers,
|
||||
MPL
|
||||
headers follow a simple convention:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/<em>component-name</em>.hpp>
|
||||
</pre>
|
||||
<p class="last">If the component's name ends in an underscore, however, the
|
||||
corresponding MPL header name does not include the trailing
|
||||
underscore. For example, <tt class="literal"><span class="pre">mpl::bool_</span></tt> can be found in
|
||||
<tt class="literal"><span class="pre"><boost/mpl/bool.hpp></span></tt>. Where the library deviates from this
|
||||
convention, we'll be sure to point it out to you.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<!-- @ignore() -->
|
||||
<dl>
|
||||
<dt>Higher-order function.</dt>
|
||||
<dd>A function that operates on or returns a function. Making
|
||||
metafunctions polymorphic with other metadata is a key
|
||||
ingredient in higher-order metaprogramming.</dd>
|
||||
<dt>Lambda expression.</dt>
|
||||
<dd>Simply put, a lambda expression is callable metadata. Without
|
||||
some form of callable metadata, higher-order metafunctions
|
||||
would be impossible. Lambda expressions have two basic forms:
|
||||
<em>metafunction classes</em> and <em>placeholder expressions</em>.</dd>
|
||||
<dt>Placeholder expression.</dt>
|
||||
<dd><p class="first">A kind of lambda expression that, through the use of
|
||||
placeholders, enables in-place <em>partial metafunction
|
||||
application</em> and <em>metafunction composition</em>. As you will see
|
||||
throughout this book, these features give us the truly amazing
|
||||
ability to build up almost any kind of complex type computation
|
||||
from more primitive metafunctions, right at its point of use:</p>
|
||||
<pre class="literal-block">
|
||||
// find the position of a type x in some_sequence such that:
|
||||
// x is convertible to 'int'
|
||||
// && x is not 'char'
|
||||
// && x is not a floating type
|
||||
typedef mpl::find_if<
|
||||
some_sequence
|
||||
, mpl::and_<
|
||||
boost::is_convertible<_1,int>
|
||||
, mpl::not_<boost::is_same<_1,char> >
|
||||
, mpl::not_<boost::is_float<_1> >
|
||||
>
|
||||
>::type iter;
|
||||
</pre>
|
||||
<p class="last">Placeholder expressions make good on the promise of algorithm reuse
|
||||
without forcing us to write new metafunction classes. The
|
||||
corresponding capability is often sorely missed in the runtime
|
||||
world of the STL, since it is often much easier to write a loop
|
||||
by hand than it is to use standard algorithms, despite their
|
||||
correctness and efficiency advantages.</p>
|
||||
</dd>
|
||||
</dl>
|
||||
<!-- @ example.prepend('''
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/find_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/is_float.hpp>
|
||||
typedef mpl::vector<char, double, short, long> some_sequence;
|
||||
''')
|
||||
compile() -->
|
||||
<dl>
|
||||
<dt>The <tt class="literal"><span class="pre">lambda</span></tt> metafunction.</dt>
|
||||
<dd>A metafunction that transforms a lambda expression into a
|
||||
corresponding metafunction class. For detailed information on
|
||||
<tt class="literal"><span class="pre">lambda</span></tt> and the lambda evaluation process,
|
||||
please see the <a class="reference" href="./reference-manual.html">the MPL reference manual</a>.</dd>
|
||||
<dt>The <tt class="literal"><span class="pre">apply</span></tt> metafunction.</dt>
|
||||
<dd>A metafunction that invokes its first argument, which must be a
|
||||
lambda expression, on its remaining arguments. In general, to
|
||||
invoke a lambda expression, you should always pass it to
|
||||
<tt class="literal"><span class="pre">mpl::apply</span></tt> along with the arguments you want to apply it
|
||||
to in lieu of using <tt class="literal"><span class="pre">lambda</span></tt> and invoking the result "manually."</dd>
|
||||
<dt>Lazy evaluation.</dt>
|
||||
<dd>A strategy of delaying evaluation until a result is
|
||||
required, thereby avoiding any unneccessary computation and any
|
||||
associated unneccessary errors. Metafunctions are only invoked
|
||||
when we access their nested <tt class="literal"><span class="pre">::type</span></tt>s, so we can supply all
|
||||
of their arguments without performing any computation and
|
||||
delay evaluation to the last possible moment.</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-importance-of-being.html" class="navigation-link">Prev</a> <a href="./exercises.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Back</a> <a href="./exercises.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Dimensional Analysis</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Prev</a> <a href="./representing-dimensions.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./higher-order.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="dimensional-analysis">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id41" name="dimensional-analysis">Dimensional Analysis</a></h1>
|
||||
<p>The first rule of doing physical calculations
|
||||
on paper is that the numbers being manipulated don't stand alone:
|
||||
most quantities have attached <em>dimensions</em>, to be ignored at our
|
||||
peril. As computations become more complex, keeping track of
|
||||
dimensions is what keeps us from inadvertently assigning a mass to
|
||||
what should be a length or adding acceleration to velocity — it
|
||||
establishes a type system for numbers.</p>
|
||||
<p>Manual checking of types is tedious, and as a result, it's also
|
||||
error-prone. When human beings become bored, their attention
|
||||
wanders and they tend to make mistakes. Doesn't type checking seem
|
||||
like the sort of job a computer might be good at, though? If we
|
||||
could establish a framework of C++ types for dimensions and
|
||||
quantities, we might be able to catch errors in formulae before
|
||||
they cause serious problems in the real world.</p>
|
||||
<p>Preventing quantities with different dimensions from interoperating
|
||||
isn't hard; we could simply represent dimensions as classes that
|
||||
only work with dimensions of the same type. What makes this
|
||||
problem interesting is that different dimensions <em>can</em> be combined,
|
||||
via multiplication or division, to produce arbitrarily complex new
|
||||
dimensions. For example, take Newton's law, which relates force to
|
||||
mass and acceleration:</p>
|
||||
<blockquote>
|
||||
<em>F</em> = <em>ma</em></blockquote>
|
||||
<p>Since mass and acceleration have different dimensions, the
|
||||
dimensions of force must somehow capture their combination. In
|
||||
fact, the dimensions of acceleration are already just such a
|
||||
composite, a change in velocity over time:</p>
|
||||
<blockquote>
|
||||
<em>dv</em>/<em>dt</em></blockquote>
|
||||
<p>Since velocity is just change in distance (<em>l</em>) over time (<em>t</em>),
|
||||
the fundamental dimensions of acceleration are:</p>
|
||||
<blockquote>
|
||||
(<em>l</em>/<em>t</em>)/<em>t</em> = <em>l</em>/<em>t</em><sup>2</sup></blockquote>
|
||||
<p>And indeed, acceleration is commonly measured in "meters per second
|
||||
squared." It follows that the dimensions of force must be:</p>
|
||||
<blockquote>
|
||||
<em>ml</em>/<em>t</em><sup>2</sup></blockquote>
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>and force is commonly measured in kg(m/s<sup>2</sup>), or
|
||||
"kilogram-meters per second squared." When multiplying quantities
|
||||
of mass and acceleration, we multiply their dimensions as well and
|
||||
carry the result along, which helps us to ensure that the result is
|
||||
meaningful. The formal name for this bookkeeping is <strong>dimensional
|
||||
analysis</strong>, and our next task will be to implement its rules in the C++
|
||||
type system. John Barton and Lee Nackman were the first to show
|
||||
how to do this in their seminal book, <em>Scientific and Engineering
|
||||
C++</em> <a class="citation-reference" href="#bn94" id="id5" name="id5">[BN94]</a>. We will recast their approach here in
|
||||
metaprogramming terms.</p>
|
||||
<table class="citation" frame="void" id="bn94" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id5" name="bn94">[BN94]</a></td><td>John J. Barton and Lee R. Nackman. <em>Scientific and
|
||||
Engineering C++: an Introduction with Advanced Techniques and
|
||||
Examples.</em> Reading, MA: Addison Wesley. ISBN
|
||||
0-201-53393-6. 1994.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./representing-dimensions.html" id="id42" name="id42">Representing Dimensions</a></li>
|
||||
<li><a class="reference" href="./representing-quantities.html" id="id43" name="id43">Representing Quantities</a></li>
|
||||
<li><a class="reference" href="./implementing-addition-and.html" id="id44" name="id44">Implementing Addition and Subtraction</a></li>
|
||||
<li><a class="reference" href="./implementing.html" id="id45" name="id45">Implementing Multiplication</a></li>
|
||||
<li><a class="reference" href="./implementing-division.html" id="id46" name="id46">Implementing Division</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Prev</a> <a href="./representing-dimensions.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./higher-order.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: ETI</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./incomplete-support-for.html" class="navigation-link">Prev</a> <a href="./resources.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./incomplete-support-for.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./portability.html" class="navigation-link">Portability</a> / <a href="./eti.html" class="navigation-link">ETI</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="eti">
|
||||
<h1><a class="toc-backref" href="./portability.html#id76" name="eti">ETI</a></h1>
|
||||
<p>In context of C++ template problems, ETI is an abbreviation for "Early
|
||||
Template Instantiation" — a Microsoft Visual C++ - specific issue that
|
||||
has been a barrier to any serious work with templates on this platform until
|
||||
Microsoft developers fixed it in Visual C++ 7.1 (2003 .NET). Although the
|
||||
problem is relatively easy to work around if the right techniques
|
||||
are applied systematically through the codebase, the approach is definitely
|
||||
tedious and time-consuming. So, if one day you discover that you are spending
|
||||
too much time dealing with the issue, consider upgrading to the
|
||||
newer version of the compiler. In fact, seriously consider it regardless.
|
||||
The benefits of saved time, money and frustration are well worth the price.</p>
|
||||
<div class="section" id="eti-the-problem">
|
||||
<h2><a name="eti-the-problem">The Problem</a></h2>
|
||||
<p>Here is a short demonstration of the issue with MSVC 6.x:</p>
|
||||
<pre class="literal-block">
|
||||
template< typename F, typename T > struct apply1
|
||||
{
|
||||
typedef typename F::template apply<T>::type type;
|
||||
};
|
||||
</pre>
|
||||
<p>Trying to compiling this innocent-looking code, we get:</p>
|
||||
<pre class="literal-block">
|
||||
portability.cpp(4) : error C2903: 'apply' : symbol is neither a class template
|
||||
nor a function template
|
||||
portability.cpp(5) : see reference to class template instantiation
|
||||
'apply1<F,T>' being compiled
|
||||
portability.cpp(4) : error C2143: syntax error : missing ',' before '<'
|
||||
portability.cpp(5) : see reference to class template instantiation
|
||||
'apply1<F,T>' being compiled
|
||||
portability.cpp(4) : error C2059: syntax error : '<'
|
||||
portability.cpp(5) : see reference to class template instantiation
|
||||
'apply1<F,T>' being compiled
|
||||
</pre>
|
||||
<p>The "symbol is neither a class template nor a function template" part of the
|
||||
diagnostics is actually often an indication of ETI-related problems. Another
|
||||
typical error message usually says something about nested type such-and-such
|
||||
not being a member of a global namespace.</p>
|
||||
<p>Both cases are two sides of the same compiler bug, which we call
|
||||
"Early template instantiation": the compiler, for internal
|
||||
purposes, in order to process class template definitions,
|
||||
instantiates class templates with dummy template parameters
|
||||
(<tt class="literal"><span class="pre">int</span></tt>'s). That can happen both during parsing of template
|
||||
definitions (and such errors are most easy to identify and fix —
|
||||
the template definition itself just doesn't compile; the example
|
||||
above falls into this category), or later during template
|
||||
instantiation, and these one are hard to detect — the bug will
|
||||
only be triggered in some particular context.</p>
|
||||
<!-- namespace-scope: nested templates are immune? -->
|
||||
<p>ETI is always performed during parsing of the namespace-scope
|
||||
template definition, which basically means that any template
|
||||
definition that is rendered invalid by substituting its template
|
||||
parameters by <tt class="literal"><span class="pre">int</span></tt>s might not compile, as it happened with our
|
||||
example:</p>
|
||||
<pre class="literal-block">
|
||||
template< typename F, typename T > struct apply1
|
||||
{
|
||||
// typedef typename F::template apply<T>::type type;
|
||||
// ETI generates this:
|
||||
typedef typename int::template apply<int>::type type;
|
||||
};
|
||||
</pre>
|
||||
<p>If you compile this, you'll get <em>exactly</em> the same diagnostics as we've just seen.</p>
|
||||
<p>Note that we've said "might not compile", because... well, the short answer is,
|
||||
"it depends". We haven't analyzed things to the point that we could tell you the
|
||||
exact condition when ETI leads to an error and when it doesn't, but
|
||||
that's not very important anyway — if it's an error, you just fix it (we'll show you how
|
||||
in a second), and if it's not, then you leave things as is. If one day the
|
||||
potential issue turns into a real one, then you apply the workaround we are about
|
||||
to give you.</p>
|
||||
</div>
|
||||
<div class="section" id="eti-the-symptoms">
|
||||
<h2><a name="eti-the-symptoms">The Symptoms</a></h2>
|
||||
<p>We've already looked at the typical diagnostics, so we won't repeat
|
||||
ourselves. Instead we'll
|
||||
just mention that many MSVC's INTERNAL COMPILER ERRORs (ICEs) are, in fact, caused
|
||||
by an ETI-related problem somewhere deep down the instantiation stack.</p>
|
||||
</div>
|
||||
<div class="section" id="eti-the-solution">
|
||||
<h2><a name="eti-the-solution">The Solution</a></h2>
|
||||
<p>There is no way we can change the compiler's behavior in this case, so what we have
|
||||
to do is to adjust to it and still make our templates do what we want. Surprisingly,
|
||||
in most cases it's quite simple to achieve:</p>
|
||||
<pre class="literal-block">
|
||||
// potentially unsafe
|
||||
template< typename F > struct apply0
|
||||
{
|
||||
typedef typename F::type type;
|
||||
};
|
||||
|
||||
// now ETI-safe
|
||||
template<> struct apply0<int>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
</pre>
|
||||
<p>Since the original template could have never been instantiated with <tt class="literal"><span class="pre">int</span></tt>,
|
||||
providing a stub <tt class="literal"><span class="pre">int</span></tt> specialization is completely innocent.</p>
|
||||
<!-- Looks like you're missing lots of stuff, like ETI_BASE - - no? -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./incomplete-support-for.html" class="navigation-link">Prev</a> <a href="./resources.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./incomplete-support-for.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,103 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Exercises</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./details.html" class="navigation-link">Prev</a> <a href="./reference-manual.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./details.html" class="navigation-link">Back</a> Along</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>
|
||||
<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="./exercises.html" class="navigation-link">Exercises</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="exercises">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id60" name="exercises">Exercises</a></h1>
|
||||
<dl>
|
||||
<dt>1-0.</dt>
|
||||
<dd>Use <tt class="literal"><span class="pre">BOOST_STATIC_ASSERT</span></tt> to add error checking to the <tt class="literal"><span class="pre">binary</span></tt>
|
||||
template presented in section <a class="reference" href="./resources.html">1</a>.4.1 so
|
||||
that <tt class="literal"><span class="pre">binary<N>::value</span></tt> causes a compilation error if <tt class="literal"><span class="pre">N</span></tt>
|
||||
contains digits other than <tt class="literal"><span class="pre">0</span></tt> or <tt class="literal"><span class="pre">1</span></tt>.</dd>
|
||||
<dt>1-1.</dt>
|
||||
<dd>Turn <tt class="literal"><span class="pre">vector_c<int,1,2,3></span></tt> into a type sequence with elements
|
||||
(2,3,4) using <tt class="literal"><span class="pre">transform</span></tt>.</dd>
|
||||
<dt>1-2.</dt>
|
||||
<dd>Turn <tt class="literal"><span class="pre">vector_c<int,1,2,3></span></tt> into a type sequence with elements
|
||||
(1,4,9) using <tt class="literal"><span class="pre">transform</span></tt>.</dd>
|
||||
<dt>1-3.</dt>
|
||||
<dd>Turn <tt class="literal"><span class="pre">T</span></tt> into <tt class="literal"><span class="pre">T****</span></tt> by using <tt class="literal"><span class="pre">twice</span></tt> twice.</dd>
|
||||
<dt>1-4.</dt>
|
||||
<dd>Turn <tt class="literal"><span class="pre">T</span></tt> into <tt class="literal"><span class="pre">T****</span></tt> using <tt class="literal"><span class="pre">twice</span></tt> on itself.</dd>
|
||||
<dt>1-5.</dt>
|
||||
<dd><p class="first">There's still a problem with the dimensional analysis code in
|
||||
section 1.1.
|
||||
Hint: What happens when you do:</p>
|
||||
<pre class="literal-block">
|
||||
f = f + m * a;
|
||||
</pre>
|
||||
<p>Repair this example using techniques shown in this
|
||||
chapter.</p>
|
||||
<!-- @ example.wrap('''void will_fail%s
|
||||
{ quantity<float,force> f(m*a);
|
||||
''' % ma_function_args, '}')
|
||||
stack[:0] = dimensional_analysis # stick support code in
|
||||
compile('all', expect_error = True) -->
|
||||
</dd>
|
||||
<dt>1-6.</dt>
|
||||
<dd>Build a lambda expression that has functionality equivalent to
|
||||
<tt class="literal"><span class="pre">twice</span></tt>. Hint: <tt class="literal"><span class="pre">mpl::apply</span></tt> is a metafunction!</dd>
|
||||
<dt>1-7*.</dt>
|
||||
<dd><p class="first">What do you think would be the semantics of the following
|
||||
constructs:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::lambda<mpl::lambda<_1> >::type t1;
|
||||
typedef mpl::apply<_1,mpl::plus<_1,_2> >::type t2;
|
||||
typedef mpl::apply<_1,std::vector<int> >::type t3;
|
||||
typedef mpl::apply<_1,std::vector<_1> >::type t4;
|
||||
typedef mpl::apply<mpl::lambda<_1>,std::vector<int> >::type t5;
|
||||
typedef mpl::apply<mpl::lambda<_1>,std::vector<_1> >::type t6;
|
||||
typedef mpl::apply<mpl::lambda<_1>,mpl::plus<_1,_2> >::type t7;
|
||||
typedef mpl::apply<_1,mpl::lambda< mpl::plus<_1,_2> > >::type t8;
|
||||
</pre>
|
||||
<!-- @example.prepend('#include <vector>')
|
||||
compile() -->
|
||||
<p class="last">Show the steps used to
|
||||
arrive at your answers and write tests verifying your assumptions.
|
||||
Did the library behavior match your reasoning? If not, analyze the
|
||||
failed tests to discover the actual expression semantics.
|
||||
Explain why your assumptions were different, what
|
||||
behavior you find more coherent, and why.</p>
|
||||
</dd>
|
||||
<dt>1-8*.</dt>
|
||||
<dd>Our dimensional analysis framework dealt with dimensions, but it
|
||||
entirely ignored the issue of <em>units</em>. A length can be
|
||||
represented in inches, feet, or meters. A force can be
|
||||
represented in newtons or in kg m/sec<sup>2</sup>. Add the
|
||||
ability to specify units and test your code. Try to make your
|
||||
interface as syntactically friendly as possible for the user.</dd>
|
||||
</dl>
|
||||
<!-- Along with Alan Turing, Church was one of the founders of computer
|
||||
science. -->
|
||||
<!-- yes, this is easier to read, but the real beauty of ``apply`` is that
|
||||
it not only works on metafunction classes, but on metafunctions passed
|
||||
with placeholder arguments. -->
|
||||
<!-- Naturally, MPL defines a series of these numbered placeholder
|
||||
types, so that we can handle metafunctions with more arguments. -->
|
||||
<!-- : in order to pass a template in the ``BinaryOperation`` position,
|
||||
``transform`` would have to be declared::
|
||||
|
||||
template <
|
||||
class Sequence1, class Sequence2
|
||||
, template <class,class> class BinaryOperation
|
||||
>
|
||||
struct transform; // returning a sequence -->
|
||||
<!-- "Programming with types" -->
|
||||
<!-- Once again, a nested ``value`` member is optional for
|
||||
metafunctions, and required for integral type wrappers. -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./details.html" class="navigation-link">Prev</a> <a href="./reference-manual.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./details.html" class="navigation-link">Back</a> Along</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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Handling Placeholders</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<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>
|
||||
<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>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="handling-placeholders">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id48" name="handling-placeholders">Handling Placeholders</a></h1>
|
||||
<p>Our implementation of <tt class="literal"><span class="pre">twice</span></tt> already works with metafunction
|
||||
classes. Ideally, we would
|
||||
like it to work with placeholder expressions too, much the same as
|
||||
<tt class="literal"><span class="pre">mpl::transform</span></tt> allows us to pass either form. For example, we
|
||||
would like to be able to write:</p>
|
||||
<pre class="literal-block">
|
||||
template <class X>
|
||||
struct two_pointers
|
||||
: twice<<strong>boost::add_pointer<_1></strong>, X>
|
||||
{};
|
||||
</pre>
|
||||
<!-- @ example.append('typedef two_pointers<int>::type intstar2;')
|
||||
compile('all', pop = 1, expect_error = True) -->
|
||||
<p>But when we look at the implementation of <tt class="literal"><span class="pre">boost::add_pointer</span></tt>,
|
||||
it becomes clear that the current definition of <tt class="literal"><span class="pre">twice</span></tt> can't
|
||||
work that way.</p>
|
||||
<pre class="literal-block">
|
||||
template <class T>
|
||||
struct add_pointer
|
||||
{
|
||||
typedef T* type;
|
||||
};
|
||||
</pre>
|
||||
<!-- @ compile() -->
|
||||
<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
|
||||
to be a metafunction class, along the lines of <tt class="literal"><span class="pre">add_pointer_f</span></tt>.
|
||||
Instead, it's just a nullary metafunction returning the almost
|
||||
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
|
||||
fail when <tt class="literal"><span class="pre">apply1</span></tt> reaches for a nested <tt class="literal"><span class="pre">::apply</span></tt>
|
||||
metafunction in <tt class="literal"><span class="pre">boost::add_pointer<_1></span></tt> and finds that it
|
||||
doesn't exist.</p>
|
||||
<p>We've determined that we don't get the behavior we want
|
||||
automatically, so what next? Since <tt class="literal"><span class="pre">mpl::transform</span></tt> can do this
|
||||
sort of thing, there ought to be a way for us to do it too — and
|
||||
so there is.</p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,141 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Higher-Order Metafunctions</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing-division.html" class="navigation-link">Prev</a> <a href="./handling-placeholders.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.html" class="navigation-link">Back</a> <a href="./handling-placeholders.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>
|
||||
<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="./higher-order.html" class="navigation-link">Higher-Order Metafunctions</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="higher-order">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id47" name="higher-order">Higher-Order Metafunctions</a></h1>
|
||||
<p>In the previous section we used two different forms —
|
||||
metafunction classes and placeholder expressions —
|
||||
to pass and return metafunctions just like any other metadata.
|
||||
Bundling metafunctions into "first class metadata" allows
|
||||
<tt class="literal"><span class="pre">transform</span></tt> to perform an infinite variety of different
|
||||
operations: in our case, multiplication and division of dimensions.
|
||||
Though the idea of using functions to manipulate other functions
|
||||
may seem simple, its great power and flexibility <a class="citation-reference" href="#hudak89" id="id9" name="id9">[Hudak89]</a> has
|
||||
earned it a fancy title: <strong>higher-order functional programming</strong>.
|
||||
A function that operates on another function is known as a
|
||||
<strong>higher-order function</strong>. It follows that <tt class="literal"><span class="pre">transform</span></tt> is a
|
||||
higher-order
|
||||
metafunction: a metafunction that operates on another metafunction.</p>
|
||||
<table class="citation" frame="void" id="hudak89" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id9" name="hudak89">[Hudak89]</a></td><td>Paul Hudak. "Conception, Evolution, and Application of
|
||||
Functional Programming Languages," ACM Computing Surveys 21,
|
||||
no. 3 Pages: 359 - 411. New York: ACM Press. 1989.
|
||||
ISSN:0360-0300. http://doi.acm.org/10.1145/72551.72554.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Now that we've seen the power of higher-order metafunctions at
|
||||
work, it would be good to be able to create new ones. In order to
|
||||
explore the basic mechanisms, let's try a simple example. Our task
|
||||
is to write a metafunction called <tt class="literal"><span class="pre">twice</span></tt>, which — given a unary
|
||||
metafunction <em>f</em> and arbitrary metadata <em>x</em> — computes:</p>
|
||||
<blockquote>
|
||||
<em>twice</em>(<em>f</em>, <em>x</em>) := <em>f</em>(<em>f</em>(<em>x</em>))</blockquote>
|
||||
<p>This might seem like a trivial example, and in fact it is. You
|
||||
won't find much use for <tt class="literal"><span class="pre">twice</span></tt> in real code. We hope you'll
|
||||
bear with us anyway: Because it doesn't do much more than accept
|
||||
and invoke a metafunction, <tt class="literal"><span class="pre">twice</span></tt> captures all the essential
|
||||
elements of "higher-orderness" without any distracting details.</p>
|
||||
<p>If <em>f</em> is a metafunction class, the definition of <tt class="literal"><span class="pre">twice</span></tt> is
|
||||
straightforward:</p>
|
||||
<pre class="literal-block">
|
||||
template <class F, class X>
|
||||
struct twice
|
||||
{
|
||||
typedef typename F::template apply<X>::type once; // f(x)
|
||||
typedef typename F::template apply<once>::type type; // f(f(x))
|
||||
};
|
||||
</pre>
|
||||
<!-- @ prefix.append(
|
||||
'''#include <boost/type_traits/add_pointer.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>''')
|
||||
|
||||
twice_test = '''
|
||||
#include <boost/mpl/assert.hpp>
|
||||
struct add_pointer_f
|
||||
{
|
||||
template <class T> struct apply : boost::add_pointer<T>
|
||||
{};
|
||||
};
|
||||
BOOST_MPL_ASSERT((boost::is_same<twice<add_pointer_f,int>::type,int**>));
|
||||
'''
|
||||
example.append(twice_test)
|
||||
compile() -->
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>Or, applying metafunction forwarding:</p>
|
||||
<pre class="literal-block">
|
||||
template <class F, class X>
|
||||
struct twice
|
||||
: F::template apply<
|
||||
typename F::template apply<X>::type
|
||||
>
|
||||
{};
|
||||
</pre>
|
||||
<!-- @ example.append(twice_test)
|
||||
compile() -->
|
||||
<div class="admonition-c-language-note admonition">
|
||||
<p class="admonition-title first">C++ Language Note</p>
|
||||
<p>The C++ standard requires the <tt class="literal"><span class="pre">template</span></tt> keyword when we use a
|
||||
<strong>dependent name</strong> that refers to a member template.
|
||||
<tt class="literal"><span class="pre">F::apply</span></tt> may or may not name a template, <em>depending</em> on the
|
||||
particular <tt class="literal"><span class="pre">F</span></tt> that is passed. See <a class="reference" href="./resources.html">the book's</a> Appendix B for more
|
||||
information about <tt class="literal"><span class="pre">template</span></tt>.</p>
|
||||
</div>
|
||||
<p>Given the need to sprinkle our code with the <tt class="literal"><span class="pre">template</span></tt> keyword,
|
||||
it would be nice to reduce the syntactic burden of invoking
|
||||
metafunction classes. As usual, the solution is to factor the
|
||||
pattern into a metafunction:</p>
|
||||
<pre class="literal-block">
|
||||
template <class UnaryMetaFunctionClass, class Arg>
|
||||
struct apply1
|
||||
: UnaryMetaFunctionClass::template apply<Arg>
|
||||
{};
|
||||
</pre>
|
||||
<p>Now <tt class="literal"><span class="pre">twice</span></tt> is just:</p>
|
||||
<pre class="literal-block">
|
||||
template <class F, class X>
|
||||
struct twice
|
||||
: apply1<F, typename apply1<F,X>::type>
|
||||
{};
|
||||
</pre>
|
||||
<p>To see <tt class="literal"><span class="pre">twice</span></tt> at work, we can apply it to a little metafunction
|
||||
class built around the <tt class="literal"><span class="pre">add_pointer</span></tt> metafunction:</p>
|
||||
<pre class="literal-block">
|
||||
struct add_pointer_f
|
||||
{
|
||||
template <class T>
|
||||
struct apply : boost::add_pointer<T> {};
|
||||
};
|
||||
</pre>
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>Now we can use <tt class="literal"><span class="pre">twice</span></tt> with <tt class="literal"><span class="pre">add_pointer_f</span></tt> to build
|
||||
pointers-to-pointers:</p>
|
||||
<pre class="literal-block">
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
twice<add_pointer_f, int>::type
|
||||
, int**
|
||||
>::value
|
||||
));
|
||||
</pre>
|
||||
<!-- @ apply1 = stack[-4]
|
||||
add_pointer_f = stack[-2]
|
||||
compile('all', pop = 0) -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing-division.html" class="navigation-link">Prev</a> <a href="./handling-placeholders.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.html" class="navigation-link">Back</a> <a href="./handling-placeholders.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Implementing Addition and Subtraction</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./representing-quantities.html" class="navigation-link">Prev</a> <a href="./implementing.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./representing-quantities.html" class="navigation-link">Back</a> <a href="./implementing.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a> / <a href="./implementing-addition-and.html" class="navigation-link">Implementing Addition and Subtraction</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="implementing-addition-and">
|
||||
<h1><a class="toc-backref" href="./dimensional-analysis.html#id44" name="implementing-addition-and">Implementing Addition and Subtraction</a></h1>
|
||||
<p>We can now easily write the rules for addition and subtraction,
|
||||
since the dimensions of the arguments must always match.</p>
|
||||
<pre class="literal-block">
|
||||
template <class T, class D>
|
||||
quantity<T,D>
|
||||
operator+(quantity<T,D> x, quantity<T,D> y)
|
||||
{
|
||||
return quantity<T,D>(x.value() + y.value());
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
quantity<T,D>
|
||||
operator-(quantity<T,D> x, quantity<T,D> y)
|
||||
{
|
||||
return quantity<T,D>(x.value() - y.value());
|
||||
}
|
||||
</pre>
|
||||
<!-- @ example.append('void test1() {') # function prologue -->
|
||||
<p>These operators enable us to write code like:</p>
|
||||
<pre class="literal-block">
|
||||
quantity<float,<strong>length</strong>> len1( 1.0f );
|
||||
quantity<float,<strong>length</strong>> len2( 2.0f );
|
||||
|
||||
len1 = len1 + len2; // OK
|
||||
</pre>
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>but prevent us from trying to add incompatible dimensions:</p>
|
||||
<pre class="literal-block">
|
||||
len1 = len2 + quantity<float,<strong>mass</strong>>( 3.7f ); // <strong>error</strong>
|
||||
</pre>
|
||||
<!-- @ stack[-1].append('}') # last 2 examples together
|
||||
compile('all', pop = 1, expect_error = True)
|
||||
|
||||
stack[-1].append('}') # just the prior example
|
||||
compile('all', pop = None) -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./representing-quantities.html" class="navigation-link">Prev</a> <a href="./implementing.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./representing-quantities.html" class="navigation-link">Back</a> <a href="./implementing.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Implementing Division</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing.html" class="navigation-link">Prev</a> <a href="./higher-order.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./implementing.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a> / <a href="./implementing-division.html" class="navigation-link">Implementing Division</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="implementing-division">
|
||||
<h1><a class="toc-backref" href="./dimensional-analysis.html#id46" name="implementing-division">Implementing Division</a></h1>
|
||||
<p>Division is similar to multiplication, but instead of adding
|
||||
exponents, we must subtract them. Rather than writing out a near
|
||||
duplicate of <tt class="literal"><span class="pre">plus_f</span></tt>, we can use the following trick to make
|
||||
<tt class="literal"><span class="pre">minus_f</span></tt> much simpler:</p>
|
||||
<pre class="literal-block">
|
||||
struct minus_f
|
||||
{
|
||||
template <class T1, class T2>
|
||||
struct apply
|
||||
: mpl::minus<T1,T2> {};
|
||||
};
|
||||
</pre>
|
||||
<!-- @ # The following is OK because we showed how to get at mpl_plus
|
||||
prefix.append('#include <boost/mpl/minus.hpp>')
|
||||
compile(1) -->
|
||||
<p>Here <tt class="literal"><span class="pre">minus_f::apply</span></tt> uses inheritance to expose the nested
|
||||
<tt class="literal"><span class="pre">type</span></tt> of its base class, <tt class="literal"><span class="pre">mpl::minus</span></tt>, so we don't have to
|
||||
write:</p>
|
||||
<pre class="literal-block">
|
||||
typedef typename ...::type type
|
||||
</pre>
|
||||
<!-- @ignore() -->
|
||||
<p>We don't have to write
|
||||
<tt class="literal"><span class="pre">typename</span></tt> here (in fact, it would be illegal), because the
|
||||
compiler knows that dependent names in <tt class="literal"><span class="pre">apply</span></tt>'s initializer
|
||||
list must be base classes. <a class="footnote-reference" href="#plus-too" id="id7" name="id7">[2]</a> This powerful
|
||||
simplification is known as <strong>metafunction forwarding</strong>; we'll apply
|
||||
it often as the book goes on. <a class="footnote-reference" href="#edg" id="id8" name="id8">[3]</a></p>
|
||||
<table class="footnote" frame="void" id="plus-too" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id7" name="plus-too">[2]</a></td><td>In case you're wondering, the same approach could
|
||||
have been applied to <tt class="literal"><span class="pre">plus_f</span></tt>, but since it's a little subtle,
|
||||
we introduced the straightforward but verbose formulation
|
||||
first.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="footnote" frame="void" id="edg" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id8" name="edg">[3]</a></td><td>Users of EDG-based compilers should consult <a class="reference" href="./resources.html">the book's</a> Appendix C
|
||||
for a caveat about metafunction forwarding. You can tell whether
|
||||
you have an EDG compiler by checking the preprocessor symbol
|
||||
<tt class="literal"><span class="pre">__EDG_VERSION__</span></tt>, which is defined by all EDG-based compilers.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Syntactic tricks notwithstanding, writing trivial classes to wrap
|
||||
existing metafunctions is going to get boring pretty quickly. Even
|
||||
though the definition of <tt class="literal"><span class="pre">minus_f</span></tt> was far less verbose than that
|
||||
of <tt class="literal"><span class="pre">plus_f</span></tt>, it's still an awful lot to type. Fortunately, MPL gives
|
||||
us a <em>much</em> simpler way to pass metafunctions around. Instead of
|
||||
building a whole metafunction class, we can invoke <tt class="literal"><span class="pre">transform</span></tt>
|
||||
this way:</p>
|
||||
<pre class="literal-block">
|
||||
typename mpl::transform<D1,D2, <strong>mpl::minus<_1,_2></strong> >::type
|
||||
</pre>
|
||||
<!-- @# Make it harmless but legit C++ so we can syntax check later
|
||||
example.wrap('template <class D1,class D2>', 'fff(D1,D2);')
|
||||
|
||||
# We explain placeholders below, so we can henceforth use them
|
||||
# without qualification -->
|
||||
<p>Those funny looking arguments (<tt class="literal"><span class="pre">_1</span></tt> and <tt class="literal"><span class="pre">_2</span></tt>) are known as
|
||||
<strong>placeholders</strong>, and they signify that when the <tt class="literal"><span class="pre">transform</span></tt>'s
|
||||
<tt class="literal"><span class="pre">BinaryOperation</span></tt> is invoked, its first and second arguments will
|
||||
be passed on to <tt class="literal"><span class="pre">minus</span></tt> in the positions indicated by <tt class="literal"><span class="pre">_1</span></tt> and
|
||||
<tt class="literal"><span class="pre">_2</span></tt>, respectively. The whole type <tt class="literal"><span class="pre">mpl::minus<_1,_2></span></tt> is
|
||||
known as a <strong>placeholder expression</strong>.</p>
|
||||
<div class="note">
|
||||
<p class="admonition-title first">Note</p>
|
||||
<p>MPL's placeholders are in the <tt class="literal"><span class="pre">mpl::placeholders</span></tt>
|
||||
namespace and defined in <tt class="literal"><span class="pre">boost/mpl/placeholders.hpp</span></tt>. In
|
||||
this book we will usually assume that you have written:</p>
|
||||
<pre class="literal-block">
|
||||
#include<boost/mpl/placeholders.hpp>
|
||||
using namespace mpl::placeholders;
|
||||
</pre>
|
||||
<p>so that they can be accessed without qualification.</p>
|
||||
</div>
|
||||
<!-- @ prefix.append(str(example)) # move to common prefix
|
||||
ignore() -->
|
||||
<p>Here's our division operator written using placeholder
|
||||
expressions:</p>
|
||||
<pre class="literal-block">
|
||||
template <class T, class D1, class D2>
|
||||
quantity<
|
||||
T
|
||||
, typename mpl::transform<D1,D2,<strong>mpl::minus<_1,_2></strong> >::type
|
||||
>
|
||||
operator/(quantity<T,D1> x, quantity<T,D2> y)
|
||||
{
|
||||
typedef typename
|
||||
mpl::transform<D1,D2,<strong>mpl::minus<_1,_2></strong> >::type dim;
|
||||
|
||||
return quantity<T,dim>( x.value() / y.value() );
|
||||
}
|
||||
</pre>
|
||||
<!-- @compile('all', pop = 1) -->
|
||||
<p>This code is considerably simpler. We can simplify it even further
|
||||
by factoring the code that calculates the new dimensions into its
|
||||
own metafunction:</p>
|
||||
<pre class="literal-block">
|
||||
template <class D1, class D2>
|
||||
struct <strong>divide_dimensions</strong>
|
||||
: mpl::transform<D1,D2,mpl::minus<_1,_2> > // forwarding again
|
||||
{};
|
||||
|
||||
template <class T, class D1, class D2>
|
||||
quantity<T, typename <strong>divide_dimensions<D1,D2></strong>::type>
|
||||
operator/(quantity<T,D1> x, quantity<T,D2> y)
|
||||
{
|
||||
return quantity<T, typename <strong>divide_dimensions<D1,D2></strong>::type>(
|
||||
x.value() / y.value());
|
||||
}
|
||||
</pre>
|
||||
<!-- @compile('all', pop = None) -->
|
||||
<p>Now we can verify our "force-on-a-laptop" computation by reversing
|
||||
it, as follows:</p>
|
||||
<pre class="literal-block">
|
||||
quantity<float,mass> m2 = f/a;
|
||||
float rounding_error = std::abs((m2 - m).value());
|
||||
</pre>
|
||||
<!-- @example.wrap('''
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
int main()
|
||||
{
|
||||
quantity<float,mass> m(5.0f);
|
||||
quantity<float,acceleration> a(9.8f);
|
||||
quantity<float,force> f = m * a;
|
||||
''','''
|
||||
assert(rounding_error < .001);
|
||||
}''')
|
||||
|
||||
dimensional_analysis = stack[:-1] # save for later
|
||||
|
||||
run('all') -->
|
||||
<p>If we got everything right, <tt class="literal"><span class="pre">rounding_error</span></tt> should be very close
|
||||
to zero. These are boring calculations, but they're just the sort
|
||||
of thing that could ruin a whole program (or worse) if you got them
|
||||
wrong. If we had written <tt class="literal"><span class="pre">a/f</span></tt> instead of <tt class="literal"><span class="pre">f/a</span></tt>, there would have
|
||||
been a compilation error, preventing a mistake from propagating
|
||||
throughout our program.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing.html" class="navigation-link">Prev</a> <a href="./higher-order.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./implementing.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,265 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Implementing Multiplication</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing-addition-and.html" class="navigation-link">Prev</a> <a href="./implementing-division.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./implementing-addition-and.html" class="navigation-link">Back</a> <a href="./implementing-division.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a> / <a href="./implementing.html" class="navigation-link">Implementing Multiplication</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="implementing">
|
||||
<h1><a class="toc-backref" href="./dimensional-analysis.html#id45" name="implementing">Implementing Multiplication</a></h1>
|
||||
<p>Multiplication is a bit more complicated than addition and
|
||||
subtraction. So far, the dimensions of the arguments and results have
|
||||
all been identical, but when multiplying, the result will usually
|
||||
have different dimensions from either of the arguments. For
|
||||
multiplication, the relation:</p>
|
||||
<blockquote>
|
||||
(<em>x</em><sup>a</sup>)(<em>x</em><sup>b</sup>) == <em>x</em> <sup>(a + b)</sup></blockquote>
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>implies that the exponents of the result dimensions should be the
|
||||
sum of corresponding exponents from the argument
|
||||
dimensions. Division is similar, except that the sum is replaced by
|
||||
a difference.</p>
|
||||
<p>To combine corresponding elements from two sequences, we'll use
|
||||
MPL's <tt class="literal"><span class="pre">transform</span></tt> algorithm. <tt class="literal"><span class="pre">transform</span></tt> is a metafunction
|
||||
that iterates through two input sequences in parallel, passing an
|
||||
element from each sequence to an arbitrary binary metafunction, and
|
||||
placing the result in an output sequence.</p>
|
||||
<pre class="literal-block">
|
||||
template <class Sequence1, class Sequence2, class BinaryOperation>
|
||||
struct transform; // returns a Sequence
|
||||
</pre>
|
||||
<p>The signature above should look familiar if you're acquainted with the
|
||||
STL <tt class="literal"><span class="pre">transform</span></tt> algorithm that accepts two <em>runtime</em> sequences
|
||||
as inputs:</p>
|
||||
<pre class="literal-block">
|
||||
template <
|
||||
class InputIterator1, class InputIterator2
|
||||
, class OutputIterator, class BinaryOperation
|
||||
>
|
||||
void transform(
|
||||
InputIterator1 start1, InputIterator2 finish1
|
||||
, InputIterator2 start2
|
||||
, OutputIterator result, BinaryOperation func);
|
||||
</pre>
|
||||
<!-- @ example.wrap('namespace shield{','}')
|
||||
compile() -->
|
||||
<p>Now we just need to pass a <tt class="literal"><span class="pre">BinaryOperation</span></tt> that adds or
|
||||
subtracts in order to multiply or divide dimensions with
|
||||
<tt class="literal"><span class="pre">mpl::transform</span></tt>. If you look through the <a class="reference" href="./reference-manual.html">the MPL reference manual</a>, you'll
|
||||
come across <tt class="literal"><span class="pre">plus</span></tt> and <tt class="literal"><span class="pre">minus</span></tt> metafunctions that do just what
|
||||
you'd expect:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/mpl/plus.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
mpl::plus<
|
||||
mpl::int_<2>
|
||||
, mpl::int_<3>
|
||||
>::type::value == 5
|
||||
));
|
||||
</pre>
|
||||
<!-- @ compile(pop = None) -->
|
||||
<div class="sidebar">
|
||||
<p class="sidebar-title first"><tt class="literal"><span class="pre">BOOST_STATIC_ASSERT</span></tt></p>
|
||||
<p>is a macro that causes a compilation error if its argument is
|
||||
false. The double parentheses are required because the C++
|
||||
preprocessor can't parse templates: it would otherwise be
|
||||
fooled by the comma into treating the condition as two separate
|
||||
macro arguments. Unlike its runtime analogue <tt class="literal"><span class="pre">assert(...)</span></tt>,
|
||||
<tt class="literal"><span class="pre">BOOST_STATIC_ASSERT</span></tt> can also be used at class scope,
|
||||
allowing us to put assertions in our metafunctions. See
|
||||
Chapter <a class="reference" href="./resources.html">8</a> for an in-depth discussion.</p>
|
||||
</div>
|
||||
<!-- @prefix.append('#include <boost/static_assert.hpp>') -->
|
||||
<p>At this point it might seem as though we have a solution, but we're
|
||||
not quite there yet. A naive attempt to apply the <tt class="literal"><span class="pre">transform</span></tt>
|
||||
algorithm in the implementation of <tt class="literal"><span class="pre">operator*</span></tt> yields a compiler
|
||||
error:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/transform.hpp>
|
||||
|
||||
template <class T, class D1, class D2>
|
||||
quantity<
|
||||
T
|
||||
, typename mpl::transform<D1,D2,mpl::plus>::type
|
||||
>
|
||||
operator*(quantity<T,D1> x, quantity<T,D2> y) { ... }
|
||||
</pre>
|
||||
<!-- @ example.replace('{ ... }',';')
|
||||
compile('all', pop = 1, expect_error = True)
|
||||
prefix +=['#include <boost/mpl/transform.hpp>'] -->
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>It fails because the protocol says that metafunction arguments
|
||||
must be types, and <tt class="literal"><span class="pre">plus</span></tt> is not a type, but a class template.
|
||||
Somehow we need to make metafunctions like <tt class="literal"><span class="pre">plus</span></tt> fit the
|
||||
metadata mold.</p>
|
||||
<p>One natural way to introduce polymorphism between metafunctions and
|
||||
metadata is to employ the wrapper idiom that gave us polymorphism
|
||||
between types and integral constants. Instead of a nested integral
|
||||
constant, we can use a class template nested within a
|
||||
<strong>metafunction class</strong>:</p>
|
||||
<pre class="literal-block">
|
||||
struct plus_f
|
||||
{
|
||||
template <class T1, class T2>
|
||||
struct apply
|
||||
{
|
||||
typedef typename mpl::plus<T1,T2>::type type;
|
||||
};
|
||||
};
|
||||
</pre>
|
||||
<div class="admonition-definition admonition">
|
||||
<p class="admonition-title first">Definition</p>
|
||||
<p>A <strong>Metafunction Class</strong> is a class with a publicly accessible
|
||||
nested metafunction called <tt class="literal"><span class="pre">apply</span></tt>.</p>
|
||||
</div>
|
||||
<p>Whereas a metafunction is a template but not a type, a
|
||||
metafunction class wraps that template within an ordinary
|
||||
non-templated class, which <em>is</em> a type. Since metafunctions
|
||||
operate on and return types, a metafunction class can be passed as
|
||||
an argument to, or returned from, another metafunction.</p>
|
||||
<p>Finally, we have a <tt class="literal"><span class="pre">BinaryOperation</span></tt> type that we can pass to
|
||||
<tt class="literal"><span class="pre">transform</span></tt> without causing a compilation error:</p>
|
||||
<pre class="literal-block">
|
||||
template <class T, class D1, class D2>
|
||||
quantity<
|
||||
T
|
||||
, typename mpl::transform<D1,D2,<strong>plus_f</strong>>::type // new dimensions
|
||||
>
|
||||
operator*(quantity<T,D1> x, quantity<T,D2> y)
|
||||
{
|
||||
typedef typename mpl::transform<D1,D2,<strong>plus_f</strong>>::type dim;
|
||||
return quantity<T,dim>( x.value() * y.value() );
|
||||
}
|
||||
</pre>
|
||||
<p>Now, if we want to compute the force exterted by gravity on a 5 kilogram
|
||||
laptop computer, that's just the acceleration due to gravity (9.8
|
||||
m/sec<sup>2</sup>) times the mass of the laptop:</p>
|
||||
<pre class="literal-block">
|
||||
quantity<float,mass> m(5.0f);
|
||||
quantity<float,acceleration> a(9.8f);
|
||||
std::cout << "force = " << (m * a).value();
|
||||
</pre>
|
||||
<!-- @example.wrap('#include <iostream>\nvoid ff() {', '}')
|
||||
|
||||
compile('all', pop = 1) -->
|
||||
<p>Our <tt class="literal"><span class="pre">operator*</span></tt> multiplies the runtime values (resulting in
|
||||
6.0f), and our metaprogram code uses <tt class="literal"><span class="pre">transform</span></tt> to sum the
|
||||
meta-sequences of fundamental dimension exponents, so that the
|
||||
result type contains a representation of a new list of exponents,
|
||||
something like:</p>
|
||||
<pre class="literal-block">
|
||||
mpl::vector_c<int,1,1,-2,0,0,0,0>
|
||||
</pre>
|
||||
<!-- @example.wrap('''
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
typedef''', 'xxxx;')
|
||||
compile() -->
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>However, if we try to write:</p>
|
||||
<pre class="literal-block">
|
||||
quantity<float,force> f = m * a;
|
||||
</pre>
|
||||
<!-- @ ma_function_args = '(quantity<float,mass> m, quantity<float,acceleration> a)'
|
||||
|
||||
example.wrap('void bogus%s {' % ma_function_args, '}')
|
||||
compile('all', pop = 1, expect_error = True) -->
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>we'll run into a little problem. Although the result of
|
||||
<tt class="literal"><span class="pre">m</span> <span class="pre">*</span> <span class="pre">a</span></tt> does indeed represent a force with exponents of mass,
|
||||
length, and time 1, 1, and -2 respectively, the type returned by
|
||||
<tt class="literal"><span class="pre">transform</span></tt> isn't a specialization of <tt class="literal"><span class="pre">vector_c</span></tt>. Instead,
|
||||
<tt class="literal"><span class="pre">transform</span></tt> works generically on the elements of its inputs and
|
||||
builds a new sequence with the appropriate elements: a type with
|
||||
many of the same sequence properties as
|
||||
<tt class="literal"><span class="pre">mpl::vector_c<int,1,1,-2,0,0,0,0></span></tt>, but with a different C++ type
|
||||
altogether. If you want to see the type's full name, you can try
|
||||
to compile the example yourself and look at the error message, but
|
||||
the exact details aren't important. The point is that
|
||||
<tt class="literal"><span class="pre">force</span></tt> names a different type, so the assignment above will fail.</p>
|
||||
<p>In order to resolve the problem, we can add an implicit conversion
|
||||
from the multiplication's result type to <tt class="literal"><span class="pre">quantity<float,force></span></tt>.
|
||||
Since we can't predict the exact types of the dimensions involved
|
||||
in any computation, this conversion will have to be templated,
|
||||
something like:</p>
|
||||
<pre class="literal-block">
|
||||
template <class T, class Dimensions>
|
||||
struct quantity
|
||||
{
|
||||
// converting constructor
|
||||
template <class OtherDimensions>
|
||||
quantity(quantity<T,OtherDimensions> const& rhs)
|
||||
: m_value(rhs.value())
|
||||
{
|
||||
}
|
||||
...
|
||||
</pre>
|
||||
<!-- @ example.append("""
|
||||
explicit quantity(T x)
|
||||
: m_value(x)
|
||||
{}
|
||||
|
||||
T value() const { return m_value; }
|
||||
private:
|
||||
T m_value;
|
||||
};""")
|
||||
|
||||
stack[quantity_declaration] = example
|
||||
ignore() -->
|
||||
<p>Unfortunately, such a general conversion undermines our whole
|
||||
purpose, allowing nonsense such as:</p>
|
||||
<pre class="literal-block">
|
||||
// Should yield a force, not a mass!
|
||||
quantity<float,mass> bogus = m * a;
|
||||
</pre>
|
||||
<!-- @ example.wrap('void bogus2%s {' % ma_function_args, '}')
|
||||
bogus_example = example
|
||||
compile('all', pop = 1) -->
|
||||
<p>We can correct that problem using another MPL algorithm,
|
||||
<tt class="literal"><span class="pre">equal</span></tt>, which tests that two sequences have the same elements:</p>
|
||||
<pre class="literal-block">
|
||||
template <class OtherDimensions>
|
||||
quantity(quantity<T,OtherDimensions> const& rhs)
|
||||
: m_value(rhs.value())
|
||||
{
|
||||
BOOST_STATIC_ASSERT((
|
||||
mpl::equal<Dimensions,OtherDimensions>::type::value
|
||||
));
|
||||
}
|
||||
</pre>
|
||||
<!-- @ example.wrap('''
|
||||
#include <boost/mpl/equal.hpp>
|
||||
|
||||
template <class T, class Dimensions>
|
||||
struct quantity
|
||||
{
|
||||
explicit quantity(T x)
|
||||
: m_value(x)
|
||||
{}
|
||||
|
||||
T value() const { return m_value; }
|
||||
''','''
|
||||
private:
|
||||
T m_value;
|
||||
};''')
|
||||
|
||||
stack[quantity_declaration] = example
|
||||
stack[-1] = bogus_example
|
||||
compile('all', pop = 1, expect_error = True) -->
|
||||
<p>Now, if the dimensions of the two quantities fail to match, the
|
||||
assertion will cause a compilation error.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./implementing-addition-and.html" class="navigation-link">Prev</a> <a href="./implementing-division.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./implementing-addition-and.html" class="navigation-link">Back</a> <a href="./implementing-division.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Incomplete Support for Lambda Expressions</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./broken-integral-constant.html" class="navigation-link">Prev</a> <a href="./eti.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./broken-integral-constant.html" class="navigation-link">Back</a> <a href="./eti.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./portability.html" class="navigation-link">Portability</a> / <a href="./incomplete-support-for.html" class="navigation-link">Incomplete Support for Lambda Expressions</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="incomplete-support-for">
|
||||
<h1><a class="toc-backref" href="./portability.html#id75" name="incomplete-support-for">Incomplete Support for Lambda Expressions</a></h1>
|
||||
<p>Seasoned MPL users will agree with us that if there is
|
||||
anything in the MPL that is seemingly magical both in power and
|
||||
its nature, then it's MPL lambda expressions. In reality, the
|
||||
mechanism that bring this to life is very straightforward and
|
||||
probably can be explained to anyone generally familiar with C++
|
||||
templates in less than 10 minutes.</p>
|
||||
<!-- People are going to hate you for saying so and not actually -->
|
||||
<!-- explaining it. -->
|
||||
<p>Unfortunately, this mechanism also happens to rely on support for
|
||||
partial template specialization and template template parameters.
|
||||
Among the so-called deficient compilers — basically, most of the
|
||||
compilers released before the year 2000 — the chances are poor
|
||||
that you'll find <em>complete</em> support for <em>both</em> of these features.
|
||||
Please see our <a class="reference" href="./portability.html#compatibility-table">compatibility table</a> for the list of the products
|
||||
which fall into this category.</p>
|
||||
<p>Although it's not possible to implement <em>fully transparent</em> lambda
|
||||
expressions without these two features, a slightly more limited
|
||||
implementation that requires some manual assistance from the
|
||||
metafunction author is possible. This section describes the manual
|
||||
work required and the limitations of the result.</p>
|
||||
<div class="section" id="incomplete-the-problem">
|
||||
<h2><a name="incomplete-the-problem">The Problem</a></h2>
|
||||
<p>If your compiler falls into the "deficient" category, the following
|
||||
valid MPL metaprogram will fail to compile for you:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/apply.hpp>
|
||||
|
||||
using namespace boost::mpl;
|
||||
|
||||
template< typename T > struct add_const
|
||||
{
|
||||
typedef T const type;
|
||||
};
|
||||
|
||||
typedef apply1< add_const<_1>,int >::type t; // t == int const
|
||||
</pre>
|
||||
<p>Worse yet, chances are it wil fail with a diagnostic backtrace
|
||||
leading you into the inside of the library and possibly creating an
|
||||
impression that there's something's wrong there. The fact is, both
|
||||
the program and the library are defect free (for the
|
||||
purpose of this particular demonstraction), and it's your compiler
|
||||
that is to blame.</p>
|
||||
</div>
|
||||
<div class="section" id="incomplete-the-solution">
|
||||
<h2><a name="incomplete-the-solution">The Solution</a></h2>
|
||||
<p>As previously mentioned, the solution requires some work from
|
||||
metafunction authors, but for the users of those metafunctions, the
|
||||
result is relatively transparent. Here's what we have to do to our
|
||||
earlier example:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/apply.hpp>
|
||||
<strong>#include <boost/mpl/aux_/lambda_support.hpp></strong>
|
||||
|
||||
using namespace boost::mpl;
|
||||
|
||||
template< typename T > struct add_const
|
||||
{
|
||||
typedef T const type;
|
||||
<strong>BOOST_MPL_AUX_LAMBDA_SUPPORT(1, add_const, (T))</strong>
|
||||
};
|
||||
|
||||
typedef apply1< add_const<_1>,int >::type t; // t == int const
|
||||
</pre>
|
||||
<p>With these two modifications, now the compiler that has been barking at us now
|
||||
happily accepts it. "Hey, that's not that bad at all!" you might say. Just put a
|
||||
little macro inside and be happy again.</p>
|
||||
</div>
|
||||
<div class="section" id="limitations">
|
||||
<h2><a name="limitations">Limitations</a></h2>
|
||||
<p>Unfortunately, that's not quite the end of the story. There are
|
||||
still cases where the above approach will fail and we will have to
|
||||
resort to writing out-of-line metafunction class. Here are the
|
||||
details:</p>
|
||||
<blockquote>
|
||||
<p>To make the lambda expression work without partial template
|
||||
specialization and
|
||||
template template parameters, the MPL has to implement some other way of
|
||||
pulling apart the template instantiations' expression tree, and the only way
|
||||
to do it is through an intrusive metafunction introspection
|
||||
mechanism. That's what hidden behind the <tt class="literal"><span class="pre">BOOST_MPL_AUX_LAMBDA_SUPPORT</span></tt> macro
|
||||
we've seen above.</p>
|
||||
<p>But then, after we've got the information we need (the metafunction's arity
|
||||
and its exact template arguments) stored inside the metafunction itself,
|
||||
the only way for the library to access it is to look inside the metafunction.
|
||||
The latter, in its turn, means instantiating the metafunction, prematurely,
|
||||
before the actuall call, <em>with one or more placeholder arguments</em>. This last
|
||||
part is a potential problem.</p>
|
||||
</blockquote>
|
||||
<p>In other words, the mechanism works as long as your metafunction is
|
||||
"placeholder-safe" (can be safely instantiated on placeholder
|
||||
arguments), which comes down to the follwing two criteria:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>The metafunction doesn't access its arguments' nested members, or</li>
|
||||
<li>The only accessed members are types named <tt class="literal"><span class="pre">::tag</span></tt> or <tt class="literal"><span class="pre">::type</span></tt> (the
|
||||
placeholders do contain these).</li>
|
||||
</ol>
|
||||
<p>If these two hold, you can safely put <tt class="literal"><span class="pre">BOOST_MPL_AUX_LAMBDA_SUPPORT</span></tt> inside
|
||||
your metafunction and forget about the issue. If not, your are out of luck and
|
||||
probably have to write a metafunction class instead.</p>
|
||||
<p>The good news are that most of the MPL's own metafunctions and <a class="reference" href="../../../type_traits/index.html" target="_top">Boost.Type Traits</a>
|
||||
templates are "placeholder-safe" and have the workaround applied to them, so
|
||||
even on broken compilers things "just work" in about 90% of use cases.</p>
|
||||
<p>Please refer to the MPL <a class="reference" href="./reference-manual.html">reference manual</a> for the details on the
|
||||
<tt class="literal"><span class="pre">BOOST_MPL_AUX_LAMBDA_SUPPORT</span></tt> macro.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./broken-integral-constant.html" class="navigation-link">Prev</a> <a href="./eti.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./broken-integral-constant.html" class="navigation-link">Back</a> <a href="./eti.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./portability.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Iterator Protocol</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./apply-lambda-semantics.html" class="navigation-link">Prev</a> <a href="./tag-dispatching-protocol.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./apply-lambda-semantics.html" class="navigation-link">Back</a> <a href="./tag-dispatching-protocol.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./iterator-protocol.html" class="navigation-link">Iterator Protocol</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="iterator-protocol">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id65" name="iterator-protocol">Iterator Protocol</a></h1>
|
||||
<p>The library no longer guarantees or relies on the direct presence
|
||||
of <tt class="literal"><span class="pre">advance</span></tt> / <tt class="literal"><span class="pre">distance</span></tt> / <tt class="literal"><span class="pre">next</span></tt> / <tt class="literal"><span class="pre">prior</span></tt> / <tt class="literal"><span class="pre">type</span></tt>
|
||||
members in iterator types; the following table summarises the new
|
||||
requirements:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="50%" />
|
||||
<col width="50%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th>Before</th>
|
||||
<th>Now</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="literal"><span class="pre">i::type</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">deref<i>::type</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="literal"><span class="pre">i::next</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">next<i>::type</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="literal"><span class="pre">i::prior</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">prior<i>::type</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="literal"><span class="pre">i::advance<n>::type</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">advance<i,n>::type</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="literal"><span class="pre">i::distance<j>::type</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">distance<i,j>::type</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="literal"><span class="pre">i::category</span></tt></td>
|
||||
<td><tt class="literal"><span class="pre">i::category</span></tt></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./apply-lambda-semantics.html" class="navigation-link">Prev</a> <a href="./tag-dispatching-protocol.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./apply-lambda-semantics.html" class="navigation-link">Back</a> <a href="./tag-dispatching-protocol.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Lambda and Non-Metafunction Templates</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<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>
|
||||
<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>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="lambda-and-non">
|
||||
<h1><a class="toc-backref" href="./lambda-details.html#id57" name="lambda-and-non">Lambda and Non-Metafunction Templates</a></h1>
|
||||
<p>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 <em>X</em> doesn't
|
||||
have a nested <tt class="literal"><span class="pre">::type</span></tt>, the result is just
|
||||
<em>X</em> itself.</p>
|
||||
<p>For example, <tt class="literal"><span class="pre">mpl::apply<std::vector<_>,</span> <span class="pre">T></span></tt> is always just
|
||||
<tt class="literal"><span class="pre">std::vector<T></span></tt>. If it weren't for this behavior, we would
|
||||
have to build trivial metafunctions to create ordinary template
|
||||
specializations in lambda expressions:</p>
|
||||
<pre class="literal-block">
|
||||
// trivial std::vector generator
|
||||
template<class U>
|
||||
struct make_vector { typedef std::vector<U> type; };
|
||||
|
||||
typedef mpl::apply<<strong>make_vector<_></strong>, T>::type vector_of_t;
|
||||
</pre>
|
||||
<p>Instead, we can simply write:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::apply<<strong>std::vector<_></strong>, T>::type vector_of_t;
|
||||
</pre>
|
||||
<!-- @ # ensure indentation works. The ReST parser will push the 2nd line left
|
||||
while stack:
|
||||
stack[-1].prepend('#include <vector>\ntypedef int T;')
|
||||
compile() -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Lambda Details</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./metafunction-composition.html" class="navigation-link">Prev</a> <a href="./placeholders.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Back</a> <a href="./details.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>
|
||||
<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></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="lambda-details">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id54" name="lambda-details">Lambda Details</a></h1>
|
||||
<p>Now that you have an idea of the semantics of MPL's <tt class="literal"><span class="pre">lambda</span></tt>
|
||||
facility, let's formalize that understanding and look at things a
|
||||
little more deeply.</p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./placeholders.html" id="id55" name="id55">Placeholders</a></li>
|
||||
<li><a class="reference" href="./placeholder-expression.html" id="id56" name="id56">Placeholder Expression Definition</a></li>
|
||||
<li><a class="reference" href="./lambda-and-non.html" id="id57" name="id57">Lambda and Non-Metafunction Templates</a></li>
|
||||
<li><a class="reference" href="./the-importance-of-being.html" id="id58" name="id58">The Importance of Being Lazy</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./metafunction-composition.html" class="navigation-link">Prev</a> <a href="./placeholders.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Back</a> <a href="./details.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Metafunction Composition</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Prev</a> <a href="./lambda-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.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>
|
||||
<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="./more-lambda-capabilities.html" class="navigation-link">More Lambda Capabilities</a> / <a href="./metafunction-composition.html" class="navigation-link">Metafunction Composition</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="metafunction-composition">
|
||||
<h1><a class="toc-backref" href="./more-lambda-capabilities.html#id53" name="metafunction-composition">Metafunction Composition</a></h1>
|
||||
<p>Lambda expressions can also be used to assemble more interesting
|
||||
computations from simple metafunctions. For example, the following
|
||||
expression, which multiplies the sum of two numbers by their
|
||||
difference, is a <strong>composition</strong> of the three metafunctions <tt class="literal"><span class="pre">multiplies</span></tt>,
|
||||
<tt class="literal"><span class="pre">plus</span></tt>, and <tt class="literal"><span class="pre">minus</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
mpl::multiplies<mpl::plus<_1,_2>, mpl::minus<_1,_2> >
|
||||
</pre>
|
||||
<!-- @ example.wrap(apply_test[0],
|
||||
', mpl::int_<5>,mpl::int_<3>' + apply_test[1] % 16)
|
||||
# Can't exactly justify this yet, but there's no way to get
|
||||
# it into the text
|
||||
prefix += ['#include <boost/mpl/multiplies.hpp>']
|
||||
compile() -->
|
||||
<p>When evaluating a lambda expression, MPL checks to see if any of its
|
||||
arguments are themselves lambda expressions, and evaluates each one
|
||||
that it finds. The results of these inner evaluations are substituted
|
||||
into the outer expression before it is evaluated.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Prev</a> <a href="./lambda-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./partial-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Miscellaneous</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./renaming-cleanup.html" class="navigation-link">Prev</a> <a href="./technical-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./renaming-cleanup.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./miscellaneous.html" class="navigation-link">Miscellaneous</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="miscellaneous">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id69" name="miscellaneous">Miscellaneous</a></h1>
|
||||
<ol class="arabic">
|
||||
<li><p class="first"><tt class="literal"><span class="pre">vector</span></tt> has been re-implemented to support constant-time
|
||||
insertion at both the beginning and the end. For example, this is now
|
||||
well-formed for a vector <tt class="literal"><span class="pre">v</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
typedef push_back<v,int>::type v1;
|
||||
typedef push_front<v1,int>::type v2;
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">The interfaces of some sequence building algorithms such as
|
||||
<tt class="literal"><span class="pre">copy</span></tt> have been changed. Please see the <a class="reference" href="./reference-manual.html">reference manual</a> for the
|
||||
details of the new interface.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./renaming-cleanup.html" class="navigation-link">Prev</a> <a href="./technical-details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./renaming-cleanup.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: More Lambda Capabilities</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-apply-metafunction.html" class="navigation-link">Prev</a> <a href="./partial-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.html" class="navigation-link">Back</a> <a href="./lambda-details.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>
|
||||
<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="./more-lambda-capabilities.html" class="navigation-link">More Lambda Capabilities</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="more-lambda-capabilities">
|
||||
<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id51" name="more-lambda-capabilities">More Lambda Capabilities</a></h1>
|
||||
<p>Lambda expressions provide much more than just the ability to pass a
|
||||
metafunction as an argument. The two capabilities described next
|
||||
combine to make lambda expressions an invaluable part of almost every
|
||||
metaprogramming task.</p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./partial-metafunction.html" id="id52" name="id52">Partial Metafunction Application</a></li>
|
||||
<li><a class="reference" href="./metafunction-composition.html" id="id53" name="id53">Metafunction Composition</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-apply-metafunction.html" class="navigation-link">Prev</a> <a href="./partial-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.html" class="navigation-link">Back</a> <a href="./lambda-details.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Numeric Metafunction Protocol/Infrastructure</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tag-dispatching-protocol.html" class="navigation-link">Prev</a> <a href="./renaming-cleanup.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tag-dispatching-protocol.html" class="navigation-link">Back</a> <a href="./renaming-cleanup.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./numeric-metafunction.html" class="navigation-link">Numeric Metafunction Protocol/Infrastructure</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="numeric-metafunction">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id67" name="numeric-metafunction">Numeric Metafunction Protocol/Infrastructure</a></h1>
|
||||
<p>The arithmetic, comparison and bitwise metafunctions are now
|
||||
<cite>polymorphic</cite>, and can operate on a variety of numeric types,
|
||||
including rational, fixed-point and complex numbers. They allow
|
||||
<cite>mixed arithmetic</cite>, meaning that you can perform an operation on
|
||||
arguments of different types, and the result will yeild the
|
||||
largest/most general of the argument types. The infrastructure
|
||||
allows user-defined numeric types to be freely intermixed with
|
||||
predefined library types. See
|
||||
<a class="reference" href="http://cvs.sourceforge.net/viewcvs.py/boost/boost/libs/mpl/test/numeric_ops.cpp?view=markup" target="_top">http://cvs.sourceforge.net/viewcvs.py/boost/boost/libs/mpl/test/numeric_ops.cpp?view=markup</a>
|
||||
for an illustrative example, and the <a class="reference" href="./reference-manual.html">reference manual</a> for
|
||||
the formal infrastructure specification.</p>
|
||||
<p>If you were using MPL numeric metafunctions on your own integral
|
||||
wrapper class similar to <tt class="literal"><span class="pre">mpl::int_</span></tt>, you can plug your class
|
||||
into the new infrustructure by extending it with the following
|
||||
member:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::integral_c_tag tag;
|
||||
</pre>
|
||||
<p>For example:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="48%" />
|
||||
<col width="52%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th>Before</th>
|
||||
<th>Now</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><pre class="first last literal-block">
|
||||
template< int n > struct my_int
|
||||
{
|
||||
static int const value = n;
|
||||
typedef my_int type;
|
||||
};
|
||||
</pre>
|
||||
</td>
|
||||
<td><pre class="first last literal-block">
|
||||
template< int n > struct my_int
|
||||
{
|
||||
<strong>typedef mpl::integral_c_tag tag;</strong>
|
||||
static int const value = n;
|
||||
typedef my_int type;
|
||||
};
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tag-dispatching-protocol.html" class="navigation-link">Prev</a> <a href="./renaming-cleanup.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tag-dispatching-protocol.html" class="navigation-link">Back</a> <a href="./renaming-cleanup.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Partial Metafunction Application</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Prev</a> <a href="./metafunction-composition.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./metafunction-composition.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.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>
|
||||
<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="./more-lambda-capabilities.html" class="navigation-link">More Lambda Capabilities</a> / <a href="./partial-metafunction.html" class="navigation-link">Partial Metafunction Application</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="partial-metafunction">
|
||||
<h1><a class="toc-backref" href="./more-lambda-capabilities.html#id52" name="partial-metafunction">Partial Metafunction Application</a></h1>
|
||||
<p>Consider the lambda expression <tt class="literal"><span class="pre">mpl::plus<_1,_1></span></tt>. A single
|
||||
argument is directed to both of <tt class="literal"><span class="pre">plus</span></tt>'s parameters, thereby
|
||||
adding a number to itself. Thus, a <em>binary</em> metafunction,
|
||||
<tt class="literal"><span class="pre">plus</span></tt>, is used to build a <em>unary</em> lambda expression. In other
|
||||
words, we've created a whole new computation! We're not done yet,
|
||||
though: By supplying a non-placeholder as one of the arguments, we
|
||||
can build a unary lambda expression that adds a fixed value, say
|
||||
42, to its argument:</p>
|
||||
<pre class="literal-block">
|
||||
mpl::plus<_1, mpl::int_<42> >
|
||||
</pre>
|
||||
<!-- @ apply_test = 'enum { value = mpl::apply<', ''' >::type::value };
|
||||
BOOST_STATIC_ASSERT(value == %d);'''
|
||||
|
||||
example.wrap(apply_test[0],
|
||||
', mpl::int_<3>' + apply_test[1] % 45)
|
||||
compile() -->
|
||||
<p>The process of binding argument values to a subset of a function's
|
||||
parameters is known in the world of functional programming as
|
||||
<strong>partial function application</strong>.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./more-lambda-capabilities.html" class="navigation-link">Prev</a> <a href="./metafunction-composition.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./metafunction-composition.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./more-lambda-capabilities.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Physical Structure</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./technical-details.html" class="navigation-link">Prev</a> <a href="./dependencies.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./dependencies.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./physical-structure.html" class="navigation-link">Physical Structure</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="physical-structure">
|
||||
<h1><a class="toc-backref" href="./technical-details.html#id71" name="physical-structure">Physical Structure</a></h1>
|
||||
<p>The library uses a fine-grained header structure with one header per public
|
||||
component (class/function template), with the header named after the component. For example,
|
||||
<tt class="literal"><span class="pre">boost::mpl::apply</span></tt> is defined in the header <tt class="literal"><span class="pre"><boost/mpl/apply.hpp></span></tt>. This
|
||||
scheme ensures both that we don't pay for what we don't use in terms of compilation time
|
||||
and header dependencies, and frees us from memorizing the
|
||||
relationship between a given header and the components it
|
||||
provides. For entities that are likely to be used together,
|
||||
such as arithmetic
|
||||
metafunctions (<tt class="literal"><span class="pre">plus</span></tt>, <tt class="literal"><span class="pre">minus</span></tt>, <tt class="literal"><span class="pre">times</span></tt>, et. al.), the library also supplies
|
||||
appropriately-named composite headers
|
||||
(<tt class="literal"><span class="pre"><boost/mpl/airthmetic.hpp></span></tt>) as a convenience.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./technical-details.html" class="navigation-link">Prev</a> <a href="./dependencies.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./dependencies.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Placeholder Expression Definition</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<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> <a href="./lambda-and-non.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Back</a> <a href="./lambda-and-non.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>
|
||||
<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>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="placeholder-expression">
|
||||
<h1><a class="toc-backref" href="./lambda-details.html#id56" name="placeholder-expression">Placeholder Expression Definition</a></h1>
|
||||
<p>Now that you know just what <em>placeholder</em> means, we can define
|
||||
<em>placeholder expression</em>:</p>
|
||||
<div class="admonition-definition admonition">
|
||||
<p class="admonition-title first">Definition</p>
|
||||
<p>A placeholder expression is either:</p>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li>a placeholder</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p><em>or</em></p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li>a template specialization with at least one argument that
|
||||
is a placeholder expression.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</div>
|
||||
<p>In other words, a placeholder expression always involves a
|
||||
placeholder.</p>
|
||||
<!-- DWA: I'm still not sure we shouldn't be at least mentioning the
|
||||
pitfall, but for now it's commented out.
|
||||
|
||||
Lambda and Nullary Metafunctions
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
The definition of *placeholder expression* above has an interesting
|
||||
implication: an ordinary nullary metafunction is never a placeholder
|
||||
expression. In other words, even though ``add_pointer<int>`` is a
|
||||
nullary metafunction, it won't be invoked in the expression below;
|
||||
the assertion will always fail:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
mpl::apply<
|
||||
boost::is_same<**boost::add_pointer<int>**,_1>
|
||||
, int\*
|
||||
>::type::value
|
||||
));
|
||||
|
||||
In order to allow a nullary metafunction to be used as a lambda
|
||||
expression, MPL provides this definition of ``arg``:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
// primary template definition (not a specialization)
|
||||
template <class F>
|
||||
struct arg
|
||||
{
|
||||
template <class A1 = void\_, class A2 = void\_, ... class *Am* = void\_>
|
||||
struct apply : F
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
When applied to a lambda expression's actual arguments, ``arg<F>``
|
||||
ignores them and simply returns ``F::type``. In other words, if
|
||||
``F`` is a nullary metafunction, ``arg<F>`` is a metafunction class
|
||||
that invokes ``F`` and returns the result. So we can transform
|
||||
add_pointer<int> into a placeholder and get the desired result
|
||||
with:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
mpl::apply<
|
||||
boost::is_same<
|
||||
**mpl::arg<boost::add_pointer<int> >**
|
||||
, _1
|
||||
>
|
||||
, int\*
|
||||
>::type::value
|
||||
)); -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<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> <a href="./lambda-and-non.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./placeholders.html" class="navigation-link">Back</a> <a href="./lambda-and-non.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Placeholders</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Prev</a> <a href="./placeholder-expression.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./placeholder-expression.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>
|
||||
<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="./placeholders.html" class="navigation-link">Placeholders</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="placeholders">
|
||||
<h1><a class="toc-backref" href="./lambda-details.html#id55" name="placeholders">Placeholders</a></h1>
|
||||
<p>The definition of "placeholder" may surprise you:</p>
|
||||
<div class="admonition-definition admonition">
|
||||
<p class="admonition-title first">Definition</p>
|
||||
<p>A <strong>placeholder</strong> is a metafunction class of the form <tt class="literal"><span class="pre">mpl::arg<X></span></tt>.</p>
|
||||
</div>
|
||||
<div class="section" id="implementation">
|
||||
<h2><a name="implementation">Implementation</a></h2>
|
||||
<p>The convenient names <tt class="literal"><span class="pre">_1</span></tt>, <tt class="literal"><span class="pre">_2</span></tt>,... <tt class="literal"><span class="pre">_5</span></tt> are actually
|
||||
<tt class="literal"><span class="pre">typedef</span></tt>s for specializations of <tt class="literal"><span class="pre">mpl::arg</span></tt> that simply
|
||||
select the <em>N</em>th argument for any <em>N</em>. <a class="footnote-reference" href="#config" id="id12" name="id12">[6]</a> The
|
||||
implementation of placeholders looks something like this:</p>
|
||||
<table class="footnote" frame="void" id="config" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id12" name="config">[6]</a></td><td>MPL provides five placeholders by default. See
|
||||
the Configuration Macros section of <a class="reference" href="./reference-manual.html">the MPL reference manual</a> for a
|
||||
description of how to change the number of placeholders
|
||||
provided.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<pre class="literal-block">
|
||||
namespace boost { namespace mpl { namespace placeholders {
|
||||
|
||||
template <int N> struct arg; // forward declarations
|
||||
struct void_;
|
||||
|
||||
template <>
|
||||
struct arg<<strong>1</strong>>
|
||||
{
|
||||
template <
|
||||
class <strong>A1</strong>, class A2 = void_, ... class A<em>m</em> = void_>
|
||||
struct apply
|
||||
{
|
||||
typedef <strong>A1</strong> type; // return the first argument
|
||||
};
|
||||
};
|
||||
typedef <strong>arg<1> _1</strong>;
|
||||
|
||||
template <>
|
||||
struct arg<<strong>2</strong>>
|
||||
{
|
||||
template <
|
||||
class A1, class <strong>A2</strong>, class A3 = void_, ...class A<em>m</em> = void_
|
||||
>
|
||||
struct apply
|
||||
{
|
||||
typedef <strong>A2</strong> type; // return the second argument
|
||||
};
|
||||
};
|
||||
typedef <strong>arg<2> _2</strong>;
|
||||
|
||||
<em>more specializations and typedefs...</em>
|
||||
|
||||
}}}
|
||||
</pre>
|
||||
<!-- @example.replace('...','') -->
|
||||
<p>Remember that invoking a metafunction class is the same as invoking
|
||||
its nested <tt class="literal"><span class="pre">apply</span></tt> metafunction. When a placeholder in a lambda
|
||||
expression is evaluated, it is invoked on the expression's actual
|
||||
arguments, returning just one of them. The results are then
|
||||
substituted back into the lambda expression and the evaluation
|
||||
process continues.</p>
|
||||
</div>
|
||||
<div class="section" id="the-unnamed-placeholder">
|
||||
<h2><a name="the-unnamed-placeholder">The Unnamed Placeholder</a></h2>
|
||||
<p>There's one special placeholder, known as the <strong>unnamed
|
||||
placeholder</strong>, that we haven't yet defined:</p>
|
||||
<pre class="literal-block">
|
||||
namespace boost { namespace mpl { namespace placeholders {
|
||||
|
||||
<strong>typedef arg<-1> _;</strong> // the unnamed placeholder
|
||||
|
||||
}}}
|
||||
</pre>
|
||||
<!-- @ stack[-2].prepend('namespace shield {')
|
||||
example.append('}') # so we don't conflict with the prefix
|
||||
compile('all') -->
|
||||
<p>The details of its implementation aren't important; all you really
|
||||
need to know about the unnamed placeholder is that it gets special
|
||||
treatment. When a lambda expression is being transformed into a
|
||||
metafunction class by <tt class="literal"><span class="pre">mpl::lambda</span></tt>,</p>
|
||||
<blockquote>
|
||||
the <em>n</em>th appearance of the unnamed placeholder <em>in a given
|
||||
template specialization</em> is replaced with <tt class="literal"><span class="pre">_</span></tt><em>n</em>.</blockquote>
|
||||
<p>So, for example, every row of Table 1.1
|
||||
below contains two equivalent lambda expressions.</p>
|
||||
<table border="1" class="table">
|
||||
<caption>Unnamed Placeholder Semantics</caption>
|
||||
<colgroup>
|
||||
<col width="48%" />
|
||||
<col width="52%" />
|
||||
</colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td><pre class="first last literal-block">
|
||||
mpl::plus<_,_>
|
||||
</pre>
|
||||
</td>
|
||||
<td><pre class="first last literal-block">
|
||||
mpl::plus<_1,_2>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td><pre class="first last literal-block">
|
||||
boost::is_same<
|
||||
_
|
||||
, boost::add_pointer<_>
|
||||
>
|
||||
</pre>
|
||||
</td>
|
||||
<td><pre class="first last literal-block">
|
||||
boost::is_same<
|
||||
_1
|
||||
, boost::add_pointer<_1>
|
||||
>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td><pre class="first last literal-block">
|
||||
mpl::multiplies<
|
||||
mpl::plus<_,_>
|
||||
, mpl::minus<_,_>
|
||||
>
|
||||
</pre>
|
||||
</td>
|
||||
<td><pre class="first last literal-block">
|
||||
mpl::multiplies<
|
||||
mpl::plus<_1,_2>
|
||||
, mpl::minus<_1,_2>
|
||||
>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- @ for n in range(len(stack)):
|
||||
stack[n].wrap('typedef ', 'type%d;' % n)
|
||||
compile('all') -->
|
||||
<p>Especially when used in simple lambda expressions, the unnamed
|
||||
placeholder often eliminates just enough syntactic "noise" to
|
||||
significantly improve readability.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./lambda-details.html" class="navigation-link">Prev</a> <a href="./placeholder-expression.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./placeholder-expression.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Portability</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./dependencies.html" class="navigation-link">Prev</a> <a href="./broken-integral-constant.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dependencies.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a> / <a href="./portability.html" class="navigation-link">Portability</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="portability">
|
||||
<h1><a class="toc-backref" href="./technical-details.html#id73" name="portability">Portability</a></h1>
|
||||
<p>It has always been a major goal of MPL development that a program
|
||||
using the MPL should compile and run without modification on a wide
|
||||
variety of compilers. To this end, the library goes to great
|
||||
lengths to hide the quirks of less-than-perfect compilers. Of
|
||||
course, there is only that much that you can do about an utterly
|
||||
broken compiler. This section describes the places where those
|
||||
quirks "leak out" of the library abstraction layer, and what you can
|
||||
do about it when they do.</p>
|
||||
<p>With respect to MPL compatibility we divide C++ compilers roughly
|
||||
into three categories:</p>
|
||||
<ol class="upperalpha simple">
|
||||
<li>Reasonably conforming compilers that "just work" with the MPL.</li>
|
||||
<li>Not-so-conforming compilers that work but require some workarounds in user code.</li>
|
||||
<li>Compilers that are so broken that it's not practical to use them for any serious
|
||||
metaprogramming work.</li>
|
||||
</ol>
|
||||
<p>We haven't tested every compiler in existence (simply because we don't have access to
|
||||
all of them), but chances are the table below
|
||||
will give you the information you are looking for. Please note that
|
||||
the fact that one version of a compiler appears
|
||||
in this list as "Not supported" does <em>not</em> mean that future versions are also
|
||||
unworkable — some vendors are working hard to correct the
|
||||
problems... and, as of this writing (late 2004), some are not.</p>
|
||||
<p>Please keep in mind that this is not a complete list!</p>
|
||||
<a class="target" id="compatibility-table" name="compatibility-table"></a><table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="27%" />
|
||||
<col width="11%" />
|
||||
<col width="11%" />
|
||||
<col width="51%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th>Compiler</th>
|
||||
<th>Versions</th>
|
||||
<th>Category</th>
|
||||
<th>Problematic Areas (if any)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td>Borland C++</td>
|
||||
<td>5.6.4</td>
|
||||
<td>B</td>
|
||||
<td><a class="reference" href="./incomplete-support-for.html">Lambda Expressions</a>, <a class="reference" href="./broken-integral-constant.html">Integral Constant Expressions</a></td>
|
||||
</tr>
|
||||
<tr><td>Borland C++</td>
|
||||
<td>5.6.1</td>
|
||||
<td>C</td>
|
||||
<td><strong>Not supported</strong></td>
|
||||
</tr>
|
||||
<tr><td>Comeau C/C++</td>
|
||||
<td>4.2.45,
|
||||
4.3.3</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>Compaq C++ (Tru64 UNIX)</td>
|
||||
<td>6.5</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>GCC</td>
|
||||
<td>3.2.2,
|
||||
3.3.1, 3.4</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>GCC</td>
|
||||
<td>2.95.3</td>
|
||||
<td>B</td>
|
||||
<td><a class="reference" href="./broken-integral-constant.html">Integral Constant Expressions</a></td>
|
||||
</tr>
|
||||
<tr><td>HP aCC</td>
|
||||
<td>3.55</td>
|
||||
<td>C</td>
|
||||
<td><strong>Not supported</strong></td>
|
||||
</tr>
|
||||
<tr><td>Intel C++</td>
|
||||
<td>7.1, 8.0</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>Metrowerks CodeWarrior</td>
|
||||
<td>8.3, 9.2</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>Microsoft Visual C++</td>
|
||||
<td>7.1</td>
|
||||
<td>A</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td>Microsoft Visual C++</td>
|
||||
<td>6.0 sp5,
|
||||
7.0</td>
|
||||
<td>B</td>
|
||||
<td><a class="reference" href="./incomplete-support-for.html">Lambda Expressions</a>, <a class="reference" href="./eti.html">ETI</a>, <a class="reference" href="./broken-integral-constant.html">Integral Constant Expressions</a></td>
|
||||
</tr>
|
||||
<tr><td>SGI MIPSpro</td>
|
||||
<td>7.3</td>
|
||||
<td>B</td>
|
||||
<td><a class="reference" href="./broken-integral-constant.html">Integral Constant Expressions</a></td>
|
||||
</tr>
|
||||
<tr><td>Sun CC</td>
|
||||
<td>5.6</td>
|
||||
<td>C</td>
|
||||
<td><strong>Not supported</strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./broken-integral-constant.html" id="id74" name="id74">Broken Integral Constant Expressions</a></li>
|
||||
<li><a class="reference" href="./incomplete-support-for.html" id="id75" name="id75">Incomplete Support for Lambda Expressions</a></li>
|
||||
<li><a class="reference" href="./eti.html" id="id76" name="id76">ETI</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./dependencies.html" class="navigation-link">Prev</a> <a href="./broken-integral-constant.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dependencies.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Reference Manual</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./exercises.html" class="navigation-link">Prev</a> <a href="./changelog-history.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Back</a> <a href="./changelog-history.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./reference-manual.html" class="navigation-link">Reference Manual</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="reference-manual">
|
||||
<h1><a class="toc-backref" href="../index.html#id61" name="reference-manual">Reference Manual</a></h1>
|
||||
<p>The MPL reference manual is an annotated formal specification of the
|
||||
library's public interface. The manual is available in two forms:</p>
|
||||
<ul class="simple">
|
||||
<li>A fully cross-referenced set of <a class="reference" href="../refmanual.html" target="_top">HTML pages</a>.</li>
|
||||
<li>A cross-referenced, printer-ready <a class="reference" href="../refmanual.pdf" target="_top">PDF</a>.</li>
|
||||
</ul>
|
||||
<p>Please choose the form that is most convenient for you, and enjoy!</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./exercises.html" class="navigation-link">Prev</a> <a href="./changelog-history.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Back</a> <a href="./changelog-history.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Renaming/Cleanup</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./numeric-metafunction.html" class="navigation-link">Prev</a> <a href="./miscellaneous.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./numeric-metafunction.html" class="navigation-link">Back</a> <a href="./miscellaneous.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./renaming-cleanup.html" class="navigation-link">Renaming/Cleanup</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="renaming-cleanup">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id68" name="renaming-cleanup">Renaming/Cleanup</a></h1>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">The <tt class="literal"><span class="pre">apply_if</span></tt> metafunction has been renamed to <tt class="literal"><span class="pre">eval_if</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">All <tt class="literal"><span class="pre">_backward</span></tt> algorithm counterparts have been renamed to use <tt class="literal"><span class="pre">reverse_</span></tt>
|
||||
prefix; e.g. <tt class="literal"><span class="pre">fold_backward</span></tt> became <tt class="literal"><span class="pre">reverse_fold</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">The <tt class="literal"><span class="pre"><boost/mpl/aux_/has_xxx.hpp></span></tt> header has been made public and became
|
||||
<tt class="literal"><span class="pre"><boost/mpl/has_xxx.hpp></span></tt>; correspondingly, the <tt class="literal"><span class="pre">BOOST_MPL_NO_AUX_HAS_XXX</span></tt>
|
||||
macro was renamed to <tt class="literal"><span class="pre">BOOST_MPL_CFG_NO_HAS_XXX</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first"><tt class="literal"><span class="pre"><boost/mpl/assert_is_same.hpp></span></tt> header has been replaced by a more
|
||||
general <tt class="literal"><span class="pre"><mpl/assert.hpp></span></tt>; the new asserts provide a significantly
|
||||
higher-quality diagnostics. See the table below for new equivalents of
|
||||
the old macros:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="45%" />
|
||||
<col width="55%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th><p class="first last">Before</p>
|
||||
</th>
|
||||
<th><p class="first last">Now</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><p class="first last"><tt class="literal"><span class="pre">BOOST_MPL_ASSERT_IS_SAME(t1,</span> <span class="pre">t2)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">BOOST_MPL_ASSERT((</span> <span class="pre">boost::is_same<t1,t2></span> <span class="pre">))</span></tt></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td><p class="first last"><tt class="literal"><span class="pre">BOOST_MPL_ASSERT_IS_NOT_SAME(t1,</span> <span class="pre">t2)</span></tt></p>
|
||||
</td>
|
||||
<td><p class="first last"><tt class="literal"><span class="pre">BOOST_MPL_ASSERT_NOT((</span> <span class="pre">boost::is_same<t1,t2></span> <span class="pre">))</span></tt></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>The "Macros/Asserts" section of the <a class="reference" href="./reference-manual.html">reference manual</a> provides a
|
||||
complete formal specification of the new macros' semantics.</p>
|
||||
</li>
|
||||
<li><p class="first">All configuration macros have been renamed to include the <tt class="literal"><span class="pre">CFG</span></tt> prefix; in
|
||||
particular, <tt class="literal"><span class="pre">BOOST_MPL_NO_FULL_LAMBDA_SUPPORT</span></tt> has become
|
||||
<tt class="literal"><span class="pre">BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">The following public headers/components have been renamed or removed as
|
||||
obsolete:</p>
|
||||
<pre class="literal-block">
|
||||
iterator_tag.hpp (renamed to iterator_tags.hpp)
|
||||
project1st.hpp
|
||||
project2nd.hpp
|
||||
select1st.hpp
|
||||
select2nd.hpp
|
||||
</pre>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./numeric-metafunction.html" class="navigation-link">Prev</a> <a href="./miscellaneous.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./numeric-metafunction.html" class="navigation-link">Back</a> <a href="./miscellaneous.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,153 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Representing Dimensions</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./dimensional-analysis.html" class="navigation-link">Prev</a> <a href="./representing-quantities.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./representing-quantities.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a> / <a href="./representing-dimensions.html" class="navigation-link">Representing Dimensions</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="representing-dimensions">
|
||||
<h1><a class="toc-backref" href="./dimensional-analysis.html#id42" name="representing-dimensions">Representing Dimensions</a></h1>
|
||||
<p>An international standard called <em>Système
|
||||
International d'Unites</em> (SI), breaks every quantity down into a
|
||||
combination of the dimensions <em>mass</em>, <em>length</em> (or <em>position</em>),
|
||||
<em>time</em>, <em>charge</em>, <em>temperature</em>, <em>intensity</em>, and <em>angle</em>. To be
|
||||
reasonably general, our system would have to be able to
|
||||
represent seven or more fundamental dimensions. It also needs
|
||||
the ability to represent composite dimensions that, like <em>force</em>,
|
||||
are built through multiplication or division of the fundamental
|
||||
ones.</p>
|
||||
<p>In general, a composite dimension is the product of powers of
|
||||
fundamental dimensions. <a class="footnote-reference" href="#divisor" id="id6" name="id6">[1]</a> If we were going to represent
|
||||
these powers for manipulation at runtime, we could use an array of
|
||||
seven <tt class="literal"><span class="pre">int</span></tt>s, with each position in the array holding the power
|
||||
of a different fundamental dimension:</p>
|
||||
<pre class="literal-block">
|
||||
typedef int dimension[7]; // m l t ...
|
||||
dimension const mass = {1, 0, 0, 0, 0, 0, 0};
|
||||
dimension const length = {0, 1, 0, 0, 0, 0, 0};
|
||||
dimension const time = {0, 0, 1, 0, 0, 0, 0};
|
||||
...
|
||||
</pre>
|
||||
<table class="footnote" frame="void" id="divisor" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id6" name="divisor">[1]</a></td><td>Divisors just contribute negative exponents, since
|
||||
1/<em>x</em> = <em>x</em><sup>-1</sup>.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>In that representation, force would be:</p>
|
||||
<pre class="literal-block">
|
||||
dimension const force = {1, 1, -2, 0, 0, 0, 0};
|
||||
</pre>
|
||||
<!-- @compile(2) -->
|
||||
<!-- @litre_translator.line_offset -= 7 -->
|
||||
<p>that is, <em>mlt</em><sup>-2</sup>. However, if we want to get dimensions into the
|
||||
type system, these arrays won't do the trick: they're all
|
||||
the same type! Instead, we need types that <em>themselves</em> represent
|
||||
sequences of numbers, so that two masses have the same type and a
|
||||
mass is a different type from a length.</p>
|
||||
<p>Fortunately, the MPL provides us with a collection of <strong>type
|
||||
sequences</strong>. For example, we can build a sequence of the built-in
|
||||
signed integral types this way:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
typedef boost::mpl::vector<
|
||||
signed char, short, int, long> signed_types;
|
||||
</pre>
|
||||
<p>How can we use a type sequence to represent numbers? Just as
|
||||
numerical metafunctions pass and return wrapper <em>types</em> having a
|
||||
nested <tt class="literal"><span class="pre">::value</span></tt>, so numerical sequences are really sequences of
|
||||
wrapper types (another example of polymorphism). To make this sort
|
||||
of thing easier, MPL supplies the <tt class="literal"><span class="pre">int_<N></span></tt> class template, which
|
||||
presents its integral argument as a nested <tt class="literal"><span class="pre">::value</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/int.hpp>
|
||||
|
||||
namespace mpl = boost::mpl; // namespace alias
|
||||
static int const five = mpl::int_<5>::value;
|
||||
</pre>
|
||||
<div class="sidebar">
|
||||
<p class="sidebar-title first">Namespace Aliases</p>
|
||||
<div class="line-block">
|
||||
<div class="line"><tt class="literal"><span class="pre">namespace</span></tt> <em>alias</em> <tt class="literal"><span class="pre">=</span></tt> <em>namespace-name</em><tt class="literal"><span class="pre">;</span></tt></div>
|
||||
</div>
|
||||
<p>declares <em>alias</em> to be a synonym for <em>namespace-name</em>. Many
|
||||
examples in this book will use <tt class="literal"><span class="pre">mpl::</span></tt> to indicate
|
||||
<tt class="literal"><span class="pre">boost::mpl::</span></tt>, but will omit the alias that makes it legal
|
||||
C++.</p>
|
||||
</div>
|
||||
<!-- @ignore() # nonsense isn't worth testing
|
||||
prefix +=['''
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
'''] -->
|
||||
<p>In fact, the library contains a whole suite of integral constant
|
||||
wrappers such as <tt class="literal"><span class="pre">long_</span></tt> and <tt class="literal"><span class="pre">bool_</span></tt>, each one wrapping a
|
||||
different type of integral constant within a class template.</p>
|
||||
<p>Now we can build our fundamental dimensions:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::vector<
|
||||
mpl::int_<1>, mpl::int_<0>, mpl::int_<0>, mpl::int_<0>
|
||||
, mpl::int_<0>, mpl::int_<0>, mpl::int_<0>
|
||||
> mass;
|
||||
|
||||
typedef mpl::vector<
|
||||
mpl::int_<0>, mpl::int_<1>, mpl::int_<0>, mpl::int_<0>
|
||||
, mpl::int_<0>, mpl::int_<0>, mpl::int_<0>
|
||||
> length;
|
||||
...
|
||||
</pre>
|
||||
<!-- @ # We explained about the implicit namespace alias above
|
||||
prefix.append("""
|
||||
namespace boost{namespace mpl {}}
|
||||
namespace mpl = boost::mpl;
|
||||
""")
|
||||
compile('all') -->
|
||||
<p>Whew! That's going to get tiring pretty quickly. Worse, it's hard
|
||||
to read and verify: The essential information, the powers of each
|
||||
fundamental dimension, is buried in repetitive syntactic "noise."
|
||||
Accordingly, MPL supplies <strong>integral sequence wrappers</strong> that allow
|
||||
us to write:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
|
||||
typedef mpl::vector_c<int,1,0,0,0,0,0,0> mass;
|
||||
typedef mpl::vector_c<int,0,1,0,0,0,0,0> length; // or position
|
||||
typedef mpl::vector_c<int,0,0,1,0,0,0,0> time;
|
||||
typedef mpl::vector_c<int,0,0,0,1,0,0,0> charge;
|
||||
typedef mpl::vector_c<int,0,0,0,0,1,0,0> temperature;
|
||||
typedef mpl::vector_c<int,0,0,0,0,0,1,0> intensity;
|
||||
typedef mpl::vector_c<int,0,0,0,0,0,0,1> angle;
|
||||
</pre>
|
||||
<p>Even though they have different types, you can think of these
|
||||
<tt class="literal"><span class="pre">mpl::vector_c</span></tt> specializations as being equivalent to the more
|
||||
verbose versions above that use <tt class="literal"><span class="pre">mpl::vector</span></tt>.</p>
|
||||
<p>If we want, we can also define a few composite dimensions:</p>
|
||||
<pre class="literal-block">
|
||||
// base dimension: m l t ...
|
||||
typedef mpl::vector_c<int,0,1,-1,0,0,0,0> velocity; // l/t
|
||||
typedef mpl::vector_c<int,0,1,-2,0,0,0,0> acceleration; // l/(t<sup>2</sup>)
|
||||
typedef mpl::vector_c<int,1,1,-1,0,0,0,0> momentum; // ml/t
|
||||
typedef mpl::vector_c<int,1,1,-2,0,0,0,0> force; // ml/(t<sup>2</sup>)
|
||||
</pre>
|
||||
<p>And, incidentally, the dimensions of scalars (like pi) can be
|
||||
described as:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::vector_c<int,0,0,0,0,0,0,0> scalar;
|
||||
</pre>
|
||||
<!-- @stack[0].replace('hpp>', 'hpp>\nnamespace {')
|
||||
stack[0].append('}')
|
||||
compile('all', pop = None) -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./dimensional-analysis.html" class="navigation-link">Prev</a> <a href="./representing-quantities.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./representing-quantities.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Representing Quantities</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./representing-dimensions.html" class="navigation-link">Prev</a> <a href="./implementing-addition-and.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./representing-dimensions.html" class="navigation-link">Back</a> <a href="./implementing-addition-and.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
<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="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a> / <a href="./representing-quantities.html" class="navigation-link">Representing Quantities</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="representing-quantities">
|
||||
<h1><a class="toc-backref" href="./dimensional-analysis.html#id43" name="representing-quantities">Representing Quantities</a></h1>
|
||||
<p>The types listed above are still pure metadata; to typecheck real
|
||||
computations we'll need to somehow bind them to our runtime data.
|
||||
A simple numeric value wrapper, parameterized on the number type <tt class="literal"><span class="pre">T</span></tt>
|
||||
and on its dimensions, fits the bill:</p>
|
||||
<pre class="literal-block">
|
||||
template <class T, class Dimensions>
|
||||
struct quantity
|
||||
{
|
||||
explicit quantity(T x)
|
||||
: m_value(x)
|
||||
{}
|
||||
|
||||
T value() const { return m_value; }
|
||||
private:
|
||||
T m_value;
|
||||
};
|
||||
</pre>
|
||||
<!-- @ quantity_declaration = len(stack) - 1 # Remember position for later -->
|
||||
<p>Now we have a way to represent numbers associated with dimensions.
|
||||
For instance, we can say:</p>
|
||||
<pre class="literal-block">
|
||||
quantity<float,length> l( 1.0f );
|
||||
quantity<float,mass> m( 2.0f );
|
||||
</pre>
|
||||
<p>Note that <tt class="literal"><span class="pre">Dimensions</span></tt> doesn't appear anywhere in the definition
|
||||
of <tt class="literal"><span class="pre">quantity</span></tt> outside the template parameter list; its <em>only</em>
|
||||
role is to ensure that <tt class="literal"><span class="pre">l</span></tt> and <tt class="literal"><span class="pre">m</span></tt> have different types.
|
||||
Because they do, we cannot make the mistake of assigning a length
|
||||
to a mass:</p>
|
||||
<pre class="literal-block">
|
||||
m = l; // compile-time type error
|
||||
</pre>
|
||||
<!-- @ example.wrap('void f() {', '}')
|
||||
compile('all', pop = 1, expect_error = True) -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./representing-dimensions.html" class="navigation-link">Prev</a> <a href="./implementing-addition-and.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./representing-dimensions.html" class="navigation-link">Back</a> <a href="./implementing-addition-and.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./dimensional-analysis.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Resources</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./eti.html" class="navigation-link">Prev</a> <a href="./acknowledgements.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-details.html" class="navigation-link">Back</a> <a href="./acknowledgements.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./resources.html" class="navigation-link">Resources</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="resources">
|
||||
<h1><a class="toc-backref" href="../index.html#id77" name="resources">Resources</a></h1>
|
||||
<a class="reference" href="http://www.awprofessional.com/titles/0321227255" target="_top"><img align="right" alt=""C++ Template Metaprogramming" cover" class="right-aligned" src="../tutorial/book_cover.png" /></a><p>For those of you whose interest in metaprogramming is not fully
|
||||
satisfied by this documentation, we've collected a few references
|
||||
to other resources that we think you are likely to fancy. Most
|
||||
notably, a book named "<a class="reference" href="http://www.awprofessional.com/titles/0321227255" target="_top">C++ Template Metaprogramming: Concepts,
|
||||
Tools, and Techniques from Boost and Beyond</a>" by David Abrahams
|
||||
and Aleksey Gurtovoy is considered to be the most authoritative and
|
||||
up-do-date treatment of the subject as of today. The tutorial
|
||||
included with this documentation is in fact an excerpt from this
|
||||
work.</p>
|
||||
<p>Other notable book resources include Andrei Alexandrescu's "<a class="reference" href="http://www.awprofessional.com/title/0201704315" target="_top">Modern C++ Design: Generic
|
||||
Programming and Design Patterns Applied</a>", in which
|
||||
Andrei explorers the appication of C++ metaprogramming techniques to implementing
|
||||
highly reusable and configurable generic designs, and "<a class="reference" href="http://www.josuttis.com/tmplbook/" target="_top">C++ Templates - The
|
||||
Complete Guide</a>", by David Vandevoorde and Nicolai M. Josuttis — <em>the</em> book
|
||||
on the details and workings of the C++ template system.</p>
|
||||
<p>We can also recommend a number online resources:</p>
|
||||
<ul class="simple">
|
||||
<li>Todd L. Veldhuizen, "<a class="reference" href="http://osl.iu.edu/~tveldhui/papers/Template-Metaprograms/meta-art.html" target="_top">Using C++ template metaprograms</a>", C++ Report
|
||||
Vol. 7 No. 4 (May 1995), pp. 36-43.</li>
|
||||
<li>Todd L. Veldhuizen and Dennis Gannon, "<a class="reference" href="http://osl.iu.edu/~tveldhui/papers/oo98.html" target="_top">Active Libraries: Rethinking the roles of
|
||||
compilers and libraries</a>", SIAM Workshop on Object Oriented Methods for Inter-operable
|
||||
Scientific and Engineering Computing, October 21-23, 1998</li>
|
||||
<li>Todd L. Veldhuizen, "<a class="reference" href="http://osl.iu.edu/~tveldhui/papers/pepm99/" target="_top">C++ Templates as Partial Evaluation</a>", 1999 ACM SIGPLAN
|
||||
Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM'99).</li>
|
||||
</ul>
|
||||
<!-- What about Todd's PhD dissertation? Too far off the beaten track? -->
|
||||
<p>Finally, if you come accross a high-quality, notable work on the
|
||||
topic that you think should be listed here, please <a class="reference" href="http://lists.boost.org/mailman/listinfo.cgi/boost" target="_top">let us know</a>!</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./eti.html" class="navigation-link">Prev</a> <a href="./acknowledgements.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./technical-details.html" class="navigation-link">Back</a> <a href="./acknowledgements.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Tag Dispatching Protocol</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./iterator-protocol.html" class="navigation-link">Prev</a> <a href="./numeric-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./iterator-protocol.html" class="navigation-link">Back</a> <a href="./numeric-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./changelog-history.html" class="navigation-link">Changelog & History</a> / <a href="./changes-in-boost-1-32-0.html" class="navigation-link">Changes in Boost 1.32.0 Release</a> / <a href="./tag-dispatching-protocol.html" class="navigation-link">Tag Dispatching Protocol</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="tag-dispatching-protocol">
|
||||
<h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id66" name="tag-dispatching-protocol">Tag Dispatching Protocol</a></h1>
|
||||
<p>The mechanism used to select algorithm implementations based on
|
||||
sequence family has been changed to use metafunction classes:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="53%" />
|
||||
<col width="47%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th>Before</th>
|
||||
<th>Now</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><em>name</em><tt class="literal"><span class="pre">_traits<Tag>::algorithm<...>::type</span></tt></td>
|
||||
<td><em>name</em><tt class="literal"><span class="pre">_impl<Tag>::apply<...>::type</span></tt></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>If your code implemented a custom sequence, it needs to be adjusted
|
||||
according to the above table; for example:</p>
|
||||
<table border="1" class="table">
|
||||
<colgroup>
|
||||
<col width="50%" />
|
||||
<col width="50%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th>Before</th>
|
||||
<th>Now</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><pre class="first last literal-block">
|
||||
template<> struct begin_traits<my_tag>
|
||||
{
|
||||
template< typename S > struct algorithm
|
||||
{
|
||||
typedef ... type;
|
||||
};
|
||||
};
|
||||
</pre>
|
||||
</td>
|
||||
<td><pre class="first last literal-block">
|
||||
template<> struct begin_<strong>impl</strong><my_tag>
|
||||
{
|
||||
template< typename S > struct <strong>apply</strong>
|
||||
{
|
||||
typedef ... type;
|
||||
};
|
||||
};
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./iterator-protocol.html" class="navigation-link">Prev</a> <a href="./numeric-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./iterator-protocol.html" class="navigation-link">Back</a> <a href="./numeric-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changes-in-boost-1-32-0.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Technical Details</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Prev</a> <a href="./physical-structure.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changelog-history.html" class="navigation-link">Back</a> <a href="./resources.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./technical-details.html" class="navigation-link">Technical Details</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="technical-details">
|
||||
<h1><a class="toc-backref" href="../index.html#id70" name="technical-details">Technical Details</a></h1>
|
||||
<p>This section collects a few technical details on the library's organization that
|
||||
do not belong into the <a class="reference" href="./reference-manual.html">reference manual</a>.</p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./physical-structure.html" id="id71" name="id71">Physical Structure</a></li>
|
||||
<li><a class="reference" href="./dependencies.html" id="id72" name="id72">Dependencies</a></li>
|
||||
<li><a class="reference" href="./portability.html" id="id73" name="id73">Portability</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Prev</a> <a href="./physical-structure.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./changelog-history.html" class="navigation-link">Back</a> <a href="./resources.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: The apply Metafunction</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-lambda-metafunction.html" class="navigation-link">Prev</a> <a href="./more-lambda-capabilities.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./the-lambda-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.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>
|
||||
<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> / <a href="./the-apply-metafunction.html" class="navigation-link">The apply Metafunction</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="the-apply-metafunction">
|
||||
<h1><a class="toc-backref" href="./handling-placeholders.html#id50" name="the-apply-metafunction">The <tt class="literal"><span class="pre">apply</span></tt> Metafunction</a></h1>
|
||||
<p>Invoking the result of <tt class="literal"><span class="pre">lambda</span></tt> is such a common pattern
|
||||
that MPL provides an <tt class="literal"><span class="pre">apply</span></tt> metafunction to do just
|
||||
that. Using <tt class="literal"><span class="pre">mpl::apply</span></tt>, our flexible version of <tt class="literal"><span class="pre">twice</span></tt>
|
||||
becomes:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/mpl/apply.hpp>
|
||||
|
||||
template <class F, class X>
|
||||
struct twice
|
||||
: mpl::apply<F, typename mpl::apply<F,X>::type>
|
||||
{};
|
||||
</pre>
|
||||
<!-- @ example.append(twice_test + '''
|
||||
BOOST_MPL_ASSERT((boost::is_same<twice<boost::add_pointer<_1>,int>::type,int**>));
|
||||
''')
|
||||
compile()
|
||||
prefix.append('#include <boost/mpl/apply.hpp>') -->
|
||||
<p>You can think of <tt class="literal"><span class="pre">mpl::apply</span></tt> as being just like the <tt class="literal"><span class="pre">apply1</span></tt>
|
||||
template that we wrote, with two additional features:</p>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">While <tt class="literal"><span class="pre">apply1</span></tt> operates only on metafunction classes, the first
|
||||
argument to <tt class="literal"><span class="pre">mpl::apply</span></tt> can be any lambda expression
|
||||
(including those built with placeholders).</p>
|
||||
</li>
|
||||
<li><p class="first">While <tt class="literal"><span class="pre">apply1</span></tt> accepts only one additional argument to which
|
||||
the metafunction class will be applied, <tt class="literal"><span class="pre">mpl::apply</span></tt> can
|
||||
invoke its first argument on any number from zero to five
|
||||
additional arguments. <a class="footnote-reference" href="#arity" id="id11" name="id11">[5]</a> For example:</p>
|
||||
<pre class="literal-block">
|
||||
// binary lambda expression applied to 2 additional arguments
|
||||
mpl::apply<
|
||||
mpl::plus<_1,_2>
|
||||
, <strong>mpl::int_<6></strong>
|
||||
, <strong>mpl::int_<7></strong>
|
||||
>::type::value // == 13
|
||||
</pre>
|
||||
</li>
|
||||
</ol>
|
||||
<table class="footnote" frame="void" id="arity" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id11" name="arity">[5]</a></td><td>See the Configuration Macros section of the <a class="reference" href="./reference-manual.html">the MPL reference manual</a>
|
||||
for a description of how to change the maximum number of
|
||||
arguments handled by <tt class="literal"><span class="pre">mpl::apply</span></tt>.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- @ prefix+=['#include <boost/mpl/plus.hpp>']
|
||||
example.wrap('enum { is13 = ','''};
|
||||
BOOST_STATIC_ASSERT(is13 == 13);''')
|
||||
compile() -->
|
||||
<div class="admonition-guideline admonition">
|
||||
<p class="admonition-title first">Guideline</p>
|
||||
<p>When writing a metafunction that invokes one of its arguments,
|
||||
use <tt class="literal"><span class="pre">mpl::apply</span></tt> so that it works with lambda expressions.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./the-lambda-metafunction.html" class="navigation-link">Prev</a> <a href="./more-lambda-capabilities.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./the-lambda-metafunction.html" class="navigation-link">Back</a> Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: The Importance of Being Lazy</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./lambda-and-non.html" class="navigation-link">Prev</a> <a href="./details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./lambda-and-non.html" class="navigation-link">Back</a> Along</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>
|
||||
<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="./the-importance-of-being.html" class="navigation-link">The Importance of Being Lazy</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="the-importance-of-being">
|
||||
<h1><a class="toc-backref" href="./lambda-details.html#id58" name="the-importance-of-being">The Importance of Being Lazy</a></h1>
|
||||
<p>Recall the definition of <tt class="literal"><span class="pre">always_int</span></tt> from the previous chapter:</p>
|
||||
<pre class="literal-block">
|
||||
struct always_int
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
</pre>
|
||||
<p>Nullary metafunctions might not seem very important at first, since
|
||||
something like <tt class="literal"><span class="pre">add_pointer<int></span></tt> could be replaced by <tt class="literal"><span class="pre">int*</span></tt> in
|
||||
any lambda expression where it appears. Not all nullary
|
||||
metafunctions are that simple, though:</p>
|
||||
<pre class="literal-block">
|
||||
typedef mpl::vector<int, char*, double&> seq;
|
||||
typedef <strong>mpl::transform<seq, boost::add_pointer<_> ></strong> calc_ptr_seq;
|
||||
</pre>
|
||||
<!-- @ example.prepend('''
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/mpl/transform.hpp>
|
||||
''')
|
||||
compile('all') -->
|
||||
<p>Note that <tt class="literal"><span class="pre">calc_ptr_seq</span></tt> is a nullary metafunction, since it has
|
||||
<tt class="literal"><span class="pre">transform</span></tt>'s nested <tt class="literal"><span class="pre">::type</span></tt>. A C++ template is not
|
||||
instantiated until we actually "look inside it," though. Just
|
||||
naming <tt class="literal"><span class="pre">calc_ptr_seq</span></tt> does not cause it to be evaluated, since we
|
||||
haven't accessed its <tt class="literal"><span class="pre">::type</span></tt> yet.</p>
|
||||
<p>Metafunctions can be invoked <em>lazily</em>, rather than immediately upon
|
||||
supplying all of their arguments. We can use <strong>lazy evaluation</strong> to
|
||||
improve compilation time when a metafunction result is only going
|
||||
to be used conditionally. We can sometimes also avoid contorting
|
||||
program structure by <em>naming</em> an invalid computation without
|
||||
actually performing it. That's what we've done with
|
||||
<tt class="literal"><span class="pre">calc_ptr_seq</span></tt> above, since you can't legally form <tt class="literal"><span class="pre">double&*</span></tt>.
|
||||
Laziness and all of its virtues will be a recurring theme
|
||||
throughout this book.</p>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./lambda-and-non.html" class="navigation-link">Prev</a> <a href="./details.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./lambda-and-non.html" class="navigation-link">Back</a> Along</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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: The lambda Metafunction</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./handling-placeholders.html" class="navigation-link">Prev</a> <a href="./the-apply-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./the-apply-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.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>
|
||||
<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> / <a href="./the-lambda-metafunction.html" class="navigation-link">The lambda Metafunction</a></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="the-lambda-metafunction">
|
||||
<h1><a class="toc-backref" href="./handling-placeholders.html#id49" name="the-lambda-metafunction">The <tt class="literal"><span class="pre">lambda</span></tt> Metafunction</a></h1>
|
||||
<p>We can <em>generate</em> a metafunction class from
|
||||
<tt class="literal"><span class="pre">boost::add_pointer<_1></span></tt>, using MPL's <tt class="literal"><span class="pre">lambda</span></tt> metafunction:</p>
|
||||
<pre class="literal-block">
|
||||
template <class X>
|
||||
struct two_pointers
|
||||
: twice<<strong>typename mpl::lambda<boost::add_pointer<_1> >::type</strong>, X>
|
||||
{};
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
two_pointers<int>::type
|
||||
, int**
|
||||
>::value
|
||||
));
|
||||
</pre>
|
||||
<!-- @ prefix.append('#include <boost/mpl/lambda.hpp>')
|
||||
compile('all') -->
|
||||
<p>We'll refer to metafunction classes like <tt class="literal"><span class="pre">add_pointer_f</span></tt> and
|
||||
placeholder expressions like <tt class="literal"><span class="pre">boost::add_pointer<_1></span></tt>
|
||||
as <strong>lambda expressions</strong>. The term, meaning "unnamed function
|
||||
object," was introduced in the 1930s by the logician Alonzo Church
|
||||
as part of a fundamental theory of computation he called the
|
||||
<em>lambda-calculus</em>. <a class="footnote-reference" href="#lambda" id="id10" name="id10">[4]</a> MPL uses the somewhat obscure word
|
||||
<tt class="literal"><span class="pre">lambda</span></tt> because of its well-established precedent in functional
|
||||
programming languages.</p>
|
||||
<table class="footnote" frame="void" id="lambda" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id10" name="lambda">[4]</a></td><td>See <a class="reference" href="http://en.wikipedia.org/wiki/Lambda_calculus" target="_top">http://en.wikipedia.org/wiki/Lambda_calculus</a> for
|
||||
an in-depth treatment, including a reference to Church's paper
|
||||
proving that the equivalence of lambda expressions is in general
|
||||
not decidable.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Although its primary purpose is to turn placeholder expressions
|
||||
into metafunction classes, <tt class="literal"><span class="pre">mpl::lambda</span></tt> can accept any lambda
|
||||
expression, even if it's already a metafunction class. In that
|
||||
case, <tt class="literal"><span class="pre">lambda</span></tt> returns its argument unchanged. MPL algorithms
|
||||
like <tt class="literal"><span class="pre">transform</span></tt> call <tt class="literal"><span class="pre">lambda</span></tt> internally, before invoking the
|
||||
resulting metafunction class, so that they work equally well with
|
||||
either kind of lambda expression. We can apply the same strategy
|
||||
to <tt class="literal"><span class="pre">twice</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
template <class F, class X>
|
||||
struct twice
|
||||
: apply1<
|
||||
typename mpl::lambda<F>::type
|
||||
, typename apply1<
|
||||
typename mpl::lambda<F>::type
|
||||
, X
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
</pre>
|
||||
<p>Now we can use <tt class="literal"><span class="pre">twice</span></tt> with metafunction classes <em>and</em>
|
||||
placeholder expressions:</p>
|
||||
<pre class="literal-block">
|
||||
int* x;
|
||||
|
||||
twice<<strong>add_pointer_f</strong>, int>::type p = &x;
|
||||
twice<<strong>boost::add_pointer<_1></strong>, int>::type q = &x;
|
||||
</pre>
|
||||
<!-- @ stack[-2:] = [ apply1, stack[-2], add_pointer_f, stack[-1]]
|
||||
compile('all') -->
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./handling-placeholders.html" class="navigation-link">Prev</a> <a href="./the-apply-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./the-apply-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./handling-placeholders.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Tutorial: Metafunctions and Higher-Order Metaprogramming</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="../index.html" class="navigation-link">Prev</a> <a href="./dimensional-analysis.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./reference-manual.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
<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></td>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<div class="section" id="tutorial-metafunctions">
|
||||
<h1><a class="toc-backref" href="../index.html#id40" name="tutorial-metafunctions">Tutorial: Metafunctions and Higher-Order Metaprogramming</a></h1>
|
||||
<table class="field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field"><th class="field-name">Note:</th><td class="field-body">The following material is an excerpt from Chapter 3 of "<a class="reference" href="http://www.awprofessional.com/titles/0321227255" target="_top">C++ Template Metaprogramming</a>",
|
||||
by David Abrahams and Aleksey Gurtovoy, ISBN 0321227255, <a class="reference" href="http://www.awprofessional.com/titles/0321227255" target="_top">http://www.awprofessional.com/titles/0321227255</a>.
|
||||
Copyright (c) 2005 by Pearson Education, Inc. Reprinted with permission.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>With the foundation laid so far, we're ready to explore one of the
|
||||
most basic uses for template metaprogramming techniques: adding
|
||||
static type checking to traditionally unchecked operations. We'll
|
||||
look at a practical example from science and engineering that can
|
||||
find applications in almost any numerical code.
|
||||
Along the way you'll learn some important new concepts and
|
||||
get a taste of metaprogramming at a high level using the MPL.</p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./dimensional-analysis.html" id="id41" name="id41">Dimensional Analysis</a></li>
|
||||
<li><a class="reference" href="./higher-order.html" id="id47" name="id47">Higher-Order Metafunctions</a></li>
|
||||
<li><a class="reference" href="./handling-placeholders.html" id="id48" name="id48">Handling Placeholders</a></li>
|
||||
<li><a class="reference" href="./more-lambda-capabilities.html" id="id51" name="id51">More Lambda Capabilities</a></li>
|
||||
<li><a class="reference" href="./lambda-details.html" id="id54" name="id54">Lambda Details</a></li>
|
||||
<li><a class="reference" href="./details.html" id="id59" name="id59">Details</a></li>
|
||||
<li><a class="reference" href="./exercises.html" id="id60" name="id60">Exercises</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="../index.html" class="navigation-link">Prev</a> <a href="./dimensional-analysis.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./reference-manual.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../index.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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
|
||||
<title>THE BOOST MPL LIBRARY: Full TOC</title>
|
||||
<link rel="stylesheet" href="../style.css" type="text/css" />
|
||||
</head>
|
||||
<body class="docframe">
|
||||
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group">Prev Next</span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group">Up <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>
|
||||
</tr></table><div class="header-separator"></div>
|
||||
<p class="topic-title first"><a name="table-of-contents">Table of Contents</a></p>
|
||||
<ul class="toc simple" id="outline">
|
||||
<li><a class="reference" href="./tutorial-metafunctions.html" id="id40" name="id40">Tutorial: Metafunctions and Higher-Order Metaprogramming</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./dimensional-analysis.html" id="id41" name="id41">Dimensional Analysis</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./representing-dimensions.html" id="id42" name="id42">Representing Dimensions</a></li>
|
||||
<li><a class="reference" href="./representing-quantities.html" id="id43" name="id43">Representing Quantities</a></li>
|
||||
<li><a class="reference" href="./implementing-addition-and.html" id="id44" name="id44">Implementing Addition and Subtraction</a></li>
|
||||
<li><a class="reference" href="./implementing.html" id="id45" name="id45">Implementing Multiplication</a></li>
|
||||
<li><a class="reference" href="./implementing-division.html" id="id46" name="id46">Implementing Division</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./higher-order.html" id="id47" name="id47">Higher-Order Metafunctions</a></li>
|
||||
<li><a class="reference" href="./handling-placeholders.html" id="id48" name="id48">Handling Placeholders</a><ul class="toc" id="outline">
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./more-lambda-capabilities.html" id="id51" name="id51">More Lambda Capabilities</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./partial-metafunction.html" id="id52" name="id52">Partial Metafunction Application</a></li>
|
||||
<li><a class="reference" href="./metafunction-composition.html" id="id53" name="id53">Metafunction Composition</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./lambda-details.html" id="id54" name="id54">Lambda Details</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./placeholders.html" id="id55" name="id55">Placeholders</a></li>
|
||||
<li><a class="reference" href="./placeholder-expression.html" id="id56" name="id56">Placeholder Expression Definition</a></li>
|
||||
<li><a class="reference" href="./lambda-and-non.html" id="id57" name="id57">Lambda and Non-Metafunction Templates</a></li>
|
||||
<li><a class="reference" href="./the-importance-of-being.html" id="id58" name="id58">The Importance of Being Lazy</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./details.html" id="id59" name="id59">Details</a></li>
|
||||
<li><a class="reference" href="./exercises.html" id="id60" name="id60">Exercises</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./reference-manual.html" id="id61" name="id61">Reference Manual</a></li>
|
||||
<li><a class="reference" href="./changelog-history.html" id="id62" name="id62">Changelog & History</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./changes-in-boost-1-32-0.html" id="id63" name="id63">Changes in Boost 1.32.0 Release</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./apply-lambda-semantics.html" id="id64" name="id64"><tt class="literal"><span class="pre">apply</span></tt>/<tt class="literal"><span class="pre">lambda</span></tt> Semantics</a></li>
|
||||
<li><a class="reference" href="./iterator-protocol.html" id="id65" name="id65">Iterator Protocol</a></li>
|
||||
<li><a class="reference" href="./tag-dispatching-protocol.html" id="id66" name="id66">Tag Dispatching Protocol</a></li>
|
||||
<li><a class="reference" href="./numeric-metafunction.html" id="id67" name="id67">Numeric Metafunction Protocol/Infrastructure</a></li>
|
||||
<li><a class="reference" href="./renaming-cleanup.html" id="id68" name="id68">Renaming/Cleanup</a></li>
|
||||
<li><a class="reference" href="./miscellaneous.html" id="id69" name="id69">Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./technical-details.html" id="id70" name="id70">Technical Details</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./physical-structure.html" id="id71" name="id71">Physical Structure</a></li>
|
||||
<li><a class="reference" href="./dependencies.html" id="id72" name="id72">Dependencies</a></li>
|
||||
<li><a class="reference" href="./portability.html" id="id73" name="id73">Portability</a><ul class="toc" id="outline">
|
||||
<li><a class="reference" href="./broken-integral-constant.html" id="id74" name="id74">Broken Integral Constant Expressions</a></li>
|
||||
<li><a class="reference" href="./incomplete-support-for.html" id="id75" name="id75">Incomplete Support for Lambda Expressions</a></li>
|
||||
<li><a class="reference" href="./eti.html" id="id76" name="id76">ETI</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="./resources.html" id="id77" name="id77">Resources</a></li>
|
||||
<li><a class="reference" href="./acknowledgements.html" id="id78" name="id78">Acknowledgements</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="footer-separator"></div>
|
||||
<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group">Prev Next</span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back Along</span><span class="navigation-group-separator"> | </span><span class="navigation-group">Up <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>
|
||||
</tr></table></body>
|
||||
</html>
|
||||
Reference in new issue
Block a user