entttree 0.1.0
Hierarchical entity management for EnTT
Loading...
Searching...
No Matches
entttree::Generator< T, V > Struct Template Reference

A C++20 coroutine-based generator that lazily yields values of type T. More...

#include <generator.h>

Classes

struct  promise_type
 

Public Types

using ret_t = std::conditional_t< std::is_void_v< V >, std::monostate, V >
 

Public Member Functions

 Generator (const Generator &)=delete
 
 Generator (Generator &&other)
 
Generatoroperator= (const Generator &)=delete
 
Generatoroperator= (Generator &&other)
 
bool next ()
 Advance to the next yielded value. Returns true if a new value is available.
 
Generatoroperator++ ()
 Advance to the next value (same as next()).
 
const Toperator* () const
 Access the most recently yielded value.
 
Toperator* ()
 Access the most recently yielded value.
 
const Toperator-> () const
 Access the most recently yielded value via pointer.
 
Toperator-> ()
 Access the most recently yielded value via pointer.
 
bool is_valid () const
 Returns true if the generator has more values to produce.
 
 operator bool () const
 Returns true if the generator has more values to produce.
 
size_t count () const
 The number of values yielded so far.
 
bool is_finished () const
 Returns true if the coroutine has finished (reached co_return).
 
ret_t & get_return_value ()
 Access the coroutine's return value (only valid after is_finished() is true).
 
const ret_t & get_return_value () const
 Access the coroutine's return value (only valid after is_finished() is true).
 

Detailed Description

template<typename T, typename V = void>
struct entttree::Generator< T, V >

A C++20 coroutine-based generator that lazily yields values of type T.

A coroutine returning Generator<T> can use co_yield to produce values and co_return to finish. The consumer drives iteration with operator++ and operator bool:

for (int i = lo; i < hi; ++i) co_yield i;
}
for (auto g = range(0, 5); g; ++g) {
std::cout << *g << "\n";
}
A system for maintaining parent-child relationships on entities.
Definition hierarchy.h:37
Template Parameters
TThe type of value yielded by the generator.
VOptional return-value type (defaults to void / std::monostate).

Definition at line 34 of file generator.h.

Member Typedef Documentation

◆ ret_t

template<typename T , typename V = void>
using entttree::Generator< T, V >::ret_t = std::conditional_t<std::is_void_v<V>, std::monostate, V>

Definition at line 36 of file generator.h.

Constructor & Destructor Documentation

◆ Generator()

template<typename T , typename V = void>
entttree::Generator< T, V >::Generator ( Generator< T, V > &&  other)
inline

Definition at line 81 of file generator.h.

◆ ~Generator()

template<typename T , typename V = void>
entttree::Generator< T, V >::~Generator ( )
inline

Definition at line 87 of file generator.h.

Member Function Documentation

◆ count()

template<typename T , typename V = void>
size_t entttree::Generator< T, V >::count ( ) const
inline

The number of values yielded so far.

Definition at line 146 of file generator.h.

◆ get_return_value() [1/2]

template<typename T , typename V = void>
ret_t & entttree::Generator< T, V >::get_return_value ( )
inline

Access the coroutine's return value (only valid after is_finished() is true).

Definition at line 152 of file generator.h.

◆ get_return_value() [2/2]

template<typename T , typename V = void>
const ret_t & entttree::Generator< T, V >::get_return_value ( ) const
inline

Access the coroutine's return value (only valid after is_finished() is true).

Definition at line 154 of file generator.h.

◆ is_finished()

template<typename T , typename V = void>
bool entttree::Generator< T, V >::is_finished ( ) const
inline

Returns true if the coroutine has finished (reached co_return).

Definition at line 149 of file generator.h.

◆ is_valid()

template<typename T , typename V = void>
bool entttree::Generator< T, V >::is_valid ( ) const
inline

Returns true if the generator has more values to produce.

Definition at line 141 of file generator.h.

References entttree::and.

Referenced by entttree::Generator< T, V >::operator bool().

◆ next()

template<typename T , typename V = void>
bool entttree::Generator< T, V >::next ( )
inline

Advance to the next yielded value. Returns true if a new value is available.

Definition at line 115 of file generator.h.

Referenced by entttree::Generator< T, V >::operator++().

◆ operator bool()

template<typename T , typename V = void>
entttree::Generator< T, V >::operator bool ( ) const
inline

Returns true if the generator has more values to produce.

Definition at line 143 of file generator.h.

References entttree::Generator< T, V >::is_valid().

◆ operator*() [1/2]

template<typename T , typename V = void>
T & entttree::Generator< T, V >::operator* ( )
inline

Access the most recently yielded value.

Definition at line 133 of file generator.h.

◆ operator*() [2/2]

template<typename T , typename V = void>
const T & entttree::Generator< T, V >::operator* ( ) const
inline

Access the most recently yielded value.

Definition at line 131 of file generator.h.

◆ operator++()

template<typename T , typename V = void>
Generator & entttree::Generator< T, V >::operator++ ( )
inline

Advance to the next value (same as next()).

Definition at line 125 of file generator.h.

References entttree::Generator< T, V >::next().

◆ operator->() [1/2]

template<typename T , typename V = void>
T * entttree::Generator< T, V >::operator-> ( )
inline

Access the most recently yielded value via pointer.

Definition at line 138 of file generator.h.

◆ operator->() [2/2]

template<typename T , typename V = void>
const T * entttree::Generator< T, V >::operator-> ( ) const
inline

Access the most recently yielded value via pointer.

Definition at line 136 of file generator.h.

◆ operator=()

template<typename T , typename V = void>
Generator & entttree::Generator< T, V >::operator= ( Generator< T, V > &&  other)
inline

Definition at line 92 of file generator.h.


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