Back to Arangodb

Numeric Metafunction

3rdParty/boost/1.78.0/libs/mpl/doc/refmanual/numeric-metafunction.html

3.12.9.14.0 KB
Original Source

| Prev Next | Back Along | Up Home | Full TOC | Front Page / Metafunctions / Concepts / Numeric Metafunction |

Numeric Metafunction

Description

A Numeric Metafunction is a Tag Dispatched Metafunction that provides a built-in infrastructure for easy implementation of mixed-type operations.

Expression requirements

In the following table and subsequent specifications, op is a placeholder token for the actual Numeric Metafunction's name, and x, y and _x_1,_x_2,... _x_n are arbitrary numeric types.

ExpressionTypeComplexity
op_tag<x>::typeIntegral ConstantAmortized constant time.
op_impl<
     op_tag<x>::type
   , op_tag<y>::type
   >::[apply](./apply.html)<x,y>::type

| Any type | Unspecified. | | op<_x_1,_x_2,... _x_n>::type | Any type | Unspecified. |

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](./apply.html)<x,y>::type r;

| Semantics: | r is the result of op application on arguments x and y. |

typedef op<_x_1,_x_2,..._x_n>::type r;

| Semantics: | r is the result of op application on arguments _x_1,_x_2,... _x_n. |

Example

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 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 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,c2> r1;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( real<r1>::value, ==, 0 );[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( imag<r1>::value, ==, 0 );

typedef[plus](./plus.html)<c1,c1> r2;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( real<r2>::value, ==, 10 );[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( imag<r2>::value, ==, -2 );

typedef[plus](./plus.html)<c2,c2> r3;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( real<r3>::value, ==, -10 );[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( imag<r3>::value, ==, 2 );

Models

See also

Tag Dispatched Metafunction, Metafunctions, numeric_cast

| 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) |