On this page
std::generator<Ref,V,Allocator>::promise_type::yield_value
|
(1) | (since C++23) |
|
(2) | (since C++23) |
|
(3) | (since C++23) |
|
(4) | (since C++23) |
An implementation of coroutine interface functions used internally to support operator co_yield
.
(yielded
is a reference type defined in std::generator
.)
2) Returns an awaitable object of an unspecified type that stores an object of type
3) Let std::remove_cvref_t<yielded>
direct-non-list-initialized with lval
, whose member functions are configures so that value_
points to that stored object. Then suspends the coroutine.
x
be some generator object.
Returns an awaitable object of an unspecified type into which g.range
is moved,
- whose member
await_ready
returns false, - whose member
await_suspend
pushesg.range.coroutine_
into*x.active_
and - resumes execution of the coroutine referred to by
g.range.coroutine_
, and - whose member
await_resume
evaluates std::rethrow_exception(except_)
ifbool(except_)
is true.- If bool(except_) is false, the
await_resume
member has no effects.
The coroutine referred to by
g.range.coroutine_
must be suspended at its initial suspend point. Otherwise the behavior is undefined.
4) Equivalent to:
auto nested = [](std::allocator_arg_t, Alloc, ranges::iterator_t<R> i,
ranges::sentinel_t<R> s) ->
std::generator<yielded, ranges::range_value_t<R>, Alloc>
{
for (; i != s; ++i)
co_yield static_cast<yielded>(*i);
};
return yield_value(ranges::elements_of(nested(
allocator_arg, r.allocator, ranges::begin(r.range), ranges::end(r.range))));
2,3) A handle referring to the coroutine whose promise object is
*this
must be at the top of *active_
of some generator object. Otherwise the behavior is undefined.
Parameters
val | - | a value which is a result of the yield-expression evaluation |
lval | - | an lvalue which is a result of the yield-expression evaluation |
g | - | a range of elements produced by a generator |
r | - | a range of elements |
Return value
1) The awaitable object of type
std::suspend_always
.
2-4) An awaitable object of an unspecified type as described above.
Exceptions
2) May throw any exception thrown by the initialization of the stored object.
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/coroutine/generator/promise_type/yield_value