|
| | Result ()=delete |
| | Default construction is disallowed.
|
| | Result (const Result< T, E > &other)=delete |
| | Copy construction is disallowed.
|
| | Result (Result< T, E > &&other) noexcept |
| | Move construction is allowed.
|
template<typename T2>
requires (!std::same_as<T, E> && !std::constructible_from<T, E> && !std::convertible_to<T, E> && !std::constructible_from<E, T> && !std::convertible_to<E, T> && !(std::convertible_to<T2, T> && std::convertible_to<T2, E>)) |
| | Result (T2 value) noexcept |
| | Constructor from arbitrary value This constructor allows construction from any value.
|
template<typename C>
requires std::invocable<C, T&&> |
| auto | and_then (C &&callable) && |
| | Bind a function to this result monadically.
|
template<typename C>
requires std::invocable<C, const T&> |
| auto | and_then (C &&callable) const & |
| | Bind a function to this result monadically.
|
| E | error () &&noexcept |
| | Returns the error by-value.
|
| E & | error () &noexcept |
| | Returns a reference to the error stored in the result.
|
| const E & | error () const &noexcept |
| | Returns a reference to the error stored in the result.
|
| bool | ok () const noexcept |
| | Checks whether this result contains a valid value, and no error.
|
| const T & | operator* () const noexcept |
| | Returns a reference into the variant to the valid value.
|
| T & | operator* () noexcept |
| | Returns a reference into the variant to the valid value.
|
| const T * | operator-> () const noexcept |
| | Allows to access members of the stored object with res->foo similar to std::optional.
|
| T * | operator-> () noexcept |
| | Allows to access members of the stored object with res->foo similar to std::optional.
|
| Result< T, E > & | operator= (const Result< T, E > &other)=delete |
| | Assignment is disallowed.
|
| Result< T, E > & | operator= (Result< T, E > &&other) noexcept |
| | Move assignment is allowed.
|
template<typename T2>
requires (!std::same_as<T, E> && !std::constructible_from<T, E> && !std::convertible_to<T, E> && !std::constructible_from<E, T> && !std::convertible_to<E, T> && !(std::convertible_to<T2, T> && std::convertible_to<T2, E>)) |
| Result< T, E > & | operator= (T2 value) noexcept |
| | Assignment operator from arbitrary value This operator allows construction from any value.
|
template<typename C>
requires std::invocable<C, T&&> |
| auto | transform (C &&callable) && |
| | Transforms the value contained in this result.
|
template<typename C>
requires std::invocable<C, const T&> |
| auto | transform (C &&callable) const & |
| | Transforms the value contained in this result.
|
| T & | value () & |
| | Retrieves the valid value from the result object.
|
| const T & | value () const & |
| | Retrieves the valid value from the result object.
|
template<typename U>
requires (std::same_as<std::decay_t<U>, T>) |
| std::conditional_t< std::is_reference_v< U >, const T &, T > | value_or (U &&v) const & |
| | Retrieves the valid value from the result object, or returns a default value if no valid value exists.
|
template<typename T, typename E = std::error_code>
class Acts::Result< T, E >
Class which encapsulates either a valid result, or an error.
- Template Parameters
-
| T | The valid result value |
| E | The error, defaults to std::error_code |
template<typename T, typename E = std::error_code>
template<typename T2>
requires (!std::same_as<T, E> && !std::constructible_from<T, E> && !std::convertible_to<T, E> && !std::constructible_from<E, T> && !std::convertible_to<E, T> && !(std::convertible_to<T2, T> && std::convertible_to<T2, E>))
Constructor from arbitrary value This constructor allows construction from any value.
This constructor is only enabled if T and E are unambiguous, meaning they cannot be implicitly converted and there is T cannot be constructed from E and vice-versa. This means that when this is invoked, the value can be propagated to the underlying variant, and the assignment will be correct, and error will be an error, and a value will be a value.
- Note
- If T and E are ambiguous, use the success and failure static factory methods.
- Template Parameters
-
| T2 | Type of the potential assignment |
- Parameters
-
| value | The potential value, could be an actual valid value or an error. |
template<typename T, typename E = std::error_code>
template<typename C>
requires std::invocable<C, T&&>
Bind a function to this result monadically.
This function takes a function f and, if this result contains a valid value x, returns f(x). If the type of x is T, then f is expected to accept type T and return Result<U>. In this case, transform would return the unhelpful type Result<Result<U>>, so and_then strips away the outer layer to return Result<U>. If the value is invalid, this returns an invalid value in Result<U>.
- Parameters
-
| [in] | callable | The transformation function to apply. |
- Note
- This is the rvalue version.
-
This functions is >>= on the functor in A of Result<A, E>.
- Returns
- The modified valid value if exists, or an error otherwise.
template<typename T, typename E = std::error_code>
template<typename C>
requires std::invocable<C, const T&>
| auto Acts::Result< T, E >::and_then |
( |
C && | callable | ) |
const & |
Bind a function to this result monadically.
This function takes a function f and, if this result contains a valid value x, returns f(x). If the type of x is T, then f is expected to accept type T and return Result<U>. In this case, transform would return the unhelpful type Result<Result<U>>, so and_then strips away the outer layer to return Result<U>. If the value is invalid, this returns an invalid value in Result<U>.
- Parameters
-
| [in] | callable | The transformation function to apply. |
- Note
- This is the lvalue version.
-
This functions is >>= on the functor in A of Result<A, E>.
- Returns
- The modified valid value if exists, or an error otherwise.
template<typename T, typename E = std::error_code>
template<typename T2>
requires (!std::same_as<T, E> && !std::constructible_from<T, E> && !std::convertible_to<T, E> && !std::constructible_from<E, T> && !std::convertible_to<E, T> && !(std::convertible_to<T2, T> && std::convertible_to<T2, E>))
| Result< T, E > & Acts::Result< T, E >::operator= |
( |
T2 | value | ) |
|
|
noexcept |
Assignment operator from arbitrary value This operator allows construction from any value.
The same rules as for the Result(T2 value) constructor apply.
- Template Parameters
-
| T2 | Type of the potential assignment |
- Parameters
-
| value | The potential value, could be an actual valid value or an error. |
- Returns
- The assigned instance