Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
ara::core::Result< T, E > Class Template Referencefinal

A wrapper around the callee's return value and its possible error. More...

#include <result.h>

Public Types

using value_type = T
 Result value type alias.
 
using error_type = E
 Result error type alias.
 

Public Member Functions

 Result (const T &t) noexcept(std::is_nothrow_copy_constructible< T >::value)
 
 Result (T &&t) noexcept(std::is_nothrow_move_constructible< T >::value)
 
 Result (const E &e) noexcept(std::is_nothrow_copy_constructible< E >::value)
 
 Result (E &&e) noexcept(std::is_nothrow_move_constructible< E >::value)
 
 Result (const Result &other) noexcept(std::is_nothrow_copy_assignable< T >::value &&std::is_nothrow_copy_assignable< E >::value)
 
 Result (Result &&other) noexcept(std::is_nothrow_move_assignable< T >::value &&std::is_nothrow_move_assignable< E >::value)
 
Resultoperator= (Result const &other) noexcept(std::is_nothrow_copy_assignable< T >::value &&std::is_nothrow_copy_assignable< E >::value)
 
Resultoperator= (Result &&other) noexcept(std::is_nothrow_move_assignable< T >::value &&std::is_nothrow_move_assignable< E >::value)
 
template<typename... Args>
void EmplaceValue (Args &&...args)
 Construct a new value from the give argument(s) and assign it to the instance value. More...
 
template<typename... Args>
void EmplaceError (Args &&...args)
 Construct a new error from the give argument(s) and assign it to the instance error. More...
 
void Swap (Result &other) noexcept(std::is_nothrow_move_assignable< T >::value &&std::is_nothrow_move_assignable< E >::value)
 Swap the current instance with another one. More...
 
bool HasValue () const noexcept
 Indicate whether the instance has a value or not. More...
 
 operator bool () const noexcept
 
const T & operator* () const &
 
T && operator* () &&
 
const T * operator-> () const
 
const T & Value () const &
 Get instance possible value. More...
 
T && Value () &&
 Get instance possible value. More...
 
const E & Error () const &
 Get instance possible error. More...
 
E && Error () &&
 Get instance possible error. More...
 
Optional< T > Ok () const &
 Get optional instance value. More...
 
Optional< T > Ok () &&
 Get optional instance value. More...
 
Optional< E > Err () const &
 Get optional instance error. More...
 
Optional< E > Err () &&
 Get optional instance error. More...
 
template<typename U >
ValueOr (U &&defaultValue) const &
 Get the instance value or the default value. More...
 
template<typename U >
ValueOr (U &&defaultValue) &&
 Get the instance value or the default value. More...
 
template<typename G >
ErrorOr (G &&defaultError) const &
 Get the instance error or the default error. More...
 
template<typename G >
ErrorOr (G &&defaultError) &&
 Get the instance error or the default error. More...
 
template<typename G >
bool CheckError (G &&error) const
 Check an error with the instance error. More...
 
const T & ValueOrThrow () const &noexcept(false)
 Get instance possible value or throw an exception. More...
 
T && ValueOrThrow () &&noexcept(false)
 Get instance possible value or throw an exception. More...
 
template<typename F >
Resolve (F &&f) const
 Get the instance value or a callable result. More...
 
template<typename F >
auto Bind (F &&f) const -> Result< decltype(f(Value())), E >
 Create a new Result by passing the instance value (if exists) to a callable. More...
 

Static Public Member Functions

static Result FromValue (const T &t) noexcept(std::is_nothrow_copy_constructible< T >::value)
 Result factory by copying its value. More...
 
static Result FromValue (T &&t) noexcept(std::is_nothrow_move_constructible< T >::value)
 Result factory by moving its value. More...
 
static Result FromError (const E &e) noexcept(std::is_nothrow_copy_constructible< E >::value)
 Result factory by copying its error. More...
 
static Result FromError (E &&e) noexcept(std::is_nothrow_move_constructible< E >::value)
 Result factory by moving its error. More...
 

Detailed Description

template<typename T, typename E = ErrorCode>
class ara::core::Result< T, E >

A wrapper around the callee's return value and its possible error.

Template Parameters
TCallee's return value type
ECallee's possible error type

Member Function Documentation

◆ Bind()

template<typename T , typename E = ErrorCode>
template<typename F >
auto ara::core::Result< T, E >::Bind ( F &&  f) const -> Result<decltype(f(Value())), E>
inline

Create a new Result by passing the instance value (if exists) to a callable.

Template Parameters
FCallable type
Parameters
fCallable that takes the instance value and returns a new Result
Returns
Callable result if the value exists, otherwise a new Result with the copied instance error

◆ CheckError()

template<typename T , typename E = ErrorCode>
template<typename G >
bool ara::core::Result< T, E >::CheckError ( G &&  error) const
inline

Check an error with the instance error.

Template Parameters
GInput error type
Returns
True if the input error equals the instance error, otherwise false

◆ EmplaceError()

template<typename T , typename E = ErrorCode>
template<typename... Args>
void ara::core::Result< T, E >::EmplaceError ( Args &&...  args)
inline

Construct a new error from the give argument(s) and assign it to the instance error.

Parameters
argsArgument(s) to construct a new error

◆ EmplaceValue()

template<typename T , typename E = ErrorCode>
template<typename... Args>
void ara::core::Result< T, E >::EmplaceValue ( Args &&...  args)
inline

Construct a new value from the give argument(s) and assign it to the instance value.

Parameters
argsArgument(s) to construct a new value

◆ Err() [1/2]

template<typename T , typename E = ErrorCode>
Optional< E > ara::core::Result< T, E >::Err ( ) &&
inline

Get optional instance error.

Returns
Optional error

◆ Err() [2/2]

template<typename T , typename E = ErrorCode>
Optional< E > ara::core::Result< T, E >::Err ( ) const &
inline

Get optional instance error.

Returns
Optional error

◆ Error() [1/2]

template<typename T , typename E = ErrorCode>
E && ara::core::Result< T, E >::Error ( ) &&
inline

Get instance possible error.

Returns
Movable error
Exceptions
std::runtime_errorThrows if there is no error

◆ Error() [2/2]

template<typename T , typename E = ErrorCode>
const E & ara::core::Result< T, E >::Error ( ) const &
inline

Get instance possible error.

Returns
Copied error
Exceptions
std::runtime_errorThrows if there is no error

◆ ErrorOr() [1/2]

template<typename T , typename E = ErrorCode>
template<typename G >
E ara::core::Result< T, E >::ErrorOr ( G &&  defaultError) &&
inline

Get the instance error or the default error.

Template Parameters
GDefault error type
Parameters
defaultErrorError to be return in absence of the instance error
Returns
Instance error if exists, otherwise the default error

◆ ErrorOr() [2/2]

template<typename T , typename E = ErrorCode>
template<typename G >
E ara::core::Result< T, E >::ErrorOr ( G &&  defaultError) const &
inline

Get the instance error or the default error.

Template Parameters
GDefault error type
Parameters
defaultErrorError to be return in absence of the instance error
Returns
Instance error if exists, otherwise the default error

◆ FromError() [1/2]

template<typename T , typename E >
Result< T, E > ara::core::Result< T, E >::FromError ( const E &  e)
staticnoexcept

Result factory by copying its error.

Parameters
eResult error
Returns
Created Result from the error

◆ FromError() [2/2]

template<typename T , typename E >
Result< T, E > ara::core::Result< T, E >::FromError ( E &&  e)
staticnoexcept

Result factory by moving its error.

Parameters
eResult error
Returns
Created Result from the error

◆ FromValue() [1/2]

template<typename T , typename E >
Result< T, E > ara::core::Result< T, E >::FromValue ( const T &  t)
staticnoexcept

Result factory by copying its value.

Parameters
tResult value
Returns
Created Result from the value

◆ FromValue() [2/2]

template<typename T , typename E >
Result< T, E > ara::core::Result< T, E >::FromValue ( T &&  t)
staticnoexcept

Result factory by moving its value.

Parameters
tResult value
Returns
Created Result from the value

◆ HasValue()

template<typename T , typename E = ErrorCode>
bool ara::core::Result< T, E >::HasValue ( ) const
inlinenoexcept

Indicate whether the instance has a value or not.

Returns
True if has a value and false if it contains an error

◆ Ok() [1/2]

template<typename T , typename E = ErrorCode>
Optional< T > ara::core::Result< T, E >::Ok ( ) &&
inline

Get optional instance value.

Returns
Optional value

◆ Ok() [2/2]

template<typename T , typename E = ErrorCode>
Optional< T > ara::core::Result< T, E >::Ok ( ) const &
inline

Get optional instance value.

Returns
Optional value

◆ operator bool()

template<typename T , typename E = ErrorCode>
ara::core::Result< T, E >::operator bool ( ) const
inlineexplicitnoexcept
Returns
True if the instance has a value and false if it contains an error

◆ operator*() [1/2]

template<typename T , typename E = ErrorCode>
T && ara::core::Result< T, E >::operator* ( ) &&
inline
Returns
Movable value
Exceptions
std::runtime_errorThrows if there is no value

◆ operator*() [2/2]

template<typename T , typename E = ErrorCode>
const T & ara::core::Result< T, E >::operator* ( ) const &
inline
Returns
Copied value
Exceptions
std::runtime_errorThrows if there is no value

◆ operator->()

template<typename T , typename E = ErrorCode>
const T * ara::core::Result< T, E >::operator-> ( ) const
inline
Returns
Constant value pointer
Exceptions
std::runtime_errorThrows if there is no value

◆ Resolve()

template<typename T , typename E = ErrorCode>
template<typename F >
T ara::core::Result< T, E >::Resolve ( F &&  f) const
inline

Get the instance value or a callable result.

Template Parameters
FCallable type
Parameters
fCallable to be invoked if no value exists
Returns
Instance value if exists, otherwise the callable result

◆ Swap()

template<typename T , typename E = ErrorCode>
void ara::core::Result< T, E >::Swap ( Result< T, E > &  other)
inlinenoexcept

Swap the current instance with another one.

Parameters
otherAnother Result for swapping

◆ Value() [1/2]

template<typename T , typename E = ErrorCode>
T && ara::core::Result< T, E >::Value ( ) &&
inline

Get instance possible value.

Returns
Movable value
Exceptions
std::runtime_errorThrows if there is no value

◆ Value() [2/2]

template<typename T , typename E = ErrorCode>
const T & ara::core::Result< T, E >::Value ( ) const &
inline

Get instance possible value.

Returns
Copied value
Exceptions
std::runtime_errorThrows if there is no value

◆ ValueOr() [1/2]

template<typename T , typename E = ErrorCode>
template<typename U >
T ara::core::Result< T, E >::ValueOr ( U &&  defaultValue) &&
inline

Get the instance value or the default value.

Template Parameters
UDefault value type
Parameters
defaultValueValue to be return in absence of the instance value
Returns
Instance value if exists, otherwise the default value

◆ ValueOr() [2/2]

template<typename T , typename E = ErrorCode>
template<typename U >
T ara::core::Result< T, E >::ValueOr ( U &&  defaultValue) const &
inline

Get the instance value or the default value.

Template Parameters
UDefault value type
Parameters
defaultValueValue to be return in absence of the instance value
Returns
Instance value if exists, otherwise the default value

◆ ValueOrThrow() [1/2]

template<typename T , typename E = ErrorCode>
T && ara::core::Result< T, E >::ValueOrThrow ( ) &&
inlinenoexcept

Get instance possible value or throw an exception.

Returns
Movable value if exists
Exceptions
std::runtime_errorThrows if there is no value

◆ ValueOrThrow() [2/2]

template<typename T , typename E = ErrorCode>
const T & ara::core::Result< T, E >::ValueOrThrow ( ) const &
inlinenoexcept

Get instance possible value or throw an exception.

Returns
Copied value if exists
Exceptions
std::runtime_errorThrows if there is no value