std::generate_n
Актуально для C++23.
#include <algorithm>
Актуально на 2024-03-20.
Define overload #1
template<class OutputIter, class Size, class Generator> constexpr OutputIter generate_n(OutputIter first, Size n, Generator gen);
Присваивает значение генерируемое функцией "gen" каждому элементу в диапазоне [first, first + n].
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIter, class Size, class Generator> ForwardIter generate_n(ExecutionPolicy&& exec, ForwardIter first, Size n, Generator gen);
TODO
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v(10);
std::generate_n(std::begin(v), std::size(v), std::rand);
for (auto it : v) {
std::cout << it << std::endl;
}
return 0;
}
1804289383 846930886 1681692777 1714636915 1957747793 424238335 719885386 1649760492 596516649 1189641421
Changelog
See also
TODO
This page was last modified on 2024-03-20