tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
partial_sum.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_PARTIAL_SUM_HPP
3#define TETL_NUMERIC_PARTIAL_SUM_HPP
4
7
8namespace etl {
9
23template <typename InputIt, typename OutputIt, typename BinaryOperation>
24constexpr auto partial_sum(InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
25{
26 if (first == last) {
27 return destination;
28 }
29
30 auto sum = *first;
31 *destination = sum;
32
33 while (++first != last) {
34 sum = op(etl::move(sum), *first);
35 *++destination = sum;
36 }
37
38 return ++destination;
39}
40
42template <typename InputIt, typename OutputIt>
43constexpr auto partial_sum(InputIt first, InputIt last, OutputIt destination) -> OutputIt
44{
45 return etl::partial_sum(first, last, destination, etl::plus<>());
46}
47
48} // namespace etl
49
50#endif // TETL_NUMERIC_PARTIAL_SUM_HPP
constexpr auto move(InputIt first, InputIt last, OutputIt destination) -> OutputIt
Moves the elements in the range [first, last), to another range beginning at destination,...
Definition move.hpp:26
constexpr auto partial_sum(InputIt first, InputIt last, OutputIt destination, BinaryOperation op) -> OutputIt
Computes the partial sums of the elements in the subranges of the range [first, last) and writes them...
Definition partial_sum.hpp:24
Definition adjacent_find.hpp:8
Function object for performing addition. Effectively calls operator+ on two instances of type T....
Definition plus.hpp:14