From Jason Turner

[coro.generator.promise]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpuajzugdd/{from.md → to.md} +209 -0
tmp/tmpuajzugdd/{from.md → to.md} RENAMED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class `generator::promise_type` <a id="coro.generator.promise">[[coro.generator.promise]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ template<class Ref, class V, class Allocator>
6
+ class generator<Ref, V, Allocator>::promise_type {
7
+ public:
8
+ generator get_return_object() noexcept;
9
+
10
+ suspend_always initial_suspend() const noexcept { return {}; }
11
+ auto final_suspend() noexcept;
12
+
13
+ suspend_always yield_value(yielded val) noexcept;
14
+
15
+ auto yield_value(const remove_reference_t<yielded>& lval)
16
+ requires is_rvalue_reference_v<yielded> &&
17
+ constructible_from<remove_cvref_t<yielded>, const remove_reference_t<yielded>&>;
18
+
19
+ template<class R2, class V2, class Alloc2, class Unused>
20
+ requires same_as<typename generator<R2, V2, Alloc2>::yielded, yielded>
21
+ auto yield_value(ranges::elements_of<generator<R2, V2, Alloc2>&&, Unused> g) noexcept;
22
+
23
+ template<ranges::input_range R, class Alloc>
24
+ requires convertible_to<ranges::range_reference_t<R>, yielded>
25
+ auto yield_value(ranges::elements_of<R, Alloc> r) noexcept;
26
+
27
+ void await_transform() = delete;
28
+
29
+ void return_void() const noexcept {}
30
+ void unhandled_exception();
31
+
32
+ void* operator new(size_t size)
33
+ requires same_as<Allocator, void> || default_initializable<Allocator>;
34
+
35
+ template<class Alloc, class... Args>
36
+ requires same_as<Allocator, void> || convertible_to<const Alloc&, Allocator>
37
+ void* operator new(size_t size, allocator_arg_t, const Alloc& alloc, const Args&...);
38
+
39
+ template<class This, class Alloc, class... Args>
40
+ requires same_as<Allocator, void> || convertible_to<const Alloc&, Allocator>
41
+ void* operator new(size_t size, const This&, allocator_arg_t, const Alloc& alloc,
42
+ const Args&...);
43
+
44
+ void operator delete(void* pointer, size_t size) noexcept;
45
+
46
+ private:
47
+ add_pointer_t<yielded> value_ = nullptr; // exposition only
48
+ exception_ptr except_; // exposition only
49
+ };
50
+ }
51
+ ```
52
+
53
+ ``` cpp
54
+ generator get_return_object() noexcept;
55
+ ```
56
+
57
+ *Returns:* A `generator` object whose member *coroutine\_* is
58
+ `coroutine_handle<promise_type>::from_promise(*this)`, and whose member
59
+ *active\_* points to an empty stack.
60
+
61
+ ``` cpp
62
+ auto final_suspend() noexcept;
63
+ ```
64
+
65
+ *Preconditions:* A handle referring to the coroutine whose promise
66
+ object is `*this` is at the top of `*`*`active_`* of some `generator`
67
+ object `x`. This function is called by that coroutine upon reaching its
68
+ final suspend point [[dcl.fct.def.coroutine]].
69
+
70
+ *Returns:* An awaitable object of unspecified type [[expr.await]] whose
71
+ member functions arrange for the calling coroutine to be suspended, pop
72
+ the coroutine handle from the top of `*x.`*`active_`*, and resume
73
+ execution of the coroutine referred to by `x.`*`active_`*`->top()` if
74
+ `*x.`*`active_`* is not empty. If it is empty, control flow returns to
75
+ the current coroutine caller or resumer [[dcl.fct.def.coroutine]].
76
+
77
+ ``` cpp
78
+ suspend_always yield_value(yielded val) noexcept;
79
+ ```
80
+
81
+ *Effects:* Equivalent to *`value_`*` = addressof(val)`.
82
+
83
+ *Returns:* `{}`.
84
+
85
+ ``` cpp
86
+ auto yield_value(const remove_reference_t<yielded>& lval)
87
+ requires is_rvalue_reference_v<yielded> &&
88
+ constructible_from<remove_cvref_t<yielded>, const remove_reference_t<yielded>&>;
89
+ ```
90
+
91
+ *Preconditions:* A handle referring to the coroutine whose promise
92
+ object is `*this` is at the top of `*`*`active_`* of some `generator`
93
+ object.
94
+
95
+ *Returns:* An awaitable object of an unspecified type [[expr.await]]
96
+ that stores an object of type `remove_cvref_t<yielded>`
97
+ direct-non-list-initialized with `lval`, whose member functions arrange
98
+ for *value\_* to point to that stored object and then suspend the
99
+ coroutine.
100
+
101
+ *Throws:* Any exception thrown by the initialization of the stored
102
+ object.
103
+
104
+ *Remarks:* A *yield-expression* that calls this function has type `void`
105
+ [[expr.yield]].
106
+
107
+ ``` cpp
108
+ template<class R2, class V2, class Alloc2, class Unused>
109
+ requires same_as<typename generator<R2, V2, Alloc2>::yielded, yielded>
110
+ auto yield_value(ranges::elements_of<generator<R2, V2, Alloc2>&&, Unused> g) noexcept;
111
+ ```
112
+
113
+ *Preconditions:* A handle referring to the coroutine whose promise
114
+ object is `*this` is at the top of `*`*`active_`* of some `generator`
115
+ object `x`. The coroutine referred to by `g.range.`*`coroutine_`* is
116
+ suspended at its initial suspend point.
117
+
118
+ *Returns:* An awaitable object of an unspecified type [[expr.await]]
119
+ into which `g.range` is moved, whose member `await_ready` returns
120
+ `false`, whose member `await_suspend` pushes
121
+ `g.range.`\textit{coroutine\_} into `*x.`*`active_`* and resumes
122
+ execution of the coroutine referred to by `g.range.`*`coroutine_`*, and
123
+ whose member `await_resume` evaluates `rethrow_exception(`*`except_`*`)`
124
+ if `bool(`*`except_`*`)` is `true`. If `bool(`*`except_`*`)` is `false`,
125
+ the `await_resume` member has no effects.
126
+
127
+ *Remarks:* A *yield-expression* that calls this function has type `void`
128
+ [[expr.yield]].
129
+
130
+ ``` cpp
131
+ template<ranges::input_range R, class Alloc>
132
+ requires convertible_to<ranges::range_reference_t<R>, yielded>
133
+ auto yield_value(ranges::elements_of<R, Alloc> r) noexcept;
134
+ ```
135
+
136
+ *Effects:* Equivalent to:
137
+
138
+ ``` cpp
139
+ auto nested = [](allocator_arg_t, Alloc, ranges::iterator_t<R> i, ranges::sentinel_t<R> s)
140
+ -> generator<yielded, ranges::range_value_t<R>, Alloc> {
141
+ for (; i != s; ++i) {
142
+ co_yield static_cast<yielded>(*i);
143
+ }
144
+ };
145
+ return yield_value(ranges::elements_of(nested(
146
+ allocator_arg, r.allocator, ranges::begin(r.range), ranges::end(r.range))));
147
+ ```
148
+
149
+ [*Note 1*: A *yield-expression* that calls this function has type
150
+ `void` [[expr.yield]]. — *end note*]
151
+
152
+ ``` cpp
153
+ void unhandled_exception();
154
+ ```
155
+
156
+ *Preconditions:* A handle referring to the coroutine whose promise
157
+ object is `*this` is at the top of `*`*`active_`* of some `generator`
158
+ object `x`.
159
+
160
+ *Effects:* If the handle referring to the coroutine whose promise object
161
+ is `*this` is the sole element of `*x.`*`active_`*, equivalent to
162
+ `throw`, otherwise, assigns `current_exception()` to *except\_*.
163
+
164
+ ``` cpp
165
+ void* operator new(size_t size)
166
+ requires same_as<Allocator, void> || default_initializable<Allocator>;
167
+
168
+ template<class Alloc, class... Args>
169
+ requires same_as<Allocator, void> || convertible_to<const Alloc&, Allocator>
170
+ void* operator new(size_t size, allocator_arg_t, const Alloc& alloc, const Args&...);
171
+
172
+ template<class This, class Alloc, class... Args>
173
+ requires same_as<Allocator, void> || convertible_to<const Alloc&, Allocator>
174
+ void* operator new(size_t size, const This&, allocator_arg_t, const Alloc& alloc,
175
+ const Args&...);
176
+ ```
177
+
178
+ Let `A` be
179
+
180
+ - `Allocator`, if it is not `void`,
181
+ - `Alloc` for the overloads with a template parameter `Alloc`, or
182
+ - `allocator<void>` otherwise.
183
+
184
+ Let `B` be `allocator_traits<A>::template rebind_alloc<U>` where `U` is
185
+ an unspecified type whose size and alignment are both
186
+ \_\_STDCPP_DEFAULT_NEW_ALIGNMENT\_\_.
187
+
188
+ *Mandates:* `allocator_traits<B>::pointer` is a pointer type.
189
+
190
+ *Effects:* Initializes an allocator `b` of type `B` with `A(alloc)`, for
191
+ the overloads with a function parameter `alloc`, and with `A()`
192
+ otherwise. Uses `b` to allocate storage for the smallest array of `U`
193
+ sufficient to provide storage for a coroutine state of size `size`, and
194
+ unspecified additional state necessary to ensure that `operator delete`
195
+ can later deallocate this memory block with an allocator equal to `b`.
196
+
197
+ *Returns:* A pointer to the allocated storage.
198
+
199
+ ``` cpp
200
+ void operator delete(void* pointer, size_t size) noexcept;
201
+ ```
202
+
203
+ *Preconditions:* `pointer` was returned from an invocation of one of the
204
+ above overloads of `operator new` with a `size` argument equal to
205
+ `size`.
206
+
207
+ *Effects:* Deallocates the storage pointed to by `pointer` using an
208
+ allocator equivalent to that used to allocate it.
209
+