mpl/doc/refmanual/numeric-metafunction.html
Steven Watanabe 6f63e9d0c6 Update generated html docs for MPL.
[SVN r64705]
2010-08-09 20:07:24 +00:00

173 lines
11 KiB
HTML

<?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.7: http://docutils.sourceforge.net/" />
<title>The MPL Reference Manual: Numeric Metafunction</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<body class="docframe refmanual">
<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tag-dispatched-metafunction.html" class="navigation-link">Prev</a>&nbsp;<a href="./trivial-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tag-dispatched-metafunction.html" class="navigation-link">Back</a>&nbsp;<a href="./trivial-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./metafunctions-concepts.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
<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> / <a href="./metafunctions-concepts.html" class="navigation-link">Concepts</a> / <a href="./numeric-metafunction.html" class="navigation-link">Numeric Metafunction</a></td>
</tr></table><div class="header-separator"></div>
<div class="section" id="numeric-metafunction">
<h1><a class="toc-backref" href="./metafunctions-concepts.html#id1517">Numeric Metafunction</a></h1>
<div class="section" id="id847">
<h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
<p>A <a class="reference internal" href="./numeric-metafunction.html">Numeric Metafunction</a> is a <a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a> that provides
a built-in infrastructure for easy implementation of mixed-type operations.</p>
</div>
<div class="section" id="id848">
<h3><a class="subsection-title" href="#expression-requirements" name="expression-requirements">Expression requirements</a></h3>
<p>In the following table and subsequent specifications, <tt class="literal"><span class="pre">op</span></tt> is a placeholder token for the actual
<a class="reference internal" href="./numeric-metafunction.html">Numeric Metafunction</a>'s name, and <tt class="literal"><span class="pre">x</span></tt>, <tt class="literal"><span class="pre">y</span></tt> and <em>x</em><sub>1</sub>,<em>x</em><sub>2</sub>,... <em>x</em><sub>n</sub> are
arbitrary numeric types.</p>
<table border="1" class="docutils table">
<colgroup>
<col width="46%" />
<col width="25%" />
<col width="29%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Expression</th>
<th class="head">Type</th>
<th class="head">Complexity</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="literal"><span class="pre">op_tag&lt;x&gt;::type</span></tt></td>
<td><a class="reference internal" href="./integral-constant.html">Integral Constant</a></td>
<td>Amortized constant time.</td>
</tr>
<tr><td><pre class="first last literal-block">
op_impl&lt;
op_tag&lt;x&gt;::type
, op_tag&lt;y&gt;::type
&gt;::<a href="./apply.html" class="identifier">apply</a>&lt;x,y&gt;::type
</pre>
</td>
<td>Any type</td>
<td>Unspecified.</td>
</tr>
<tr><td><tt class="literal"><span class="pre">op&lt;</span></tt><em>x</em><sub>1</sub>,<em>x</em><sub>2</sub>,... <em>x</em><sub>n</sub><tt class="literal"><span class="pre">&gt;::type</span></tt></td>
<td>Any type</td>
<td>Unspecified.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id849">
<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
<pre class="literal-block">
typedef op_tag&lt;x&gt;::type tag;
</pre>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">tag</span></tt> is a tag type for <tt class="literal"><span class="pre">x</span></tt> for <tt class="literal"><span class="pre">op</span></tt>.
<tt class="literal"><span class="pre">tag::value</span></tt> is <tt class="literal"><span class="pre">x</span></tt>'s <em>conversion rank</em>.</td>
</tr>
</tbody>
</table>
<!-- .......................................................................... -->
<pre class="literal-block">
typedef op_impl&lt;
op_tag&lt;x&gt;::type
, op_tag&lt;y&gt;::type
&gt;::<a href="./apply.html" class="identifier">apply</a>&lt;x,y&gt;::type r;
</pre>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">r</span></tt> is the result of <tt class="literal"><span class="pre">op</span></tt> application on arguments <tt class="literal"><span class="pre">x</span></tt>
and <tt class="literal"><span class="pre">y</span></tt>.</td>
</tr>
</tbody>
</table>
<!-- .......................................................................... -->
<pre class="literal-block">
typedef op&lt;<em>x</em><sub>1</sub>,<em>x</em><sub>2</sub>,... <em>x</em><sub>n</sub>&gt;::type r;
</pre>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">r</span></tt> is the result of <tt class="literal"><span class="pre">op</span></tt> application on arguments <em>x</em><sub>1</sub>,<em>x</em><sub>2</sub>,... <em>x</em><sub>n</sub>.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id850">
<h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
<pre class="literal-block">
struct complex_tag : <a href="./int.html" class="identifier">int_</a>&lt;10&gt; {};
template&lt; typename Re, typename Im &gt; struct complex
{
typedef complex_tag tag;
typedef complex type;
typedef Re real;
typedef Im imag;
};
template&lt; typename C &gt; struct real : C::real {};
template&lt; typename C &gt; struct imag : C::imag {};
namespace boost { namespace mpl {
template&lt;&gt;
struct plus_impl&lt; complex_tag,complex_tag &gt;
{
template&lt; typename N1, typename N2 &gt; struct <a href="./apply.html" class="identifier">apply</a>
: complex&lt;
<a href="./plus.html" class="identifier">plus</a>&lt; typename N1::real, typename N2::real &gt;
, <a href="./plus.html" class="identifier">plus</a>&lt; typename N1::imag, typename N2::imag &gt;
&gt;
{
};
};
}}
typedef complex&lt; <a href="./int.html" class="identifier">int_</a>&lt;5&gt;, <a href="./int.html" class="identifier">int_</a>&lt;-1&gt; &gt; c1;
typedef complex&lt; <a href="./int.html" class="identifier">int_</a>&lt;-5&gt;, <a href="./int.html" class="identifier">int_</a>&lt;1&gt; &gt; c2;
typedef <a href="./plus.html" class="identifier">plus</a>&lt;c1,c2&gt; r1;
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( real&lt;r1&gt;::value, ==, 0 );
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( imag&lt;r1&gt;::value, ==, 0 );
typedef <a href="./plus.html" class="identifier">plus</a>&lt;c1,c1&gt; r2;
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( real&lt;r2&gt;::value, ==, 10 );
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( imag&lt;r2&gt;::value, ==, -2 );
typedef <a href="./plus.html" class="identifier">plus</a>&lt;c2,c2&gt; r3;
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( real&lt;r3&gt;::value, ==, -10 );
<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( imag&lt;r3&gt;::value, ==, 2 );
</pre>
</div>
<div class="section" id="id851">
<h3><a class="subsection-title" href="#models" name="models">Models</a></h3>
<ul class="simple">
<li><a class="reference internal" href="./plus.html">plus</a></li>
<li><a class="reference internal" href="./minus.html">minus</a></li>
<li><a class="reference internal" href="./times.html">times</a></li>
<li><a class="reference internal" href="./divides.html">divides</a></li>
</ul>
</div>
<div class="section" id="id852">
<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
<p><a class="reference internal" href="./tag-dispatched-metafunction.html">Tag Dispatched Metafunction</a>, <a class="reference internal" href="./metafunctions.html">Metafunctions</a>, <a class="reference internal" href="./numeric-cast.html">numeric_cast</a></p>
<!-- Metafunctions/Concepts//Trivial Metafunction |70 -->
</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="./tag-dispatched-metafunction.html" class="navigation-link">Prev</a>&nbsp;<a href="./trivial-metafunction.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tag-dispatched-metafunction.html" class="navigation-link">Back</a>&nbsp;<a href="./trivial-metafunction.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./metafunctions-concepts.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div>
Distributed under the Boost Software License, Version 1.0. (See accompanying
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>
</html>