Template Struct Generator

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.

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.

Generator(const Generator&) = delete

Deleted copy constructor.

Generator &operator=(const Generator&) = delete

Deleted copy assignment operator.

Generator(Generator&&) = default

Default move constructor.

Generator &operator=(Generator&&) = default

Default move assignment operator.

inline ~Generator()

Destructor destroys the coroutine handle.

inline explicit operator bool()

Check if more values are available.

Returns:

true if generator has more values, false otherwise.

inline T operator()()

Get the next value from the generator.

Returns:

Next yielded value.

Public Members

handle_type h_
struct promise_type

Coroutine promise implementation.

Public Functions

inline Generator get_return_object()

Create generator from promise.

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.

Public Members

T value

Current yielded value.

std::exception_ptr exception

Exception captured during generation.