negate.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BOOST_MPL_NEGATE_HPP_INCLUDED
  2. #define BOOST_MPL_NEGATE_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  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. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/integral_c.hpp>
  14. #include <boost/mpl/aux_/msvc_eti_base.hpp>
  15. #include <boost/mpl/aux_/na_spec.hpp>
  16. #include <boost/mpl/aux_/lambda_support.hpp>
  17. #include <boost/mpl/aux_/config/eti.hpp>
  18. #include <boost/mpl/aux_/config/integral.hpp>
  19. #include <boost/mpl/aux_/config/static_constant.hpp>
  20. namespace boost { namespace mpl {
  21. template< typename Tag > struct negate_impl;
  22. template< typename T > struct negate_tag
  23. {
  24. typedef typename T::tag type;
  25. };
  26. template<
  27. typename BOOST_MPL_AUX_NA_PARAM(N)
  28. >
  29. struct negate
  30. #if !defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
  31. : negate_impl<
  32. typename negate_tag<N>::type
  33. >::template apply<N>::type
  34. #else
  35. : aux::msvc_eti_base< typename apply_wrap1<
  36. negate_impl< typename negate_tag<N>::type >
  37. , N
  38. >::type >::type
  39. #endif
  40. {
  41. BOOST_MPL_AUX_LAMBDA_SUPPORT(1, negate, (N))
  42. };
  43. BOOST_MPL_AUX_NA_SPEC(1, negate)
  44. #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC)
  45. namespace aux {
  46. template< typename T, T n > struct negate_wknd
  47. {
  48. BOOST_STATIC_CONSTANT(T, value = -n);
  49. typedef integral_c<T,value> type;
  50. };
  51. }
  52. #endif
  53. template<>
  54. struct negate_impl<integral_c_tag>
  55. {
  56. #if defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC)
  57. template< typename N > struct apply
  58. : aux::negate_wknd< typename N::value_type, N::value >
  59. #else
  60. template< typename N > struct apply
  61. : integral_c< typename N::value_type, (-N::value) >
  62. #endif
  63. {
  64. };
  65. };
  66. }}
  67. #endif // BOOST_MPL_NEGATE_HPP_INCLUDED