File indexing completed on 2025-01-18 10:09:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RANGES_V3_NUMERIC_ACCUMULATE_HPP
0014 #define RANGES_V3_NUMERIC_ACCUMULATE_HPP
0015
0016 #include <meta/meta.hpp>
0017
0018 #include <range/v3/functional/arithmetic.hpp>
0019 #include <range/v3/functional/identity.hpp>
0020 #include <range/v3/functional/invoke.hpp>
0021 #include <range/v3/iterator/concepts.hpp>
0022 #include <range/v3/iterator/traits.hpp>
0023 #include <range/v3/range/access.hpp>
0024 #include <range/v3/range/concepts.hpp>
0025 #include <range/v3/range/traits.hpp>
0026 #include <range/v3/utility/static_const.hpp>
0027
0028 #include <range/v3/detail/prologue.hpp>
0029
0030 namespace ranges
0031 {
0032
0033
0034 struct accumulate_fn
0035 {
0036 template(typename I, typename S, typename T, typename Op = plus,
0037 typename P = identity)(
0038 requires sentinel_for<S, I> AND input_iterator<I> AND
0039 indirectly_binary_invocable_<Op, T *, projected<I, P>> AND
0040 assignable_from<T &, indirect_result_t<Op &, T *, projected<I, P>>>)
0041 T operator()(I first, S last, T init, Op op = Op{},
0042 P proj = P{}) const
0043 {
0044 for(; first != last; ++first)
0045 init = invoke(op, init, invoke(proj, *first));
0046 return init;
0047 }
0048
0049 template(typename Rng, typename T, typename Op = plus, typename P = identity)(
0050 requires input_range<Rng> AND
0051 indirectly_binary_invocable_<Op, T *, projected<iterator_t<Rng>, P>> AND
0052 assignable_from<
0053 T &, indirect_result_t<Op &, T *, projected<iterator_t<Rng>, P>>>)
0054 T operator()(Rng && rng, T init, Op op = Op{}, P proj = P{}) const
0055 {
0056 return (*this)(
0057 begin(rng), end(rng), std::move(init), std::move(op), std::move(proj));
0058 }
0059 };
0060
0061 RANGES_INLINE_VARIABLE(accumulate_fn, accumulate)
0062
0063 }
0064
0065 #include <range/v3/detail/epilogue.hpp>
0066
0067 #endif