]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_PLUS_ASSIGN_HPP_INCLUDED | |
10 | #define BOOST_TT_HAS_PLUS_ASSIGN_HPP_INCLUDED | |
11 | ||
11fdf7f2 TL |
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/is_same.hpp> | |
44 | #include <boost/type_traits/is_pointer.hpp> | |
45 | #include <boost/type_traits/is_arithmetic.hpp> | |
46 | #include <boost/type_traits/add_reference.hpp> | |
47 | #include <boost/type_traits/remove_pointer.hpp> | |
48 | #include <boost/type_traits/remove_reference.hpp> | |
49 | #include <boost/type_traits/remove_cv.hpp> | |
50 | #include <utility> | |
51 | ||
52 | namespace boost | |
53 | { | |
54 | ||
55 | namespace binary_op_detail { | |
56 | ||
57 | struct dont_care; | |
58 | ||
59 | template <class T, class U, class Ret, class = boost::void_t<>> | |
60 | struct has_plus_assign_ret_imp : public boost::false_type {}; | |
61 | ||
62 | template <class T, class U, class Ret> | |
63 | struct has_plus_assign_ret_imp<T, U, Ret, boost::void_t<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())> > | |
64 | : 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> {}; | |
65 | ||
66 | template <class T, class U, class = boost::void_t<> > | |
67 | struct has_plus_assign_void_imp : public boost::false_type {}; | |
68 | ||
69 | template <class T, class U> | |
70 | struct has_plus_assign_void_imp<T, U, boost::void_t<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())> > | |
71 | : public boost::integral_constant<bool, ::boost::is_void<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())>::value> {}; | |
72 | ||
73 | template <class T, class U, class = boost::void_t<>> | |
74 | struct has_plus_assign_dc_imp : public boost::false_type {}; | |
75 | ||
76 | template <class T, class U> | |
77 | struct has_plus_assign_dc_imp<T, U, boost::void_t<decltype(std::declval<typename add_reference<T>::type>() += std::declval<typename add_reference<U>::type>())> > | |
78 | : public boost::true_type {}; | |
79 | ||
80 | template <class T, class U, class Ret> | |
81 | struct has_plus_assign_filter_ret : public boost::binary_op_detail:: has_plus_assign_ret_imp <T, U, Ret> {}; | |
82 | template <class T, class U> | |
83 | struct has_plus_assign_filter_ret<T, U, void> : public boost::binary_op_detail:: has_plus_assign_void_imp <T, U> {}; | |
84 | template <class T, class U> | |
85 | 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> {}; | |
86 | ||
87 | template <class T, class U, class Ret, bool f> | |
88 | struct has_plus_assign_filter_impossible : public boost::binary_op_detail:: has_plus_assign_filter_ret <T, U, Ret> {}; | |
89 | template <class T, class U, class Ret> | |
90 | struct has_plus_assign_filter_impossible<T, U, Ret, true> : public boost::false_type {}; | |
91 | ||
92 | } | |
93 | ||
94 | template <class T, class U = T, class Ret = boost::binary_op_detail::dont_care> | |
95 | 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> {}; | |
96 | ||
97 | } | |
98 | ||
99 | #else | |
100 | ||
7c673cae FG |
101 | #define BOOST_TT_TRAIT_NAME has_plus_assign |
102 | #define BOOST_TT_TRAIT_OP += | |
103 | #define BOOST_TT_FORBIDDEN_IF\ | |
104 | (\ | |
105 | /* Lhs==pointer and Rhs==pointer */\ | |
106 | (\ | |
107 | ::boost::is_pointer< Lhs_noref >::value && \ | |
108 | ::boost::is_pointer< Rhs_noref >::value\ | |
109 | ) || \ | |
110 | /* Lhs==void* and Rhs==fundamental */\ | |
111 | (\ | |
112 | ::boost::is_pointer< Lhs_noref >::value && \ | |
113 | ::boost::is_void< Lhs_noptr >::value && \ | |
114 | ::boost::is_fundamental< Rhs_nocv >::value\ | |
115 | ) || \ | |
116 | /* Rhs==void* and Lhs==fundamental */\ | |
117 | (\ | |
118 | ::boost::is_pointer< Rhs_noref >::value && \ | |
119 | ::boost::is_void< Rhs_noptr >::value && \ | |
120 | ::boost::is_fundamental< Lhs_nocv >::value\ | |
121 | ) || \ | |
122 | /* Lhs==pointer and Rhs==fundamental and Rhs!=integral */\ | |
123 | (\ | |
124 | ::boost::is_pointer< Lhs_noref >::value && \ | |
125 | ::boost::is_fundamental< Rhs_nocv >::value && \ | |
126 | (! ::boost::is_integral< Rhs_noref >::value )\ | |
127 | ) || \ | |
128 | /* Rhs==pointer and Lhs==fundamental and Lhs!=bool */\ | |
129 | (\ | |
130 | ::boost::is_pointer< Rhs_noref >::value && \ | |
131 | ::boost::is_fundamental< Lhs_nocv >::value && \ | |
132 | (! ::boost::is_same< Lhs_nocv, bool >::value )\ | |
133 | ) || \ | |
134 | /* (Lhs==fundamental or Lhs==pointer) and (Rhs==fundamental or Rhs==pointer) and (Lhs==const) */\ | |
135 | (\ | |
136 | (\ | |
137 | ::boost::is_fundamental< Lhs_nocv >::value || \ | |
138 | ::boost::is_pointer< Lhs_noref >::value\ | |
139 | ) && \ | |
140 | ( \ | |
141 | ::boost::is_fundamental< Rhs_nocv >::value || \ | |
142 | ::boost::is_pointer< Rhs_noref >::value\ | |
143 | ) && \ | |
144 | ::boost::is_const< Lhs_noref >::value\ | |
145 | )\ | |
146 | ) | |
147 | ||
148 | ||
149 | #include <boost/type_traits/detail/has_binary_operator.hpp> | |
150 | ||
151 | #undef BOOST_TT_TRAIT_NAME | |
152 | #undef BOOST_TT_TRAIT_OP | |
153 | #undef BOOST_TT_FORBIDDEN_IF | |
154 | ||
155 | #endif | |
11fdf7f2 | 156 | #endif |