Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

The MPL Reference Manual: numeric_cast

Boost , ,

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Front Page / Metafunctions / Miscellaneous / numeric_cast

numeric_cast

Synopsis

template<
      typename SourceTag
    , typename TargetTag
    >
struct numeric_cast;

Description

Каждая специализация numeric_cast представляет собой пользовательский унитарный класс Metafunction Class, обеспечивающий преобразование между двумя числовыми типами.

Parameters

Parameter Requirement Description
Тег Интегральная постоянная Тег для типа источника конверсии.
TargetTag Интегральная постоянная Тег для типа назначения конверсии.

Expression semantics

Если 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.

Complexity

Не уточняется.

Example

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.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-20 07:01:10/0.0077199935913086/1