1 // (C) Copyright Frederic Bron 2009-2011.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef TT_HAS_BINARY_OPERATORS_HPP
7 #define TT_HAS_BINARY_OPERATORS_HPP
9 #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wunused-function"
15 // test with one template parameter
16 #define TEST_T(TYPE,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE>::value), RESULT)
17 // test with one template parameter plus return value
18 #define TEST_TR(TYPE,RET,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE,TYPE,RET>::value), RESULT)
19 // test with two template parameters
20 #define TEST_TT(TYPE1,TYPE2,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE1,TYPE2>::value), RESULT)
21 // test with two template parameters plus return value
22 #define TEST_TTR(TYPE1,TYPE2,RET,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE1,TYPE2,RET>::value), RESULT)
30 struct internal { ret operator BOOST_TT_TRAIT_OP (const internal&) const; };
33 inline ret operator BOOST_TT_TRAIT_OP (const external&, const external&) { return ret(); }
35 struct comma1_ret { };
36 struct ret_with_comma1 { comma1_ret operator,(int); };
38 struct internal_comma1 { ret_with_comma1 operator BOOST_TT_TRAIT_OP (const internal_comma1&) const; };
40 struct external_comma1 { };
41 ret_with_comma1 operator BOOST_TT_TRAIT_OP (const external_comma1&, const external_comma1&) { return ret_with_comma1(); }
43 struct ret_with_comma2 { void operator,(int); };
45 struct internal_comma2 { ret_with_comma2 operator BOOST_TT_TRAIT_OP (const internal_comma2&) const; };
47 struct external_comma2 { };
48 ret_with_comma2 operator BOOST_TT_TRAIT_OP (const external_comma2&, const external_comma2&){ return ret_with_comma2(); }
50 struct returns_int { int operator BOOST_TT_TRAIT_OP (const returns_int&); };
52 struct returns_void { void operator BOOST_TT_TRAIT_OP (const returns_void&); };
54 struct returns_void_star { void *operator BOOST_TT_TRAIT_OP (const returns_void_star&); };
56 struct returns_double { double operator BOOST_TT_TRAIT_OP (const returns_double&); };
59 struct convertible_to_ret1 { operator ret1 () const; };
60 struct returns_convertible_to_ret1 { convertible_to_ret1 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret1&); };
62 struct convertible_to_ret2 { };
63 struct ret2 { ret2(const convertible_to_ret2); };
64 struct returns_convertible_to_ret2 { convertible_to_ret2 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret2&); };
67 class Derived1 : public Base1 { };
69 bool operator BOOST_TT_TRAIT_OP (const Base1&, const Base1&) { return true; }
72 struct Derived2 : public Base2 {
73 Derived2(int); // to check if it works with a class that is not default constructible
76 bool operator BOOST_TT_TRAIT_OP (const Derived2&, const Derived2&) { return true; }
81 struct B : public A { };
85 inline bool operator BOOST_TT_TRAIT_OP (const C&, void*) { return true; }
86 inline bool operator BOOST_TT_TRAIT_OP (void*, const D&) { return true; }
87 inline bool operator BOOST_TT_TRAIT_OP (const C&, const D&) { return true; }
89 struct private_op { private: void operator BOOST_TT_TRAIT_OP (const private_op&) {} };
94 inline bool operator BOOST_TT_TRAIT_OP (const ambiguous_A&, const ambiguous_A&) { return true; }
95 struct ambiguous_B { operator ambiguous_A()const { return ambiguous_A(); } };
97 //class internal_private { ret operator BOOST_TT_TRAIT_OP (const internal_private&) const; };
101 TEST_TT(void, void, false);
102 TEST_TTR(void, void, void, false);
103 TEST_TTR(void, void, int, false);
105 TEST_T(without, false);
106 TEST_T(internal, true);
107 TEST_T(external, true);
108 TEST_T(internal_comma1, true);
109 TEST_T(external_comma1, true);
110 TEST_T(internal_comma2, true);
111 TEST_T(external_comma2, true);
112 TEST_T(returns_int, true);
113 TEST_T(returns_void, true);
114 TEST_T(returns_void_star, true);
115 TEST_T(returns_double, true);
116 TEST_T(returns_convertible_to_ret1, true);
117 TEST_T(returns_convertible_to_ret2, true);
119 TEST_T(Derived1, true);
120 TEST_T(Base2, false);
121 TEST_T(Derived2, true);
123 TEST_TR(without, void, false);
124 TEST_TR(without, bool, false);
125 TEST_TR(internal, void, false);
126 TEST_TR(internal, bool, false);
127 TEST_TR(internal, ret, true);
128 TEST_TR(internal_comma1, void, false);
129 TEST_TR(internal_comma1, bool, false);
130 TEST_TR(internal_comma1, ret_with_comma1, true);
131 TEST_TR(internal_comma2, void, false);
132 TEST_TR(internal_comma2, bool, false);
133 TEST_TR(internal_comma2, ret_with_comma2, true);
134 TEST_TR(external, void, false);
135 TEST_TR(external, bool, false);
136 TEST_TR(external, ret, true);
137 TEST_TR(returns_int, void, false);
138 TEST_TR(returns_int, bool, true);
139 TEST_TR(returns_int, int, true);
140 TEST_TR(returns_void, void, true);
141 TEST_TR(returns_void, bool, false);
142 TEST_TR(returns_void_star, bool, true);
143 TEST_TR(returns_double, void, false);
144 TEST_TR(returns_double, bool, true);
145 TEST_TR(returns_double, double, true);
146 TEST_TR(returns_convertible_to_ret1, void, false);
147 TEST_TR(returns_convertible_to_ret1, ret1, true);
148 TEST_TR(returns_convertible_to_ret2, ret2, true);
149 TEST_TR(Base1, bool, true);
150 TEST_TR(Derived1, bool, true);
151 TEST_TR(Base2, bool, false);
152 TEST_TR(Derived2, bool, true);
153 // compile time error
154 // TEST_T(internal_private, false);
155 #if defined(BOOST_TT_HAS_ACCURATE_BINARY_OPERATOR_DETECTION)
156 // There are some things that pass that wouldn't otherwise do so:
157 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
158 TEST_TR(private_op, bool, false);
159 TEST_T(private_op, false);
161 TEST_TR(ambiguous_A, bool, true);
162 TEST_T(ambiguous_A, true);
163 TEST_TR(ambiguous_B, bool, true);
164 TEST_T(ambiguous_B, true);
170 #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900)
171 #pragma GCC diagnostic pop