| 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 | |
| 9 | #ifndef BOOST_TT_HAS_MINUS_HPP_INCLUDED |
| 10 | #define BOOST_TT_HAS_MINUS_HPP_INCLUDED |
| 11 | |
| 12 | #include <boost/config.hpp> |
| 13 | #include <boost/type_traits/detail/config.hpp> |
| 14 | |
| 15 | // cannot include this header without getting warnings of the kind: |
| 16 | // gcc: |
| 17 | // warning: value computed is not used |
| 18 | // warning: comparison between signed and unsigned integer expressions |
| 19 | // msvc: |
| 20 | // warning C4018: '<' : signed/unsigned mismatch |
| 21 | // warning C4244: '+=' : conversion from 'double' to 'char', possible loss of data |
| 22 | // warning C4547: '*' : operator before comma has no effect; expected operator with side-effect |
| 23 | // warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) |
| 24 | // warning C4804: '<' : unsafe use of type 'bool' in operation |
| 25 | // warning C4805: '==' : unsafe mix of type 'bool' and type 'char' in operation |
| 26 | // cannot find another implementation -> declared as system header to suppress these warnings. |
| 27 | #if defined(__GNUC__) |
| 28 | # pragma GCC system_header |
| 29 | #elif defined(BOOST_MSVC) |
| 30 | # pragma warning ( push ) |
| 31 | # pragma warning ( disable : 4018 4244 4547 4800 4804 4805 4913 4133) |
| 32 | # if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000) |
| 33 | # pragma warning ( disable : 6334) |
| 34 | # endif |
| 35 | #endif |
| 36 | |
| 37 | #if defined(BOOST_TT_HAS_ACCURATE_BINARY_OPERATOR_DETECTION) |
| 38 | |
| 39 | #include <boost/type_traits/integral_constant.hpp> |
| 40 | #include <boost/type_traits/make_void.hpp> |
| 41 | #include <boost/type_traits/is_convertible.hpp> |
| 42 | #include <boost/type_traits/is_void.hpp> |
| 43 | #include <boost/type_traits/add_reference.hpp> |
| 44 | #include <boost/type_traits/remove_pointer.hpp> |
| 45 | #include <boost/type_traits/remove_reference.hpp> |
| 46 | #include <utility> |
| 47 | |
| 48 | namespace boost |
| 49 | { |
| 50 | |
| 51 | namespace binary_op_detail { |
| 52 | |
| 53 | struct dont_care; |
| 54 | |
| 55 | template <class T, class U, class Ret, class = void> |
| 56 | struct has_minus_ret_imp : public boost::false_type {}; |
| 57 | |
| 58 | template <class T, class U, class Ret> |
| 59 | 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> |
| 60 | : 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> {}; |
| 61 | |
| 62 | template <class T, class U, class = void > |
| 63 | struct has_minus_void_imp : public boost::false_type {}; |
| 64 | |
| 65 | template <class T, class U> |
| 66 | 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> |
| 67 | : public boost::integral_constant<bool, ::boost::is_void<decltype(std::declval<typename add_reference<T>::type>() - std::declval<typename add_reference<U>::type>())>::value> {}; |
| 68 | |
| 69 | template <class T, class U, class = void> |
| 70 | struct has_minus_dc_imp : public boost::false_type {}; |
| 71 | |
| 72 | template <class T, class U> |
| 73 | 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> |
| 74 | : public boost::true_type {}; |
| 75 | |
| 76 | template <class T, class U, class Ret> |
| 77 | struct has_minus_ret_filter : public boost::binary_op_detail::has_minus_ret_imp <T, U, Ret> {}; |
| 78 | template <class T, class U> |
| 79 | struct has_minus_ret_filter<T, U, void> : public boost::binary_op_detail::has_minus_void_imp <T, U> {}; |
| 80 | template <class T, class U> |
| 81 | struct has_minus_ret_filter<T, U, boost::binary_op_detail::dont_care> : public boost::binary_op_detail::has_minus_dc_imp <T, U> {}; |
| 82 | |
| 83 | template <class T, class U, class Ret, bool b> |
| 84 | struct has_minus_void_ptr_filter : public boost::binary_op_detail::has_minus_ret_filter <T, U, Ret> {}; |
| 85 | template <class T, class U, class Ret> |
| 86 | struct has_minus_void_ptr_filter<T, U, Ret, true> : public boost::false_type {}; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | template <class T, class U = T, class Ret = boost::binary_op_detail::dont_care> |
| 91 | struct has_minus : |
| 92 | public boost::binary_op_detail::has_minus_void_ptr_filter< |
| 93 | T, U, Ret, |
| 94 | boost::is_void<typename remove_pointer<typename remove_reference<T>::type>::type>::value |
| 95 | || boost::is_void<typename remove_pointer<typename remove_reference<U>::type>::type>::value> {}; |
| 96 | |
| 97 | |
| 98 | } |
| 99 | |
| 100 | #else |
| 101 | |
| 102 | |
| 103 | #define BOOST_TT_TRAIT_NAME has_minus |
| 104 | #define BOOST_TT_TRAIT_OP - |
| 105 | #define BOOST_TT_FORBIDDEN_IF\ |
| 106 | (\ |
| 107 | /* Lhs==pointer and Rhs==fundamental and Rhs!=integral */\ |
| 108 | (\ |
| 109 | ::boost::is_pointer< Lhs_noref >::value && \ |
| 110 | ::boost::is_fundamental< Rhs_nocv >::value && \ |
| 111 | (! ::boost::is_integral< Rhs_noref >::value )\ |
| 112 | ) || \ |
| 113 | /* Lhs==void* and (Rhs==fundamental or Rhs==pointer) */\ |
| 114 | (\ |
| 115 | ::boost::is_pointer< Lhs_noref >::value && \ |
| 116 | ::boost::is_void< Lhs_noptr >::value && \ |
| 117 | ( \ |
| 118 | ::boost::is_fundamental< Rhs_nocv >::value || \ |
| 119 | ::boost::is_pointer< Rhs_noref >::value\ |
| 120 | )\ |
| 121 | ) || \ |
| 122 | /* Rhs==void* and (Lhs==fundamental or Lhs==pointer) */\ |
| 123 | (\ |
| 124 | ::boost::is_pointer< Rhs_noref >::value && \ |
| 125 | ::boost::is_void< Rhs_noptr >::value && \ |
| 126 | (\ |
| 127 | ::boost::is_fundamental< Lhs_nocv >::value || \ |
| 128 | ::boost::is_pointer< Lhs_noref >::value\ |
| 129 | )\ |
| 130 | ) ||\ |
| 131 | /* Lhs=fundamental and Rhs=pointer */\ |
| 132 | (\ |
| 133 | ::boost::is_fundamental< Lhs_nocv >::value && \ |
| 134 | ::boost::is_pointer< Rhs_noref >::value\ |
| 135 | ) ||\ |
| 136 | /* two different pointers */\ |
| 137 | (\ |
| 138 | ::boost::is_pointer< Lhs_noref >::value && \ |
| 139 | ::boost::is_pointer< Rhs_noref >::value && \ |
| 140 | (! ::boost::is_same< Lhs_nocv, Rhs_nocv >::value )\ |
| 141 | )\ |
| 142 | ) |
| 143 | |
| 144 | #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) |
| 145 | |
| 146 | #include <boost/type_traits/detail/has_binary_operator.hpp> |
| 147 | |
| 148 | #undef BOOST_TT_TRAIT_NAME |
| 149 | #undef BOOST_TT_TRAIT_OP |
| 150 | #undef BOOST_TT_FORBIDDEN_IF |
| 151 | |
| 152 | #endif |
| 153 | |
| 154 | #if defined(BOOST_MSVC) |
| 155 | # pragma warning (pop) |
| 156 | #endif |
| 157 | |
| 158 | #endif |
| 159 | |