tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
reduce.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2#ifndef TETL_NUMERIC_REDUCE_HPP
3#define TETL_NUMERIC_REDUCE_HPP
4
9
10namespace etl {
11
15template <typename InputIter, typename T, typename BinaryOp>
16[[nodiscard]] constexpr auto reduce(InputIter first, InputIter last, T init, BinaryOp op) -> T
17{
18 return accumulate(first, last, init, op);
19}
20
24template <typename InputIter, typename T>
25[[nodiscard]] constexpr auto reduce(InputIter first, InputIter last, T init) -> T
26{
27 return reduce(first, last, init, etl::plus<>());
28}
29
33template <typename InputIter>
34[[nodiscard]] constexpr auto reduce(InputIter first, InputIter last) ->
36{
38 return reduce(first, last, init);
39}
40
41} // namespace etl
42
43#endif // TETL_NUMERIC_REDUCE_HPP
constexpr auto reduce(InputIter first, InputIter last, T init, BinaryOp op) -> T
Similar to etl::accumulate.
Definition reduce.hpp:16
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
iterator_traits is the type trait class that provides uniform interface to the properties of LegacyIt...
Definition iterator_traits.hpp:47
Function object for performing addition. Effectively calls operator+ on two instances of type T....
Definition plus.hpp:14