File: conversion_traits.html

package info (click to toggle)
boost 1.33.1-10
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 100,948 kB
  • ctags: 145,103
  • sloc: cpp: 573,492; xml: 49,055; python: 15,626; ansic: 13,588; sh: 2,099; yacc: 858; makefile: 660; perl: 427; lex: 111; csh: 6
file content (334 lines) | stat: -rw-r--r-- 11,987 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<HTML>
  <HEAD>
	 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
	 <LINK REL="stylesheet" TYPE="text/css" HREF="../../../../boost.css">
         <TITLE>Boost Numeric Conversion Library - Conversion Traits</TITLE>
  </HEAD>
  <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000ff" VLINK="#800080">
	 <TABLE BORDER="0" CELLPADDING="7" CELLSPACING="0" WIDTH="100%"
	  SUMMARY="header">
		<TR>
		  <TH VALIGN="top" WIDTH="300">
			 <H3><A HREF="../../../../index.htm"><IMG HEIGHT="86" WIDTH="277"
				ALT="C++ Boost" SRC="../../../../boost.png" BORDER="0"></A></H3> </TH>
		  <TH VALIGN="top">
			 <H1 ALIGN="center">Boost Numeric Conversion Library</H1>

      <H1><A HREF="http://www.boost.org">Header </A><A
				HREF="../../../../boost/numeric/conversion/conversion_traits.hpp">boost/numeric/conversion/conversion_traits.hpp</A></H1>
			 </TH>
		</TR>
	 </TABLE> <HR>
	 <H2>Contents</H2>
	 <DL CLASS="page-index">
           <DT><A HREF="#types">Types</A></DT>
	 </DL>
	 <UL>

  <LI><A HREF="#ncm"><CODE>enumeration boost::numeric::int_float_mixture_enum;</CODE></A></LI>
  <LI><A HREF="#ncsm"><CODE>enumeration boost::numeric::sign_mixture_enum;</CODE></A></LI>
  <LI><A HREF="#ncum"><CODE>enumeration boost::numeric::udt_builtin_mixture_enum;</CODE></A></LI>
  <LI><A HREF="#ifm"><CODE>template class boost::numeric::int_float_mixture&lt;T,S&gt;</CODE></A></LI>
  <LI><A HREF="#sm"><CODE>template class boost::numeric::sign_mixture&lt;T,S&gt;</CODE></A></LI>
  <LI><A HREF="#ubm"><CODE>template class boost::numeric::udt_builtin_mixture&lt;T,S&gt;</CODE></A></LI>
  <LI><A HREF="#isr"><CODE>template class boost::numeric::is_subranged&lt;T,S&gt;</CODE></A></LI>
  <LI><A HREF="#nct"><CODE>template class boost::numeric::conversion_traits&lt;T,S&gt;</CODE></A></LI>
	 </UL>
	 <DL><DT><A HREF="#examples">Example(s)</A></DT></DL>
         <HR>

<H2><A NAME="types"></A>Types</H2>

<H2><CODE><A NAME="ncm">enumeration int_float_mixture</A>_enum</CODE></H2>

<PRE>namespace boost { namespace numeric {

  enum int_float_mixture_enum
  {
     integral_to_integral
    ,integral_to_float
    ,float_to_integral
    ,float_to_float
  } ;

} } // namespace boost::numeric
</PRE>

<H2><CODE><A NAME="ncsm">enumeration sign_mixture</A>_enum</CODE></H2>

<PRE>namespace boost { namespace numeric {

enum sign_mixture_enum
  {
     unsigned_to_unsigned
    ,signed_to_signed
    ,signed_to_unsigned
    ,unsigned_to_signed
  } ;

} } // namespace boost::numeric</PRE>

<H2><CODE><A NAME="ncum">enumeration  udt_builtin_mixture</A>_enum</CODE></H2>

<PRE>namespace boost { namespace numeric {

  enum udt_builtin_mixture_enum
  {
     builtin_to_builtin
    ,builtin_to_udt
    ,udt_to_builtin
    ,udt_to_udt
  } ;

} } // namespace boost::numeric</PRE>

<hr>

<H2><A NAME="ifm"><CODE>template class int_float_mixture&lt;&gt;</CODE></A></H2>

<PRE>namespace boost { namespace numeric {

  template &lt;class T, class S&gt;
  struct int_float_mixture : mpl::integral_c&lt;int_float_mixture_enum, <i>impl-def-value</i>&gt; {} ;

} } // namespace boost::numeric
</PRE>
<p>Classifying <code>S</code> and <code>T</code> as either <code>integral</code>
or <code>float</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
indicates the combination of these attributes. <br>
Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::int_float_mixture_enum</CODE></A>
</p>

<hr>

<H2><A NAME="sm"><CODE>template class sign_mixture&lt;&gt;</CODE></A></H2>

<PRE>namespace boost { namespace numeric {

  template &lt;class T, class S&gt;
  struct sign_mixture : mpl::integral_c&lt;sign_mixture_enum, <i>impl-def-value</i>&gt; {} ;

} } // namespace boost::numeric
</PRE>
<p>Classifying <code>S</code> and <code>T</code> as either <code>signed</code>
or <code>unsigned</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
indicates the combination of these attributes. <br>
Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::sign_mixture_enum</CODE></A>
</p>

<hr>

<H2><A NAME="ubm"><CODE>template class udt_builtin_mixture&lt;&gt;</CODE></A></H2>

<PRE>namespace boost { namespace numeric {

  template &lt;class T, class S&gt;
  struct udt_builtin_mixture : mpl::integral_c&lt;udt_builtin__mixture_enum, <i>impl-def-value</i>&gt; {} ;

} } // namespace boost::numeric
</PRE>
<p>Classifying <code>S</code> and <code>T</code> as either <code>user-defined</code>
or <code>builtin</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>
indicates the combination of these attributes. <br>
Its <code>::value</code> is of enumeration type <A HREF="#ncm"><CODE>boost::numeric::udt_builtin_mixture_enum</CODE></A>
</p>

<hr>

<H2><A NAME="isr"><CODE>template class is_subranged&lt;&gt;</CODE></A></H2>

<PRE>namespace boost { namespace numeric {

  template &lt;class T, class S&gt;
  struct is_subranged : mpl::bool_&lt;<i>impl-def-value</i>&gt; {} ;

} } // namespace boost::numeric
</PRE>
<p>Indicates if the range of the target type T is a subset of the range of the source type S.
That is: if there are some source values which fall out of the Target type's range.<br>
It is a boolean <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>..<br>
It does not indicate if
a <i>particular</i> conversion is effectively out of range; it indicates that
some conversion <i>might be</i> out of range because not all the source values
are representable as Target type.</p>

<hr>

<H2><A NAME="nct"><CODE>template class conversion_traits&lt;&gt;</CODE></A></H2>

<PRE>namespace boost { namespace numeric {


  template &lt;class T, class S&gt;
  struct conversion_traits
  {
    mpl::integral_c&lt;int_float_mixture_enum  , ...&gt; int_float_mixture ;
    mpl::integral_c&lt;sign_mixture_enum       , ...&gt; sign_mixture;
    mpl::integral_c&lt;udt_builtin_mixture_enum, ...&gt; udt_builtin_mixture ;

    mpl::bool_&lt;...&gt; subranged ;
    mpl::bool_&lt;...&gt; trivial ;

    typedef T target_type   ;
    typedef S source_type   ;
    typedef ... argument_type ;
    typedef ... result_type   ;
    typedef ... supertype     ;
    typedef ... subtype       ;
  } ;

} } // namespace numeric, namespace boost
</PRE>
<BLOCKQUOTE>

  <P>This traits class indicates some properties of a <i>numeric conversion direction</i>:
    from a source type <code>S</code> to a target type <code>T</code>. It does not indicate the properties of
    a <i>specific</i> conversion, but of the conversion <i>direction</i>. See
    <A href="definitions.html#subranged">Definitions</A> for details.<br>
  </P>

  <P>The traits class provides the following
     <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constants</a>
     of enumeration type. They express the <i>combination</i> of certain attributes of the Source and
    Target types (thus they are call <i>mixture</i>):</P>
		<TABLE BORDER="1">
		  <TR>
			 <TD>&nbsp;<CODE><B>int_float_mixture</B></CODE>&nbsp;</TD>

      <TD>
        <P>Same as given by the traits class <A HREF="#ifm"><CODE>int_float_mixture</CODE></A></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>sign_mixture</B></CODE>&nbsp;</TD>

      <TD>
        <P>Same as given by the traits class <A HREF="#sm"><CODE>sign_mixture</CODE></A></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>udt_builtin_mixture</B></CODE>&nbsp;</TD>

      <TD>
        <P>Same as given by the traits class <A HREF="#ubm"><CODE>udt_builtin_mixture</CODE></A></P>
      </TD>
		  </TR>
		</TABLE>

  <P>The traits class provides the following
     <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constants</a>
    of boolean type which indicates indirectly the relation between the Source and Target
    <i>ranges</i>
    (see <A href="definitions.html#range">Definitions</A> for details).</P>
		<TABLE BORDER="1">
		  <TR>
			 <TD>&nbsp;<CODE> <B>subranged</B></CODE>&nbsp;</TD>

      <TD>
        <P>Same as given by <A HREF="#isr"><CODE>is_subranged</CODE></A></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE> <B>trivial</B></CODE>&nbsp;</TD>

      <TD>
        <P>Indicates if both Source and Target, <u>without cv-qualifications</u>, are
          the same type.<br>
          Its <code>::value</code> is of boolean type.</P>
      </TD>
		  </TR>
		</TABLE>

  <P>The traits class provides the following types. They are the Source and Target
    types classified and qualified for different purposes.</P>

  <TABLE BORDER="1" width="720">
    <TR>
			 <TD>&nbsp;<CODE><B>target_type</B></CODE>&nbsp;</TD>
			 <TD>

        <P>The template parameter <CODE>T</CODE><EM> without cv-qualifications</EM></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>source_type</B></CODE>&nbsp;</TD>
			 <TD>

        <P>The template parameter <CODE>S</CODE><EM> without cv-qualifications</EM></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>argument_type</B></CODE>&nbsp;</TD>
			 <TD>
 		<P>This type is either <CODE>source_type</CODE> or <CODE>source_type
const&amp;</CODE>. <BR> It represents the <I>optimal</I> argument type for the
 		  <A HREF="converter.html">converter</A> member functions.<BR>
          If <CODE>S</CODE> is a built-in type, this is <CODE>source_type</CODE>,
          otherwise, this is <CODE>source_type const&amp;</CODE>. </P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>result_type</B></CODE></TD>
			 <TD>
				<P>This type is either <CODE>target_type</CODE> or <CODE>target_type
const&amp;</CODE> <BR> It represents the return type of the
				  <A HREF="converter.html">converter</A> member functions.<BR>
          If <CODE>T==S</CODE>, it is <CODE>target_type const&amp;</CODE>, otherwise,
          it is <CODE>target_type</CODE>.</P>
      </TD>
		  </TR>
		  <TR>

      <TD height="37">&nbsp;<CODE><B>supertype</B></CODE></TD>

      <TD height="37">
        <P>If the conversion is <CODE>subranged</CODE>, it is <CODE>source_type</CODE>,
          otherwise, it is <CODE>target_type</CODE></P>
      </TD>
		  </TR>
		  <TR>
			 <TD>&nbsp;<CODE><B>subtype</B></CODE></TD>
      <TD height="37">
        <P>If the conversion is <CODE>subranged</CODE>, it is <CODE>target_type</CODE>,
          otherwise, it is <CODE>source_type</CODE></P>
      </TD>
		  </TR>
		</TABLE> </BLOCKQUOTE> <HR>

<H2><A NAME="examples">Examples</A></H2>
<BLOCKQUOTE>
  <PRE>#include &lt;boost/numeric/conversion_traits.hpp&gt;

int main() {

  // A trivial conversion.
  typedef boost::numeric::conversion_traits&lt;short,short&gt; Short2Short_Traits ;
  assert ( Short2Short_Traits::trivial::value ) ;

  // A subranged conversion.
  typedef boost::numeric::conversion_traits&lt;double,unsigned int&gt; UInt2Double_Traits ;
  assert (  UInt2Double_Traits::mixture::value == boost::numeric::integral_to_float ) ;
  assert (  UInt2Double_Traits::sign_mixture::value == boost::numeric::unsigned_to_signed ) ;
  assert ( !UInt2Double_Traits::subranged::value ) ;
  assert ( typeid(UInt2Double_Traits::supertype) == typeid(double) ) ;
  assert ( typeid(UInt2Double_Traits::subtype) == typeid(unsigned int) ) ;

  // A doubly subranged conversion.
  assert (    boost::numeric::conversion_traits&lt;short, unsigned short&gt;::subranged::value
           &amp;&amp; boost::numeric::conversion_traits&lt;unsigned short, short&gt;::subranged::value
         )

  return 0;
}</PRE>
   </BLOCKQUOTE>
<HR>
<P>Back to <A HREF="index.html">Numeric Conversion library index</A></P>
<HR>
<P>Revised 16 May 2005</P>
<p> Copyright Fernando Luis Cacciola Carballal, 2004</p>
<p> Use, modification, and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
www.boost.org/LICENSE_1_0.txt</a>)</p>
</BODY>
</HTML>