1 // Copyright 2015-2017 Hans Dembinski
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)
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>
17 #include <initializer_list>
20 #include <type_traits>
21 #include <unordered_map>
24 #include "std_ostream.hpp"
25 #include "throw_exception.hpp"
26 #include "utility_allocator.hpp"
28 using namespace boost::histogram;
29 using namespace boost::histogram::detail;
36 A value(int) const { return {}; }
39 char value(int) const { return 0; }
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>));
54 BOOST_TEST_TRAIT_FALSE((has_method_options<A>));
55 BOOST_TEST_TRAIT_TRUE((has_method_options<B>));
58 // has_method_metadata
65 BOOST_TEST_TRAIT_FALSE((has_method_metadata<A>));
66 BOOST_TEST_TRAIT_TRUE((has_method_metadata<B>));
75 using C = axis::integer<int, axis::null_type, use_default>;
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>));
85 using B = std::vector<int>;
86 using C = std::map<int, int>;
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>));
96 using B = std::vector<int>;
97 using C = std::map<int, int>;
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>));
107 using B = std::vector<int>;
108 using C = std::map<int, int>;
109 using D = std::array<int, 10>;
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>));
120 using B = std::vector<int>;
121 using C = std::map<int, int>;
122 using D = std::array<int, 10>;
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>));
133 using B = std::vector<int>;
134 using C = unlimited_storage<>;
136 BOOST_TEST_TRAIT_FALSE((is_storage<A>));
137 BOOST_TEST_TRAIT_FALSE((is_storage<B>));
138 BOOST_TEST_TRAIT_TRUE((is_storage<C>));
144 using B = std::vector<int>;
145 using C = std::map<int, int>;
146 using D = std::map<A, int>;
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>));
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>));
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>));
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>));
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>));
220 using E = axis::variant<axis::regular<>>;
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>));
231 using A = std::vector<int>;
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>));
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>));
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<>>>));
256 // is_sequence_of_axis
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)>));
272 // has_operator_equal
276 bool operator==(const B&) const { return true; }
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&>));
289 B& operator+=(const B&) { return *this; }
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&>));
298 return boost::report_errors();