]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/detail_detect_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / histogram / test / detail_detect_test.cpp
1 // Copyright 2015-2017 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <array>
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/core/lightweight_test_trait.hpp>
10 #include <boost/histogram/axis/integer.hpp>
11 #include <boost/histogram/axis/regular.hpp>
12 #include <boost/histogram/axis/variable.hpp>
13 #include <boost/histogram/axis/variant.hpp>
14 #include <boost/histogram/detail/detect.hpp>
15 #include <boost/histogram/unlimited_storage.hpp>
16 #include <deque>
17 #include <initializer_list>
18 #include <map>
19 #include <string>
20 #include <type_traits>
21 #include <unordered_map>
22 #include <utility>
23 #include <vector>
24 #include "std_ostream.hpp"
25 #include "throw_exception.hpp"
26 #include "utility_allocator.hpp"
27
28 using namespace boost::histogram;
29 using namespace boost::histogram::detail;
30
31 int main() {
32 // has_method_value*
33 {
34 struct A {};
35 struct B {
36 A value(int) const { return {}; }
37 };
38 struct C {
39 char value(int) const { return 0; }
40 };
41
42 BOOST_TEST_TRAIT_FALSE((has_method_value<A>));
43 BOOST_TEST_TRAIT_TRUE((has_method_value<B>));
44 BOOST_TEST_TRAIT_TRUE((has_method_value<C>));
45 }
46
47 // has_method_options
48 {
49 struct A {};
50 struct B {
51 void options() {}
52 };
53
54 BOOST_TEST_TRAIT_FALSE((has_method_options<A>));
55 BOOST_TEST_TRAIT_TRUE((has_method_options<B>));
56 }
57
58 // has_method_metadata
59 {
60 struct A {};
61 struct B {
62 void metadata();
63 };
64
65 BOOST_TEST_TRAIT_FALSE((has_method_metadata<A>));
66 BOOST_TEST_TRAIT_TRUE((has_method_metadata<B>));
67 }
68
69 // has_method_update
70 {
71 struct A {};
72 struct B {
73 void update(int) {}
74 };
75 using C = axis::integer<int, axis::null_type, use_default>;
76
77 BOOST_TEST_TRAIT_FALSE((has_method_update<A>));
78 BOOST_TEST_TRAIT_TRUE((has_method_update<B>));
79 BOOST_TEST_TRAIT_TRUE((has_method_update<C>));
80 }
81
82 // has_method_resize
83 {
84 struct A {};
85 using B = std::vector<int>;
86 using C = std::map<int, int>;
87
88 BOOST_TEST_TRAIT_FALSE((has_method_resize<A>));
89 BOOST_TEST_TRAIT_TRUE((has_method_resize<B>));
90 BOOST_TEST_TRAIT_FALSE((has_method_resize<C>));
91 }
92
93 // has_method_size
94 {
95 struct A {};
96 using B = std::vector<int>;
97 using C = std::map<int, int>;
98
99 BOOST_TEST_TRAIT_FALSE((has_method_size<A>));
100 BOOST_TEST_TRAIT_TRUE((has_method_size<B>));
101 BOOST_TEST_TRAIT_TRUE((has_method_size<C>));
102 }
103
104 // has_method_clear
105 {
106 struct A {};
107 using B = std::vector<int>;
108 using C = std::map<int, int>;
109 using D = std::array<int, 10>;
110
111 BOOST_TEST_TRAIT_FALSE((has_method_clear<A>));
112 BOOST_TEST_TRAIT_TRUE((has_method_clear<B>));
113 BOOST_TEST_TRAIT_TRUE((has_method_clear<C>));
114 BOOST_TEST_TRAIT_FALSE((has_method_clear<D>));
115 }
116
117 // has_allocator
118 {
119 struct A {};
120 using B = std::vector<int>;
121 using C = std::map<int, int>;
122 using D = std::array<int, 10>;
123
124 BOOST_TEST_TRAIT_FALSE((has_method_clear<A>));
125 BOOST_TEST_TRAIT_TRUE((has_method_clear<B>));
126 BOOST_TEST_TRAIT_TRUE((has_method_clear<C>));
127 BOOST_TEST_TRAIT_FALSE((has_method_clear<D>));
128 }
129
130 // is_storage
131 {
132 struct A {};
133 using B = std::vector<int>;
134 using C = unlimited_storage<>;
135
136 BOOST_TEST_TRAIT_FALSE((is_storage<A>));
137 BOOST_TEST_TRAIT_FALSE((is_storage<B>));
138 BOOST_TEST_TRAIT_TRUE((is_storage<C>));
139 }
140
141 // is_indexable
142 {
143 struct A {};
144 using B = std::vector<int>;
145 using C = std::map<int, int>;
146 using D = std::map<A, int>;
147
148 BOOST_TEST_TRAIT_FALSE((is_indexable<A>));
149 BOOST_TEST_TRAIT_TRUE((is_indexable<B>));
150 BOOST_TEST_TRAIT_TRUE((is_indexable<C>));
151 BOOST_TEST_TRAIT_FALSE((is_indexable<D>));
152 }
153
154 // is_transform
155 {
156 struct A {};
157 struct B {
158 double forward(A);
159 A inverse(double);
160 };
161
162 BOOST_TEST_TRAIT_FALSE((is_transform<A, double>));
163 BOOST_TEST_TRAIT_TRUE((is_transform<B, A>));
164 BOOST_TEST_TRAIT_TRUE((is_transform<axis::transform::id, double>));
165 }
166
167 // is_vector_like
168 {
169 struct A {};
170 using B = std::vector<int>;
171 using C = std::array<int, 10>;
172 using D = std::map<unsigned, int>;
173 using E = std::deque<int>;
174 BOOST_TEST_TRAIT_FALSE((is_vector_like<A>));
175 BOOST_TEST_TRAIT_TRUE((is_vector_like<B>));
176 BOOST_TEST_TRAIT_FALSE((is_vector_like<C>));
177 BOOST_TEST_TRAIT_FALSE((is_vector_like<D>));
178 BOOST_TEST_TRAIT_TRUE((is_vector_like<E>));
179 }
180
181 // is_array_like
182 {
183 struct A {};
184 using B = std::vector<int>;
185 using C = std::array<int, 10>;
186 using D = std::map<unsigned, int>;
187 BOOST_TEST_TRAIT_FALSE((is_array_like<A>));
188 BOOST_TEST_TRAIT_FALSE((is_array_like<B>));
189 BOOST_TEST_TRAIT_TRUE((is_array_like<C>));
190 BOOST_TEST_TRAIT_FALSE((is_array_like<D>));
191 }
192
193 // is_map_like
194 {
195 struct A {};
196 using B = std::vector<int>;
197 using C = std::array<int, 10>;
198 using D = std::map<unsigned, int>;
199 using E = std::unordered_map<unsigned, int>;
200 BOOST_TEST_TRAIT_FALSE((is_map_like<A>));
201 BOOST_TEST_TRAIT_FALSE((is_map_like<B>));
202 BOOST_TEST_TRAIT_FALSE((is_map_like<C>));
203 BOOST_TEST_TRAIT_TRUE((is_map_like<D>));
204 BOOST_TEST_TRAIT_TRUE((is_map_like<E>));
205 }
206
207 // is_axis
208 {
209 struct A {};
210 struct B {
211 int index(double);
212 int size() const;
213 };
214 struct C {
215 int index(double);
216 };
217 struct D {
218 int size();
219 };
220 using E = axis::variant<axis::regular<>>;
221
222 BOOST_TEST_TRAIT_FALSE((is_axis<A>));
223 BOOST_TEST_TRAIT_TRUE((is_axis<B>));
224 BOOST_TEST_TRAIT_FALSE((is_axis<C>));
225 BOOST_TEST_TRAIT_FALSE((is_axis<D>));
226 BOOST_TEST_TRAIT_FALSE((is_axis<E>));
227 }
228
229 // is_iterable
230 {
231 using A = std::vector<int>;
232 using B = int[3];
233 using C = std::initializer_list<int>;
234 BOOST_TEST_TRAIT_FALSE((is_iterable<int>));
235 BOOST_TEST_TRAIT_TRUE((is_iterable<A>));
236 BOOST_TEST_TRAIT_TRUE((is_iterable<B>));
237 BOOST_TEST_TRAIT_TRUE((is_iterable<C>));
238 }
239
240 // is_streamable
241 {
242 struct Foo {};
243 BOOST_TEST_TRAIT_TRUE((is_streamable<int>));
244 BOOST_TEST_TRAIT_TRUE((is_streamable<std::string>));
245 BOOST_TEST_TRAIT_FALSE((is_streamable<Foo>));
246 }
247
248 // is_axis_variant
249 {
250 struct A {};
251 BOOST_TEST_TRAIT_FALSE((is_axis_variant<A>));
252 BOOST_TEST_TRAIT_TRUE((is_axis_variant<axis::variant<>>));
253 BOOST_TEST_TRAIT_TRUE((is_axis_variant<axis::variant<axis::regular<>>>));
254 }
255
256 // is_sequence_of_axis
257 {
258 using A = std::vector<axis::regular<>>;
259 using B = std::vector<axis::variant<axis::regular<>>>;
260 using C = std::vector<int>;
261 auto v = std::vector<axis::variant<axis::regular<>, axis::integer<>>>();
262 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis<A>));
263 BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis<A>));
264 BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis_variant<A>));
265 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis<B>));
266 BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis_variant<B>));
267 BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis<B>));
268 BOOST_TEST_TRAIT_FALSE((is_sequence_of_any_axis<C>));
269 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis<decltype(v)>));
270 }
271
272 // has_operator_equal
273 {
274 struct A {};
275 struct B {
276 bool operator==(const B&) const { return true; }
277 };
278
279 BOOST_TEST_TRAIT_FALSE((has_operator_equal<A, A>));
280 BOOST_TEST_TRAIT_FALSE((has_operator_equal<B, A>));
281 BOOST_TEST_TRAIT_TRUE((has_operator_equal<B, B>));
282 BOOST_TEST_TRAIT_TRUE((has_operator_equal<const B&, const B&>));
283 }
284
285 // has_operator_radd
286 {
287 struct A {};
288 struct B {
289 B& operator+=(const B&) { return *this; }
290 };
291
292 BOOST_TEST_TRAIT_FALSE((has_operator_radd<A, A>));
293 BOOST_TEST_TRAIT_FALSE((has_operator_radd<B, A>));
294 BOOST_TEST_TRAIT_TRUE((has_operator_radd<B, B>));
295 BOOST_TEST_TRAIT_TRUE((has_operator_radd<B&, const B&>));
296 }
297
298 return boost::report_errors();
299 }