xentara-utils v2.0.4
The Xentara Utility Library
|
deprecated A value that may be replaced by an error code More...
#include <xentara/utils/eh/Failable.hpp>
Public Member Functions | |
template<typename RhsValue > requires std::equality_comparable_with<Value, detail::IfNotFailable<RhsValue>> && (!std::is_same_v<std::remove_cvref_t<RhsValue>, std::error_code>) && (!std::is_error_code_enum_v<RhsValue>) | |
auto | operator== (const RhsValue &value) -> bool |
Comparison operator for a valid value. | |
auto | operator== (const std::error_code &errorCode) -> bool |
Comparison operator for an error code. | |
template<typename Enum > requires std::is_error_code_enum_v<Enum> | |
auto | operator== (Enum errorEnum) noexcept -> Failable & |
Comparison operator for an error enum. | |
Constructing valid values | |
Failable () noexcept(std::is_nothrow_constructible_v< Value >) | |
Default Constructor. Constructs an object containing a default constructed value. | |
template<typename Initializer > requires std::is_constructible_v<Value, Initializer &&> && (!std::is_same_v<std::remove_cvref_t<Initializer>, std::in_place_t>) && (!std::is_same_v<std::remove_cvref_t<Initializer>, Failable<Value>>) && (!std::is_same_v<std::remove_cvref_t<Initializer>, std::error_code>) && (!std::is_error_code_enum_v<Initializer>) | |
Failable (Initializer &&initializer) noexcept(std::is_nothrow_constructible_v< Value, Initializer && >) | |
Constructor that constructs a valid value from an initializer. | |
template<typename Argument1 , typename Argument2 , typename... MoreArguments> requires std::is_constructible_v<Value, Argument1 &&, Argument2 &&, MoreArguments &&...> && (!std::is_same_v<std::remove_cvref_t<Argument1>, std::in_place_t>) && (!std::is_constructible_v<std::error_code, Argument1 &&, Argument2 &&, MoreArguments &&...>) | |
Failable (Argument1 &&argument1, Argument2 &&argument2, MoreArguments &&... moreArguments) noexcept(std::is_nothrow_constructible_v< Value, Argument1 &&, Argument2 &&, MoreArguments &&... >) | |
Constructor that constructs a valid value from two or more arguments. | |
template<typename... Arguments> requires std::is_constructible_v<Value, Arguments...> | |
Failable (std::in_place_t, Arguments &&... arguments) noexcept(std::is_nothrow_constructible_v< Value, Arguments &&... >) | |
In-place constructor. | |
Constructing error objects | |
Failable (const std::error_code &errorCode) noexcept | |
Constructor for an error code. | |
Failable (int errorValue, const std::error_category &category) noexcept | |
Constructor for an error value. | |
template<typename Enum > requires std::is_error_code_enum_v<Enum> | |
Failable (Enum errorEnum) noexcept | |
Constructor for an error enum. | |
Assigning valid values | |
template<typename NewValue > requires std::is_assignable_v<Value, NewValue &&> && std::is_constructible_v<Value, NewValue &&> && (!std::is_same_v<std::remove_cvref_t<NewValue>, Failable<Value>>) && (!std::is_same_v<std::remove_cvref_t<NewValue>, std::error_code>) && (!std::is_error_code_enum_v<NewValue>) | |
auto | operator= (NewValue &&newValue) noexcept(std::is_nothrow_assignable_v< Value, NewValue && > &&std::is_nothrow_constructible_v< Value, NewValue && >) -> Failable & |
Assignment operator for a valid value. | |
Assigning errors | |
auto | operator= (const std::error_code &errorCode) noexcept -> Failable & |
Assignment operator for an error code. | |
auto | assign (int errorValue, const std::error_category &category) noexcept -> Failable & |
Assigns an error value from within a certain error category. | |
template<typename Enum > requires std::is_error_code_enum_v<Enum> | |
auto | operator= (Enum errorEnum) noexcept -> Failable & |
Assignment operator for an error enum. | |
Copying, Moving, and Assigning other [Failable]s | |
Failable (const Failable &)=default | |
Copy constructor. | |
Failable (Failable &&)=default | |
Move constructor. | |
template<typename RelatedValue > requires std::is_constructible_v<Value, const RelatedValue &> && (!std::is_same_v<RelatedValue, Value>) | |
Failable (const Failable< RelatedValue > &relatedValue) noexcept(std::is_nothrow_constructible_v< Value, const RelatedValue & >) | |
Copy constructor for related Failable. | |
template<typename RelatedValue > requires std::is_constructible_v<Value, RelatedValue &&> && (!std::is_same_v<RelatedValue, Value>) | |
Failable (Failable< RelatedValue > &&relatedValue) noexcept(std::is_nothrow_constructible_v< Value, RelatedValue && >) | |
Move constructor for related Failable. | |
auto | operator= (const Failable &) -> Failable &=default |
Assignment operator. | |
auto | operator= (Failable &&) -> Failable &=default |
Move assignment operator. | |
template<typename RelatedValue > requires std::is_assignable_v<Value, const RelatedValue &> && std::is_constructible_v<Value, const RelatedValue &> && (!std::is_same_v<RelatedValue, Value>) | |
auto | operator= (const Failable< RelatedValue > &relatedValue) noexcept(std::is_nothrow_constructible_v< Value, const RelatedValue & >) -> Failable & |
Assignment operator for related value. | |
template<typename RelatedValue > requires std::is_assignable_v<Value, RelatedValue &&> && std::is_constructible_v<Value, RelatedValue &&> && (!std::is_same_v<RelatedValue, Value>) | |
auto | operator= (Failable< RelatedValue > &&relatedValue) noexcept(std::is_nothrow_assignable_v< Value, RelatedValue && > &&std::is_nothrow_constructible_v< Value, RelatedValue && >) -> Failable & |
Move assignment operator for related value. | |
Accessing the value | |
operator bool () const noexcept | |
Determines if the object contains a valid value. | |
auto | operator* () noexcept -> Value & |
Gets the value without checking. | |
auto | operator* () const noexcept -> const Value & |
Gets the value without checking. | |
auto | operator-> () noexcept -> std::add_pointer_t< Value > |
Accesses a member of the contained value without checking. | |
auto | operator-> () const noexcept -> std::add_pointer_t< const Value > |
Accesses a member of the contained value without checking. | |
auto | hasValue () const noexcept -> bool |
Determines if the object contains a valid value. | |
auto | value () noexcept -> std::add_pointer_t< Value > |
Gets the value, if there is one. | |
auto | value () const noexcept -> std::add_pointer_t< const Value > |
Gets the value, if there is one. | |
auto | valueOr (const Value &fallback) const &noexcept(std::is_nothrow_copy_constructible_v< Value >) -> Value |
Gets the value or a fallback value. | |
auto | valueOr (Value &&fallback) const &noexcept(std::is_nothrow_copy_constructible_v< Value > &&std::is_nothrow_move_constructible_v< Value >) -> Value |
Gets the value or a fallback value. | |
auto | valueOr (const Value &fallback) &&noexcept(std::is_nothrow_copy_constructible_v< Value > &&std::is_nothrow_move_constructible_v< Value >) -> Value |
Gets the value or a fallback value. | |
auto | valueOr (Value &&fallback) &&noexcept(std::is_nothrow_move_constructible_v< Value >) -> Value |
Gets the value or a fallback value. | |
auto | valueOr (std::reference_wrapper< const Value > fallback) const noexcept -> const Value & |
Gets a reference to the value or to a fallback value. | |
auto | valueOr (std::reference_wrapper< Value > fallback) noexcept -> Value & |
Gets a mutable reference to the value or to a fallback value. | |
template<std::invocable<> Fallback> | |
auto | valueOr (Fallback &&fallback) const &noexcept(std::is_nothrow_invocable_r_v< Value, Fallback && >) -> Value |
Gets the value or generates a fallback value. | |
template<std::invocable<> Fallback> | |
auto | valueOr (Fallback &&fallback) &&noexcept(std::is_nothrow_invocable_r_v< Value, Fallback && >) -> Value |
Gets the value or generates a fallback value. | |
template<std::invocable<> Fallback> requires std::is_reference_v<std::invoke_result_t<Fallback &&>> && std::convertible_to<std::invoke_result_t<Fallback &&>, const Value&> | |
auto | valueOr (Fallback &&fallback) const -> const Value & |
Gets the value or generates a fallback value. | |
template<std::invocable<> Fallback> requires std::is_reference_v<std::invoke_result_t<Fallback &&>> && std::convertible_to<std::invoke_result_t<Fallback &&>, Value&> | |
auto | valueOr (Fallback &&fallback) -> Value & |
Gets the value or generates a reference to a fallback value. | |
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments> | |
auto | valueOrThrow (ExceptionArguments &&... exceptionArguments) const -> const Value & |
Gets the value, or throws the error. | |
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments> | |
auto | valueOrThrow (ExceptionArguments &&... exceptionArguments) -> Value & |
Gets the value, or throws the error. | |
Accessing the error | |
auto | error () const noexcept -> std::error_code |
Gets the error, if there is one. | |
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments> | |
auto | throwError (ExceptionArguments &&... exceptionArguments) const -> void |
Throws the error if the object contains an error instead of a value. | |
Conversion to std::optional | |
operator std::optional< Value > () const & | |
Returns the value as an optional. | |
operator std::optional< Value > () && | |
Returns the value as an optional. | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename LhsValue , typename RhsValue > | |
auto | operator== (const Failable< LhsValue > &lhs, const Failable< RhsValue > &rhs) -> bool |
Comparison operator for two failables. | |
template<typename RelatedValue , typename Value > | |
auto | failableCast (const Failable< Value > &failable) noexcept(std::is_nothrow_constructible_v< RelatedValue, const Value & >) -> Failable< RelatedValue > |
Explicitly casts a failable to a related type. | |
template<typename RelatedValue , typename Value > | |
auto | failableCast (Failable< Value > &&failable) noexcept(std::is_nothrow_constructible_v< RelatedValue, Value && >) -> Failable< RelatedValue > |
Explicitly casts a failable to a related type. | |
deprecated A value that may be replaced by an error code
Value | The type of value that the object should contain |
|
noexcept |
Default Constructor. Constructs an object containing a default constructed value.
|
noexcept |
Constructor that constructs a valid value from an initializer.
initializer | The object to initialize the value with. |
|
noexcept |
Constructor that constructs a valid value from two or more arguments.
Similarly, if the first argument is convertible to an integer, and the second argument is a reference to an std::error_category, the error constructor will be called instead. In that case, you need prefix the parameters with std::in_place.
argument1 | The first argument to pass to the value's constructor. |
argument2 | The first argument to pass to the value's constructor. |
moreArguments | The remaining arguments to pass to the value's constructor, if any. |
|
noexcept |
In-place constructor.
This constructor constructs a valid object from a list of arguments.
arguments | The arguments to pass to the value's constructor. |
|
noexcept |
Constructor for an error code.
This constructor constructs an invalid object containing the specified error code.
errorCode | The desired error code. |
|
noexcept |
Constructor for an error value.
This constructor constructs an invalid object containing the specified error value and category.
errorValue | The desired error value. |
category | The relevant error category. |
|
noexcept |
Constructor for an error enum.
This constructor constructs an invalid object containing the error code corresponding to the specified error enum.
errorEnum | The desired error enum. |
|
default |
Copy constructor.
|
default |
Move constructor.
|
noexcept |
|
noexcept |
|
noexcept |
Assigns an error value from within a certain error category.
This constructor constructs an invalid object containing the specified error value and category.
errorValue | The desired error value. |
category | The relevant error category. |
|
noexcept |
Gets the error, if there is one.
|
noexcept |
Determines if the object contains a valid value.
|
explicitnoexcept |
Determines if the object contains a valid value.
xentara::utils::eh::deprecated::Failable< Value >::operator std::optional< Value > | ( | ) | && |
Returns the value as an optional.
xentara::utils::eh::deprecated::Failable< Value >::operator std::optional< Value > | ( | ) | const & |
Returns the value as an optional.
|
noexcept |
Gets the value without checking.
|
noexcept |
Gets the value without checking.
|
noexcept |
Accesses a member of the contained value without checking.
|
noexcept |
Accesses a member of the contained value without checking.
|
default |
Assignment operator.
|
noexcept |
Assignment operator for related value.
Copies the value or error from a related convertible value
|
noexcept |
Assignment operator for an error code.
Turns the object into an invalid object containing the specified error code.
errorCode | The desired error code. |
|
noexcept |
Assignment operator for an error enum.
Turns the object into an invalid object containing the error code corresponding to the specified error enum.
errorEnum | The desired error enum. |
|
default |
Move assignment operator.
|
noexcept |
Move assignment operator for related value.
Moves the value or error from a related convertible value
|
noexcept |
Assignment operator for a valid value.
Turns the object into a valid value, if it wasn't one already.
newValue | The value to assign. |
auto xentara::utils::eh::deprecated::Failable< Value >::operator== | ( | const RhsValue & | value | ) | -> bool |
Comparison operator for a valid value.
This operator compares the failable to a value. If the object contains an error instead of a valid value, the comparison will always fail, and 'false' is returned.
value | The value to compare with |
auto xentara::utils::eh::deprecated::Failable< Value >::operator== | ( | const std::error_code & | errorCode | ) | -> bool |
Comparison operator for an error code.
This operator compares the failable to an error code. If the object contains a valid value instead of an error, the error code will be compared to std::error_code().
errorCode | The error code to compare with |
|
noexcept |
Comparison operator for an error enum.
This operator compares the failable to an error enum. If the object contains a valid value instead of an error, the result depends on the type of error enum:
errorEnum | The error enum to compare with |
auto xentara::utils::eh::deprecated::Failable< Value >::throwError | ( | ExceptionArguments &&... | exceptionArguments | ) | const -> void |
Throws the error if the object contains an error instead of a value.
Exception | The type of exception to throw. |
exceptionArguments | Additional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes. |
Exception | The object contained an error |
|
noexcept |
Gets the value, if there is one.
|
noexcept |
Gets the value, if there is one.
|
noexcept |
Gets the value or a fallback value.
fallback | The value to return if the object contains an error instead of a value |
|
noexcept |
Gets the value or a fallback value.
fallback | The value to return if the object contains an error instead of a value |
|
noexcept |
Gets the value or generates a fallback value.
fallback | A callable used to generate the return value if the object contains an error instead of a value |
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr | ( | Fallback && | fallback | ) | -> Value & |
Gets the value or generates a reference to a fallback value.
fallback | A callable used to get a reference to the return value if the object contains an error instead of a value |
|
noexcept |
Gets the value or generates a fallback value.
fallback | A callable used to generate the return value if the object contains an error instead of a value |
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr | ( | Fallback && | fallback | ) | const -> const Value & |
Gets the value or generates a fallback value.
fallback | A callable used to get a reference to the return value if the object contains an error instead of a value |
|
noexcept |
Gets a reference to the value or to a fallback value.
fallback | The value to return if the object contains an error instead of a value |
|
noexcept |
Gets a mutable reference to the value or to a fallback value.
fallback | The value to return if the object contains an error instead of a value |
|
noexcept |
Gets the value or a fallback value.
fallback | The value to return if the object contains an error instead of a value |
|
noexcept |
Gets the value or a fallback value.
fallback | The value to return if the object contains an error instead of a value |
auto xentara::utils::eh::deprecated::Failable< Value >::valueOrThrow | ( | ExceptionArguments &&... | exceptionArguments | ) | -> Value & |
Gets the value, or throws the error.
Exception | The type of exception to throw. |
exceptionArguments | Additional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes. |
Exception | the object contained an error |
auto xentara::utils::eh::deprecated::Failable< Value >::valueOrThrow | ( | ExceptionArguments &&... | exceptionArguments | ) | const -> const Value & |
Gets the value, or throws the error.
Exception | The type of exception to throw. |
exceptionArguments | Additional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes. |
Exception | the object contained an error |
|
related |
Explicitly casts a failable to a related type.
This explicit cast function casts the failable to a Failable with a related type. It is equivalent to the conversion constructor, but does not trigger any compiler warnings on narrowing conversions.
|
related |
Explicitly casts a failable to a related type.
This explicit cast function casts the failable to a Failable with a related type. It is equivalent to the conversion constructor, but does not trigger any compiler warnings on narrowing conversions.