]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <?xml version="1.0" encoding="utf-8" ?> |
2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
4 | <head> | |
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
6 | <meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" /> | |
7 | <title>The MPL Reference Manual: Metafunctions</title> | |
8 | <link rel="stylesheet" href="../style.css" type="text/css" /> | |
9 | </head> | |
10 | <body class="docframe refmanual"> | |
11 | <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./for-each.html" class="navigation-link">Prev</a> <a href="./metafunctions-concepts.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./algorithms.html" class="navigation-link">Back</a> <a href="./data-types.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../refmanual.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> | |
12 | <td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./metafunctions.html" class="navigation-link">Metafunctions</a></td> | |
13 | </tr></table><div class="header-separator"></div> | |
14 | <div class="section" id="metafunctions"> | |
15 | <h1><a class="toc-backref" href="../refmanual.html#id1510">Metafunctions</a></h1> | |
16 | <p id="label-metafunctions">The MPL includes a number of predefined metafunctions that can be roughly | |
17 | classified in two categories: <cite>general purpose metafunctions</cite>, dealing with | |
18 | conditional <a class="reference internal" href="./type-selection.html">type selection</a> and higher-order metafunction <a class="reference internal" href="./invocation.html">invocation</a>, | |
19 | <a class="reference internal" href="./composition-and-argument-binding.html">composition</a>, and <a class="reference internal" href="./composition-and-argument-binding.html">argument binding</a>, and <cite>numeric metafunctions</cite>, | |
20 | incapsulating built-in and user-defined <a class="reference internal" href="./arithmetic-operations.html">arithmetic</a>, <a class="reference internal" href="./comparisons.html">comparison</a>, | |
21 | <a class="reference internal" href="./logical-operations.html">logical</a>, and <a class="reference internal" href="./bitwise-operations.html">bitwise</a> operations.</p> | |
22 | <p>Given that it is possible to perform integer numeric computations at | |
23 | compile time using the conventional operators notation, the need for the | |
24 | second category might be not obvious, but it in fact plays a cental role in | |
25 | making programming with MPL seemingly effortless. In | |
26 | particular, there are at least two contexts where built-in language | |
27 | facilities fall short <a class="footnote-reference" href="#portability" id="id820">[3]</a>:</p> | |
28 | <ol class="arabic simple"> | |
29 | <li>Passing a computation to an algorithm.</li> | |
30 | <li>Performing a computation on non-integer data.</li> | |
31 | </ol> | |
32 | <p>The second use case deserves special attention. In contrast to the built-in, | |
33 | strictly integer compile-time arithmetics, the MPL numeric metafunctions are | |
34 | <em>polymorphic</em>, with support for <em>mixed-type arithmetics</em>. This means that they | |
35 | can operate on a variety of numeric types — for instance, rational, | |
36 | fixed-point or complex numbers, — and that, in general, you are allowed to | |
37 | freely intermix these types within a single expression. See <a class="reference internal" href="./numeric-metafunction.html">Numeric Metafunction</a> concept for more details on the MPL numeric infrastructure.</p> | |
38 | <!-- The provided `infrastructure`__ allows easy plugging of user-defined numeric | |
39 | types | |
40 | Naturally, they also , meaning that you can perform a computation on the | |
41 | arguments of different types, and the result will yeild the largest/most general | |
42 | of them. For user-defined numeric types, they provide an `infrastructure`__ that | |
43 | allows easy plugging and seemless integration with predefined library | |
44 | types. details. | |
45 | ||
46 | __ `Numeric Metafunction`_ --> | |
47 | <p>To reduce a negative syntactical impact of the metafunctions notation | |
48 | over the infix operator notation, all numeric metafunctions | |
49 | allow to pass up to N arguments, where N is defined by the value of | |
50 | <a class="reference internal" href="./limit-metafunction-arity.html">BOOST_MPL_LIMIT_METAFUNCTION_ARITY</a> configuration macro.</p> | |
51 | <table class="docutils footnote" frame="void" id="portability" rules="none"> | |
52 | <colgroup><col class="label" /><col /></colgroup> | |
53 | <tbody valign="top"> | |
54 | <tr><td class="label"><a class="fn-backref" href="#id820">[3]</a></td><td>All other considerations aside, as of the time of this writing | |
55 | (early 2004), using built-in operators on integral constants still often | |
56 | present a portability problem — many compilers cannot handle particular | |
57 | forms of expressions, forcing us to use conditional compilation. Because MPL | |
58 | numeric metafunctions work on types and encapsulate these kind of workarounds | |
59 | internally, they elude these problems, so if you aim for portability, it is | |
60 | generally adviced to use them in the place of the conventional operators, even | |
61 | at the price of slightly decreased readability.</td></tr> | |
62 | </tbody> | |
63 | </table> | |
64 | <ul class="toc simple" id="outline"> | |
65 | <li><a class="reference internal" href="./metafunctions-concepts.html" id="id1511">Concepts</a></li> | |
66 | <li><a class="reference internal" href="./type-selection.html" id="id1519">Type Selection</a></li> | |
67 | <li><a class="reference internal" href="./invocation.html" id="id1524">Invocation</a></li> | |
68 | <li><a class="reference internal" href="./composition-and-argument-binding.html" id="id1528">Composition and Argument Binding</a></li> | |
69 | <li><a class="reference internal" href="./arithmetic-operations.html" id="id1535">Arithmetic Operations</a></li> | |
70 | <li><a class="reference internal" href="./comparisons.html" id="id1542">Comparisons</a></li> | |
71 | <li><a class="reference internal" href="./logical-operations.html" id="id1549">Logical Operations</a></li> | |
72 | <li><a class="reference internal" href="./bitwise-operations.html" id="id1553">Bitwise Operations</a></li> | |
73 | <li><a class="reference internal" href="./trivial.html" id="id1559">Trivial</a></li> | |
74 | <li><a class="reference internal" href="./string-operations.html" id="id1561">String Operations</a></li> | |
75 | <li><a class="reference internal" href="./miscellaneous.html" id="id1563">Miscellaneous</a></li> | |
76 | </ul> | |
77 | </div> | |
78 | ||
79 | <div class="footer-separator"></div> | |
80 | <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./for-each.html" class="navigation-link">Prev</a> <a href="./metafunctions-concepts.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./algorithms.html" class="navigation-link">Back</a> <a href="./data-types.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="../refmanual.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> | |
81 | <td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> | |
82 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
83 | file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body> | |
84 | </html> |