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<T,S></CODE></A></LI> |
---|
32 | <LI><A HREF="#sm"><CODE>template class boost::numeric::sign_mixture<T,S></CODE></A></LI> |
---|
33 | <LI><A HREF="#ubm"><CODE>template class boost::numeric::udt_builtin_mixture<T,S></CODE></A></LI> |
---|
34 | <LI><A HREF="#isr"><CODE>template class boost::numeric::is_subranged<T,S></CODE></A></LI> |
---|
35 | <LI><A HREF="#nct"><CODE>template class boost::numeric::conversion_traits<T,S></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 | |
---|
61 | enum 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<></CODE></A></H2> |
---|
88 | |
---|
89 | <PRE>namespace boost { namespace numeric { |
---|
90 | |
---|
91 | template <class T, class S> |
---|
92 | struct int_float_mixture : mpl::integral_c<int_float_mixture_enum, <i>impl-def-value</i>> {} ; |
---|
93 | |
---|
94 | } } // namespace boost::numeric |
---|
95 | </PRE> |
---|
96 | <p>Classifying <code>S</code> and <code>T</code> as either <code>integral</code> |
---|
97 | or <code>float</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a> |
---|
98 | indicates the combination of these attributes. <br> |
---|
99 | Its <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<></CODE></A></H2> |
---|
105 | |
---|
106 | <PRE>namespace boost { namespace numeric { |
---|
107 | |
---|
108 | template <class T, class S> |
---|
109 | struct sign_mixture : mpl::integral_c<sign_mixture_enum, <i>impl-def-value</i>> {} ; |
---|
110 | |
---|
111 | } } // namespace boost::numeric |
---|
112 | </PRE> |
---|
113 | <p>Classifying <code>S</code> and <code>T</code> as either <code>signed</code> |
---|
114 | or <code>unsigned</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a> |
---|
115 | indicates the combination of these attributes. <br> |
---|
116 | Its <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<></CODE></A></H2> |
---|
122 | |
---|
123 | <PRE>namespace boost { namespace numeric { |
---|
124 | |
---|
125 | template <class T, class S> |
---|
126 | struct udt_builtin_mixture : mpl::integral_c<udt_builtin__mixture_enum, <i>impl-def-value</i>> {} ; |
---|
127 | |
---|
128 | } } // namespace boost::numeric |
---|
129 | </PRE> |
---|
130 | <p>Classifying <code>S</code> and <code>T</code> as either <code>user-defined</code> |
---|
131 | or <code>builtin</code>, this <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a> |
---|
132 | indicates the combination of these attributes. <br> |
---|
133 | Its <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<></CODE></A></H2> |
---|
139 | |
---|
140 | <PRE>namespace boost { namespace numeric { |
---|
141 | |
---|
142 | template <class T, class S> |
---|
143 | struct is_subranged : mpl::bool_<<i>impl-def-value</i>> {} ; |
---|
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. |
---|
148 | That is: if there are some source values which fall out of the Target type's range.<br> |
---|
149 | It is a boolean <a href="../../../mpl/doc/refmanual/integral-constant.html">MPL's Integral Constant</a>..<br> |
---|
150 | It does not indicate if |
---|
151 | a <i>particular</i> conversion is effectively out of range; it indicates that |
---|
152 | some conversion <i>might be</i> out of range because not all the source values |
---|
153 | are representable as Target type.</p> |
---|
154 | |
---|
155 | <hr> |
---|
156 | |
---|
157 | <H2><A NAME="nct"><CODE>template class conversion_traits<></CODE></A></H2> |
---|
158 | |
---|
159 | <PRE>namespace boost { namespace numeric { |
---|
160 | |
---|
161 | |
---|
162 | template <class T, class S> |
---|
163 | struct conversion_traits |
---|
164 | { |
---|
165 | mpl::integral_c<int_float_mixture_enum , ...> int_float_mixture ; |
---|
166 | mpl::integral_c<sign_mixture_enum , ...> sign_mixture; |
---|
167 | mpl::integral_c<udt_builtin_mixture_enum, ...> udt_builtin_mixture ; |
---|
168 | |
---|
169 | mpl::bool_<...> subranged ; |
---|
170 | mpl::bool_<...> 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> <CODE><B>int_float_mixture</B></CODE> </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> <CODE><B>sign_mixture</B></CODE> </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> <CODE><B>udt_builtin_mixture</B></CODE> </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> <CODE> <B>subranged</B></CODE> </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> <CODE> <B>trivial</B></CODE> </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> <CODE><B>target_type</B></CODE> </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> <CODE><B>source_type</B></CODE> </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> <CODE><B>argument_type</B></CODE> </TD> |
---|
262 | <TD> |
---|
263 | <P>This type is either <CODE>source_type</CODE> or <CODE>source_type |
---|
264 | const&</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&</CODE>. </P> |
---|
268 | </TD> |
---|
269 | </TR> |
---|
270 | <TR> |
---|
271 | <TD> <CODE><B>result_type</B></CODE></TD> |
---|
272 | <TD> |
---|
273 | <P>This type is either <CODE>target_type</CODE> or <CODE>target_type |
---|
274 | const&</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&</CODE>, otherwise, |
---|
277 | it is <CODE>target_type</CODE>.</P> |
---|
278 | </TD> |
---|
279 | </TR> |
---|
280 | <TR> |
---|
281 | |
---|
282 | <TD height="37"> <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> <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 <boost/numeric/conversion_traits.hpp> |
---|
301 | |
---|
302 | int main() { |
---|
303 | |
---|
304 | // A trivial conversion. |
---|
305 | typedef boost::numeric::conversion_traits<short,short> Short2Short_Traits ; |
---|
306 | assert ( Short2Short_Traits::trivial::value ) ; |
---|
307 | |
---|
308 | // A subranged conversion. |
---|
309 | typedef boost::numeric::conversion_traits<double,unsigned int> 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<short, unsigned short>::subranged::value |
---|
318 | && boost::numeric::conversion_traits<unsigned short, short>::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 |
---|
330 | License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt"> |
---|
331 | LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> |
---|
332 | www.boost.org/LICENSE_1_0.txt</a>)</p> |
---|
333 | </BODY> |
---|
334 | </HTML> |
---|