utility_histogram.hpp 1.8 KB

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