tmp/tmpr_5uateh/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Overview <a id="coroutine.generator.overview">[[coroutine.generator.overview]]</a>
|
| 2 |
+
|
| 3 |
+
Class template `generator` presents a view of the elements yielded by
|
| 4 |
+
the evaluation of a coroutine.
|
| 5 |
+
|
| 6 |
+
A `generator` generates a sequence of elements by repeatedly resuming
|
| 7 |
+
the coroutine from which it was returned. Elements of the sequence are
|
| 8 |
+
produced by the coroutine each time a `co_yield` statement is evaluated.
|
| 9 |
+
When the `co_yield` statement is of the form `co_yield elements_of(r)`,
|
| 10 |
+
each element of the range `r` is successively produced as an element of
|
| 11 |
+
the sequence.
|
| 12 |
+
|
| 13 |
+
[*Example 1*:
|
| 14 |
+
|
| 15 |
+
``` cpp
|
| 16 |
+
generator<int> ints(int start = 0) {
|
| 17 |
+
while (true)
|
| 18 |
+
co_yield start++;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
void f() {
|
| 22 |
+
for (auto i : ints() | views::take(3))
|
| 23 |
+
cout << i << ' '; // prints 0 1 2
|
| 24 |
+
}
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
— *end example*]
|
| 28 |
+
|