]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
5 | ||
92f5a8d4 TL |
6 | // It would be nice to get rid of the unnamed namespace here, |
7 | // but for now we just turn off inspection reporting :( | |
8 | // boostinspect:nounnamed | |
9 | ||
7c673cae FG |
10 | #ifndef TT_HAS_BINARY_OPERATORS_HPP |
11 | #define TT_HAS_BINARY_OPERATORS_HPP | |
12 | ||
13 | #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900) | |
14 | #pragma GCC diagnostic push | |
15 | #pragma GCC diagnostic ignored "-Wunused-function" | |
16 | #endif | |
17 | ||
18 | ||
19 | // test with one template parameter | |
20 | #define TEST_T(TYPE,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE>::value), RESULT) | |
21 | // test with one template parameter plus return value | |
22 | #define TEST_TR(TYPE,RET,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE,TYPE,RET>::value), RESULT) | |
23 | // test with two template parameters | |
24 | #define TEST_TT(TYPE1,TYPE2,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE1,TYPE2>::value), RESULT) | |
25 | // test with two template parameters plus return value | |
26 | #define TEST_TTR(TYPE1,TYPE2,RET,RESULT) BOOST_CHECK_INTEGRAL_CONSTANT((::boost::BOOST_TT_TRAIT_NAME<TYPE1,TYPE2,RET>::value), RESULT) | |
27 | ||
28 | namespace { | |
29 | ||
30 | struct without { }; | |
31 | ||
32 | struct ret { }; | |
33 | ||
34 | struct internal { ret operator BOOST_TT_TRAIT_OP (const internal&) const; }; | |
35 | ||
36 | struct external { }; | |
37 | inline ret operator BOOST_TT_TRAIT_OP (const external&, const external&) { return ret(); } | |
38 | ||
39 | struct comma1_ret { }; | |
40 | struct ret_with_comma1 { comma1_ret operator,(int); }; | |
41 | ||
42 | struct internal_comma1 { ret_with_comma1 operator BOOST_TT_TRAIT_OP (const internal_comma1&) const; }; | |
43 | ||
44 | struct external_comma1 { }; | |
45 | ret_with_comma1 operator BOOST_TT_TRAIT_OP (const external_comma1&, const external_comma1&) { return ret_with_comma1(); } | |
46 | ||
47 | struct ret_with_comma2 { void operator,(int); }; | |
48 | ||
49 | struct internal_comma2 { ret_with_comma2 operator BOOST_TT_TRAIT_OP (const internal_comma2&) const; }; | |
50 | ||
51 | struct external_comma2 { }; | |
52 | ret_with_comma2 operator BOOST_TT_TRAIT_OP (const external_comma2&, const external_comma2&){ return ret_with_comma2(); } | |
53 | ||
54 | struct returns_int { int operator BOOST_TT_TRAIT_OP (const returns_int&); }; | |
55 | ||
56 | struct returns_void { void operator BOOST_TT_TRAIT_OP (const returns_void&); }; | |
57 | ||
58 | struct returns_void_star { void *operator BOOST_TT_TRAIT_OP (const returns_void_star&); }; | |
59 | ||
60 | struct returns_double { double operator BOOST_TT_TRAIT_OP (const returns_double&); }; | |
61 | ||
62 | struct ret1 { }; | |
63 | struct convertible_to_ret1 { operator ret1 () const; }; | |
64 | struct returns_convertible_to_ret1 { convertible_to_ret1 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret1&); }; | |
65 | ||
66 | struct convertible_to_ret2 { }; | |
67 | struct ret2 { ret2(const convertible_to_ret2); }; | |
68 | struct returns_convertible_to_ret2 { convertible_to_ret2 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret2&); }; | |
69 | ||
70 | class Base1 { }; | |
71 | class Derived1 : public Base1 { }; | |
72 | ||
73 | bool operator BOOST_TT_TRAIT_OP (const Base1&, const Base1&) { return true; } | |
74 | ||
75 | class Base2 { }; | |
76 | struct Derived2 : public Base2 { | |
77 | Derived2(int); // to check if it works with a class that is not default constructible | |
78 | }; | |
79 | ||
80 | bool operator BOOST_TT_TRAIT_OP (const Derived2&, const Derived2&) { return true; } | |
81 | ||
82 | struct tag { }; | |
83 | ||
84 | struct A { }; | |
85 | struct B : public A { }; | |
86 | ||
87 | struct C { }; | |
88 | struct D { }; | |
89 | inline bool operator BOOST_TT_TRAIT_OP (const C&, void*) { return true; } | |
90 | inline bool operator BOOST_TT_TRAIT_OP (void*, const D&) { return true; } | |
91 | inline bool operator BOOST_TT_TRAIT_OP (const C&, const D&) { return true; } | |
92 | ||
11fdf7f2 TL |
93 | struct private_op { private: void operator BOOST_TT_TRAIT_OP (const private_op&) {} }; |
94 | ||
95 | struct ambiguous_A | |
96 | { | |
97 | }; | |
98 | inline bool operator BOOST_TT_TRAIT_OP (const ambiguous_A&, const ambiguous_A&) { return true; } | |
99 | struct ambiguous_B { operator ambiguous_A()const { return ambiguous_A(); } }; | |
100 | ||
7c673cae FG |
101 | //class internal_private { ret operator BOOST_TT_TRAIT_OP (const internal_private&) const; }; |
102 | ||
103 | void common() { | |
104 | TEST_T(void, false); | |
105 | TEST_TT(void, void, false); | |
106 | TEST_TTR(void, void, void, false); | |
107 | TEST_TTR(void, void, int, false); | |
108 | ||
109 | TEST_T(without, false); | |
110 | TEST_T(internal, true); | |
111 | TEST_T(external, true); | |
112 | TEST_T(internal_comma1, true); | |
113 | TEST_T(external_comma1, true); | |
114 | TEST_T(internal_comma2, true); | |
115 | TEST_T(external_comma2, true); | |
116 | TEST_T(returns_int, true); | |
117 | TEST_T(returns_void, true); | |
118 | TEST_T(returns_void_star, true); | |
119 | TEST_T(returns_double, true); | |
120 | TEST_T(returns_convertible_to_ret1, true); | |
121 | TEST_T(returns_convertible_to_ret2, true); | |
122 | TEST_T(Base1, true); | |
123 | TEST_T(Derived1, true); | |
124 | TEST_T(Base2, false); | |
125 | TEST_T(Derived2, true); | |
126 | ||
127 | TEST_TR(without, void, false); | |
128 | TEST_TR(without, bool, false); | |
129 | TEST_TR(internal, void, false); | |
130 | TEST_TR(internal, bool, false); | |
131 | TEST_TR(internal, ret, true); | |
132 | TEST_TR(internal_comma1, void, false); | |
133 | TEST_TR(internal_comma1, bool, false); | |
134 | TEST_TR(internal_comma1, ret_with_comma1, true); | |
135 | TEST_TR(internal_comma2, void, false); | |
136 | TEST_TR(internal_comma2, bool, false); | |
137 | TEST_TR(internal_comma2, ret_with_comma2, true); | |
138 | TEST_TR(external, void, false); | |
139 | TEST_TR(external, bool, false); | |
140 | TEST_TR(external, ret, true); | |
141 | TEST_TR(returns_int, void, false); | |
142 | TEST_TR(returns_int, bool, true); | |
143 | TEST_TR(returns_int, int, true); | |
144 | TEST_TR(returns_void, void, true); | |
145 | TEST_TR(returns_void, bool, false); | |
146 | TEST_TR(returns_void_star, bool, true); | |
147 | TEST_TR(returns_double, void, false); | |
148 | TEST_TR(returns_double, bool, true); | |
149 | TEST_TR(returns_double, double, true); | |
150 | TEST_TR(returns_convertible_to_ret1, void, false); | |
151 | TEST_TR(returns_convertible_to_ret1, ret1, true); | |
152 | TEST_TR(returns_convertible_to_ret2, ret2, true); | |
153 | TEST_TR(Base1, bool, true); | |
154 | TEST_TR(Derived1, bool, true); | |
155 | TEST_TR(Base2, bool, false); | |
156 | TEST_TR(Derived2, bool, true); | |
157 | // compile time error | |
158 | // TEST_T(internal_private, false); | |
11fdf7f2 TL |
159 | #if defined(BOOST_TT_HAS_ACCURATE_BINARY_OPERATOR_DETECTION) |
160 | // There are some things that pass that wouldn't otherwise do so: | |
161 | #if !BOOST_WORKAROUND(BOOST_MSVC, < 1910) | |
162 | TEST_TR(private_op, bool, false); | |
163 | TEST_T(private_op, false); | |
164 | #endif | |
165 | TEST_TR(ambiguous_A, bool, true); | |
166 | TEST_T(ambiguous_A, true); | |
167 | TEST_TR(ambiguous_B, bool, true); | |
168 | TEST_T(ambiguous_B, true); | |
169 | #endif | |
7c673cae FG |
170 | } |
171 | ||
172 | } | |
173 | ||
174 | #if defined(__GNUC__) && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ > 40900) | |
175 | #pragma GCC diagnostic pop | |
176 | #endif | |
177 | ||
178 | #endif | |
179 |