Error propagation primitive: value or error status.
The pw::Result<T, StatusType> class template is a union of a StatusType object (pw::Status by default) and an object of type T. Result<T, StatusType> models an object that is either a usable object, or an error status (of type StatusType) explaining why such an object is not present. It is typically the return value of a function which may fail.
To simplify its use in generic code and coroutines, Result is specialized for void.
Result<T, StatusType> can never hold an OK error status; instead, the presence of an object of type T indicates success (status().ok() == true). Use the Result<T, StatusType>::ok() member function to check for success.
Example:
Accessing the object held by a Result<T, StatusType> should be performed via operator* or operator->, after a call to ok() confirms that the Result<T, StatusType> holds an object of type T:
Example:
Using Result<T, StatusType>::value() when no valid value is present will trigger a PW_ASSERT.
Example:
A Result<T*> can be constructed from a null pointer like any other pointer value, and the result will be that ok() returns true and value() returns nullptr. Checking the value of a pointer in a Result<T*> generally requires a bit more care, to ensure both that a value is present and that value is not null:
Example factory implementation returning Result<T>:
Prefer returning StatusType (or Result<void, StatusType> in generic code) instead of Result<StatusType, StatusType> when no additional value is needed. However, Result<StatusType, StatusType> is supported for generic code that wraps functions returning StatusType.
Because the value type and the status type are the same in Result<StatusType, StatusType>, constructing, assigning, or comparing with a StatusType (or StatusType::Code) always operates on the contained value (ok() == true), even if the provided status is not OK. To set an error status on a Result<StatusType, StatusType>, call reset(). To check or compare the status of the Result itself, use ok() or status().
| T | Type of the contained value (or void). |
| StatusType | Status type that represents the error. Defaults to pw::Status. Must be derived from pw::StatusBase and use an enum code. |
Public Types | |
| using | value_type = T |
| using | status_type = StatusType |
Public Member Functions | |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, Status >, int > = 0> | |
| constexpr | Result () noexcept |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr | Result () noexcept |
Constructs an empty Optional<T> with no value (has_value() == false). | |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr | Result (std::nullopt_t) noexcept |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr Result & | operator= (std::nullopt_t) noexcept |
Resets an Optional<T> to an empty state (has_value() == false). | |
| constexpr | Result (const Result &)=default |
| constexpr Result & | operator= (const Result &)=default |
| constexpr | Result (Result &&)=default |
| constexpr Result & | operator= (Result &&)=default |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromResult< T, U, const U &, StatusType, true >, int > = 0> | |
| constexpr | Result (const Result< U, StatusType > &other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromResult< T, U, const U &, StatusType, false >, int > = 0> | |
| constexpr | Result (const Result< U, StatusType > &other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromResult< T, U, U &&, StatusType, true >, int > = 0> | |
| constexpr | Result (Result< U, StatusType > &&other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromResult< T, U, U &&, StatusType, false >, int > = 0> | |
| constexpr | Result (Result< U, StatusType > &&other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanAssignFromResult< T, U, const U &, StatusType >, int > = 0> | |
| constexpr Result & | operator= (const Result< U, StatusType > &other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanAssignFromResult< T, U, U &&, StatusType >, int > = 0> | |
| constexpr Result & | operator= (Result< U, StatusType > &&other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromStdOptional< T, U, const U &, StatusType, true >, int > = 0> | |
| constexpr | Result (const std::optional< U > &other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromStdOptional< T, U, const U &, StatusType, false >, int > = 0> | |
| constexpr | Result (const std::optional< U > &other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromStdOptional< T, U, U &&, StatusType, true >, int > = 0> | |
| constexpr | Result (std::optional< U > &&other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanConvertFromStdOptional< T, U, U &&, StatusType, false >, int > = 0> | |
| constexpr | Result (std::optional< U > &&other) noexcept |
| template<typename U , std::enable_if_t< internal_result::kCanAssignFromStdOptional< T, U, const U &, StatusType >, int > = 0> | |
| constexpr Result & | operator= (const std::optional< U > &other) noexcept |
Assigns an Optional<T> from a std::optional<U>. | |
| template<typename U , std::enable_if_t< internal_result::kCanAssignFromStdOptional< T, U, U &&, StatusType >, int > = 0> | |
| constexpr Result & | operator= (std::optional< U > &&other) noexcept |
Assigns an Optional<T> from a std::optional<U>. | |
| template<typename U = status_type, std::enable_if_t< internal_result::kCanConstructFromStatus< T, U &&, StatusType, true >, int > = 0> | |
| constexpr | Result (U &&v) |
| template<typename U = status_type, std::enable_if_t< internal_result::kCanConstructFromStatus< T, U &&, StatusType, false >, int > = 0> | |
| constexpr | Result (U &&v) |
| template<typename U = status_type, std::enable_if_t< internal_result::kCanAssignFromStatus< T, U &&, StatusType >, int > = 0> | |
| constexpr Result & | operator= (U &&v) |
| template<typename U = std::remove_cv_t<T>, typename = std::enable_if_t< internal_result::kCanAssignFromValue<T, U&&, StatusType>>> | |
| constexpr Result & | operator= (U &&v) noexcept |
| template<typename... Args, std::enable_if_t< std::is_constructible_v< T, Args... >, int > = 0> | |
| constexpr | Result (std::in_place_t, Args &&... args) noexcept |
| template<typename U , typename... Args, std::enable_if_t< std::is_constructible_v< T, std::initializer_list< U > &, Args... >, int > = 0> | |
| constexpr | Result (std::in_place_t, std::initializer_list< U > ilist, Args &&... args) noexcept |
| template<typename U = std::remove_cv_t<T>, std::enable_if_t< internal_result::kCanConstructFromValue< T, U &&, StatusType, true >, int > = 0> | |
| constexpr | Result (U &&u) noexcept |
| template<typename U = std::remove_cv_t<T>, std::enable_if_t< internal_result::kCanConstructFromValue< T, U &&, StatusType, false >, int > = 0> | |
| constexpr | Result (U &&u) noexcept |
| constexpr bool | ok () const noexcept |
| constexpr bool | has_value () const noexcept |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr | operator bool () const noexcept |
| template<typename S = StatusType, typename U = std::remove_cv_t<T>, std::enable_if_t< std::is_same_v< S, HasValue > &&std::is_constructible_v< U, const T & >, int > = 0> | |
| constexpr std::optional< U > | std_optional () const &noexcept |
| template<typename S = StatusType, typename U = std::remove_cv_t<T>, std::enable_if_t< std::is_same_v< S, HasValue > &&std::is_constructible_v< U, T && >, int > = 0> | |
| constexpr std::optional< U > | std_optional () &&noexcept |
| constexpr status_type | status () const noexcept |
| template<typename S = StatusType, std::enable_if_t< std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr void | reset () noexcept |
| template<typename S = StatusType, std::enable_if_t<!std::is_same_v< S, HasValue >, int > = 0> | |
| constexpr void | reset (status_type error_status) |
| template<typename C , typename S = StatusType, std::enable_if_t<!std::is_same_v< S, HasValue > &&std::is_same_v< C, typename S::Code >, int > = 0> | |
| constexpr void | reset (C code) |
| template<typename status_type::Code kCode> | |
| constexpr void | reset () noexcept |
| constexpr const T & | value () const &PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr T & | value () &PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr const T && | value () const &&PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr T && | value () &&PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr const T & | operator* () const &noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr T & | operator* () &noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr const T && | operator* () const &&noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr T && | operator* () &&noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr const T * | operator-> () const noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| constexpr T * | operator-> () noexcept PW_ATTRIBUTE_LIFETIME_BOUND |
| template<typename U = std::remove_cv_t<T>> | |
| constexpr std::remove_cv_t< T > | value_or (U &&default_value) const &noexcept |
| template<typename U = std::remove_cv_t<T>> | |
| constexpr std::remove_cv_t< T > | value_or (U &&default_value) &&noexcept |
| constexpr void | IgnoreError () const noexcept |
| template<typename... Args, std::enable_if_t< std::is_constructible_v< T, Args... >, int > = 0> | |
| constexpr T & | emplace (Args &&... args) noexcept |
| template<typename U , typename... Args, std::enable_if_t< std::is_constructible_v< T, std::initializer_list< U > &, Args... >, int > = 0> | |
| constexpr T & | emplace (std::initializer_list< U > ilist, Args &&... args) noexcept |
| void | swap (Result &other) noexcept |
Swaps the contents of *this and other. | |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, T & >, int > = 0, typename Ret = internal_result::InvokeResultType<Fn, T&>> | |
| constexpr Ret | and_then (Fn &&function) & |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, T && >, int > = 0, typename Ret = internal_result::InvokeResultType<Fn, T&&>> | |
| constexpr Ret | and_then (Fn &&function) && |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, const T & >, int > = 0, typename Ret = internal_result::InvokeResultType<Fn, const T&>> | |
| constexpr Ret | and_then (Fn &&function) const & |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, const T && >, int > = 0, typename Ret = internal_result::InvokeResultType<Fn, const T&&>> | |
| constexpr Ret | and_then (Fn &&function) const && |
| template<typename Fn , typename U = T, typename S = status_type, std::enable_if_t< std::is_copy_constructible_v< U > &&std::is_copy_constructible_v< S > &&internal_result::kIsOrElseInvocable< Fn, const status_type & >, int > = 0> | |
| constexpr Result< T, StatusType > | or_else (Fn &&function) const & |
| template<typename Fn , typename U = T, typename S = status_type, std::enable_if_t< std::is_move_constructible_v< U > &&std::is_move_constructible_v< S > &&internal_result::kIsOrElseInvocable< Fn, status_type && >, int > = 0> | |
| constexpr Result< T, StatusType > | or_else (Fn &&function) && |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, T & >, int > = 0, typename Ret = internal_result::TransformResultType<StatusType, Fn, T&>> | |
| constexpr Result< Ret, StatusType > | transform (Fn &&function) & |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, T && >, int > = 0, typename Ret = internal_result::TransformResultType<StatusType, Fn, T&&>> | |
| constexpr Result< Ret, StatusType > | transform (Fn &&function) && |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, const T & >, int > = 0, typename Ret = internal_result::TransformResultType<StatusType, Fn, const T&>> | |
| constexpr Result< Ret, StatusType > | transform (Fn &&function) const & |
| template<typename Fn , std::enable_if_t< std::is_invocable_v< Fn, const T && >, int > = 0, typename Ret = internal_result::TransformResultType<StatusType, Fn, const T&&>> | |
| constexpr Result< Ret, StatusType > | transform (Fn &&function) const && |
Friends | |
| struct | internal_result::Monadic |
| template<typename U , typename S > | |
| constexpr U && | internal::ConvertToValue (Result< U, S > &result) noexcept |
| template<typename U = T, std::enable_if_t< std::is_move_constructible_v< U > &&std::is_swappable_v< U > &&std::is_move_constructible_v< status_type > &&std::is_swappable_v< status_type >, int > = 0> | |
| void | swap (Result &lhs, Result &rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator== (const Result &lhs, status_type rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator== (status_type lhs, const Result &rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator!= (const Result &lhs, status_type rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator!= (status_type lhs, const Result &rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusCodeComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator== (const Result &lhs, typename status_type::Code rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusCodeComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator== (typename status_type::Code lhs, const Result &rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusCodeComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator!= (const Result &lhs, typename status_type::Code rhs) noexcept |
| template<typename U = T, std::enable_if_t< internal_result::kEnableStatusCodeComparison< U, status_type >, int > = 0> | |
| constexpr bool | operator!= (typename status_type::Code lhs, const Result &rhs) noexcept |
| using pw::Result< T, StatusType >::status_type = StatusType |
The status type used to represent the status of this Result. Defaults to pw::Status.
| using pw::Result< T, StatusType >::value_type = T |
Generic value_type member for use within generic programming. This usage is analogous to that of std::optional::value_type.
|
inlineexplicitconstexprnoexcept |
Constructs a new Result<T> with a pw::Status::Unknown() status.
This constructor is marked explicit to prevent usages in return values (e.g. return {}) under the misconception that Result<std::vector<int>> (for example) will be initialized with an empty vector.
Only enabled when StatusType is pw::Status.
|
inlineconstexprnoexcept |
Constructs an empty Optional<T> from std::nullopt (has_value() == false).
|
constexprdefault |
Result<T, StatusType> is copy constructible if T is copy constructible (and trivially copy constructible if T and StatusType are trivially copy constructible).
|
constexprdefault |
Result<T, StatusType> is move constructible if T is move constructible (and trivially move constructible if T and StatusType are trivially move constructible).
|
inlineconstexprnoexcept |
Constructs a new Result<T, StatusType> from a Result<U, StatusType> when T is constructible from U.
To avoid ambiguity, these constructors are disabled if T is also constructible from Result<U, StatusType>. This constructor is explicit if and only if the corresponding construction of T from U is explicit. (This constructor inherits its explicitness from the underlying constructor.)
|
inlineconstexprnoexcept |
Constructs an Optional<T> from a std::optional<U> when T is constructible from U.
Disabled unless StatusType is HasValue and T is not constructible or convertible from std::optional<U> directly (except when T is bool; see LWG 3836). Explicit if and only if converting U to T is explicit.
|
inlineexplicitconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineexplicitconstexprnoexcept |
|
inlineconstexpr |
Constructs a new Result<T, StatusType> with a non-OK status.
After calling this constructor, this->ok() will be false and calls to value() will trigger a PW_ASSERT.
The constructor takes any type U that is constructible/convertible to status_type. This constructor is explicit if and only if U is not implicitly convertible to status_type.
Disabled when T is StatusType (in which case constructing from a status initializes the contained value; use reset() to set an error status).
!status_type(std::forward<U>(v)).ok(). This requirement is asserted via PW_ASSERT.
|
inlineexplicitconstexprnoexcept |
Constructs the inner value T in-place using the provided args, using the T(args...) constructor.
|
inlineconstexprnoexcept |
Constructs the inner value T in-place using the provided arg, using the T(U) (direct-initialization) constructor.
T can be constructed from a U. Can accept move or copy constructors.This constructor is explicit if U is not convertible to T. To avoid ambiguity, this constructor is disabled if U is a Result<J, StatusType>, where J is convertible to T.
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
Reconstructs the inner value T in-place using the provided args, using the T(args...) constructor.
T.
|
inlineconstexprnoexcept |
Reconstructs the inner value T in-place using the provided args, using the T(args...) constructor.
T.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Ignores any errors. This method does nothing except potentially suppress complaints from any tools that are checking that errors are not dropped.
|
inlineconstexprnoexcept |
Result<T, StatusType> holds a T value. This member function is analogous to Status::ok() and should be used similarly to check the status of return values.Example:
|
inlineexplicitconstexprnoexcept |
Explicit boolean conversion operator for Optional<T>. Returns true if a value is present (has_value() == true).
|
inlineconstexprnoexcept |
PW_ASSERT_ENABLE_DEBUG is enabled (via PW_DASSERT).this->ok() == true, otherwise the behavior is undefined.Use this->ok() to verify that there is a current value within the Result<T, StatusType>. Alternatively, see the value() member function for a similar API that guarantees crashing if there is no current value.
|
inlineconstexprnoexcept |
PW_ASSERT_ENABLE_DEBUG is enabled (via PW_DASSERT).this->ok() == true, otherwise the behavior is undefined.Use this->ok() to verify that there is a current value within the Result<T, StatusType>. Alternatively, see the value() member function for a similar API that guarantees crashing if there is no current value.
|
inlineconstexprnoexcept |
PW_ASSERT_ENABLE_DEBUG is enabled (via PW_DASSERT).this->ok() == true, otherwise the behavior is undefined.Use this->ok() to verify that there is a current value within the Result<T, StatusType>. Alternatively, see the value() member function for a similar API that guarantees crashing if there is no current value.
|
inlineconstexprnoexcept |
PW_ASSERT_ENABLE_DEBUG is enabled (via PW_DASSERT).this->ok() == true, otherwise the behavior is undefined.Use this->ok() to verify that there is a current value within the Result<T, StatusType>. Alternatively, see the value() member function for a similar API that guarantees crashing if there is no current value.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
constexprdefault |
Result<T, StatusType> is copy assignable if T is copy constructible and copy assignable (and trivially copy assignable if T and StatusType are trivially destructible, copy constructible, and copy assignable).
|
inlineconstexprnoexcept |
Assigns a Result<T, StatusType> from a Result<U, StatusType>.
Result<T, StatusType> is constructible and assignable from Result<U, StatusType> and Result<T, StatusType> cannot be directly assigned from Result<U, StatusType>. Result<T, StatusType> and Result<U, StatusType> are OK, assigns U to T directly. Result<T, StatusType> is OK and Result<U, StatusType> contains an error code, destroys the value of Result<T, StatusType> and assigns the error status from Result<U, StatusType>. Result<T, StatusType> contains an error code and Result<U, StatusType> is OK, directly initializes T from U. Result<T, StatusType> and Result<U, StatusType> contain an error code, assigns the status in Result<U, StatusType> to Result<T, StatusType>.
|
constexprdefault |
Result<T, StatusType> is move assignable if T is move constructible and move assignable (and trivially move assignable if T and StatusType are trivially destructible, move constructible, and move assignable).
|
inlineconstexprnoexcept |
Assigns an Optional<T> from a std::optional<U>.
|
inlineconstexpr |
Assigns a non-OK status to this Result<T, StatusType>, destroying any currently held value.
Disabled when T is StatusType (in which case assigning a status updates the contained value; use reset() to set an error status).
!status_type(std::forward<U>(v)).ok(). This requirement is asserted via PW_ASSERT.
|
inlineconstexprnoexcept |
Perfect-forwarding value assignment operator.
If *this contains a T value before the call, the contained value is assigned from std::forward<U>(v). Otherwise, it is directly initialized from std::forward<U>(v).
std::is_constructible_v<T, U> is true. std::is_assignable_v<T&, U> is true. std::is_same_v<Result<T, StatusType>, std::remove_cvref_t<U>> is false. U to T is not ambiguous. If U is Result<V, StatusType> and T is constructible and assignable from both Result<V, StatusType> and V, the assignment is considered bug-prone and ambiguous and thus will fail to compile. For example:
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
Destroys the contained value, if any, and resets an Optional<T> to an empty state (has_value() == false).
|
inlineconstexprnoexcept |
Destroys the contained value, if any, and resets an Optional<T> to an empty state (has_value() == false).
|
inlineconstexpr |
Destroys the contained value, if any, and resets an Optional<T> to an empty state (has_value() == false).
|
inlineconstexpr |
Destroys the contained value, if any, and sets the status. The status must not be OK. To avoid a runtime check, use the reset<kCode>() function template whenever possible.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Converts an Optional<T> (Result<T, HasValue>) to a std::optional<std::remove_cv_t<T>>.
This is a named method rather than a conversion operator because std::optional's forwarding constructor optional(U&&) is an exact match in direct-initialization (e.g. std::optional<bool> s(opt)) and would construct the bool from explicit operator bool(), yielding has_value() instead of the held value.
|
inlineconstexprnoexcept |
Converts an Optional<T> (Result<T, HasValue>) to a std::optional<std::remove_cv_t<T>>.
This is a named method rather than a conversion operator because std::optional's forwarding constructor optional(U&&) is an exact match in direct-initialization (e.g. std::optional<bool> s(opt)) and would construct the bool from explicit operator bool(), yielding has_value() instead of the held value.
|
inlineconstexpr |
Result<U, StatusType> containing the result of invoking function on the held value if *this contains a value. Otherwise, returns a Result<U, StatusType> with the same status as *this.For Optional<T> (StatusType is HasValue), function must return a non-reference, non-void, non-array object type other than std::in_place_t or std::nullopt_t (matching std::optional::transform).
|
inlineconstexpr |
Result<U, StatusType> containing the result of invoking function on the held value if *this contains a value. Otherwise, returns a Result<U, StatusType> with the same status as *this.For Optional<T> (StatusType is HasValue), function must return a non-reference, non-void, non-array object type other than std::in_place_t or std::nullopt_t (matching std::optional::transform).
|
inlineconstexpr |
Result<U, StatusType> containing the result of invoking function on the held value if *this contains a value. Otherwise, returns a Result<U, StatusType> with the same status as *this.For Optional<T> (StatusType is HasValue), function must return a non-reference, non-void, non-array object type other than std::in_place_t or std::nullopt_t (matching std::optional::transform).
|
inlineconstexpr |
Result<U, StatusType> containing the result of invoking function on the held value if *this contains a value. Otherwise, returns a Result<U, StatusType> with the same status as *this.For Optional<T> (StatusType is HasValue), function must return a non-reference, non-void, non-array object type other than std::in_place_t or std::nullopt_t (matching std::optional::transform).
|
inlineconstexpr |
this->ok(). Otherwise, terminates the process via PW_ASSERT.If you have already checked the status using this->ok(), you probably want to use operator*() or operator->() to access the value instead of value.
For value types that are cheap to copy, prefer simple code:
Otherwise, if the value type is expensive to copy, but can be left in the Result<T, StatusType>, simply assign to a reference:
Otherwise, if the value type supports an efficient move, it can be used as follows:
The std::move on result instead of on the whole expression enables warnings about possible uses of the result object after the move.
|
inlineconstexpr |
this->ok(). Otherwise, terminates the process via PW_ASSERT.If you have already checked the status using this->ok(), you probably want to use operator*() or operator->() to access the value instead of value.
For value types that are cheap to copy, prefer simple code:
Otherwise, if the value type is expensive to copy, but can be left in the Result<T, StatusType>, simply assign to a reference:
Otherwise, if the value type supports an efficient move, it can be used as follows:
The std::move on result instead of on the whole expression enables warnings about possible uses of the result object after the move.
|
inlineconstexpr |
this->ok(). Otherwise, terminates the process via PW_ASSERT.If you have already checked the status using this->ok(), you probably want to use operator*() or operator->() to access the value instead of value.
For value types that are cheap to copy, prefer simple code:
Otherwise, if the value type is expensive to copy, but can be left in the Result<T, StatusType>, simply assign to a reference:
Otherwise, if the value type supports an efficient move, it can be used as follows:
The std::move on result instead of on the whole expression enables warnings about possible uses of the result object after the move.
|
inlineconstexpr |
this->ok(). Otherwise, terminates the process via PW_ASSERT.If you have already checked the status using this->ok(), you probably want to use operator*() or operator->() to access the value instead of value.
For value types that are cheap to copy, prefer simple code:
Otherwise, if the value type is expensive to copy, but can be left in the Result<T, StatusType>, simply assign to a reference:
Otherwise, if the value type supports an efficient move, it can be used as follows:
The std::move on result instead of on the whole expression enables warnings about possible uses of the result object after the move.
|
inlineconstexprnoexcept |
this->ok() == true. Otherwise constructs a value using the provided default_value.Unlike value, this function returns by value, copying the current value if necessary. If the value type supports an efficient move, it can be used as follows:
Unlike with value, calling std::move() on the result of value_or will still trigger a copy.
|
inlineconstexprnoexcept |
this->ok() == true. Otherwise constructs a value using the provided default_value.Unlike value, this function returns by value, copying the current value if necessary. If the value type supports an efficient move, it can be used as follows:
Unlike with value, calling std::move() on the result of value_or will still trigger a copy.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
Compares the status of a Result<T, StatusType> with a status code.
Disabled when T is StatusType or StatusType::Code (in which case operator== compares against the held value).
|
friend |
|
friend |
|
friend |
Swaps two Result<T, StatusType> objects via ADL. Only participates in overload resolution if T is move-constructible and swappable.