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