has_minus_assign.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_minus_assign_ASSIGN_HPP_INCLUDED
  9. #define BOOST_TT_has_minus_assign_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_pointer.hpp>
  39. #include <boost/type_traits/add_reference.hpp>
  40. #include <boost/type_traits/remove_pointer.hpp>
  41. #include <boost/type_traits/remove_reference.hpp>
  42. #include <utility>
  43. namespace boost
  44. {
  45. namespace binary_op_detail {
  46. struct dont_care;
  47. template <class T, class U, class Ret, class = void>
  48. struct has_minus_assign_ret_imp : public boost::false_type {};
  49. template <class T, class U, class Ret>
  50. struct has_minus_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>
  51. : 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> {};
  52. template <class T, class U, class = void >
  53. struct has_minus_assign_void_imp : public boost::false_type {};
  54. template <class T, class U>
  55. struct has_minus_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>
  56. : public boost::integral_constant<bool, ::boost::is_void<decltype(std::declval<typename add_reference<T>::type>() -= std::declval<typename add_reference<U>::type>())>::value> {};
  57. template <class T, class U, class = void>
  58. struct has_minus_assign_dc_imp : public boost::false_type {};
  59. template <class T, class U>
  60. struct has_minus_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>
  61. : public boost::true_type {};
  62. template <class T, class U, class Ret>
  63. struct has_minus_assign_ret_filter : public boost::binary_op_detail::has_minus_assign_ret_imp <T, U, Ret> {};
  64. template <class T, class U>
  65. struct has_minus_assign_ret_filter<T, U, void> : public boost::binary_op_detail::has_minus_assign_void_imp <T, U> {};
  66. template <class T, class U>
  67. struct has_minus_assign_ret_filter<T, U, boost::binary_op_detail::dont_care> : public boost::binary_op_detail::has_minus_assign_dc_imp <T, U> {};
  68. template <class T, class U, class Ret, bool b>
  69. struct has_minus_assign_void_ptr_filter : public boost::binary_op_detail::has_minus_assign_ret_filter <T, U, Ret> {};
  70. template <class T, class U, class Ret>
  71. struct has_minus_assign_void_ptr_filter<T, U, Ret, true> : public boost::false_type {};
  72. }
  73. template <class T, class U = T, class Ret = boost::binary_op_detail::dont_care>
  74. struct has_minus_assign :
  75. public boost::binary_op_detail::has_minus_assign_void_ptr_filter<
  76. T, U, Ret,
  77. boost::is_void<typename remove_pointer<typename remove_reference<T>::type>::type>::value
  78. || boost::is_void<typename remove_pointer<typename remove_reference<U>::type>::type>::value
  79. || (boost::is_pointer<typename remove_reference<T>::type>::value && boost::is_pointer<typename remove_reference<U>::type>::value)> {};
  80. }
  81. #else
  82. #define BOOST_TT_TRAIT_NAME has_minus_assign
  83. #define BOOST_TT_TRAIT_OP -=
  84. #define BOOST_TT_FORBIDDEN_IF\
  85. (\
  86. /* Lhs==pointer and Rhs==fundamental and Rhs!=integral */\
  87. (\
  88. ::boost::is_pointer< Lhs_noref >::value && \
  89. ::boost::is_fundamental< Rhs_nocv >::value && \
  90. (! ::boost::is_integral< Rhs_noref >::value )\
  91. ) || \
  92. /* Lhs==void* and Rhs==fundamental */\
  93. (\
  94. ::boost::is_pointer< Lhs_noref >::value && \
  95. ::boost::is_void< Lhs_noptr >::value && \
  96. ::boost::is_fundamental< Rhs_nocv >::value\
  97. ) || \
  98. /* Rhs==void* and Lhs==fundamental */\
  99. (\
  100. ::boost::is_pointer< Rhs_noref >::value && \
  101. ::boost::is_void< Rhs_noptr >::value && \
  102. ::boost::is_fundamental< Lhs_nocv >::value\
  103. ) || \
  104. /* Lhs=fundamental and Rhs=pointer */\
  105. (\
  106. ::boost::is_fundamental< Lhs_nocv >::value && \
  107. ::boost::is_pointer< Rhs_noref >::value\
  108. ) || \
  109. /* Lhs==pointer and Rhs==pointer */\
  110. (\
  111. ::boost::is_pointer< Lhs_noref >::value && \
  112. ::boost::is_pointer< Rhs_noref >::value\
  113. ) || \
  114. /* (Lhs==fundamental or Lhs==pointer) and (Rhs==fundamental or Rhs==pointer) and (Lhs==const) */\
  115. (\
  116. (\
  117. ::boost::is_fundamental< Lhs_nocv >::value || \
  118. ::boost::is_pointer< Lhs_noref >::value\
  119. ) && \
  120. (\
  121. ::boost::is_fundamental< Rhs_nocv >::value || \
  122. ::boost::is_pointer< Rhs_noref >::value\
  123. ) && \
  124. ::boost::is_const< Lhs_noref >::value\
  125. )\
  126. )
  127. #include <boost/type_traits/detail/has_binary_operator.hpp>
  128. #undef BOOST_TT_TRAIT_NAME
  129. #undef BOOST_TT_TRAIT_OP
  130. #undef BOOST_TT_FORBIDDEN_IF
  131. #endif
  132. #if defined(BOOST_MSVC)
  133. # pragma warning (pop)
  134. #endif
  135. #endif