std::generator
From cppreference.com
Defined in header <generator>
|
||
template< class Ref, |
(since C++23) | |
The class template 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 elements_of(rng), each element of the range
rng
is successively produced as an element of the sequence.
Contents |
Template parameters
Ref | - | TODO |
V | - | TODO |
Allocator | - | TODO |
Data members
TODO
Member types
TODO
Member functions
Inherited from std::ranges::view_interface | |
returns whether the derived view is empty. Provided if it satisfies sized_range or forward_range . (public member function of std::ranges::view_interface<D> )
| |
(C++23) |
returns a constant iterator to the beginning of the range. (public member function of std::ranges::view_interface<D> )
|
(C++23) |
returns a sentinel for the constant iterator of the range. (public member function of std::ranges::view_interface<D> )
|
returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D> )
|
Nested classes
Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_generator |
202207L | (C++23) | std::generator – synchronous coroutine generator for ranges
|
Example
Run this code
#include <generator> #include <ranges> #include <iostream> std::generator<char> letters(char first) { for (;; co_yield first++); } int main() { for (const char ch : letters('a') | std::views::take(13*2)) std::cout << ch << ' '; std::cout << '\n'; }
Output:
a b c d e f g h i j k l m n o p q r s t u v w x y z
See also
(C++20) |
creates a coroutine handle that has no observable effects when resumed or destroyed (function) |