JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::generator_range< T > Class Template Referencefinal

A range-like wrapper that enables iteration over a generator factory. More...

#include <jh/asynchronous/generator.h>

Inheritance diagram for jh::generator_range< T >:

Classes

class  iterator

Public Types

using generator_factory_t = std::function<generator<T>()>

Public Member Functions

 generator_range (generator_factory_t factory)
iterator begin () const

Static Public Member Functions

static std::default_sentinel_t end () noexcept

Detailed Description

template<typename T>
class jh::generator_range< T >

A range-like wrapper that enables iteration over a generator factory.

generator_range<T> provides a repeatable and range-compatible interface for coroutine-based generators. Instead of storing a single generator instance (which would be consumed after one iteration), it holds a factory function that can produce a fresh jh::async::generator<T> each time.

The factory must have one of the following signatures:

This mechanism enforces U == typed::monostate, meaning the generator cannot depend on external send() input values. The resulting range can thus be freely iterated and reused.

Key Properties

  • Each call to begin() constructs a new generator instance via the stored factory.
  • Fully compatible with std::ranges and STL algorithms.
  • Usable in for(auto v : range), std::views::zip(...), and similar constructs.
  • Guarantees value-type semantics — T must be copyable.
Note
The factory does not accept runtime arguments. It must capture all external state through its closure (via [...] capture). Passing parameterized generators must be done by creating multiple distinct factories.
Template Parameters
TThe yielded value type of the underlying jh::async::generator.
See also
jh::to_range

The documentation for this class was generated from the following file: