xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::eh::deprecated::Failable< Value > Class Template Reference

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.
 

Detailed Description

template<typename Value>
class xentara::utils::eh::deprecated::Failable< Value >

deprecated A value that may be replaced by an error code

Template Parameters
ValueThe type of value that the object should contain
Deprecated:
This class has been deprecated in favour of xentara::utils::eh::expected

Constructor & Destructor Documentation

◆ Failable() [1/11]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::Failable ( )
noexcept

Default Constructor. Constructs an object containing a default constructed value.

◆ Failable() [2/11]

template<typename 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>)
xentara::utils::eh::deprecated::Failable< Value >::Failable ( Initializer &&  initializer)
noexcept

Constructor that constructs a valid value from an initializer.

Note
You cannot use this constructor to initialize the value with an object of type std::in_place_t, std::error_code, or with an error code enum for which std::is_error_code_enum_v is true. Use the in place constructor instead.
Parameters
initializerThe object to initialize the value with.

◆ Failable() [3/11]

template<typename Value >
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 &&...>)
xentara::utils::eh::deprecated::Failable< Value >::Failable ( Argument1 &&  argument1,
Argument2 &&  argument2,
MoreArguments &&...  moreArguments 
)
noexcept

Constructor that constructs a valid value from two or more arguments.

Note
If the first argument is of type std::in_place_t, the in place constructor will be called instead. If you need to initialize an object with an argument list that start with std::in_place, you must specify std::in_place twice.

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.

Parameters
argument1The first argument to pass to the value's constructor.
argument2The first argument to pass to the value's constructor.
moreArgumentsThe remaining arguments to pass to the value's constructor, if any.

◆ Failable() [4/11]

template<typename Value >
template<typename... Arguments>
requires std::is_constructible_v<Value, Arguments...>
xentara::utils::eh::deprecated::Failable< Value >::Failable ( std::in_place_t  ,
Arguments &&...  arguments 
)
noexcept

In-place constructor.

This constructor constructs a valid object from a list of arguments.

Parameters
argumentsThe arguments to pass to the value's constructor.

◆ Failable() [5/11]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::Failable ( const std::error_code errorCode)
noexcept

Constructor for an error code.

This constructor constructs an invalid object containing the specified error code.

Parameters
errorCodeThe desired error code.

◆ Failable() [6/11]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::Failable ( int  errorValue,
const std::error_category category 
)
noexcept

Constructor for an error value.

This constructor constructs an invalid object containing the specified error value and category.

Parameters
errorValueThe desired error value.
categoryThe relevant error category.

◆ Failable() [7/11]

template<typename Value >
template<typename Enum >
requires std::is_error_code_enum_v<Enum>
xentara::utils::eh::deprecated::Failable< Value >::Failable ( Enum  errorEnum)
noexcept

Constructor for an error enum.

This constructor constructs an invalid object containing the error code corresponding to the specified error enum.

Parameters
errorEnumThe desired error enum.

◆ Failable() [8/11]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::Failable ( const Failable< Value > &  )
default

Copy constructor.

◆ Failable() [9/11]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::Failable ( Failable< Value > &&  )
default

Move constructor.

◆ Failable() [10/11]

template<typename Value >
template<typename RelatedValue >
requires std::is_constructible_v<Value, const RelatedValue &> && (!std::is_same_v<RelatedValue, Value>)
xentara::utils::eh::deprecated::Failable< Value >::Failable ( const Failable< RelatedValue > &  relatedValue) const &
noexcept

Copy constructor for related Failable.

Copies the value or error from a Failable of a related type

◆ Failable() [11/11]

template<typename Value >
template<typename RelatedValue >
requires std::is_constructible_v<Value, RelatedValue &&> && (!std::is_same_v<RelatedValue, Value>)
xentara::utils::eh::deprecated::Failable< Value >::Failable ( Failable< RelatedValue > &&  relatedValue) const &&
noexcept

Move constructor for related Failable.

Moves the value or error from a Failable of a related type

Member Function Documentation

◆ assign()

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::assign ( int  errorValue,
const std::error_category category 
) -> Failable &
noexcept

Assigns an error value from within a certain error category.

This constructor constructs an invalid object containing the specified error value and category.

Parameters
errorValueThe desired error value.
categoryThe relevant error category.
Returns
A reference to this object

◆ error()

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::error ( ) const -> std::error_code
noexcept

Gets the error, if there is one.

Returns
The error, or std::error_code() if the object contains a value instead of an error

◆ hasValue()

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::hasValue ( ) const -> bool
noexcept

Determines if the object contains a valid value.

Returns
Return true if the object contains a value, or false if it contains an error.

◆ operator bool()

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::operator bool ( ) const
explicitnoexcept

Determines if the object contains a valid value.

Returns
Return true if the object contains a value, or false if it contains an error.

◆ operator std::optional< Value >() [1/2]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::operator std::optional< Value > ( ) &&

Returns the value as an optional.

Returns
The value, or std::nullopt if the object does not contain a valid value

◆ operator std::optional< Value >() [2/2]

template<typename Value >
xentara::utils::eh::deprecated::Failable< Value >::operator std::optional< Value > ( ) const &

Returns the value as an optional.

Returns
The value, or std::nullopt if the object does not contain a valid value

◆ operator*() [1/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator* ( ) const -> const Value &
noexcept

Gets the value without checking.

Attention
No check is performed to verify that object actually contains a valid value. This function must only be called after checking that the value is valid using hasValue() or operator bool().
Returns
The value. If the object does not contain a value, the return value is not usable.

◆ operator*() [2/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator* ( ) -> Value &
noexcept

Gets the value without checking.

Attention
No check is performed to verify that object actually contains a valid value. This function must only be called after checking that the value is valid using hasValue() or operator bool().
Returns
The value. If the object does not contain a value, the return value is not usable.

◆ operator->() [1/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator-> ( ) const -> std::add_pointer_t<const Value>
noexcept

Accesses a member of the contained value without checking.

Attention
No check is performed to verify that object actually contains a valid value. This function must only be called after checking that the value is valid using hasValue() or operator bool().
Returns
A pointer to the value. If the object does not contain a value, the return value is not usable.

◆ operator->() [2/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator-> ( ) -> std::add_pointer_t<Value>
noexcept

Accesses a member of the contained value without checking.

Attention
No check is performed to verify that object actually contains a valid value. This function must only be called after checking that the value is valid using hasValue() or operator bool().
Returns
A pointer to the value. If the object does not contain a value, the return value is not usable.

◆ operator=() [1/7]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator= ( const Failable< Value > &  ) -> Failable &=default
default

Assignment operator.

◆ operator=() [2/7]

template<typename Value >
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 xentara::utils::eh::deprecated::Failable< Value >::operator= ( const Failable< RelatedValue > &  relatedValue) const & -> Failable &
noexcept

Assignment operator for related value.

Copies the value or error from a related convertible value

Returns
A reference to this object

◆ operator=() [3/7]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator= ( const std::error_code errorCode) -> Failable &
noexcept

Assignment operator for an error code.

Turns the object into an invalid object containing the specified error code.

Parameters
errorCodeThe desired error code.
Returns
A reference to this object

◆ operator=() [4/7]

template<typename Value >
template<typename Enum >
requires std::is_error_code_enum_v<Enum>
auto xentara::utils::eh::deprecated::Failable< Value >::operator= ( Enum  errorEnum) -> Failable &
noexcept

Assignment operator for an error enum.

Turns the object into an invalid object containing the error code corresponding to the specified error enum.

Parameters
errorEnumThe desired error enum.
Returns
A reference to this object

◆ operator=() [5/7]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::operator= ( Failable< Value > &&  ) -> Failable &=default
default

Move assignment operator.

◆ operator=() [6/7]

template<typename Value >
template<typename RelatedValue >
requires std::is_assignable_v<Value, RelatedValue &&> && std::is_constructible_v<Value, RelatedValue &&> && (!std::is_same_v<RelatedValue, Value>)
auto xentara::utils::eh::deprecated::Failable< Value >::operator= ( Failable< RelatedValue > &&  relatedValue) const && -> Failable &
noexcept

Move assignment operator for related value.

Moves the value or error from a related convertible value

Returns
A reference to this object

◆ operator=() [7/7]

template<typename Value >
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 xentara::utils::eh::deprecated::Failable< Value >::operator= ( NewValue &&  newValue) const && -> Failable &
noexcept

Assignment operator for a valid value.

Turns the object into a valid value, if it wasn't one already.

Parameters
newValueThe value to assign.
Returns
A reference to this object

◆ operator==() [1/3]

template<typename Value >
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 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.

Parameters
valueThe value to compare with
Returns
true if the object contains the specified value

◆ operator==() [2/3]

template<typename Value >
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().

Parameters
errorCodeThe error code to compare with
Returns
true if the object contains the specified error code

◆ operator==() [3/3]

template<typename Value >
template<typename Enum >
requires std::is_error_code_enum_v<Enum>
auto xentara::utils::eh::deprecated::Failable< Value >::operator== ( Enum  errorEnum) -> Failable &
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:

  • For std::errc, the enum is compared with std::errc(0)
  • For all other enum types, the result will always be false
    Parameters
    errorEnumThe error enum to compare with
    Returns
    true if the object contains the specified error enum

◆ throwError()

template<typename Value >
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments>
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.

Template Parameters
ExceptionThe type of exception to throw.
Parameters
exceptionArgumentsAdditional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes.
Exceptions
ExceptionThe object contained an error

◆ value() [1/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::value ( ) const -> std::add_pointer_t<const Value>
noexcept

Gets the value, if there is one.

Returns
A pointer to the value, or nullptr if the object contains an error instead of a value

◆ value() [2/2]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::value ( ) -> std::add_pointer_t<Value>
noexcept

Gets the value, if there is one.

Returns
A pointer to the value, or nullptr if the object contains an error instead of a value

◆ valueOr() [1/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( const Value &  fallback) const && -> Value
noexcept

Gets the value or a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
The value, or fallback if the object contains an error instead of a value

◆ valueOr() [2/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( const Value &  fallback) const & -> Value
noexcept

Gets the value or a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
The value, or fallback if the object contains an error instead of a value

◆ valueOr() [3/10]

template<typename Value >
template<std::invocable<> Fallback>
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Fallback &&  fallback) && -> Value
noexcept

Gets the value or generates a fallback value.

Parameters
fallbackA callable used to generate the return value if the object contains an error instead of a value
Returns
The value. If the object contains an error instead of a value, fallback is called to generate the return value.

◆ valueOr() [4/10]

template<typename 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 xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Fallback &&  fallback) -> Value &

Gets the value or generates a reference to a fallback value.

Parameters
fallbackA callable used to get a reference to the return value if the object contains an error instead of a value
Returns
The value. If the object contains an error instead of a value, fallback is called to get a reference to the return value.

◆ valueOr() [5/10]

template<typename Value >
template<std::invocable<> Fallback>
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Fallback &&  fallback) const && -> Value
noexcept

Gets the value or generates a fallback value.

Parameters
fallbackA callable used to generate the return value if the object contains an error instead of a value
Returns
The value. If the object contains an error instead of a value, fallback is called to generate the return value.

◆ valueOr() [6/10]

template<typename 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 xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Fallback &&  fallback) const -> const Value &

Gets the value or generates a fallback value.

Parameters
fallbackA callable used to get a reference to the return value if the object contains an error instead of a value
Returns
The value. If the object contains an error instead of a value, fallback is called to get a reference to the return value.

◆ valueOr() [7/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( std::reference_wrapper< const Value >  fallback) const -> const Value &
noexcept

Gets a reference to the value or to a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
A reference to the value, or a reference to fallback if the object contains an error instead of a value

◆ valueOr() [8/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( std::reference_wrapper< Value >  fallback) -> Value &
noexcept

Gets a mutable reference to the value or to a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
A reference to the value, or a reference to fallback if the object contains an error instead of a value

◆ valueOr() [9/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Value &&  fallback) const && -> Value
noexcept

Gets the value or a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
The value, or fallback if the object contains an error instead of a value

◆ valueOr() [10/10]

template<typename Value >
auto xentara::utils::eh::deprecated::Failable< Value >::valueOr ( Value &&  fallback) const && -> Value
noexcept

Gets the value or a fallback value.

Parameters
fallbackThe value to return if the object contains an error instead of a value
Returns
The value, or fallback if the object contains an error instead of a value

◆ valueOrThrow() [1/2]

template<typename Value >
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments>
auto xentara::utils::eh::deprecated::Failable< Value >::valueOrThrow ( ExceptionArguments &&...  exceptionArguments) -> Value &

Gets the value, or throws the error.

Template Parameters
ExceptionThe type of exception to throw.
Parameters
exceptionArgumentsAdditional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes.
Returns
A reference to the value
Exceptions
Exceptionthe object contained an error

◆ valueOrThrow() [2/2]

template<typename Value >
template<std::derived_from< std::system_error > Exception = std::system_error, typename... ExceptionArguments>
auto xentara::utils::eh::deprecated::Failable< Value >::valueOrThrow ( ExceptionArguments &&...  exceptionArguments) const -> const Value &

Gets the value, or throws the error.

Template Parameters
ExceptionThe type of exception to throw.
Parameters
exceptionArgumentsAdditional arguments for the exception constructor. This is usually the [what](std::exception::what) string, but can be any arguments the constructor of Exception takes.
Returns
A reference to the value
Exceptions
Exceptionthe object contained an error

Friends And Related Symbol Documentation

◆ failableCast() [1/2]

template<typename RelatedValue , typename Value >
auto failableCast ( const Failable< Value > &  failable) -> Failable<RelatedValue>
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.

◆ failableCast() [2/2]

template<typename RelatedValue , typename Value >
auto failableCast ( Failable< Value > &&  failable) -> Failable<RelatedValue>
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.

◆ operator==()

template<typename LhsValue , typename RhsValue >
auto operator== ( const Failable< LhsValue > &  lhs,
const Failable< RhsValue > &  rhs 
) -> bool
related

Comparison operator for two failables.