1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #ifndef BOOST_HISTOGRAM_ALGORITHM_SUM_HPP
- #define BOOST_HISTOGRAM_ALGORITHM_SUM_HPP
- #include <boost/histogram/accumulators/sum.hpp>
- #include <boost/histogram/fwd.hpp>
- #include <boost/histogram/indexed.hpp>
- #include <boost/mp11/utility.hpp>
- #include <type_traits>
- namespace boost {
- namespace histogram {
- namespace algorithm {
- template <class A, class S>
- auto sum(const histogram<A, S>& hist, const coverage cov = coverage::all) {
- using T = typename histogram<A, S>::value_type;
-
- using sum_type = mp11::mp_if<std::is_arithmetic<T>, accumulators::sum<double>, T>;
- sum_type sum;
- if (cov == coverage::all)
- for (auto&& x : hist) sum += x;
- else
-
- for (auto&& x : indexed(hist)) sum += *x;
- using R = mp11::mp_if<std::is_arithmetic<T>, double, T>;
- return static_cast<R>(sum);
- }
- }
- }
- }
- #endif
|