1.2 KiB
1.2 KiB
[coroutine.generator.overview]
25 Ranges library [ranges]
25.8 Range generators [coro.generator]
25.8.1 Overview [coroutine.generator.overview]
Class template generator presents a view of the elements yielded by the evaluation of a coroutine.
A generator generates a sequence of elements by repeatedly resuming the coroutine from which it was returned.
Elements of the sequence are produced by the coroutine each time a co_yield statement is evaluated.
When the co_yield statement is of the formco_yield elements_of(r), each element of the range r is successively produced as an element of the sequence.
[Example 1: generator ints(int start = 0) {while (true)co_yield start++;}void f() {for (auto i : ints() | views::take(3)) cout << i << ' '; // prints 0 1 2} â end example]