• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main()31 int main() {
32   // is_storage
33   {
34     struct A {};
35     using B = std::vector<int>;
36     using C = unlimited_storage<>;
37 
38     BOOST_TEST_TRAIT_FALSE((is_storage<A>));
39     BOOST_TEST_TRAIT_FALSE((is_storage<B>));
40     BOOST_TEST_TRAIT_TRUE((is_storage<C>));
41   }
42 
43   // is_indexable
44   {
45     struct A {};
46     using B = std::vector<int>;
47     using C = std::map<int, int>;
48     using D = std::map<A, int>;
49 
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>));
54   }
55 
56   // is_transform
57   {
58     struct A {};
59     struct B {
60       double forward(A);
61       A inverse(double);
62     };
63 
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>));
67   }
68 
69   // is_vector_like
70   {
71     struct A {};
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>));
81   }
82 
83   // is_array_like
84   {
85     struct A {};
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>));
93   }
94 
95   // is_map_like
96   {
97     struct A {};
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>));
107   }
108 
109   // is_axis
110   {
111     struct A {};
112     struct B {
113       int index(double);
114       int size() const;
115     };
116     struct C {
117       int index(double);
118     };
119     struct D {
120       int size();
121     };
122     using E = axis::variant<axis::regular<>>;
123 
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>));
129   }
130 
131   // is_iterable
132   {
133     using A = std::vector<int>;
134     using B = int[3];
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>));
140   }
141 
142   // is_streamable
143   {
144     struct Foo {};
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>));
148   }
149 
150   // is_axis_variant
151   {
152     struct A {};
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<>>>));
156   }
157 
158   // is_sequence_of_axis
159   {
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)>));
172   }
173 
174   // has_operator_equal
175   {
176     struct A {};
177     struct B {
178       bool operator==(const B&) const { return true; }
179     };
180 
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&>));
185   }
186 
187   // has_operator_radd
188   {
189     struct A {};
190     struct B {
191       B& operator+=(const B&) { return *this; }
192     };
193 
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&>));
198   }
199 
200   return boost::report_errors();
201 }
202