Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:10

0001 // Copyright 2019 Hans Dembinski
0002 //
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_HISTOGRAM_DETAIL_ACCUMULATOR_TRAITS_HPP
0008 #define BOOST_HISTOGRAM_DETAIL_ACCUMULATOR_TRAITS_HPP
0009 
0010 #include <boost/histogram/detail/priority.hpp>
0011 #include <boost/histogram/fwd.hpp>
0012 #include <tuple>
0013 #include <type_traits>
0014 
0015 namespace boost {
0016 
0017 // forward declare accumulator_set so that it can be matched below
0018 namespace accumulators {
0019 template <class, class, class>
0020 struct accumulator_set;
0021 }
0022 
0023 namespace histogram {
0024 namespace detail {
0025 
0026 template <bool WeightSupport, class... Ts>
0027 struct accumulator_traits_holder {
0028   static constexpr bool weight_support = WeightSupport;
0029   using args = std::tuple<Ts...>;
0030 };
0031 
0032 // member function pointer with weight_type as first argument is better match
0033 template <class R, class T, class U, class... Ts>
0034 accumulator_traits_holder<true, Ts...> accumulator_traits_impl_call_op(
0035     R (T::*)(boost::histogram::weight_type<U>, Ts...));
0036 
0037 template <class R, class T, class U, class... Ts>
0038 accumulator_traits_holder<true, Ts...> accumulator_traits_impl_call_op(
0039     R (T::*)(boost::histogram::weight_type<U>&, Ts...));
0040 
0041 template <class R, class T, class U, class... Ts>
0042 accumulator_traits_holder<true, Ts...> accumulator_traits_impl_call_op(
0043     R (T::*)(boost::histogram::weight_type<U>&&, Ts...));
0044 
0045 template <class R, class T, class U, class... Ts>
0046 accumulator_traits_holder<true, Ts...> accumulator_traits_impl_call_op(
0047     R (T::*)(const boost::histogram::weight_type<U>&, Ts...));
0048 
0049 // member function pointer only considered if all specializations above fail
0050 template <class R, class T, class... Ts>
0051 accumulator_traits_holder<false, Ts...> accumulator_traits_impl_call_op(R (T::*)(Ts...));
0052 
0053 template <class T>
0054 auto accumulator_traits_impl(T&, priority<2>)
0055     -> decltype(accumulator_traits_impl_call_op(&T::operator()));
0056 
0057 template <class T>
0058 auto accumulator_traits_impl(T&, priority<2>)
0059     -> decltype(std::declval<T&>() += std::declval<boost::histogram::weight_type<int>>(),
0060                 accumulator_traits_holder<true>{});
0061 
0062 // fallback for simple arithmetic types that do not implement adding a weight_type
0063 template <class T>
0064 auto accumulator_traits_impl(T&, priority<1>)
0065     -> decltype(std::declval<T&>() += 0, accumulator_traits_holder<true>{});
0066 
0067 template <class T>
0068 auto accumulator_traits_impl(T&, priority<0>) -> accumulator_traits_holder<false>;
0069 
0070 // for boost.accumulators compatibility
0071 template <class S, class F, class W>
0072 accumulator_traits_holder<false, S> accumulator_traits_impl(
0073     boost::accumulators::accumulator_set<S, F, W>&, priority<2>) {
0074   static_assert(std::is_same<W, void>::value,
0075                 "accumulator_set with weights is not directly supported, please use "
0076                 "a wrapper class that implements the Accumulator concept");
0077 }
0078 
0079 template <class T>
0080 using accumulator_traits =
0081     decltype(accumulator_traits_impl(std::declval<T&>(), priority<2>{}));
0082 
0083 } // namespace detail
0084 } // namespace histogram
0085 } // namespace boost
0086 
0087 #endif