|
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 |
| The promise type used to implement to coroutine. More... | |
Public Types | |
| using | promise_type = Promise |
| A type required by the coroutine implementation. | |
Public Member Functions | |
| Generator () noexcept | |
| Creates a new empty generator. | |
| Generator (const Generator &other)=delete | |
| Disables copy constructor. | |
| Generator & | operator= (const Generator &other)=delete |
| Disables copy assignment operator. | |
| Generator (Generator &&other) noexcept | |
| Creates a new generator by moving the contents of another. | |
| Generator & | operator= (Generator &&other) noexcept |
| Assigns the generator by moving the contents of another. | |
| ~Generator () | |
| Destroys the generator and it's corresponding coroutine. | |
| Iterator | begin () |
| Iterator | end () noexcept |
Private Types | |
| using | CoroutineHandle = coroutine_handle< Promise > |
| The coroutine handle type. | |
| 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 | |
| Generator (CoroutineHandle coroutine) noexcept | |
Creates a new Generator 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 is called the coroutine is created initially suspended. Execution of the coroutine enters the coroutine body when the Generator::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 type.
A type required by the coroutine implementation.
|
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.
Disables copy constructor.
|
inlinenoexcept |
Creates a new generator by moving the contents of another.
| other | The generator to move from. |
|
inline |
Destroys the generator and it's corresponding coroutine.
|
inlineexplicitprivatenoexcept |
Creates a new Generator from an existing coroutine handle.
| coroutine | The coroutine handle to create the generator with |
|
inline |
|
inlinenoexcept |
|
delete |
Disables copy assignment operator.
|
inlinenoexcept |
Assigns the generator by moving the contents of another.
| other | The generator to move from. |
|
private |