Open 3D Engine AzCore API Reference
24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
|
#include <Outcome.h>
Public Types | |
using | ValueType = typename BaseType::value_type |
using | ErrorType = typename BaseType::error_type |
Public Member Functions | |
AZ_FORCE_INLINE | Outcome () |
AZ_FORCE_INLINE | Outcome (const SuccessType &success) |
Constructs successful outcome, where value is copy-constructed. | |
AZ_FORCE_INLINE | Outcome (SuccessType &&success) |
Constructs successful outcome, where value is move-constructed. | |
AZ_FORCE_INLINE | Outcome (const FailureType &failure) |
Constructs failed outcome, where error is copy-constructed. | |
AZ_FORCE_INLINE | Outcome (FailureType &&failure) |
Constructs failed outcome, where error is move-constructed. | |
AZ_FORCE_INLINE | Outcome (const Outcome &other) |
Copy constructor. | |
AZ_FORCE_INLINE | Outcome (Outcome &&other) |
Move constructor. | |
AZ_FORCE_INLINE Outcome & | operator= (const Outcome &other) |
Copy-assignment from other outcome. | |
AZ_FORCE_INLINE Outcome & | operator= (const SuccessType &success) |
Copy value into outcome. Outcome is now successful. | |
AZ_FORCE_INLINE Outcome & | operator= (const FailureType &failure) |
Copy error into outcome. Outcome is now failed. | |
AZ_FORCE_INLINE Outcome & | operator= (Outcome &&other) |
Move-assignment from other outcome. | |
AZ_FORCE_INLINE Outcome & | operator= (SuccessType &&success) |
Move value into outcome. Outcome is now successful. | |
AZ_FORCE_INLINE Outcome & | operator= (FailureType &&failure) |
Move error into outcome. Outcome is now failed. | |
AZ_FORCE_INLINE bool | IsSuccess () const |
Returns whether outcome was a success, containing a valid value. | |
AZ_FORCE_INLINE | operator bool () const |
template<class Value_Type = ValueType, class = AZStd::enable_if_t<!AZStd::is_void_v<Value_Type>>> | |
AZ_FORCE_INLINE Value_Type & | GetValue () |
template<class Value_Type = ValueType, class = AZStd::enable_if_t<!AZStd::is_void_v<Value_Type>>> | |
AZ_FORCE_INLINE const Value_Type & | GetValue () const |
template<class Value_Type = ValueType, class = AZStd::enable_if_t<!AZStd::is_void_v<Value_Type>>> | |
AZ_FORCE_INLINE Value_Type && | TakeValue () |
template<class U , class Value_Type = ValueType, class = AZStd::enable_if_t<!AZStd::is_void_v<Value_Type>>> | |
AZ_FORCE_INLINE Value_Type | GetValueOr (U &&defaultValue) const |
template<class Error_Type = ErrorType, class = AZStd::enable_if_t<!AZStd::is_void_v<Error_Type>>> | |
AZ_FORCE_INLINE Error_Type & | GetError () |
template<class Error_Type = ErrorType, class = AZStd::enable_if_t<!AZStd::is_void_v<Error_Type>>> | |
AZ_FORCE_INLINE const Error_Type & | GetError () const |
template<class Error_Type = ErrorType, class = AZStd::enable_if_t<!AZStd::is_void_v<Error_Type>>> | |
AZ_FORCE_INLINE Error_Type && | TakeError () |
Outcome is intended for use as the return type of a function that may fail. A successful outcome contains the desired value, while a failed outcome contains an error. Either the value exists or the error exists, the other type is never even constructed.
Check the outcome's IsSuccess() before accessing its contents via GetValue() or GetError().
Outcome performs no dynamic allocations and holds the value or error type within its own memory footprint.
ValueT | The value type contained in a successful outcome. void is an acceptable value type. |
ErrorT | The error type contained in a failed outcome. void is an acceptable error type. |
An outcome is constructed with the aid of helper functions Success<ValueT>(ValueT&& value) and Failure<ErrorT>(ErrorT&& error):
Example Usage:
AZ_FORCE_INLINE AZ::Outcome< ValueT, ErrorT >::Outcome |
AZ_FORCE_INLINE Error_Type & AZ::Outcome< ValueT, ErrorT >::GetError |
Returns error for failed outcome. Behavior is undefined if outcome was a success.
AZ_FORCE_INLINE Value_Type & AZ::Outcome< ValueT, ErrorT >::GetValue |
Returns value from successful outcome. Behavior is undefined if outcome was a failure.
AZ_FORCE_INLINE Value_Type AZ::Outcome< ValueT, ErrorT >::GetValueOr | ( | U && | defaultValue | ) | const |
Returns value from successful outcome. defaultValue is returned if outcome was a failure.
AZ_FORCE_INLINE Error_Type && AZ::Outcome< ValueT, ErrorT >::TakeError |
Returns error for failed outcome as rvalue reference. Note that outcome's error may have its contents stolen, rendering it invalid for further access. Behavior is undefined if outcome was a success.
AZ_FORCE_INLINE Value_Type && AZ::Outcome< ValueT, ErrorT >::TakeValue |
Returns value from successful outcome as rvalue reference. Note that outcome's value may have its contents stolen, rendering it invalid for further access. Behavior is undefined if outcome was a failure.