@specsoftdev live:.cid.8e17e9b93cabb607 specsoftdev@gmail.com
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