Debian Codegraph @

3rd_party/range-v3/range/v3/numeric/accumulate.hpp

raw
1 /// \file
2 // Range v3 library
3 //
4 // Copyright Eric Niebler 2013-present
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13 #ifndef RANGES_V3_NUMERIC_ACCUMULATE_HPP
14 #define RANGES_V3_NUMERIC_ACCUMULATE_HPP
15
16 #include <meta/meta.hpp>
17
18 #include <range/v3/functional/arithmetic.hpp>
19 #include <range/v3/functional/identity.hpp>
20 #include <range/v3/functional/invoke.hpp>
21 #include <range/v3/iterator/concepts.hpp>
22 #include <range/v3/iterator/traits.hpp>
23 #include <range/v3/range/access.hpp>
24 #include <range/v3/range/concepts.hpp>
25 #include <range/v3/range/traits.hpp>
26 #include <range/v3/utility/static_const.hpp>
27
28 #include <range/v3/detail/prologue.hpp>
29
30 namespace ranges
31 {
32 /// \addtogroup group-numerics
33 /// @{
34 struct accumulate_fn
35 {
36 template(typename I, typename S, typename T, typename Op = plus,
37 typename P = identity)(
38 requires sentinel_for<S, I> AND input_iterator<I> AND
39 indirectly_binary_invocable_<Op, T *, projected<I, P>> AND
40 assignable_from<T &, indirect_result_t<Op &, T *, projected<I, P>>>)
41 T operator()(I first, S last, T init, Op op = Op{},
42 P proj = P{}) const
43 {
44 for(; first != last; ++first)
45 init = invoke(op, init, invoke(proj, *first));
46 return init;
47 }
48
49 template(typename Rng, typename T, typename Op = plus, typename P = identity)(
50 requires input_range<Rng> AND
51 indirectly_binary_invocable_<Op, T *, projected<iterator_t<Rng>, P>> AND
52 assignable_from<
53 T &, indirect_result_t<Op &, T *, projected<iterator_t<Rng>, P>>>)
54 T operator()(Rng && rng, T init, Op op = Op{}, P proj = P{}) const
55 {
56 return (*this)(
57 begin(rng), end(rng), std::move(init), std::move(op), std::move(proj));
58 }
59 };
60
61 RANGES_INLINE_VARIABLE(accumulate_fn, accumulate)
62 /// @}
63 } // namespace ranges
64
65 #include <range/v3/detail/epilogue.hpp>
66
67 #endif