|
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.
|
#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_type & | operator* () |
| const value_type * | operator-> () |
| bool | operator== (const iterator &other) const |
| bool | operator!= (const iterator &other) const |
Public Attributes | |
| std::optional< std::reference_wrapper< generator > > | gen |
| std::optional< value_type > | current_value |
| bool | is_begin = false |
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.
std::input_iterator_tag T. std::runtime_error. 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.
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.