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
;
35 using B
= std::vector
<int>;
36 using C
= unlimited_storage
<>;
38 BOOST_TEST_TRAIT_FALSE((is_storage
<A
>));
39 BOOST_TEST_TRAIT_FALSE((is_storage
<B
>));
40 BOOST_TEST_TRAIT_TRUE((is_storage
<C
>));
46 using B
= std::vector
<int>;
47 using C
= std::map
<int, int>;
48 using D
= std::map
<A
, int>;
50 BOOST_TEST_TRAIT_FALSE((is_indexable
<A
>));
51 BOOST_TEST_TRAIT_TRUE((is_indexable
<B
>));
52 BOOST_TEST_TRAIT_TRUE((is_indexable
<C
>));
53 BOOST_TEST_TRAIT_FALSE((is_indexable
<D
>));
64 BOOST_TEST_TRAIT_FALSE((is_transform
<A
, double>));
65 BOOST_TEST_TRAIT_TRUE((is_transform
<B
, A
>));
66 BOOST_TEST_TRAIT_TRUE((is_transform
<axis::transform::id
, double>));
72 using B
= std::vector
<int>;
73 using C
= std::array
<int, 10>;
74 using D
= std::map
<unsigned, int>;
75 using E
= std::deque
<int>;
76 BOOST_TEST_TRAIT_FALSE((is_vector_like
<A
>));
77 BOOST_TEST_TRAIT_TRUE((is_vector_like
<B
>));
78 BOOST_TEST_TRAIT_FALSE((is_vector_like
<C
>));
79 BOOST_TEST_TRAIT_FALSE((is_vector_like
<D
>));
80 BOOST_TEST_TRAIT_TRUE((is_vector_like
<E
>));
86 using B
= std::vector
<int>;
87 using C
= std::array
<int, 10>;
88 using D
= std::map
<unsigned, int>;
89 BOOST_TEST_TRAIT_FALSE((is_array_like
<A
>));
90 BOOST_TEST_TRAIT_FALSE((is_array_like
<B
>));
91 BOOST_TEST_TRAIT_TRUE((is_array_like
<C
>));
92 BOOST_TEST_TRAIT_FALSE((is_array_like
<D
>));
98 using B
= std::vector
<int>;
99 using C
= std::array
<int, 10>;
100 using D
= std::map
<unsigned, int>;
101 using E
= std::unordered_map
<unsigned, int>;
102 BOOST_TEST_TRAIT_FALSE((is_map_like
<A
>));
103 BOOST_TEST_TRAIT_FALSE((is_map_like
<B
>));
104 BOOST_TEST_TRAIT_FALSE((is_map_like
<C
>));
105 BOOST_TEST_TRAIT_TRUE((is_map_like
<D
>));
106 BOOST_TEST_TRAIT_TRUE((is_map_like
<E
>));
122 using E
= axis::variant
<axis::regular
<>>;
124 BOOST_TEST_TRAIT_FALSE((is_axis
<A
>));
125 BOOST_TEST_TRAIT_TRUE((is_axis
<B
>));
126 BOOST_TEST_TRAIT_FALSE((is_axis
<C
>));
127 BOOST_TEST_TRAIT_FALSE((is_axis
<D
>));
128 BOOST_TEST_TRAIT_FALSE((is_axis
<E
>));
133 using A
= std::vector
<int>;
135 using C
= std::initializer_list
<int>;
136 BOOST_TEST_TRAIT_FALSE((is_iterable
<int>));
137 BOOST_TEST_TRAIT_TRUE((is_iterable
<A
>));
138 BOOST_TEST_TRAIT_TRUE((is_iterable
<B
>));
139 BOOST_TEST_TRAIT_TRUE((is_iterable
<C
>));
145 BOOST_TEST_TRAIT_TRUE((is_streamable
<int>));
146 BOOST_TEST_TRAIT_TRUE((is_streamable
<std::string
>));
147 BOOST_TEST_TRAIT_FALSE((is_streamable
<Foo
>));
153 BOOST_TEST_TRAIT_FALSE((is_axis_variant
<A
>));
154 BOOST_TEST_TRAIT_TRUE((is_axis_variant
<axis::variant
<>>));
155 BOOST_TEST_TRAIT_TRUE((is_axis_variant
<axis::variant
<axis::regular
<>>>));
158 // is_sequence_of_axis
160 using A
= std::vector
<axis::regular
<>>;
161 using B
= std::vector
<axis::variant
<axis::regular
<>>>;
162 using C
= std::vector
<int>;
163 auto v
= std::vector
<axis::variant
<axis::regular
<>, axis::integer
<>>>();
164 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis
<A
>));
165 BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis
<A
>));
166 BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis_variant
<A
>));
167 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis
<B
>));
168 BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis_variant
<B
>));
169 BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis
<B
>));
170 BOOST_TEST_TRAIT_FALSE((is_sequence_of_any_axis
<C
>));
171 BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis
<decltype(v
)>));
174 // has_operator_equal
178 bool operator==(const B
&) const { return true; }
181 BOOST_TEST_TRAIT_FALSE((has_operator_equal
<A
, A
>));
182 BOOST_TEST_TRAIT_FALSE((has_operator_equal
<B
, A
>));
183 BOOST_TEST_TRAIT_TRUE((has_operator_equal
<B
, B
>));
184 BOOST_TEST_TRAIT_TRUE((has_operator_equal
<const B
&, const B
&>));
191 B
& operator+=(const B
&) { return *this; }
194 BOOST_TEST_TRAIT_FALSE((has_operator_radd
<A
, A
>));
195 BOOST_TEST_TRAIT_FALSE((has_operator_radd
<B
, A
>));
196 BOOST_TEST_TRAIT_TRUE((has_operator_radd
<B
, B
>));
197 BOOST_TEST_TRAIT_TRUE((has_operator_radd
<B
&, const B
&>));
200 // is_explicitly_convertible
204 operator A() { return A
{}; }
207 explicit operator A();
215 BOOST_TEST_TRAIT_TRUE((is_explicitly_convertible
<A
, A
>));
216 BOOST_TEST_TRAIT_FALSE((is_explicitly_convertible
<A
, B
>));
217 BOOST_TEST_TRAIT_TRUE((is_explicitly_convertible
<B
, A
>));
218 BOOST_TEST_TRAIT_TRUE((is_explicitly_convertible
<C
, A
>));
219 BOOST_TEST_TRAIT_TRUE((is_explicitly_convertible
<A
, D
>));
220 BOOST_TEST_TRAIT_TRUE((is_explicitly_convertible
<A
, E
>));
228 BOOST_TEST_TRAIT_FALSE((is_complete
<A
>));
229 BOOST_TEST_TRAIT_TRUE((is_complete
<B
>));
232 return boost::report_errors();