is_incrementable.hpp 3.0 KB

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