Horizon
Loading...
Searching...
No Matches
accumulate.hpp
Go to the documentation of this file.
1
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
26#include <range/v3/utility/static_const.hpp>
27
28#include <range/v3/detail/prologue.hpp>
29
30namespace ranges
31{
35 {
36 template(typename I, typename S, typename T, typename Op = plus,
37 typename P = identity)(
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)
63} // namespace ranges
64
65#include <range/v3/detail/epilogue.hpp>
66
67#endif
The input_iterator concept.
The input_range concept.
The sentinel_for concept.
decltype(begin(declval(Rng &))) iterator_t
Definition access.hpp:698
Tiny meta-programming library.
Definition accumulate.hpp:35
Definition identity.hpp:25
Definition arithmetic.hpp:25