tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
generate_n.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_GENERATE_N_HPP
5#define TETL_ALGORITHM_GENERATE_N_HPP
6
7namespace etl {
8
9/// \brief Assigns values, generated by given function object `g`, to the first
10/// count elements in the range beginning at `first`, if `count > 0`. Does
11/// nothing otherwise.
12///
13/// \param first The range of elements to generate.
14/// \param count Number of the elements to generate.
15/// \param g Generator function object that will be called.
16///
17/// https://en.cppreference.com/w/cpp/algorithm/generate_n
18///
19/// \ingroup algorithm
20template <typename OutputIt, typename SizeT, typename Generator>
21constexpr auto generate_n(OutputIt first, SizeT count, Generator g) -> OutputIt
22{
23 for (; count > 0; ++first, --count) {
24 *first = g();
25 }
26 return first;
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_GENERATE_N_HPP
constexpr auto generate_n(OutputIt first, SizeT count, Generator g) -> OutputIt
Assigns values, generated by given function object g, to the first count elements in the range beginn...
Definition generate_n.hpp:21
Definition adjacent_find.hpp:9