template<typename T, typename Transform = void>
struct nix::Generator< T, Transform >
Coroutine-based iterator modeled loosely on Rust std::iter::Iterator interface. Like Rust's Iterator and unlike common C++ iterators, a Generator returns std::optional<T> values from its next() function, but unlike both it can also transform items produced within using a Transform function object the Generator holds before returning them via next(). To allow generator nesting a Transform may also return another Generator instance for any yielded value, in this case the new Generator will temporarily take priority over the previously running one and have its values returned until it is exhausted, then return to the previous Generator. This mechanism may nest Generator to arbitrary depths.
- Template Parameters
-
| T | item type |
| Transform | transform function object type, or void for no transform |
template<typename T, typename Transform = void>
If the coroutine held by the Generator has not finished, runs it until it yields a value, throws any exception, or returns. If the coroutine yields a value this value is passed to a persistent instance of Transform that is held by the Generator, and the result of this call is returned. If the coroutine throws an exception, or the Transform throws an exception while processing an item, that exception is rethrown and the Generator will not return any more non-std::nullopt values from next(). Once the contained coroutine has completed or an exception has been thrown the Generator can no longer return any valid values, only std::nullopt. Exceptions thrown are thrown only once, further invocations of next() return std::nullopt.
- Returns
- std::nullopt if the coroutine has completed, or a value