25 Algorithms library [algorithms]

25.7 Mutating sequence operations [alg.modifying.operations]

25.7.7 Generate [alg.generate]

template<class ForwardIterator, class Generator> constexpr void generate(ForwardIterator first, ForwardIterator last, Generator gen); template<class ExecutionPolicy, class ForwardIterator, class Generator> void generate(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Generator gen); template<class OutputIterator, class Size, class Generator> constexpr OutputIterator generate_n(OutputIterator first, Size n, Generator gen); template<class ExecutionPolicy, class ForwardIterator, class Size, class Generator> ForwardIterator generate_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, Generator gen); template<input_­or_­output_­iterator O, sentinel_­for<O> S, copy_­constructible F> requires invocable<F&> && indirectly_­writable<O, invoke_result_t<F&>> constexpr O ranges::generate(O first, S last, F gen); template<class R, copy_­constructible F> requires invocable<F&> && output_­range<R, invoke_result_t<F&>> constexpr borrowed_iterator_t<R> ranges::generate(R&& r, F gen); template<input_­or_­output_­iterator O, copy_­constructible F> requires invocable<F&> && indirectly_­writable<O, invoke_result_t<F&>> constexpr O ranges::generate_n(O first, iter_difference_t<O> n, F gen);
Let N be for the generate_­n algorithms, and last - first for the generate algorithms.
Mandates: Size is convertible to an integral type ([conv.integral], [class.conv]).
Effects: Assigns the result of successive evaluations of gen() through each iterator in the range [first, first + N).
Returns: first + N.
Complexity: Exactly N evaluations of gen() and assignments.