simple_promise


A simple_promise<T> is the simplest “returning” promise. The internal state maintains an optional<T> which is set by the coroutine body. This allows a [coroutine Type](#Coroutine-Types) to pull out the return type and provide it to the caller. simple_promise<T> satisfies the Returnable concept.

The coroutine key words available are co_return (ARG) where T is constructible from ARG, co_return (std::nullopt_t) in the case the promise cannot be fulfilled and co_await (AwaitableProxy) for suspension.


template<typename T = void>
class zab::simple_promise : public zab::simple_common<simple_promise<void>>

The promise of some value used be simple_future’s.

Template Parameters

T – The type of the promised value.

Public Types

using returns = std::optional<T>

Public Functions

simple_promise() = default
~simple_promise() = default
inline returns &&data() noexcept
template<typename ...Args>
inline void return_value(Args&&... _args) noexcept

Creates the promised object from some values.

One day they may support co_return x y z;

Parameters

_args – The arguments to construct T with.

Template Parameters

Args – The types of the arguments.

inline void return_value(returns &&_move) noexcept

Construct the optional of T.

Parameters

_move – The optional to move.

inline void return_value(std::nullopt_t) noexcept

No value is returned.

inline void return_value(const returns &_copy) noexcept

Construct the optional of T.

Parameters

_copy[in] The optional to copy