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

The MPL Reference Manual: Numeric Metafunction

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 / Concepts / Numeric Metafunction

Numeric Metafunction

Description

А.Нумерная метафункция— этоМетафункция с меткой, которая обеспечивает встроенную инфраструктуру для легкой реализации операций смешанного типа.

Expression requirements

В следующей таблице и последующих спецификацияхopявляется токеном заполнителя для фактическогоЧисловая метафункция's name, andx,yиx1,x2, ...xnявляются произвольными числовыми типами.

Expression Type Complexity
op_tag::type Интегральная постоянная Амортизированное постоянное время.
<
op_impl<
     op_tag<x>::type
   , op_tag<y>::type
   >::apply<x,y>::type
>
Любой тип Не уточняется.
op<x1,x2, ...xn>::type Любой тип Не уточняется.

Expression semantics

typedef op_tag<x>::type tag;
Semantics:tag is a tag type for x for op. tag::value is x's conversion rank.
typedef op_impl<
      op_tag<x>::type
    , op_tag<y>::type
    >::apply<x,y>::type r;
Semantics:r is the result of op application on arguments x and y.
typedef op<x1,x2,... xn>::type r;
Semantics:r is the result of op application on arguments x1,x2,... xn.

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 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 complex< int_<5>, int_<-1> > c1;
typedef complex< int_<-5>, int_<1> > c2;
typedef plus<c1,c2> r1;
BOOST_MPL_ASSERT_RELATION( real<r1>::value, ==, 0 );
BOOST_MPL_ASSERT_RELATION( imag<r1>::value, ==, 0 );
typedef plus<c1,c1> r2;
BOOST_MPL_ASSERT_RELATION( real<r2>::value, ==, 10 );
BOOST_MPL_ASSERT_RELATION( imag<r2>::value, ==, -2 );
typedef plus<c2,c2> r3;
BOOST_MPL_ASSERT_RELATION( real<r3>::value, ==, -10 );
BOOST_MPL_ASSERT_RELATION( imag<r3>::value, ==, 2 );

Статья The MPL Reference Manual: Numeric Metafunction раздела может быть полезна для разработчиков на c++ и boost.




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



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


реклама


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

Время компиляции файла: 2024-08-30 11:47:00
2025-07-04 20:06:03/0.0058269500732422/0