| 1 | //////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // Copyright Vicente J. Botet Escriba 2010 |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // See http://www.boost.org/libs/mpl for documentation. |
| 10 | // |
| 11 | //////////////////////////////////////////////////////////////////// |
| 12 | #ifndef BOOST_MPL_ABS_HPP_INCLUDED |
| 13 | #define BOOST_MPL_ABS_HPP_INCLUDED |
| 14 | |
| 15 | #include <boost/mpl/integral_c.hpp> |
| 16 | #include <boost/mpl/aux_/na_spec.hpp> |
| 17 | #include <boost/mpl/aux_/lambda_support.hpp> |
| 18 | #include <boost/mpl/aux_/config/integral.hpp> |
| 19 | #include <boost/mpl/aux_/config/static_constant.hpp> |
| 20 | |
| 21 | #if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) \ |
| 22 | && !defined(BOOST_MPL_PREPROCESSING_MODE) \ |
| 23 | && !defined(__CUDACC__) \ |
| 24 | && ( defined(BOOST_MSVC) \ |
| 25 | || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \ |
| 26 | ) |
| 27 | |
| 28 | # define BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2 |
| 29 | |
| 30 | #endif |
| 31 | |
| 32 | namespace boost { namespace mpl { |
| 33 | |
| 34 | template< typename Tag > struct abs_impl; |
| 35 | |
| 36 | template< typename T > struct abs_tag |
| 37 | { |
| 38 | typedef typename T::tag type; |
| 39 | }; |
| 40 | |
| 41 | template< |
| 42 | typename BOOST_MPL_AUX_NA_PARAM(N) |
| 43 | > |
| 44 | struct abs |
| 45 | : abs_impl< |
| 46 | typename abs_tag<N>::type |
| 47 | >::template apply<N>::type |
| 48 | { |
| 49 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1, abs, (N)) |
| 50 | }; |
| 51 | |
| 52 | BOOST_MPL_AUX_NA_SPEC(1, abs) |
| 53 | |
| 54 | template< |
| 55 | typename T |
| 56 | , T n1 |
| 57 | > |
| 58 | struct abs_c |
| 59 | : abs<integral_c<T,n1> > |
| 60 | { |
| 61 | }; |
| 62 | |
| 63 | #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) |
| 64 | namespace aux { |
| 65 | template< typename T, T n > struct abs_wknd |
| 66 | { |
| 67 | BOOST_STATIC_CONSTANT(T, value = (n < 0 ? -n : n)); |
| 68 | typedef integral_c<T,value> type; |
| 69 | }; |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | template<> |
| 74 | struct abs_impl<integral_c_tag> |
| 75 | { |
| 76 | #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) |
| 77 | template< typename N > struct apply |
| 78 | : aux::abs_wknd< typename N::value_type, N::value > |
| 79 | #else |
| 80 | template< typename N > struct apply |
| 81 | : integral_c< typename N::value_type, ((N::value < 0) ? (-N::value) : N::value ) > |
| 82 | #endif |
| 83 | { |
| 84 | }; |
| 85 | }; |
| 86 | |
| 87 | }} |
| 88 | |
| 89 | #endif // BOOST_MPL_ABS_HPP_INCLUDED |
| 90 | |