tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
for_each_n.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_FOR_EACH_N_HPP
5#define TETL_ALGORITHM_FOR_EACH_N_HPP
6
7namespace etl {
8
9/// \brief Applies the given function object f to the result of dereferencing
10/// every iterator in the range `[first, first + n]` in order.
11///
12/// \param first The beginning of the range to apply the function to.
13/// \param n The number of elements to apply the function to.
14/// \param f Function object, to be applied to the result of dereferencing every
15/// iterator in the range.
16///
17/// https://en.cppreference.com/w/cpp/algorithm/for_each_n
18///
19/// \ingroup algorithm
20template <typename InputIt, typename Size, typename UnaryFunc>
21constexpr auto for_each_n(InputIt first, Size n, UnaryFunc f) noexcept -> InputIt
22{
23 for (Size i = 0; i < n; ++first, (void)++i) {
24 f(*first);
25 }
26 return first;
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_FOR_EACH_N_HPP
constexpr auto for_each_n(InputIt first, Size n, UnaryFunc f) noexcept -> InputIt
Applies the given function object f to the result of dereferencing every iterator in the range [first...
Definition for_each_n.hpp:21
Definition adjacent_find.hpp:9