3rdParty/boost/1.78.0/libs/mpl/doc/refmanual/numeric-cast.html
| Prev Next | Back Along | Up Home | Full TOC | Front Page / Metafunctions / Miscellaneous / numeric_cast |
template<
typename SourceTag
, typename TargetTag
>
struct[numeric\_cast](./numeric-cast.html);
Each numeric_cast specialization is a user-specialized unary Metafunction Class providing a conversion between two numeric types.
#include <[boost/mpl/numeric\_cast.hpp](../../../../boost/mpl/numeric_cast.hpp)>
| Parameter | Requirement | Description |
|---|---|---|
| SourceTag | Integral Constant | A tag for the conversion's source type. |
| TargetTag | Integral Constant | A tag for the conversion's destination type. |
If x and y are two numeric types, x is convertible to y, and x_tag and y_tag are the types' corresponding Integral Constant tags:
typedef[apply\_wrap](./apply-wrap.html)2<[numeric\_cast](./numeric-cast.html)<x_tag,y_tag>,x >::type r;
| Return type: | A type. | | Semantics: | r is a value of x converted to the type of y. |
Unspecified.
struct complex_tag :[int\_](./int.html)<10> {};
template< typename Re, typename Im > struct complex
{
typedef complex_tag tag;
typedef complex type;
typedef Re real;
typedef Im imag;
};
template< typename C > struct real : C::real {};
template< typename C > struct imag : C::imag {};
namespace boost { namespace mpl {
template<> struct[numeric\_cast](./numeric-cast.html)< integral_c_tag,complex_tag >
{
template< typename N > struct[apply](./apply.html): complex< N,[integral\_c](./integral-c.html)< typename N::[value\_type](./value-type.html), 0 > >
{
};
};
template<>
struct plus_impl< complex_tag,complex_tag >
{
template< typename N1, typename N2 > struct[apply](./apply.html): complex<[plus](./plus.html)< typename N1::real, typename N2::real >
,[plus](./plus.html)< typename N1::imag, typename N2::imag >
>
{
};
};
}}
typedef[int\_](./int.html)<2> i;
typedef complex<[int\_](./int.html)<5>,[int\_](./int.html)<-1> > c1;
typedef complex<[int\_](./int.html)<-5>,[int\_](./int.html)<1> > c2;
typedef[plus](./plus.html)<c1,i> r4;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( real<r4>::value, ==, 7 );[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( imag<r4>::value, ==, -1 );
typedef[plus](./plus.html)<i,c2> r5;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( real<r5>::value, ==, -3 );[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( imag<r5>::value, ==, 1 );
Metafunctions, Numeric Metafunction, plus, minus, times
| Prev Next | Back Along | Up Home | Full TOC |
Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |