Template Struct Generator¶
Defined in File generator.h
Nested Relationships¶
Nested Types¶
Struct Documentation¶
-
template<typename T>
struct Generator¶ Coroutine-based generator for lazy iteration.
Generator provides a C++20 coroutine-based iterator that yields values on demand. Used for streaming operations where producing all values upfront would be inefficient.
Supports both functional-style iteration via operator() and C++ iterator protocol for use with range-based for loops and standard algorithms.
- Template Parameters:
T – Type of values yielded by the generator.
Public Types
-
using handle_type = std::coroutine_handle<promise_type>¶
Public Functions
-
inline explicit Generator(handle_type h)¶
Construct generator from coroutine handle.
-
inline Generator(Generator &&other) noexcept¶
Move constructor - transfers ownership and nulls source handle.
-
inline Generator &operator=(Generator &&other) noexcept¶
Move assignment operator - transfers ownership and nulls source handle.
-
inline ~Generator()¶
Destructor destroys the coroutine handle if valid.
-
inline iterator begin()¶
Get iterator to the beginning of the generator. Advances to the first value.
-
inline std::default_sentinel_t end()¶
Get sentinel marking the end of the generator.
-
inline explicit operator bool()¶
Check if more values are available.
- Returns:
true if generator has more values, false otherwise.
Public Members
-
handle_type h_¶
-
struct iterator¶
Iterator for C++ range-based for loop support.
Public Types
-
using iterator_category = std::input_iterator_tag¶
-
using difference_type = std::ptrdiff_t¶
Public Functions
-
inline bool operator==(std::default_sentinel_t) const¶
Public Members
-
handle_type h_¶
-
using iterator_category = std::input_iterator_tag¶
-
struct promise_type¶
Coroutine promise implementation.
Public Functions
-
inline std::suspend_always initial_suspend()¶
Suspend at coroutine start.
-
inline std::suspend_always final_suspend() noexcept¶
Suspend at coroutine end.
-
inline void unhandled_exception()¶
Handle unhandled exceptions.
-
template<std::convertible_to<T> From>
inline std::suspend_always yield_value(From &&from)¶ Yield a value from the coroutine.
-
inline void return_void()¶
Complete coroutine without returning a value.
-
inline std::suspend_always initial_suspend()¶