]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/type_traits/test/has_binary_operators.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / type_traits / test / has_binary_operators.hpp
CommitLineData
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
28namespace {
29
30struct without { };
31
32struct ret { };
33
1e59de90 34struct internal { BOOST_TT_PROC ret operator BOOST_TT_TRAIT_OP (const internal&) const; };
7c673cae
FG
35
36struct external { };
1e59de90 37inline BOOST_TT_PROC ret operator BOOST_TT_TRAIT_OP (const external&, const external&) { return ret(); }
7c673cae
FG
38
39struct comma1_ret { };
1e59de90 40struct ret_with_comma1 { BOOST_TT_PROC comma1_ret operator,(int); };
7c673cae 41
1e59de90 42struct internal_comma1 { BOOST_TT_PROC ret_with_comma1 operator BOOST_TT_TRAIT_OP (const internal_comma1&) const; };
7c673cae
FG
43
44struct external_comma1 { };
1e59de90 45BOOST_TT_PROC ret_with_comma1 operator BOOST_TT_TRAIT_OP (const external_comma1&, const external_comma1&) { return ret_with_comma1(); }
7c673cae 46
1e59de90 47struct ret_with_comma2 { BOOST_TT_PROC void operator,(int); };
7c673cae 48
1e59de90 49struct internal_comma2 { BOOST_TT_PROC ret_with_comma2 operator BOOST_TT_TRAIT_OP (const internal_comma2&) const; };
7c673cae
FG
50
51struct external_comma2 { };
1e59de90 52BOOST_TT_PROC ret_with_comma2 operator BOOST_TT_TRAIT_OP (const external_comma2&, const external_comma2&){ return ret_with_comma2(); }
7c673cae 53
1e59de90 54struct returns_int { BOOST_TT_PROC int operator BOOST_TT_TRAIT_OP (const returns_int&)const; };
7c673cae 55
1e59de90 56struct returns_void { BOOST_TT_PROC void operator BOOST_TT_TRAIT_OP (const returns_void&)const; };
7c673cae 57
1e59de90 58struct returns_void_star { BOOST_TT_PROC void *operator BOOST_TT_TRAIT_OP (const returns_void_star&)const; };
7c673cae 59
1e59de90 60struct returns_double { BOOST_TT_PROC double operator BOOST_TT_TRAIT_OP (const returns_double&)const; };
7c673cae
FG
61
62struct ret1 { };
1e59de90
TL
63struct convertible_to_ret1 { BOOST_TT_PROC operator ret1 () const; };
64struct returns_convertible_to_ret1 { BOOST_TT_PROC convertible_to_ret1 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret1&)const; };
7c673cae
FG
65
66struct convertible_to_ret2 { };
1e59de90
TL
67struct ret2 { BOOST_TT_PROC ret2(const convertible_to_ret2); };
68struct returns_convertible_to_ret2 { BOOST_TT_PROC convertible_to_ret2 operator BOOST_TT_TRAIT_OP (const returns_convertible_to_ret2&)const; };
7c673cae
FG
69
70class Base1 { };
71class Derived1 : public Base1 { };
72
1e59de90 73BOOST_TT_PROC bool operator BOOST_TT_TRAIT_OP (const Base1&, const Base1&) { return true; }
7c673cae
FG
74
75class Base2 { };
76struct Derived2 : public Base2 {
1e59de90 77 BOOST_TT_PROC Derived2(int); // to check if it works with a class that is not default constructible
7c673cae
FG
78};
79
1e59de90 80BOOST_TT_PROC bool operator BOOST_TT_TRAIT_OP (const Derived2&, const Derived2&) { return true; }
7c673cae
FG
81
82struct tag { };
83
84struct A { };
85struct B : public A { };
86
87struct C { };
88struct D { };
1e59de90
TL
89BOOST_TT_PROC inline bool operator BOOST_TT_TRAIT_OP (const C&, void*) { return true; }
90BOOST_TT_PROC inline bool operator BOOST_TT_TRAIT_OP (void*, const D&) { return true; }
91BOOST_TT_PROC inline bool operator BOOST_TT_TRAIT_OP (const C&, const D&) { return true; }
7c673cae 92
1e59de90 93struct private_op { private: BOOST_TT_PROC void operator BOOST_TT_TRAIT_OP (const private_op&) {} };
11fdf7f2
TL
94
95struct ambiguous_A
96{
97};
1e59de90
TL
98inline BOOST_TT_PROC bool operator BOOST_TT_TRAIT_OP (const ambiguous_A&, const ambiguous_A&) { return true; }
99struct ambiguous_B { BOOST_TT_PROC operator ambiguous_A()const { return ambiguous_A(); } };
11fdf7f2 100
7c673cae
FG
101//class internal_private { ret operator BOOST_TT_TRAIT_OP (const internal_private&) const; };
102
1e59de90 103BOOST_TT_PROC void common() {
7c673cae
FG
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