integral_wrapper.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright Aleksey Gurtovoy 2000-2006
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. // NO INCLUDE GUARDS, THE HEADER IS INTENDED FOR MULTIPLE INCLUSION!
  12. #include <boost/mpl/integral_c_tag.hpp>
  13. #include <boost/mpl/aux_/static_cast.hpp>
  14. #include <boost/mpl/aux_/nttp_decl.hpp>
  15. #include <boost/mpl/aux_/config/static_constant.hpp>
  16. #include <boost/mpl/aux_/config/workaround.hpp>
  17. #include <boost/preprocessor/cat.hpp>
  18. #if !defined(AUX_WRAPPER_NAME)
  19. # define AUX_WRAPPER_NAME BOOST_PP_CAT(AUX_WRAPPER_VALUE_TYPE,_)
  20. #endif
  21. #if !defined(AUX_WRAPPER_PARAMS)
  22. # define AUX_WRAPPER_PARAMS(N) BOOST_MPL_AUX_NTTP_DECL(AUX_WRAPPER_VALUE_TYPE, N)
  23. #endif
  24. #if !defined(AUX_WRAPPER_INST)
  25. # if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
  26. # define AUX_WRAPPER_INST(value) AUX_WRAPPER_NAME< value >
  27. # else
  28. # define AUX_WRAPPER_INST(value) BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE::AUX_WRAPPER_NAME< value >
  29. # endif
  30. #endif
  31. BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN
  32. template< AUX_WRAPPER_PARAMS(N) >
  33. struct AUX_WRAPPER_NAME
  34. {
  35. BOOST_STATIC_CONSTANT(AUX_WRAPPER_VALUE_TYPE, value = N);
  36. // agurt, 08/mar/03: SGI MIPSpro C++ workaround, have to #ifdef because some
  37. // other compilers (e.g. MSVC) are not particulary happy about it
  38. #if BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
  39. typedef struct AUX_WRAPPER_NAME type;
  40. #else
  41. typedef AUX_WRAPPER_NAME type;
  42. #endif
  43. typedef AUX_WRAPPER_VALUE_TYPE value_type;
  44. typedef integral_c_tag tag;
  45. // have to #ifdef here: some compilers don't like the 'N + 1' form (MSVC),
  46. // while some other don't like 'value + 1' (Borland), and some don't like
  47. // either
  48. #if BOOST_WORKAROUND(__EDG_VERSION__, <= 243)
  49. private:
  50. BOOST_STATIC_CONSTANT(AUX_WRAPPER_VALUE_TYPE, next_value = BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (N + 1)));
  51. BOOST_STATIC_CONSTANT(AUX_WRAPPER_VALUE_TYPE, prior_value = BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (N - 1)));
  52. public:
  53. typedef AUX_WRAPPER_INST(next_value) next;
  54. typedef AUX_WRAPPER_INST(prior_value) prior;
  55. #elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561)) \
  56. || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(502)) \
  57. || (BOOST_WORKAROUND(__HP_aCC, <= 53800) && (BOOST_WORKAROUND(__hpxstd98, != 1)))
  58. typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (N + 1)) ) next;
  59. typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (N - 1)) ) prior;
  60. #else
  61. typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value + 1)) ) next;
  62. typedef AUX_WRAPPER_INST( BOOST_MPL_AUX_STATIC_CAST(AUX_WRAPPER_VALUE_TYPE, (value - 1)) ) prior;
  63. #endif
  64. // enables uniform function call syntax for families of overloaded
  65. // functions that return objects of both arithmetic ('int', 'long',
  66. // 'double', etc.) and wrapped integral types (for an example, see
  67. // "mpl/example/power.cpp")
  68. BOOST_CONSTEXPR operator AUX_WRAPPER_VALUE_TYPE() const { return static_cast<AUX_WRAPPER_VALUE_TYPE>(this->value); }
  69. };
  70. #if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
  71. template< AUX_WRAPPER_PARAMS(N) >
  72. AUX_WRAPPER_VALUE_TYPE const AUX_WRAPPER_INST(N)::value;
  73. #endif
  74. BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE
  75. #undef AUX_WRAPPER_NAME
  76. #undef AUX_WRAPPER_PARAMS
  77. #undef AUX_WRAPPER_INST
  78. #undef AUX_WRAPPER_VALUE_TYPE