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::async::generator< T, U >::iterator Struct Referencefinal

#include <jh/asynchronous/generator.h>

Public Types

using iterator_concept = std::input_iterator_tag
using value_type = T
using pointer = value_type *
using reference = value_type &

Public Member Functions

 iterator (generator &g)
iterator & operator++ ()
iterator operator++ (int)
const value_typeoperator* ()
const value_typeoperator-> ()
bool operator== (const iterator &other) const
bool operator!= (const iterator &other) const

Public Attributes

std::optional< std::reference_wrapper< generator > > gen
std::optional< value_typecurrent_value
bool is_begin = false

Detailed Description

template<typename T, typename U = typed::monostate>
struct jh::async::generator< T, U >::iterator

Iterator

Input iterator for jh::async::generator<T, U>. Enables range-based iteration (for(auto v : gen)) when U == typed::monostate. Iteration is single-pass: once a value is consumed, it cannot be revisited.

  • Category: std::input_iterator_tag
  • Value semantics: dereferencing yields a copy of T.
  • Safety: dereferencing an exhausted iterator throws std::runtime_error.
Operations
  • iterator(generator& g) — constructs an iterator bound to a generator.
  • operator++() — advances to the next yielded value.
  • operator*() — returns a const reference to the current value.
  • operator->() — returns a pointer to the current value.
  • operator==(const iterator&) / operator!=() — compare iterator positions.

When the generator finishes, the iterator becomes equal to generator::end(). Attempting to increment beyond this point is undefined.

Input Restrictions

Iteration is always supported, even when U != typed::monostate; however, begin() and end() are deliberately omitted to prevent unintended ranged-for iteration with implicit empty input.

For generators expecting input (U non-monostate), users must construct iterator{gen} manually to iterate, or advance the coroutine explicitly using next(), send(), or send_ite().

Within the coroutine, co_await may appear selectively— if no value is sent, a default-constructed U{} is supplied.


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