Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/doc/refmanual/numeric-cast.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 9.6 KB
Line 
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 MPL Reference Manual: numeric_cast</title>
11<link rel="stylesheet" href="../style.css" type="text/css" />
12</head>
13<body class="docframe refmanual">
14<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./inherit-linearly.html" class="navigation-link">Prev</a>&nbsp;<a href="./min.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./inherit-linearly.html" class="navigation-link">Back</a>&nbsp;<a href="./min.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./miscellaneous.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>
15<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="./miscellaneous.html" class="navigation-link">Miscellaneous</a> / <a href="./numeric-cast.html" class="navigation-link">numeric_cast</a></td>
16</tr></table><div class="header-separator"></div>
17<div class="section" id="numeric-cast">
18<h1><a class="toc-backref" href="./miscellaneous.html#id492" name="numeric-cast">numeric_cast</a></h1>
19<div class="section" id="numeric-synopsis">
20<h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3>
21<pre class="literal-block">
22template&lt; 
23      typename SourceTag
24    , typename TargetTag
25    &gt;
26struct <a href="./numeric-cast.html" class="identifier">numeric_cast</a>;
27</pre>
28</div>
29<div class="section" id="miscellaneous-numeric-description">
30<h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
31<p>Each <tt class="literal"><span class="pre"><a href="./numeric-cast.html" class="identifier">numeric_cast</a></span></tt> specialization is a user-specialized unary <a class="reference" href="./metafunction-class.html">Metafunction Class</a> 
32providing a conversion between two numeric types.</p>
33</div>
34<div class="section" id="numeric-header">
35<h3><a class="subsection-title" href="#header" name="header">Header</a></h3>
36<pre class="literal-block">
37#include &lt;<a href="../../../../boost/mpl/numeric_cast.hpp" class="header">boost/mpl/numeric_cast.hpp</a>&gt;
38</pre>
39</div>
40<div class="section" id="numeric-parameters">
41<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3>
42<table border="1" class="table">
43<colgroup>
44<col width="17%" />
45<col width="30%" />
46<col width="53%" />
47</colgroup>
48<thead valign="bottom">
49<tr><th>Parameter</th>
50<th>Requirement</th>
51<th>Description</th>
52</tr>
53</thead>
54<tbody valign="top">
55<tr><td><tt class="literal"><span class="pre">SourceTag</span></tt></td>
56<td><a class="reference" href="./integral-constant.html">Integral Constant</a></td>
57<td>A tag for the conversion's source type.</td>
58</tr>
59<tr><td><tt class="literal"><span class="pre">TargetTag</span></tt></td>
60<td><a class="reference" href="./integral-constant.html">Integral Constant</a></td>
61<td>A tag for the conversion's destination type.</td>
62</tr>
63</tbody>
64</table>
65</div>
66<div class="section" id="miscellaneous-numeric-expression-semantics">
67<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
68<p>If <tt class="literal"><span class="pre">x</span></tt> and <tt class="literal"><span class="pre">y</span></tt> are two numeric types, <tt class="literal"><span class="pre">x</span></tt> is convertible to <tt class="literal"><span class="pre">y</span></tt>, and
69<tt class="literal"><span class="pre">x_tag</span></tt> and <tt class="literal"><span class="pre">y_tag</span></tt> are the types' corresponding <a class="reference" href="./integral-constant.html">Integral Constant</a> tags:</p>
70<pre class="literal-block">
71typedef <a href="./apply-wrap.html" class="identifier">apply_wrap</a><tt class="literal"><span class="pre">2</span></tt>&lt; <a href="./numeric-cast.html" class="identifier">numeric_cast</a>&lt;x_tag,y_tag&gt;,x &gt;::type  r;
72</pre>
73<table class="field-list" frame="void" rules="none">
74<col class="field-name" />
75<col class="field-body" />
76<tbody valign="top">
77<tr class="field"><th class="field-name">Return type:</th><td class="field-body">A type.</td>
78</tr>
79<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><tt class="literal"><span class="pre">r</span></tt> is a value of <tt class="literal"><span class="pre">x</span></tt> converted to the type of <tt class="literal"><span class="pre">y</span></tt>.</td>
80</tr>
81</tbody>
82</table>
83</div>
84<div class="section" id="numeric-complexity">
85<h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3>
86<p>Unspecified.</p>
87</div>
88<div class="section" id="miscellaneous-numeric-example">
89<h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
90<pre class="literal-block">
91struct complex_tag : <a href="./int.html" class="identifier">int_</a>&lt;10&gt; {};
92
93template&lt; typename Re, typename Im &gt; struct complex
94{
95    typedef complex_tag tag;
96    typedef complex type;
97    typedef Re real;
98    typedef Im imag;
99};
100
101template&lt; typename C &gt; struct real : C::real {};
102template&lt; typename C &gt; struct imag : C::imag {};
103
104namespace boost { namespace mpl {
105
106template&lt;&gt; struct <a href="./numeric-cast.html" class="identifier">numeric_cast</a>&lt; integral_c_tag,complex_tag &gt;
107{
108    template&lt; typename N &gt; struct <a href="./apply.html" class="identifier">apply</a>
109        : complex&lt; N, <a href="./integral-c.html" class="identifier">integral_c</a>&lt; typename N::<a href="./value-type.html" class="identifier">value_type</a>, 0 &gt; &gt;
110    {
111    };
112};
113
114template&lt;&gt;
115struct plus_impl&lt; complex_tag,complex_tag &gt;
116{
117    template&lt; typename N1, typename N2 &gt; struct <a href="./apply.html" class="identifier">apply</a>
118        : complex&lt;
119              <a href="./plus.html" class="identifier">plus</a>&lt; typename N1::real, typename N2::real &gt;
120            , <a href="./plus.html" class="identifier">plus</a>&lt; typename N1::imag, typename N2::imag &gt;
121            &gt;
122    {
123    };
124};
125
126}}
127
128typedef <a href="./int.html" class="identifier">int_</a>&lt;2&gt; i;
129typedef 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;
130typedef 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;
131
132typedef <a href="./plus.html" class="identifier">plus</a>&lt;c1,i&gt; r4;
133<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( real&lt;r4&gt;::value, ==, 7 );
134<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( imag&lt;r4&gt;::value, ==, -1 );
135
136typedef <a href="./plus.html" class="identifier">plus</a>&lt;i,c2&gt; r5;
137<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( real&lt;r5&gt;::value, ==, -3 );
138<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( imag&lt;r5&gt;::value, ==, 1 );
139</pre>
140</div>
141<div class="section" id="miscellaneous-numeric-see-also">
142<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
143<p><a class="reference" href="./metafunctions.html">Metafunctions</a>, <a class="reference" href="./numeric-metafunction.html">Numeric Metafunction</a>, <a class="refentry reference" href="./plus.html"><tt class="refentry literal"><span class="pre">plus</span></tt></a>, <a class="refentry reference" href="./minus.html"><tt class="refentry literal"><span class="pre">minus</span></tt></a>, <a class="refentry reference" href="./times.html"><tt class="refentry literal"><span class="pre">times</span></tt></a></p>
144<!-- modtime: November 10, 2004 04:36:52 +0000 -->
145<!-- Metafunctions/Miscellaneous//min |80 -->
146</div>
147</div>
148
149<div class="footer-separator"></div>
150<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./inherit-linearly.html" class="navigation-link">Prev</a>&nbsp;<a href="./min.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./inherit-linearly.html" class="navigation-link">Back</a>&nbsp;<a href="./min.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./miscellaneous.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>
151</tr></table></body>
152</html>
Note: See TracBrowser for help on using the repository browser.