tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
accumulate.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_ACCUMULATE_HPP
3#define TETL_NUMERIC_ACCUMULATE_HPP
4
6
7namespace etl {
8
12template <typename InputIt, typename Type>
13[[nodiscard]] constexpr auto accumulate(InputIt first, InputIt last, Type init) noexcept -> Type
14{
15 for (; first != last; ++first) {
16 init = etl::move(init) + *first;
17 }
18 return init;
19}
20
24template <typename InputIt, typename Type, typename BinaryOperation>
25[[nodiscard]] constexpr auto accumulate(InputIt first, InputIt last, Type init, BinaryOperation op) noexcept -> Type
26{
27 for (; first != last; ++first) {
28 init = op(etl::move(init), *first);
29 }
30 return init;
31}
32
33} // namespace etl
34
35#endif // TETL_NUMERIC_ACCUMULATE_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 accumulate(InputIt first, InputIt last, Type init) noexcept -> Type
Computes the sum of the given value init and the elements in the range [first, last).
Definition accumulate.hpp:13
Definition adjacent_find.hpp:8