template<typename... T>
result class
The result class can carry the three kinds of results an asynchronous operation possibly can return, it's implemented in a variant like data structure which is also specialized to hold arbitrary arguments.
Contents
The result can be in the following three states:
- no result: If the operation didn't finish
- a value: If the operation finished successfully
- an exception: If the operation finished with an exception or was cancelled.
The interface of the result object is similar to the one proposed in the std::expected
proposal:
result<std::string> result = make_result("Hello World!"); bool(result); result.is_value(); result.is_exception(); *result; // Same as result.get_value() result.get_value(); result.get_exception();
Public static functions
- static auto from(T... values) -> result
- Creates a present result from the given values.
-
static auto from(exception_
arg_ t, exception_ t exception) -> result - Creates a present result from the given exception.
- static auto empty() -> result
- Creates an empty result.
Constructors, destructors, conversion operators
- operator bool() const explicit constexpr noexcept
- Returns true if the state of the result holds the result.
Public functions
- void set_empty()
- Set the result to an empty state.
- void set_value(T... values)
- Set the result to a the state which holds the corresponding value.
-
void set_exception(exception_
t exception) - Set the result into a state which holds the corresponding exception.
- void set_canceled()
- Set the result into a state which holds the cancellation token.
- auto is_empty() const -> bool noexcept
- Returns true if the state of the result is empty.
- auto is_value() const -> bool noexcept
- Returns true if the state of the result holds the result.
- auto is_exception() const -> bool noexcept
- Returns true if the state of the result holds a present exception.
- auto get_value() &noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
- auto get_value() const &noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
- auto get_value() &&noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
- auto operator*() &noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
- auto operator*() const &noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
- auto operator*() &&noexcept -> decltype(auto)
- Returns the values of the result, if the result doesn't hold the value the behaviour is undefined but will assert in debug mode.
-
auto get_exception() &noexcept -> exception_
t& - Returns the exception of the result, if the result doesn't hold an exception the behaviour is undefined but will assert in debug mode.
-
auto get_exception() const &noexcept -> exception_
t const & - Returns the exception of the result, if the result doesn't hold an exception the behaviour is undefined but will assert in debug mode.
-
auto get_exception() &&noexcept -> exception_
t&& - Returns the exception of the result, if the result doesn't hold an exception the behaviour is undefined but will assert in debug mode.