Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / utility_histogram.hpp
1 // Copyright 2018 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 #ifndef BOOST_HISTOGRAM_TEST_UTILITY_HISTOGRAM_HPP
8 #define BOOST_HISTOGRAM_TEST_UTILITY_HISTOGRAM_HPP
9
10 #include <boost/histogram/axis/category.hpp>
11 #include <boost/histogram/axis/integer.hpp>
12 #include <boost/histogram/axis/regular.hpp>
13 #include <boost/histogram/axis/variable.hpp>
14 #include <boost/histogram/axis/variant.hpp>
15 #include <boost/histogram/make_histogram.hpp>
16 #include <boost/mp11/algorithm.hpp>
17 #include <type_traits>
18 #include <vector>
19
20 namespace boost {
21 namespace histogram {
22
23 template <typename... Ts>
24 auto make_axis_vector(const Ts&... ts) {
25   // make sure the variant is never trivial (contains only one type)
26   using R = axis::regular<double, boost::use_default, axis::null_type>;
27   using I = axis::integer<int, axis::null_type, axis::option::none_t>;
28   using V = axis::variable<double, axis::null_type>;
29   using C = axis::category<int, axis::null_type>;
30   using Var = boost::mp11::mp_unique<axis::variant<Ts..., R, I, V, C>>;
31   return std::vector<Var>({Var(ts)...});
32 }
33
34 using static_tag = std::false_type;
35 using dynamic_tag = std::true_type;
36
37 template <typename... Axes>
38 auto make(static_tag, const Axes&... axes) {
39   return make_histogram(axes...);
40 }
41
42 template <typename S, typename... Axes>
43 auto make_s(static_tag, S&& s, const Axes&... axes) {
44   return make_histogram_with(s, axes...);
45 }
46
47 template <typename... Axes>
48 auto make(dynamic_tag, const Axes&... axes) {
49   return make_histogram(make_axis_vector(axes...));
50 }
51
52 template <typename S, typename... Axes>
53 auto make_s(dynamic_tag, S&& s, const Axes&... axes) {
54   return make_histogram_with(s, make_axis_vector(axes...));
55 }
56
57 } // namespace histogram
58 } // namespace boost
59
60 #endif