1 // Copyright 2015-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_DETAIL_COMMON_TYPE_HPP
8 #define BOOST_HISTOGRAM_DETAIL_COMMON_TYPE_HPP
9
10 #include <boost/histogram/detail/detect.hpp>
11 #include <boost/histogram/fwd.hpp>
12 #include <boost/mp11/list.hpp>
13 #include <boost/mp11/utility.hpp>
14 #include <tuple>
15 #include <type_traits>
16
17 namespace boost {
18 namespace histogram {
19 namespace detail {
20 // clang-format off
21 template <class T, class U>
22 using common_axes = mp11::mp_cond<
23 is_tuple<T>, T,
24 is_tuple<U>, U,
25 is_sequence_of_axis<T>, T,
26 is_sequence_of_axis<U>, U,
27 std::true_type, T
28 >;
29 // clang-format on
30
31 // Non-PODs rank highest, then floats, than integers; types with more capacity are higher
32 template <class Storage>
type_rank()33 static constexpr std::size_t type_rank() {
34 using T = typename Storage::value_type;
35 return !std::is_pod<T>::value * 10000 + std::is_floating_point<T>::value * 100 +
36 10 * sizeof(T) + 2 * is_array_like<Storage>::value +
37 is_vector_like<Storage>::value;
38 ;
39 }
40
41 template <class T, class U>
42 using common_storage = mp11::mp_if_c<(type_rank<T>() >= type_rank<U>()), T, U>;
43 } // namespace detail
44 } // namespace histogram
45 } // namespace boost
46
47 #endif
48