1 | <?xml version="1.0" encoding="utf-8" ?> |
---|
2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
4 | <head> |
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
6 | <meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" /> |
---|
7 | <title>THE BOOST MPL LIBRARY: Numeric Metafunction Protocol/Infrastructure</title> |
---|
8 | <link rel="stylesheet" href="../style.css" type="text/css" /> |
---|
9 | </head> |
---|
10 | <body class="docframe"> |
---|
11 | <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./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> |
---|
12 | <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> |
---|
13 | </tr></table><div class="header-separator"></div> |
---|
14 | <div class="section" id="numeric-metafunction"> |
---|
15 | <h1><a class="toc-backref" href="./changes-in-boost-1-32-0.html#id67" name="numeric-metafunction">Numeric Metafunction Protocol/Infrastructure</a></h1> |
---|
16 | <p>The arithmetic, comparison and bitwise metafunctions are now |
---|
17 | <cite>polymorphic</cite>, and can operate on a variety of numeric types, |
---|
18 | including rational, fixed-point and complex numbers. They allow |
---|
19 | <cite>mixed arithmetic</cite>, meaning that you can perform an operation on |
---|
20 | arguments of different types, and the result will yeild the |
---|
21 | largest/most general of the argument types. The infrastructure |
---|
22 | allows user-defined numeric types to be freely intermixed with |
---|
23 | predefined library types. See |
---|
24 | <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> |
---|
25 | for an illustrative example, and the <a class="reference" href="./reference-manual.html">reference manual</a> for |
---|
26 | the formal infrastructure specification.</p> |
---|
27 | <p>If you were using MPL numeric metafunctions on your own integral |
---|
28 | wrapper class similar to <tt class="literal"><span class="pre">mpl::int_</span></tt>, you can plug your class |
---|
29 | into the new infrustructure by extending it with the following |
---|
30 | member:</p> |
---|
31 | <pre class="literal-block"> |
---|
32 | typedef mpl::integral_c_tag tag; |
---|
33 | </pre> |
---|
34 | <p>For example:</p> |
---|
35 | <table border="1" class="table"> |
---|
36 | <colgroup> |
---|
37 | <col width="48%" /> |
---|
38 | <col width="52%" /> |
---|
39 | </colgroup> |
---|
40 | <thead valign="bottom"> |
---|
41 | <tr><th>Before</th> |
---|
42 | <th>Now</th> |
---|
43 | </tr> |
---|
44 | </thead> |
---|
45 | <tbody valign="top"> |
---|
46 | <tr><td><pre class="first last literal-block"> |
---|
47 | template< int n > struct my_int |
---|
48 | { |
---|
49 | static int const value = n; |
---|
50 | typedef my_int type; |
---|
51 | }; |
---|
52 | </pre> |
---|
53 | </td> |
---|
54 | <td><pre class="first last literal-block"> |
---|
55 | template< int n > struct my_int |
---|
56 | { |
---|
57 | <strong>typedef mpl::integral_c_tag tag;</strong> |
---|
58 | static int const value = n; |
---|
59 | typedef my_int type; |
---|
60 | }; |
---|
61 | </pre> |
---|
62 | </td> |
---|
63 | </tr> |
---|
64 | </tbody> |
---|
65 | </table> |
---|
66 | </div> |
---|
67 | |
---|
68 | <div class="footer-separator"></div> |
---|
69 | <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> |
---|
70 | </tr></table></body> |
---|
71 | </html> |
---|