10#if !defined(__cpp_coroutines) && !defined(__cpp_impl_coroutine)
11#error "Generator: Unsupported platform!"
133 using Value = std::remove_reference_t<T>;
136 using Reference = std::conditional_t<std::is_reference_v<T>,
T,
T&>;
181 mValue = std::addressof(
const_cast<std::remove_reference_t<T>&
>(
aValue));
492 return task.address() !=
nullptr;
546 auto& p = CoroutineHandle::from_address(handle.address()).promise();
#define CE_FORCE_INLINE
Definition Macros.hpp:367
#define CE_LIKELY
Definition Macros.hpp:396
#define CE_UNLIKELY
Definition Macros.hpp:397
An iterator type that allows the caller to iterate over the results of a generator.
Definition Generator.hpp:530
Iterator & await_resume()
Definition Generator.hpp:628
bool operator!=(const Iterator &rhs) const noexcept
Check if two iterator are not equal.
Definition Generator.hpp:569
reference operator*() noexcept
Dereferences the iterator and returns a reference to the last yielded value.
Definition Generator.hpp:589
reference operator*() const noexcept
Dereferences the iterator and returns a reference to the last yielded value.
Definition Generator.hpp:594
Iterator & operator++()
Resumes the generator coroutine and runs until the next value is yielded by it.
Definition Generator.hpp:577
T const & reference
Definition Generator.hpp:554
Iterator(std::nullptr_t) noexcept
Initialize an past-the-end iterator.
Definition Generator.hpp:540
pointer operator->() noexcept
Dereferences the iterator and returns a pointer to the last yielded value.
Definition Generator.hpp:599
Iterator(const AsyncCoroutineHandle handle) noexcept
Creates a new Iterator object with an attached coroutine handle.
Definition Generator.hpp:545
T value_type
Definition Generator.hpp:553
bool operator==(const Iterator &rhs) const noexcept
Check if two iterator are equal.
Definition Generator.hpp:563
Promise * mPromise
Definition Generator.hpp:532
bool await_ready() const noexcept
Definition Generator.hpp:606
Iterator operator++(int)=delete
Post increment is not supported.
void await_suspend(AsyncCoroutineHandle rh) noexcept
Definition Generator.hpp:619
std::input_iterator_tag iterator_category
Definition Generator.hpp:551
T const * pointer
Definition Generator.hpp:555
pointer operator->() const noexcept
Dereferences the iterator and returns a pointer to the last yielded value.
Definition Generator.hpp:604
Iterator() noexcept
Iterator needs to be default-constructible to satisfy the Range concept.
Definition Generator.hpp:537
std::ptrdiff_t difference_type
Definition Generator.hpp:552
Definition Generator.hpp:403
AsyncGenerator get_return_object() noexcept
Definition Generator.hpp:436
AsyncCoroutineHandle task
The task currently being awaited.
Definition Generator.hpp:416
void rethrow()
If an exception was thrown in the coroutine, rethrows it.
Definition Generator.hpp:521
void return_void() noexcept
Definition Generator.hpp:476
bool await_ready() const noexcept
Definition Generator.hpp:486
Reference value() const noexcept
Definition Generator.hpp:517
Lockable mutex
A lockable object that sychronizes access to the promise when executing asynchronous code.
Definition Generator.hpp:420
Promise & yield_value(std::remove_reference_t< T > &value) noexcept
Yields a new value to the generator.
Definition Generator.hpp:449
void unhandled_exception() noexcept
A method called internally by the compiler when an exception is thrown in the coroutine.
Definition Generator.hpp:465
Promise & yield_value(std::remove_reference_t< T > &&value) noexcept
Yields a new value to the generator.
Definition Generator.hpp:457
void await_resume() noexcept
Definition Generator.hpp:501
constexpr suspend_always initial_suspend() const noexcept
Definition Generator.hpp:439
std::exception_ptr exception
The exception throw by the coroutine.
Definition Generator.hpp:413
std::optional< Pointer > current
The value returned by the last continuation of the coroutine.
Definition Generator.hpp:409
constexpr suspend_always final_suspend() const noexcept
Definition Generator.hpp:442
void await_suspend(const AsyncCoroutineHandle handle) noexcept
Definition Generator.hpp:495
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:319
T * Pointer
Definition Generator.hpp:329
Iterator end() noexcept
Definition Generator.hpp:400
CoroutineHandle mCoroutine
Definition Generator.hpp:344
AsyncGenerator(AsyncGenerator &&other) noexcept
Creates a new generator by moving the contents of another.
Definition Generator.hpp:359
~AsyncGenerator() noexcept
Definition Generator.hpp:369
AsyncGenerator(Promise *promise) noexcept
Creates a new AsyncGenerator from an existing coroutine handle.
Definition Generator.hpp:381
AsyncGenerator & operator=(AsyncGenerator &&other) noexcept
Assigns the generator by moving the contents of another.
Definition Generator.hpp:364
AsyncGenerator & operator=(const AsyncGenerator &)=delete
Disables copy assignment operator.
AsyncGenerator(const AsyncGenerator &)=delete
Disables copy constructor.
CeresEngine::suspend_always suspend_always
An alias to std::suspend_always.
Definition Generator.hpp:338
CeresEngine::suspend_never suspend_never
An alias to std::suspend_never.
Definition Generator.hpp:341
AsyncGenerator() noexcept
Creates a new empty generator.
Definition Generator.hpp:349
coroutine_handle< Promise > CoroutineHandle
The coroutine handle type.
Definition Generator.hpp:332
T & Reference
Definition Generator.hpp:328
coroutine_handle<> AsyncCoroutineHandle
The coroutine handle for an asynchronous task.
Definition Generator.hpp:335
Iterator begin()
Definition Generator.hpp:385
An iterator type that allows the caller to iterate over the results of a generator.
Definition Generator.hpp:226
bool operator==(const Iterator &other) const noexcept
Check if two iterator are equal.
Definition Generator.hpp:255
reference operator*() const noexcept
Dereferences the iterator and returns a reference to the last yielded value.
Definition Generator.hpp:285
Iterator & operator++()
Resumes the generator coroutine and runs until the next value is yielded by it.
Definition Generator.hpp:266
bool operator!=(const Iterator &other) const noexcept
Check if two iterator are not equal.
Definition Generator.hpp:261
Iterator(CoroutineHandle coroutine) noexcept
Creates a new Iterator object with an attached coroutine handle.
Definition Generator.hpp:240
Iterator() noexcept
Iterator needs to be default-constructible to satisfy the Range concept.
Definition Generator.hpp:235
std::ptrdiff_t difference_type
Definition Generator.hpp:244
std::input_iterator_tag iterator_category
Definition Generator.hpp:243
CoroutineHandle mCoroutine
The coroutine handle instance.
Definition Generator.hpp:230
typename Promise::Pointer pointer
Definition Generator.hpp:247
typename Promise::Value value_type
Definition Generator.hpp:245
typename Promise::Reference reference
Definition Generator.hpp:246
pointer operator->() const noexcept
Dereferences the iterator and returns a pointer to the last yielded value.
Definition Generator.hpp:290
void operator++(int)
Resumes the generator coroutine and runs until the next value is yielded by it.
Definition Generator.hpp:280
The promise type used to implement to coroutine.
Definition Generator.hpp:130
void rethrow()
If an exception was thrown in the coroutine, rethrows it.
Definition Generator.hpp:216
void return_void() noexcept
A method called internally by the compiler when the coroutine successfully finishes.
Definition Generator.hpp:202
constexpr suspend_always initial_suspend() const noexcept
Definition Generator.hpp:160
Promise()=default
Creates a new promise object.
std::remove_reference_t< T > Value
The value type returned by the generator.
Definition Generator.hpp:133
std::conditional_t< std::is_reference_v< T >, T, T & > Reference
A reference of Value.
Definition Generator.hpp:136
void unhandled_exception() noexcept
A method called internally by the compiler when an exception is thrown in the coroutine.
Definition Generator.hpp:196
Pointer mValue
The value returned by the last continuation of the coroutine.
Definition Generator.hpp:143
Value * Pointer
A pointer of Value.
Definition Generator.hpp:139
suspend_always yield_value(const std::remove_reference_t< T > &aValue) noexcept
Yields a new value to the generator.
Definition Generator.hpp:180
suspend_always yield_value(std::remove_reference_t< T > &aValue) noexcept
Yields a new value to the generator.
Definition Generator.hpp:170
suspend_never await_transform(U &&value)=delete
Don't allow any use of 'co_await' inside the generator coroutine.
constexpr suspend_always final_suspend() const noexcept
Definition Generator.hpp:163
std::exception_ptr mException
The exception throw by the coroutine.
Definition Generator.hpp:147
Generator get_return_object() noexcept
Creates a new Generator object.
Definition Generator.hpp:157
Reference getValue() const noexcept
Definition Generator.hpp:212
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:50
~Generator()
Destroys the generator and it's corresponding coroutine.
Definition Generator.hpp:96
Iterator begin()
Definition Generator.hpp:109
Generator(CoroutineHandle coroutine) noexcept
Creates a new Generator from an existing coroutine handle.
Definition Generator.hpp:105
Generator() noexcept
Creates a new empty generator.
Definition Generator.hpp:75
CeresEngine::suspend_never suspend_never
An alias to std::suspend_never.
Definition Generator.hpp:67
Iterator end() noexcept
Definition Generator.hpp:126
Generator(Generator &&other) noexcept
Creates a new generator by moving the contents of another.
Definition Generator.hpp:85
Generator & operator=(Generator &&other) noexcept
Assigns the generator by moving the contents of another.
Definition Generator.hpp:90
CeresEngine::suspend_always suspend_always
An alias to std::suspend_always.
Definition Generator.hpp:64
Generator(const Generator &other)=delete
Disables copy constructor.
Generator & operator=(const Generator &other)=delete
Disables copy assignment operator.
coroutine_handle< Promise > CoroutineHandle
The coroutine handle type.
Definition Generator.hpp:61
CoroutineHandle mCoroutine
Definition Generator.hpp:70
The class UniqueLock is a general-purpose mutex ownership wrapper allowing deferred locking,...
Definition Threading.hpp:270
Definition Application.hpp:19
decltype(auto) lock(Func &&func, Ts &... objects)
Definition Threading.hpp:667
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25