is_incrementable.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright David Abrahams 2004. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef IS_INCREMENTABLE_DWA200415_HPP
  5. # define IS_INCREMENTABLE_DWA200415_HPP
  6. # include <boost/type_traits/detail/template_arity_spec.hpp>
  7. # include <boost/type_traits/remove_cv.hpp>
  8. # include <boost/mpl/aux_/lambda_support.hpp>
  9. # include <boost/mpl/bool.hpp>
  10. # include <boost/detail/workaround.hpp>
  11. // Must be the last include
  12. # include <boost/type_traits/detail/bool_trait_def.hpp>
  13. namespace boost { namespace detail {
  14. // is_incrementable<T> metafunction
  15. //
  16. // Requires: Given x of type T&, if the expression ++x is well-formed
  17. // it must have complete type; otherwise, it must neither be ambiguous
  18. // nor violate access.
  19. // This namespace ensures that ADL doesn't mess things up.
  20. namespace is_incrementable_
  21. {
  22. // a type returned from operator++ when no increment is found in the
  23. // type's own namespace
  24. struct tag {};
  25. // any soaks up implicit conversions and makes the following
  26. // operator++ less-preferred than any other such operator that
  27. // might be found via ADL.
  28. struct any { template <class T> any(T const&); };
  29. // This is a last-resort operator++ for when none other is found
  30. # if BOOST_WORKAROUND(__GNUC__, == 4) && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
  31. }
  32. namespace is_incrementable_2
  33. {
  34. is_incrementable_::tag operator++(is_incrementable_::any const&);
  35. is_incrementable_::tag operator++(is_incrementable_::any const&,int);
  36. }
  37. using namespace is_incrementable_2;
  38. namespace is_incrementable_
  39. {
  40. # else
  41. tag operator++(any const&);
  42. tag operator++(any const&,int);
  43. # endif
  44. # if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
  45. || BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  46. # define BOOST_comma(a,b) (a)
  47. # else
  48. // In case an operator++ is found that returns void, we'll use ++x,0
  49. tag operator,(tag,int);
  50. # define BOOST_comma(a,b) (a,b)
  51. # endif
  52. # if defined(BOOST_MSVC)
  53. # pragma warning(push)
  54. # pragma warning(disable:4913) // Warning about operator,
  55. # endif
  56. // two check overloads help us identify which operator++ was picked
  57. char (& check(tag) )[2];
  58. template <class T>
  59. char check(T const&);
  60. template <class T>
  61. struct impl
  62. {
  63. static typename boost::remove_cv<T>::type& x;
  64. BOOST_STATIC_CONSTANT(
  65. bool
  66. , value = sizeof(is_incrementable_::check(BOOST_comma(++x,0))) == 1
  67. );
  68. };
  69. template <class T>
  70. struct postfix_impl
  71. {
  72. static typename boost::remove_cv<T>::type& x;
  73. BOOST_STATIC_CONSTANT(
  74. bool
  75. , value = sizeof(is_incrementable_::check(BOOST_comma(x++,0))) == 1
  76. );
  77. };
  78. # if defined(BOOST_MSVC)
  79. # pragma warning(pop)
  80. # endif
  81. }
  82. # undef BOOST_comma
  83. template<typename T>
  84. struct is_incrementable
  85. BOOST_TT_AUX_BOOL_C_BASE(::boost::detail::is_incrementable_::impl<T>::value)
  86. {
  87. BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::boost::detail::is_incrementable_::impl<T>::value)
  88. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_incrementable,(T))
  89. };
  90. template<typename T>
  91. struct is_postfix_incrementable
  92. BOOST_TT_AUX_BOOL_C_BASE(::boost::detail::is_incrementable_::impl<T>::value)
  93. {
  94. BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(::boost::detail::is_incrementable_::postfix_impl<T>::value)
  95. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_postfix_incrementable,(T))
  96. };
  97. } // namespace detail
  98. BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::detail::is_incrementable)
  99. BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1, ::boost::detail::is_postfix_incrementable)
  100. } // namespace boost
  101. # include <boost/type_traits/detail/bool_trait_undef.hpp>
  102. #endif // IS_INCREMENTABLE_DWA200415_HPP