common_type.hpp 1.3 KB

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