1 // (C) Copyright 2009-2011 Frederic Bron.
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).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_HAS_MINUS_HPP_INCLUDED
10 #define BOOST_TT_HAS_MINUS_HPP_INCLUDED
12 #include <boost/config.hpp>
13 #include <boost/type_traits/detail/config.hpp>
15 // cannot include this header without getting warnings of the kind:
17 // warning: value computed is not used
18 // warning: comparison between signed and unsigned integer expressions
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.
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)
37 #if defined(BOOST_TT_HAS_ACCURATE_BINARY_OPERATOR_DETECTION)
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>
51 namespace binary_op_detail {
55 template <class T, class U, class Ret, class = void>
56 struct has_minus_ret_imp : public boost::false_type {};
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> {};
62 template <class T, class U, class = void >
63 struct has_minus_void_imp : public boost::false_type {};
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> {};
69 template <class T, class U, class = void>
70 struct has_minus_dc_imp : public boost::false_type {};
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 {};
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> {};
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 {};
90 template <class T, class U = T, class Ret = boost::binary_op_detail::dont_care>
92 public boost::binary_op_detail::has_minus_void_ptr_filter<
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> {};
103 #define BOOST_TT_TRAIT_NAME has_minus
104 #define BOOST_TT_TRAIT_OP -
105 #define BOOST_TT_FORBIDDEN_IF\
107 /* Lhs==pointer and Rhs==fundamental and Rhs!=integral */\
109 ::boost::is_pointer< Lhs_noref >::value && \
110 ::boost::is_fundamental< Rhs_nocv >::value && \
111 (! ::boost::is_integral< Rhs_noref >::value )\
113 /* Lhs==void* and (Rhs==fundamental or Rhs==pointer) */\
115 ::boost::is_pointer< Lhs_noref >::value && \
116 ::boost::is_void< Lhs_noptr >::value && \
118 ::boost::is_fundamental< Rhs_nocv >::value || \
119 ::boost::is_pointer< Rhs_noref >::value\
122 /* Rhs==void* and (Lhs==fundamental or Lhs==pointer) */\
124 ::boost::is_pointer< Rhs_noref >::value && \
125 ::boost::is_void< Rhs_noptr >::value && \
127 ::boost::is_fundamental< Lhs_nocv >::value || \
128 ::boost::is_pointer< Lhs_noref >::value\
131 /* Lhs=fundamental and Rhs=pointer */\
133 ::boost::is_fundamental< Lhs_nocv >::value && \
134 ::boost::is_pointer< Rhs_noref >::value\
136 /* two different pointers */\
138 ::boost::is_pointer< Lhs_noref >::value && \
139 ::boost::is_pointer< Rhs_noref >::value && \
140 (! ::boost::is_same< Lhs_nocv, Rhs_nocv >::value )\
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)
146 #include <boost/type_traits/detail/has_binary_operator.hpp>
148 #undef BOOST_TT_TRAIT_NAME
149 #undef BOOST_TT_TRAIT_OP
150 #undef BOOST_TT_FORBIDDEN_IF
154 #if defined(BOOST_MSVC)
155 # pragma warning (pop)