![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
The MPL Reference Manual: numeric_castBoost , ,
|
Front Page / Metafunctions / Miscellaneous / numeric_cast |
template< typename SourceTag , typename TargetTag > struct numeric_cast;
Каждая специализация numeric_cast представляет собой пользовательский унитарный класс Metafunction Class, обеспечивающий преобразование между двумя числовыми типами.
#include <boost/mpl/numeric_cast.hpp>
Parameter | Requirement | Description |
---|---|---|
Тег | Интегральная постоянная | Тег для типа источника конверсии. |
TargetTag | Интегральная постоянная | Тег для типа назначения конверсии. |
Если x и y являются двумя числовыми типами, x конвертируется в y, а x_tag и y_tag являются соответствующими типам Integral Constant теги:
typedef apply_wrap2< numeric_cast<x_tag,y_tag>,x >::type r;
Return type: | A type. |
---|---|
Semantics: | r is a value of x converted to the type of y. |
Не уточняется.
struct complex_tag : int_<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< integral_c_tag,complex_tag > { template< typename N > struct apply : complex< N, integral_c< typename N::value_type, 0 > > { }; }; template<> struct plus_impl< complex_tag,complex_tag > { template< typename N1, typename N2 > struct apply : complex< plus< typename N1::real, typename N2::real > , plus< typename N1::imag, typename N2::imag > > { }; }; }} typedef int_<2> i; typedef complex< int_<5>, int_<-1> > c1; typedef complex< int_<-5>, int_<1> > c2; typedef plus<c1,i> r4; BOOST_MPL_ASSERT_RELATION( real<r4>::value, ==, 7 ); BOOST_MPL_ASSERT_RELATION( imag<r4>::value, ==, -1 ); typedef plus<i,c2> r5; BOOST_MPL_ASSERT_RELATION( real<r5>::value, ==, -3 ); BOOST_MPL_ASSERT_RELATION( imag<r5>::value, ==, 1 );
) |
Статья The MPL Reference Manual: numeric_cast раздела может быть полезна для разработчиков на c++ и boost.
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.
:: Главная :: ::
реклама |