sign.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_SIGN_HPP_INCLUDED
  13. #define BOOST_MPL_SIGN_HPP_INCLUDED
  14. #include <boost/mpl/integral_c.hpp>
  15. #include <boost/mpl/aux_/na_spec.hpp>
  16. #include <boost/mpl/aux_/lambda_support.hpp>
  17. #include <boost/mpl/aux_/config/integral.hpp>
  18. #include <boost/mpl/aux_/config/static_constant.hpp>
  19. #if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2) \
  20. && !defined(BOOST_MPL_PREPROCESSING_MODE) \
  21. && !defined(__CUDACC__) \
  22. && ( defined(BOOST_MSVC) \
  23. || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \
  24. )
  25. # define BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2
  26. #endif
  27. namespace boost { namespace mpl {
  28. template< typename Tag > struct sign_impl;
  29. template< typename T > struct sign_tag
  30. {
  31. typedef typename T::tag type;
  32. };
  33. template<
  34. typename BOOST_MPL_AUX_NA_PARAM(N)
  35. >
  36. struct sign
  37. : sign_impl<
  38. typename sign_tag<N>::type
  39. >::template apply<N>::type
  40. {
  41. BOOST_MPL_AUX_LAMBDA_SUPPORT(1, sign, (N))
  42. };
  43. BOOST_MPL_AUX_NA_SPEC(1, sign)
  44. template<
  45. typename T
  46. , T n1
  47. >
  48. struct sign_c
  49. : sign<integral_c<T,n1> >
  50. {
  51. };
  52. #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2)
  53. namespace aux {
  54. template< typename T, T n > struct sign_wknd
  55. {
  56. BOOST_STATIC_CONSTANT(T, value = (n == 0 ? 0 : (n < 0 ? -1 : 1)));
  57. typedef integral_c<T,value> type;
  58. };
  59. }
  60. #endif
  61. template<>
  62. struct sign_impl<integral_c_tag>
  63. {
  64. #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC_2)
  65. template< typename N > struct apply
  66. : aux::sign_wknd< typename N::value_type, N::value >
  67. #else
  68. template< typename N > struct apply
  69. : integral_c< typename N::value_type, (N::value == 0 ? 0 : (N::value < 0 ? -1 : 1)) >
  70. #endif
  71. {
  72. };
  73. };
  74. }}
  75. #endif // BOOST_MPL_SIGN_HPP_INCLUDED