Files
cppdraft_translate/cppdraft/alg/generate.md
2025-10-25 03:02:53 +03:00

6.9 KiB

[alg.generate]

26 Algorithms library [algorithms]

26.7 Mutating sequence operations [alg.modifying.operations]

26.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 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 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 n, F gen);

template<execution-policy Ep, random_access_iterator O, sized_sentinel_for S, copy_constructible F> requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>> O ranges::generate(Ep&& exec, O first, S last, F gen); template<execution-policy Ep, sized-random-access-range R, copy_constructible F> requires invocable<F&> && indirectly_writable<iterator_t, invoke_result_t<F&>> borrowed_iterator_t ranges::generate(Ep&& exec, R&& r, F gen); template<execution-policy Ep, random_access_iterator O, copy_constructible F> requires invocable<F&> && indirectly_writable<O, invoke_result_t<F&>> O ranges::generate_n(Ep&& exec, O first, iter_difference_t n, F gen); `

1

#

Let N be max(0, n) for the generate_n algorithms, andlast - first for the generate algorithms.

2

#

Mandates: Size is convertible to an integral type ([conv.integral], [class.conv]).

3

#

Effects: Assigns the result of successive evaluations of gen() through each iterator in the range [first, first + N).

4

#

Returns: first + N.

5

#

Complexity: Exactly N evaluations of gen() and assignments.

6

#

Remarks: gen may modify objects via its arguments for parallel algorithm overloads ([algorithms.parallel.user]).