std::generator
Defined in header <generator>
|
||
template< class Ref, |
(1) | (since C++23) |
namespace pmr { template< class Ref, class V = void > |
(2) | (since C++23) |
std::generator
presents a view
of the elements yielded by the evaluation of a coroutine.A std::generator
generates a sequence of elements by repeatedly resuming the coroutine from which it was returned.
Each time a co_yield statement is evaluated, the coroutine produces one element of the sequence.
When the co_yield statement is of the form co_yield ranges::elements_of(rng), each element of the range
rng is successively produced as an element of the sequence.
std::generator
models view
and input_range
.
The behavior of a program that adds a specialization for std::generator
is undefined.
Contents |
[edit] Template parameters
Ref | - | the reference type (ranges::range_reference_t) of the generator. If V is void, both the reference type and the value type are inferred from Ref
|
V | - | the value type (ranges::range_value_t) of the generator, or void |
Allocator | - | an allocator type or void |
If Allocator
is not void, then the behavior is undefined if Allocator
does not meet the Allocator requirements.
[edit] Member types
Member | Definition |
value (private)
|
std::conditional_t<std::is_void_v<V>, std::remove_cvref_t<Ref>, V>; (exposition-only member type*) |
reference (private)
|
std::conditional_t<std::is_void_v<V>, Ref&&, Ref>; (exposition-only member type*) |
yielded
|
std::conditional_t<std::is_reference_v<reference >, reference , const reference &>
|
Type requirements | ||
-std::allocator_traits<Allocator>::pointer is a pointer type. | ||
-value is a cv-unqualified object type.
| ||
-reference is either a reference type, or a cv-unqualified object type that models copy_constructible .
| ||
-Let RRef denote std::remove_reference_t<reference >&&, if reference is a reference type, and reference otherwise.
|
The program is ill-formed if any of these type requirements is not satisfied.
[edit] Data members
Member | Definition |
active_ (private)
|
Internally, each active instance of
|
coroutine_ (private)
|
a handle of type std::coroutine_handle<promise_type> (exposition-only member object*) |
[edit] Member functions
constructs a generator object (public member function) | |
effectively destroys the entire stack of yielded generator s (public member function) | |
assigns a generator object (public member function) |