piped::generator
<piped/generator.hpp>
template<typename CRTP>
struct piped::generator;
Generator should be a base class for user-built generators. It provides methods to implicitly use the generator as a C++-style container with begin()
/end()
.
Generators should publicly inherit this with CRTP, and implement:
option_type
is any type implementing operator*()
to dereference a value, and should be implicitly bool-convertible to describe whether it contains a value or not. Dereferencing with no value is undefined. Pointers (prefer ptr<T>
) and std::optional<T>
are two examples.
If empty()
returns true, next()
is expected to return empty_v<T>
.
Likewise, if empty()
returns false, next()
is expected to produce a value.
Note generators do not have to generalize on any T
: value_type
may be fixed, but it is expected to be defined, along with option_type
.
Name | Description |
---|---|
begin() | |
end() |
Members
begin()
<piped/generator.hpp>
iterator piped::generator< CRTP >::begin()
Description
This returns an iterator suitable for range-based-for-like iteration. It is not expected that you can use algorithms, or store or reuse copies.
end()
<piped/generator.hpp>
end_iterator piped::generator< CRTP >::end()
Description
This returns the generator as an end iterator, which when compared with the iterator returned by begin()
, will appropriately check if the generator is empty.