Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/conversion/doc/conversion_traits.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 11.7 KB
Line 
1<HTML>
2  <HEAD>
3         <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
4         <LINK REL="stylesheet" TYPE="text/css" HREF="../../../../boost.css">
5         <TITLE>Boost Numeric Conversion Library - Conversion Traits</TITLE>
6  </HEAD>
7  <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000ff" VLINK="#800080">
8         <TABLE BORDER="0" CELLPADDING="7" CELLSPACING="0" WIDTH="100%"
9          SUMMARY="header">
10                <TR>
11                  <TH VALIGN="top" WIDTH="300">
12                         <H3><A HREF="../../../../index.htm"><IMG HEIGHT="86" WIDTH="277"
13                                ALT="C++ Boost" SRC="../../../../boost.png" BORDER="0"></A></H3> </TH>
14                  <TH VALIGN="top">
15                         <H1 ALIGN="center">Boost Numeric Conversion Library</H1>
16
17      <H1><A HREF="http://www.boost.org">Header </A><A
18                                HREF="../../../../boost/numeric/conversion/conversion_traits.hpp">boost/numeric/conversion/conversion_traits.hpp</A></H1>
19                         </TH>
20                </TR>
21         </TABLE> <HR>
22         <H2>Contents</H2>
23         <DL CLASS="page-index">
24           <DT><A HREF="#types">Types</A></DT>
25         </DL>
26         <UL>
27
28  <LI><A HREF="#ncm"><CODE>enumeration boost::numeric::int_float_mixture_enum;</CODE></A></LI>
29  <LI><A HREF="#ncsm"><CODE>enumeration boost::numeric::sign_mixture_enum;</CODE></A></LI>
30  <LI><A HREF="#ncum"><CODE>enumeration boost::numeric::udt_builtin_mixture_enum;</CODE></A></LI>
31  <LI><A HREF="#ifm"><CODE>template class boost::numeric::int_float_mixture&lt;T,S&gt;</CODE></A></LI>
32  <LI><A HREF="#sm"><CODE>template class boost::numeric::sign_mixture&lt;T,S&gt;</CODE></A></LI>
33  <LI><A HREF="#ubm"><CODE>template class boost::numeric::udt_builtin_mixture&lt;T,S&gt;</CODE></A></LI>
34  <LI><A HREF="#isr"><CODE>template class boost::numeric::is_subranged&lt;T,S&gt;</CODE></A></LI>
35  <LI><A HREF="#nct"><CODE>template class boost::numeric::conversion_traits&lt;T,S&gt;</CODE></A></LI>
36         </UL>
37         <DL><DT><A HREF="#examples">Example(s)</A></DT></DL>
38         <HR>
39
40<H2><A NAME="types"></A>Types</H2>
41
42<H2><CODE><A NAME="ncm">enumeration int_float_mixture</A>_enum</CODE></H2>
43
44<PRE>namespace boost { namespace numeric {
45
46  enum int_float_mixture_enum
47  {
48     integral_to_integral
49    ,integral_to_float
50    ,float_to_integral
51    ,float_to_float
52  } ;
53
54} } // namespace boost::numeric
55</PRE>
56
57<H2><CODE><A NAME="ncsm">enumeration sign_mixture</A>_enum</CODE></H2>
58
59<PRE>namespace boost { namespace numeric {
60
61enum sign_mixture_enum
62  {
63     unsigned_to_unsigned
64    ,signed_to_signed
65    ,signed_to_unsigned
66    ,unsigned_to_signed
67  } ;
68
69} } // namespace boost::numeric</PRE>
70
71<H2><CODE><A NAME="ncum">enumeration  udt_builtin_mixture</A>_enum</CODE></H2>
72
73<PRE>namespace boost { namespace numeric {
74
75  enum udt_builtin_mixture_enum
76  {
77     builtin_to_builtin
78    ,builtin_to_udt
79    ,udt_to_builtin
80    ,udt_to_udt
81  } ;
82
83} } // namespace boost::numeric</PRE>
84
85<hr>
86
87<H2><A NAME="ifm"><CODE>template class int_float_mixture&lt;&gt;</CODE></A></H2>
88
89<PRE>namespace boost { namespace numeric {
90
91  template &lt;class T, class S&gt;
92  struct int_float_mixture : mpl::integral_c&lt;int_float_mixture_enum, <i>impl-def-value</i>&gt; {} ;
93
94} } // namespace boost::numeric
95</PRE>
96<p>Classifying <code>S</code> and <code>T</code> as either <code>integral</code>
97or <code>float</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
98indicates the combination of these attributes. <br>
99Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::int_float_mixture_enum</CODE></A>
100</p>
101
102<hr>
103
104<H2><A NAME="sm"><CODE>template class sign_mixture&lt;&gt;</CODE></A></H2>
105
106<PRE>namespace boost { namespace numeric {
107
108  template &lt;class T, class S&gt;
109  struct sign_mixture : mpl::integral_c&lt;sign_mixture_enum, <i>impl-def-value</i>&gt; {} ;
110
111} } // namespace boost::numeric
112</PRE>
113<p>Classifying <code>S</code> and <code>T</code> as either <code>signed</code>
114or <code>unsigned</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
115indicates the combination of these attributes. <br>
116Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::sign_mixture_enum</CODE></A>
117</p>
118
119<hr>
120
121<H2><A NAME="ubm"><CODE>template class udt_builtin_mixture&lt;&gt;</CODE></A></H2>
122
123<PRE>namespace boost { namespace numeric {
124
125  template &lt;class T, class S&gt;
126  struct udt_builtin_mixture : mpl::integral_c&lt;udt_builtin__mixture_enum, <i>impl-def-value</i>&gt; {} ;
127
128} } // namespace boost::numeric
129</PRE>
130<p>Classifying <code>S</code> and <code>T</code> as either <code>user-defined</code>
131or <code>builtin</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
132indicates the combination of these attributes. <br>
133Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::udt_builtin_mixture_enum</CODE></A>
134</p>
135
136<hr>
137
138<H2><A NAME="isr"><CODE>template class is_subranged&lt;&gt;</CODE></A></H2>
139
140<PRE>namespace boost { namespace numeric {
141
142  template &lt;class T, class S&gt;
143  struct is_subranged : mpl::bool_&lt;<i>impl-def-value</i>&gt; {} ;
144
145} } // namespace boost::numeric
146</PRE>
147<p>Indicates if the range of the target type T is a subset of the range of the source type S.
148That is: if there are some source values which fall out of the Target type's range.<br>
149It is a boolean <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>..<br>
150It does not indicate if
151a <i>particular</i> conversion is effectively out of range; it indicates that
152some conversion <i>might be</i> out of range because not all the source values
153are representable as Target type.</p>
154
155<hr>
156
157<H2><A NAME="nct"><CODE>template class conversion_traits&lt;&gt;</CODE></A></H2>
158
159<PRE>namespace boost { namespace numeric {
160
161
162  template &lt;class T, class S&gt;
163  struct conversion_traits
164  {
165    mpl::integral_c&lt;int_float_mixture_enum  , ...&gt; int_float_mixture ;
166    mpl::integral_c&lt;sign_mixture_enum       , ...&gt; sign_mixture;
167    mpl::integral_c&lt;udt_builtin_mixture_enum, ...&gt; udt_builtin_mixture ;
168
169    mpl::bool_&lt;...&gt; subranged ;
170    mpl::bool_&lt;...&gt; trivial ;
171
172    typedef T target_type   ;
173    typedef S source_type   ;
174    typedef ... argument_type ;
175    typedef ... result_type   ;
176    typedef ... supertype     ;
177    typedef ... subtype       ;
178  } ;
179
180} } // namespace numeric, namespace boost
181</PRE>
182<BLOCKQUOTE>
183
184  <P>This traits class indicates some properties of a <i>numeric conversion direction</i>:
185    from a source type <code>S</code> to a target type <code>T</code>. It does not indicate the properties of
186    a <i>specific</i> conversion, but of the conversion <i>direction</i>. See
187    <A href="definitions.html#subranged">Definitions</A> for details.<br>
188  </P>
189
190  <P>The traits class provides the following
191     <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constants</a>
192     of enumeration type. They express the <i>combination</i> of certain attributes of the Source and
193    Target types (thus they are call <i>mixture</i>):</P>
194                <TABLE BORDER="1">
195                  <TR>
196                         <TD>&nbsp;<CODE><B>int_float_mixture</B></CODE>&nbsp;</TD>
197
198      <TD>
199        <P>Same as given by the traits class <A HREF="#ifm"><CODE>int_float_mixture</CODE></A></P>
200      </TD>
201                  </TR>
202                  <TR>
203                         <TD>&nbsp;<CODE><B>sign_mixture</B></CODE>&nbsp;</TD>
204
205      <TD>
206        <P>Same as given by the traits class <A HREF="#sm"><CODE>sign_mixture</CODE></A></P>
207      </TD>
208                  </TR>
209                  <TR>
210                         <TD>&nbsp;<CODE><B>udt_builtin_mixture</B></CODE>&nbsp;</TD>
211
212      <TD>
213        <P>Same as given by the traits class <A HREF="#ubm"><CODE>udt_builtin_mixture</CODE></A></P>
214      </TD>
215                  </TR>
216                </TABLE>
217
218  <P>The traits class provides the following
219     <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constants</a>
220    of boolean type which indicates indirectly the relation between the Source and Target
221    <i>ranges</i>
222    (see <A href="definitions.html#range">Definitions</A> for details).</P>
223                <TABLE BORDER="1">
224                  <TR>
225                         <TD>&nbsp;<CODE> <B>subranged</B></CODE>&nbsp;</TD>
226
227      <TD>
228        <P>Same as given by <A HREF="#isr"><CODE>is_subranged</CODE></A></P>
229      </TD>
230                  </TR>
231                  <TR>
232                         <TD>&nbsp;<CODE> <B>trivial</B></CODE>&nbsp;</TD>
233
234      <TD>
235        <P>Indicates if both Source and Target, <u>without cv-qualifications</u>, are
236          the same type.<br>
237          Its <code>::value</code> is of boolean type.</P>
238      </TD>
239                  </TR>
240                </TABLE>
241
242  <P>The traits class provides the following types. They are the Source and Target
243    types classified and qualified for different purposes.</P>
244
245  <TABLE BORDER="1" width="720">
246    <TR>
247                         <TD>&nbsp;<CODE><B>target_type</B></CODE>&nbsp;</TD>
248                         <TD>
249
250        <P>The template parameter <CODE>T</CODE><EM> without cv-qualifications</EM></P>
251      </TD>
252                  </TR>
253                  <TR>
254                         <TD>&nbsp;<CODE><B>source_type</B></CODE>&nbsp;</TD>
255                         <TD>
256
257        <P>The template parameter <CODE>S</CODE><EM> without cv-qualifications</EM></P>
258      </TD>
259                  </TR>
260                  <TR>
261                         <TD>&nbsp;<CODE><B>argument_type</B></CODE>&nbsp;</TD>
262                         <TD>
263                <P>This type is either <CODE>source_type</CODE> or <CODE>source_type
264const&amp;</CODE>. <BR> It represents the <I>optimal</I> argument type for the
265                  <A HREF="converter.html">converter</A> member functions.<BR>
266          If <CODE>S</CODE> is a built-in type, this is <CODE>source_type</CODE>,
267          otherwise, this is <CODE>source_type const&amp;</CODE>. </P>
268      </TD>
269                  </TR>
270                  <TR>
271                         <TD>&nbsp;<CODE><B>result_type</B></CODE></TD>
272                         <TD>
273                                <P>This type is either <CODE>target_type</CODE> or <CODE>target_type
274const&amp;</CODE> <BR> It represents the return type of the
275                                  <A HREF="converter.html">converter</A> member functions.<BR>
276          If <CODE>T==S</CODE>, it is <CODE>target_type const&amp;</CODE>, otherwise,
277          it is <CODE>target_type</CODE>.</P>
278      </TD>
279                  </TR>
280                  <TR>
281
282      <TD height="37">&nbsp;<CODE><B>supertype</B></CODE></TD>
283
284      <TD height="37">
285        <P>If the conversion is <CODE>subranged</CODE>, it is <CODE>source_type</CODE>,
286          otherwise, it is <CODE>target_type</CODE></P>
287      </TD>
288                  </TR>
289                  <TR>
290                         <TD>&nbsp;<CODE><B>subtype</B></CODE></TD>
291      <TD height="37">
292        <P>If the conversion is <CODE>subranged</CODE>, it is <CODE>target_type</CODE>,
293          otherwise, it is <CODE>source_type</CODE></P>
294      </TD>
295                  </TR>
296                </TABLE> </BLOCKQUOTE> <HR>
297
298<H2><A NAME="examples">Examples</A></H2>
299<BLOCKQUOTE>
300  <PRE>#include &lt;boost/numeric/conversion_traits.hpp&gt;
301
302int main() {
303
304  // A trivial conversion.
305  typedef boost::numeric::conversion_traits&lt;short,short&gt; Short2Short_Traits ;
306  assert ( Short2Short_Traits::trivial::value ) ;
307
308  // A subranged conversion.
309  typedef boost::numeric::conversion_traits&lt;double,unsigned int&gt; UInt2Double_Traits ;
310  assert (  UInt2Double_Traits::mixture::value == boost::numeric::integral_to_float ) ;
311  assert (  UInt2Double_Traits::sign_mixture::value == boost::numeric::unsigned_to_signed ) ;
312  assert ( !UInt2Double_Traits::subranged::value ) ;
313  assert ( typeid(UInt2Double_Traits::supertype) == typeid(double) ) ;
314  assert ( typeid(UInt2Double_Traits::subtype) == typeid(unsigned int) ) ;
315
316  // A doubly subranged conversion.
317  assert (    boost::numeric::conversion_traits&lt;short, unsigned short&gt;::subranged::value
318           &amp;&amp; boost::numeric::conversion_traits&lt;unsigned short, short&gt;::subranged::value
319         )
320
321  return 0;
322}</PRE>
323   </BLOCKQUOTE>
324<HR>
325<P>Back to <A HREF="index.html">Numeric Conversion library index</A></P>
326<HR>
327<P>Revised 16 May 2005</P>
328<p>© Copyright Fernando Luis Cacciola Carballal, 2004</p>
329<p> Use, modification, and distribution are subject to the Boost Software
330License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
331LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
332www.boost.org/LICENSE_1_0.txt</a>)</p>
333</BODY>
334</HTML>
Note: See TracBrowser for help on using the repository browser.