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