Index: doc/src/refmanual/abs.rst =================================================================== --- doc/src/refmanual/abs.rst (revision 0) +++ doc/src/refmanual/abs.rst (revision 0) @@ -0,0 +1,114 @@ +.. Metafunctions/Arithmetic Operations//abs |70 + +abs +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + > + struct abs + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the absolute value of its argument. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T`` | |Integral Constant| | Operation's argument. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant| ``c``: + +.. parsed-literal:: + + typedef abs::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< c::value_type, ( (c::value<0)?(-c::value):(c::value) ) > r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef abs r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : abs::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef abs< int_<-10> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, 10 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, int > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |plus|, |minus|, |times| + + +.. copyright:: Copyright © 2010 Vicente J. Botet Escriba + 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) Property changes on: doc\src\refmanual\abs.rst ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: doc/src/refmanual/gcd.rst =================================================================== --- doc/src/refmanual/gcd.rst (revision 0) +++ doc/src/refmanual/gcd.rst (revision 0) @@ -0,0 +1,131 @@ +.. Metafunctions/Arithmetic Operations//gcd |90 + +gcd +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T1 + , typename T2 + , typename T3 = |unspecified| + |...| + , typename T\ *n* = |unspecified| + > + struct gcd + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the greatest common divisor (gcd) of its arguments. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| |T1...Tn| | |Integral Constant| | Operation's arguments. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant|\ s |c1...cn|: + + +.. parsed-literal:: + + typedef gcd::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef + if_c + > + > > c; + + typedef gcd::type r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef gcd r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : gcd::type {}; + + + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef gcd< int_<10>, int_<4>, long_<6> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, 2 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, long > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |divde|, |lcm|, |times| + + +.. copyright:: 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) Property changes on: doc\src\refmanual\gcd.rst ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: doc/src/refmanual/NumericMetafunction.rst =================================================================== --- doc/src/refmanual/NumericMetafunction.rst (revision 67512) +++ doc/src/refmanual/NumericMetafunction.rst (working copy) @@ -130,6 +130,11 @@ * |minus| * |times| * |divides| +* |modulus| +* |negate| +* |abs| +* |sign| +* |gcd| See also Index: doc/src/refmanual/sign.rst =================================================================== --- doc/src/refmanual/sign.rst (revision 0) +++ doc/src/refmanual/sign.rst (revision 0) @@ -0,0 +1,114 @@ +.. Metafunctions/Arithmetic Operations//sign |80 + +sign +==== + +Synopsis +-------- + +.. parsed-literal:: + + template< + typename T + > + struct sign + { + typedef |unspecified| type; + }; + + + +Description +----------- + +Returns the sign of its argument. + + +Header +------ + +.. parsed-literal:: + + #include + #include + + +Model of +-------- + +|Numeric Metafunction| + + +Parameters +---------- + ++---------------+---------------------------+-----------------------------------------------+ +| Parameter | Requirement | Description | ++===============+===========================+===============================================+ +| ``T`` | |Integral Constant| | Operation's argument. | ++---------------+---------------------------+-----------------------------------------------+ + +|Note:| |numeric metafunction note| |-- end note| + + +Expression semantics +-------------------- + +For any |Integral Constant| ``c``: + +.. parsed-literal:: + + typedef sign::type r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + typedef integral_c< c::value_type, ( (c::value<0)?-1:(0 r; + +.. .......................................................................... + +.. parsed-literal:: + + typedef sign r; + +:Return type: + |Integral Constant|. + +:Semantics: + Equivalent to + + .. parsed-literal:: + + struct r : sign::type {}; + + +Complexity +---------- + +Amortized constant time. + + +Example +------- + +.. parsed-literal:: + + typedef sign< int_<-10> >::type r; + BOOST_MPL_ASSERT_RELATION( r::value, ==, -1 ); + BOOST_MPL_ASSERT(( is_same< r::value_type, int > )); + + +See also +-------- + +|Arithmetic Operations|, |Numeric Metafunction|, |numeric_cast|, |plus|, |minus|, |times| + + +.. copyright:: Copyright © 2010 Vicente J. Botet Escriba + 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) Property changes on: doc\src\refmanual\sign.rst ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Index: test/arithmetic.cpp =================================================================== --- test/arithmetic.cpp (revision 67512) +++ test/arithmetic.cpp (working copy) @@ -20,7 +20,19 @@ typedef int_<0> _0; typedef int_<1> _1; typedef int_<3> _3; + typedef int_<4> _4; + typedef int_<6> _6; + typedef int_<7> _7; typedef int_<10> _10; + typedef int_<18> _18; + typedef int_<30> _30; + typedef int_<42> _42; + typedef int_<-1> m1; + typedef int_<-3> m3; + typedef int_<-6> m6; + typedef int_<-7> m7; + typedef int_<-9> m9; + typedef int_<-10> m10; MPL_ASSERT_RELATION( (plus<_0,_10>::value), ==, 10 ); MPL_ASSERT_RELATION( (plus<_10,_0>::value), ==, 10 ); @@ -47,4 +59,41 @@ #endif MPL_ASSERT_RELATION( negate<_10>::value, ==, -10 ); + + MPL_ASSERT_RELATION( abs<_10>::value, ==, 10 ); + MPL_ASSERT_RELATION( abs<_0>::value, ==, 0 ); + MPL_ASSERT_RELATION( abs::value, ==, 10 ); + + MPL_ASSERT_RELATION( sign<_10>::value, ==, 1 ); + MPL_ASSERT_RELATION( sign<_0>::value, ==, 0 ); + MPL_ASSERT_RELATION( sign::value, ==, -1 ); + + MPL_ASSERT_RELATION( (gcd<_1,m1>::value), ==, 1 ); + MPL_ASSERT_RELATION( (gcd::value), ==, 1 ); + MPL_ASSERT_RELATION( (gcd<_1,_1>::value), ==, 1 ); + MPL_ASSERT_RELATION( (gcd::value), ==, 1 ); + MPL_ASSERT_RELATION( (gcd<_0,_0>::value), ==, 0 ); + MPL_ASSERT_RELATION( (gcd<_7,_0>::value), ==, 7 ); + MPL_ASSERT_RELATION( (gcd<_0,_6>::value), ==, 6 ); + MPL_ASSERT_RELATION( (gcd::value), ==, 7 ); + MPL_ASSERT_RELATION( (gcd<_0,m6>::value), ==, 6 ); + MPL_ASSERT_RELATION( (gcd<_42,_30>::value), ==, 6 ); + MPL_ASSERT_RELATION( (gcd<_6,m9>::value), ==, 3 ); + MPL_ASSERT_RELATION( (gcd::value), ==, 6 ); + MPL_ASSERT_RELATION( (gcd<_3,_7>::value), ==, 1 ); + + MPL_ASSERT_RELATION( (lcm<_1,m1>::value), ==, 1 ); + MPL_ASSERT_RELATION( (lcm::value), ==, 1 ); + MPL_ASSERT_RELATION( (lcm<_1,_1>::value), ==, 1 ); + MPL_ASSERT_RELATION( (lcm::value), ==, 1 ); + MPL_ASSERT_RELATION( (lcm<_0,_0>::value), ==, 0 ); + MPL_ASSERT_RELATION( (lcm<_7,_0>::value), ==, 0 ); + MPL_ASSERT_RELATION( (lcm<_0,_6>::value), ==, 0 ); + MPL_ASSERT_RELATION( (lcm::value), ==, 0 ); + MPL_ASSERT_RELATION( (lcm<_0,m6>::value), ==, 0 ); + MPL_ASSERT_RELATION( (lcm<_18,_30>::value), ==, 90 ); + MPL_ASSERT_RELATION( (lcm<_6,m9>::value), ==, 18 ); + MPL_ASSERT_RELATION( (lcm::value), ==, 6 ); + MPL_ASSERT_RELATION( (lcm<_3,_7>::value), ==, 21 ); + }