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
7
namespace
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
20
template
<
typename
OutputIt,
typename
SizeT,
typename
Generator>
21
constexpr
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
etl::generate_n
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
etl
Definition
adjacent_find.hpp:9
include
etl
_algorithm
generate_n.hpp
Generated on Sun Sep 7 2025 19:14:46 for tetl by
1.9.8