has_plus_assign.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // (C) Copyright 2009-2011 Frederic Bron.
  2. //
  3. // Use, modification and distribution are subject to the Boost Software License,
  4. // Version 1.0. (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/type_traits for most recent version including documentation.
  8. #ifndef BOOST_TT_HAS_PLUS_ASSIGN_HPP_INCLUDED
  9. #define BOOST_TT_HAS_PLUS_ASSIGN_HPP_INCLUDED
  10. #include <boost/config.hpp>
  11. #include <boost/type_traits/detail/config.hpp>
  12. // cannot include this header without getting warnings of the kind:
  13. // gcc:
  14. // warning: value computed is not used
  15. // warning: comparison between signed and unsigned integer expressions
  16. // msvc:
  17. // warning C4018: '<' : signed/unsigned mismatch
  18. // warning C4244: '+=' : conversion from 'double' to 'char', possible loss of data
  19. // warning C4547: '*' : operator before comma has no effect; expected operator with side-effect
  20. // warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
  21. // warning C4804: '<' : unsafe use of type 'bool' in operation
  22. // warning C4805: '==' : unsafe mix of type 'bool' and type 'char' in operation
  23. // cannot find another implementation -> declared as system header to suppress these warnings.
  24. #if defined(__GNUC__)
  25. # pragma GCC system_header
  26. #elif defined(BOOST_MSVC)
  27. # pragma warning ( push )
  28. # pragma warning ( disable : 4018 4244 4547 4800 4804 4805 4913 4133)
  29. # if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000)
  30. # pragma warning ( disable : 6334)
  31. # endif
  32. #endif
  33. #if defined(BOOST_TT_HAS_ACCURATE_BINARY_OPERATOR_DETECTION)
  34. #include <boost/type_traits/integral_constant.hpp>
  35. #include <boost/type_traits/make_void.hpp>
  36. #include <boost/type_traits/is_convertible.hpp>
  37. #include <boost/type_traits/is_void.hpp>
  38. #include <boost/type_traits/is_same.hpp>
  39. #include <boost/type_traits/is_pointer.hpp>
  40. #include <boost/type_traits/is_arithmetic.hpp>
  41. #include <boost/type_traits/add_reference.hpp>
  42. #include <boost/type_traits/remove_pointer.hpp>
  43. #include <boost/type_traits/remove_reference.hpp>
  44. #include <boost/type_traits/remove_cv.hpp>
  45. #include <utility>
  46. namespace boost
  47. {
  48. namespace binary_op_detail {
  49. struct dont_care;
  50. template <class T, class U, class Ret, class = void>
  51. struct has_plus_assign_ret_imp : public boost::false_type {};
  52. template <class T, class U, class Ret>
  53. struct has_plus_assign_ret_imp<T, U, Ret, typename boost::make_void<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())>::type>
  54. : public boost::integral_constant<bool, ::boost::is_convertible<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>()), Ret>::value> {};
  55. template <class T, class U, class = void >
  56. struct has_plus_assign_void_imp : public boost::false_type {};
  57. template <class T, class U>
  58. struct has_plus_assign_void_imp<T, U, typename boost::make_void<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())>::type>
  59. : public boost::integral_constant<bool, ::boost::is_void<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())>::value> {};
  60. template <class T, class U, class = void>
  61. struct has_plus_assign_dc_imp : public boost::false_type {};
  62. template <class T, class U>
  63. struct has_plus_assign_dc_imp<T, U, typename boost::make_void<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())>::type>
  64. : public boost::true_type {};
  65. template <class T, class U, class Ret>
  66. struct has_plus_assign_filter_ret : public boost::binary_op_detail:: has_plus_assign_ret_imp <T, U, Ret> {};
  67. template <class T, class U>
  68. struct has_plus_assign_filter_ret<T, U, void> : public boost::binary_op_detail:: has_plus_assign_void_imp <T, U> {};
  69. template <class T, class U>
  70. struct has_plus_assign_filter_ret<T, U, boost::binary_op_detail::dont_care> : public boost::binary_op_detail:: has_plus_assign_dc_imp <T, U> {};
  71. template <class T, class U, class Ret, bool f>
  72. struct has_plus_assign_filter_impossible : public boost::binary_op_detail:: has_plus_assign_filter_ret <T, U, Ret> {};
  73. template <class T, class U, class Ret>
  74. struct has_plus_assign_filter_impossible<T, U, Ret, true> : public boost::false_type {};
  75. }
  76. template <class T, class U = T, class Ret = boost::binary_op_detail::dont_care>
  77. struct has_plus_assign : public boost::binary_op_detail:: has_plus_assign_filter_impossible <T, U, Ret, boost::is_arithmetic<typename boost::remove_reference<T>::type>::value && boost::is_pointer<typename remove_reference<U>::type>::value && !boost::is_same<bool, typename boost::remove_cv<typename remove_reference<T>::type>::type>::value> {};
  78. }
  79. #else
  80. #define BOOST_TT_TRAIT_NAME has_plus_assign
  81. #define BOOST_TT_TRAIT_OP +=
  82. #define BOOST_TT_FORBIDDEN_IF\
  83. (\
  84. /* Lhs==pointer and Rhs==pointer */\
  85. (\
  86. ::boost::is_pointer< Lhs_noref >::value && \
  87. ::boost::is_pointer< Rhs_noref >::value\
  88. ) || \
  89. /* Lhs==void* and Rhs==fundamental */\
  90. (\
  91. ::boost::is_pointer< Lhs_noref >::value && \
  92. ::boost::is_void< Lhs_noptr >::value && \
  93. ::boost::is_fundamental< Rhs_nocv >::value\
  94. ) || \
  95. /* Rhs==void* and Lhs==fundamental */\
  96. (\
  97. ::boost::is_pointer< Rhs_noref >::value && \
  98. ::boost::is_void< Rhs_noptr >::value && \
  99. ::boost::is_fundamental< Lhs_nocv >::value\
  100. ) || \
  101. /* Lhs==pointer and Rhs==fundamental and Rhs!=integral */\
  102. (\
  103. ::boost::is_pointer< Lhs_noref >::value && \
  104. ::boost::is_fundamental< Rhs_nocv >::value && \
  105. (! ::boost::is_integral< Rhs_noref >::value )\
  106. ) || \
  107. /* Rhs==pointer and Lhs==fundamental and Lhs!=bool */\
  108. (\
  109. ::boost::is_pointer< Rhs_noref >::value && \
  110. ::boost::is_fundamental< Lhs_nocv >::value && \
  111. (! ::boost::is_same< Lhs_nocv, bool >::value )\
  112. ) || \
  113. /* (Lhs==fundamental or Lhs==pointer) and (Rhs==fundamental or Rhs==pointer) and (Lhs==const) */\
  114. (\
  115. (\
  116. ::boost::is_fundamental< Lhs_nocv >::value || \
  117. ::boost::is_pointer< Lhs_noref >::value\
  118. ) && \
  119. ( \
  120. ::boost::is_fundamental< Rhs_nocv >::value || \
  121. ::boost::is_pointer< Rhs_noref >::value\
  122. ) && \
  123. ::boost::is_const< Lhs_noref >::value\
  124. )\
  125. )
  126. #include <boost/type_traits/detail/has_binary_operator.hpp>
  127. #undef BOOST_TT_TRAIT_NAME
  128. #undef BOOST_TT_TRAIT_OP
  129. #undef BOOST_TT_FORBIDDEN_IF
  130. #endif
  131. #if defined(BOOST_MSVC)
  132. # pragma warning (pop)
  133. #endif
  134. #endif