|
CeresEngine 0.2.0
A game development framework
|
A generator represents a coroutine type that produces a sequence of values of type T, where values are produced lazily and synchronously.
More...
#include <CeresEngine/Foundation/Generator.hpp>
Classes | |
| class | Iterator |
| An iterator type that allows the caller to iterate over the results of a generator. More... | |
| class | Promise |
Public Types | |
| using | promise_type = Promise |
| A type required by the coroutine implementation. | |
Public Member Functions | |
| AsyncGenerator () noexcept | |
| Creates a new empty generator. | |
| AsyncGenerator (const AsyncGenerator &)=delete | |
| Disables copy constructor. | |
| AsyncGenerator & | operator= (const AsyncGenerator &)=delete |
| Disables copy assignment operator. | |
| AsyncGenerator (AsyncGenerator &&other) noexcept | |
| Creates a new generator by moving the contents of another. | |
| AsyncGenerator & | operator= (AsyncGenerator &&other) noexcept |
| Assigns the generator by moving the contents of another. | |
| ~AsyncGenerator () noexcept | |
| Iterator | begin () |
| Iterator | end () noexcept |
Private Types | |
| using | Reference = T & |
| using | Pointer = T * |
| using | CoroutineHandle = coroutine_handle< Promise > |
| The coroutine handle type. | |
| using | AsyncCoroutineHandle = coroutine_handle<> |
| The coroutine handle for an asynchronous task. | |
| using | suspend_always = CeresEngine::suspend_always |
An alias to std::suspend_always. | |
| using | suspend_never = CeresEngine::suspend_never |
An alias to std::suspend_never. | |
Private Member Functions | |
| AsyncGenerator (Promise *promise) noexcept | |
Creates a new AsyncGenerator from an existing coroutine handle. | |
Private Attributes | |
| CoroutineHandle | mCoroutine |
A generator represents a coroutine type that produces a sequence of values of type T, where values are produced lazily and synchronously.
The coroutine body is able to yield values of type T using the co_yield keyword. Note, however, that the coroutine body is not able to use the co_await keyword; values must be produced synchronously.
When a coroutine function returning a Generator<T> is called the coroutine is created initially suspended. Execution of the coroutine enters the coroutine body when the Generator<T>::begin() method is called and continues until either the first co_yield statement is reached or the coroutine runs to completion.
If the returned iterator is not equal to the end() iterator then dereferencing the iterator will return a reference to the value passed to the co_yield statement.
Calling operator++() on the iterator will resume execution of the coroutine and continue until either the next co_yield point is reached or the coroutine runs to completion.
Any unhandled exceptions thrown by the coroutine will propagate out of the begin() or operator++() calls to the caller.
| T | the value type returned by the generator. |
|
private |
The coroutine handle for an asynchronous task.
|
private |
The coroutine handle type.
|
private |
| using CeresEngine::AsyncGenerator< T, Lockable >::promise_type = Promise |
A type required by the coroutine implementation.
|
private |
|
private |
An alias to std::suspend_always.
|
private |
An alias to std::suspend_never.
|
inlinenoexcept |
Creates a new empty generator.
This generator will always return an empty set of elements.
|
delete |
Disables copy constructor.
|
inlinenoexcept |
Creates a new generator by moving the contents of another.
| other | The generator to move from. |
|
inlinenoexcept |
|
inlineexplicitprivatenoexcept |
Creates a new AsyncGenerator from an existing coroutine handle.
| promise | The promise object to create the async generator from |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
Assigns the generator by moving the contents of another.
| other | The generator to move from. |
|
delete |
Disables copy assignment operator.
|
private |