Front Page / Changelog & History / Changes in Boost 1.32.0 Release / Numeric Metafunction Protocol/Infrastructure

Numeric Metafunction Protocol/Infrastructure

The arithmetic, comparison and bitwise metafunctions are now polymorphic, and can operate on a variety of numeric types, including rational, fixed-point and complex numbers. They allow mixed arithmetic, meaning that you can perform an operation on arguments of different types, and the result will yield the largest/most general of the argument types. The infrastructure allows user-defined numeric types to be freely intermixed with predefined library types. See libs/mpl/test/numeric_ops.cpp for an illustrative example, and the reference manual for the formal infrastructure specification.

If you were using MPL numeric metafunctions on your own integral wrapper class similar to mpl::int_, you can plug your class into the new infrastructure by extending it with the following member:

typedef mpl::integral_c_tag tag;

For example:

Before Now
template< int n > struct my_int
{
    static int const value = n;
    typedef my_int type;
};
template< int n > struct my_int
{
    typedef mpl::integral_c_tag tag;
    static int const value = n;
    typedef my_int type;
};