has_minus.hpp 6.4 KB

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