Diag-Client-Lib
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
core_type::Result< void, E > Class Template Referencefinal

Specialization of class Result for "void" values. More...

#include <result.h>

Collaboration diagram for core_type::Result< void, E >:
Collaboration graph
[legend]

Classes

struct  empty_value
 An empty value for handling void type in value type. More...
 

Public Types

using value_type = void
 Type alias for the type T of values, always "void" for this specialization. More...
 
using error_type = E
 Type alias for the type E of errors. More...
 

Public Member Functions

constexpr Result () noexcept
 Construct a new Result with a "void" value. More...
 
constexpr Result (const E &e) noexcept
 Construct a new Result from the specified error (given as lvalue) More...
 
constexpr Result (E &&e) noexcept
 Construct a new Result from the specified error (given as rvalue) More...
 
 Result (const Result &other)=default
 Copy-construct a new Result from another instance. More...
 
Resultoperator= (const Result &other)=default
 Copy-assign another Result to this instance. More...
 
 Result (Result &&other) noexcept(std::is_nothrow_move_constructible< E >::value)=default
 Move-construct a new Result from another instance. More...
 
Resultoperator= (Result &&other) noexcept(std::is_nothrow_move_constructible< E >::value &&std::is_nothrow_move_assignable< E >::value)=default
 Move-assign another Result to this instance. More...
 
 ~Result () noexcept
 Destruct an instance of Result. More...
 
void EmplaceValue () noexcept
 Put a new value into this instance, constructed in-place from the given arguments. More...
 
template<typename... Args>
void EmplaceError (Args &&...args) noexcept
 Put a new error into this instance, constructed in-place from the given arguments. More...
 
bool HasValue () const noexcept
 Check whether *this contains a value. More...
 
 operator bool () const noexcept
 Check whether *this contains a value. More...
 
const E & Error () const &noexcept
 Access the contained error. More...
 
E && Error () &&noexcept
 Access the contained error. More...
 
std::optional< E > Err () const &noexcept
 Return the contained error as an Optional. More...
 
std::optional< E > Err () &&noexcept
 Return the contained error as an Optional. More...
 
template<typename F , typename E2 = std::invoke_result_t<F, E>>
Result< void, E2 > MapError (F &&fn)
 Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself. More...
 
template<typename F , typename E2 = std::invoke_result_t<F, E>>
Result< void, E2 > CheckError (F &&fn)
 Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself. More...
 
template<typename F >
Result AndThen (F &&fn) &&noexcept
 Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself. More...
 
template<typename F >
Result OrElse (F &&fn) &&noexcept
 Returns the result itself if it contains a value; otherwise, returns the result of the given function on the error value. More...
 
template<typename G >
ErrorOr (G &&defaultError) const &noexcept
 Return the contained error or the given default error. More...
 
template<typename G >
ErrorOr (G &&defaultError) &&noexcept
 Return the contained error or the given default error. More...
 
template<typename F >
void Resolve (F &&f) const
 Do nothing or call a function. More...
 

Static Public Member Functions

static Result FromValue () noexcept
 Build a new Result with "void" as value. More...
 
static Result FromError (const E &e) noexcept
 Build a new Result from the specified error (given as lvalue) More...
 
static Result FromError (E &&e) noexcept
 Build a new Result from the specified error (given as rvalue) More...
 
template<typename... Args>
static Result FromError (Args &&...args) noexcept
 Build a new Result from an error that is constructed in-place from the given arguments. More...
 

Private Attributes

Result< empty_value, E > storage_
 Storage to contain an empty value or error of type E. More...
 

Detailed Description

template<typename E>
class core_type::Result< void, E >

Specialization of class Result for "void" values.

This class is implemented based on API specification of ara::core::Result from Adaptive Platform Core AUTOSAR AP R21-11

Template Parameters
EThe type of error

Definition at line 453 of file result.h.

Member Typedef Documentation

◆ error_type

template<typename E >
using core_type::Result< void, E >::error_type = E

Type alias for the type E of errors.

Definition at line 463 of file result.h.

◆ value_type

template<typename E >
using core_type::Result< void, E >::value_type = void

Type alias for the type T of values, always "void" for this specialization.

Definition at line 458 of file result.h.

Constructor & Destructor Documentation

◆ Result() [1/5]

template<typename E >
constexpr core_type::Result< void, E >::Result ( )
inlineexplicitconstexprnoexcept

Construct a new Result with a "void" value.

Definition at line 510 of file result.h.

510 : storage_{empty_value{}} {}
Result< empty_value, E > storage_
Storage to contain an empty value or error of type E.
Definition: result.h:749

◆ Result() [2/5]

template<typename E >
constexpr core_type::Result< void, E >::Result ( const E &  e)
inlineexplicitconstexprnoexcept

Construct a new Result from the specified error (given as lvalue)

Parameters
[in]eThe error to put into the Result

Definition at line 517 of file result.h.

517 : storage_{e} {}

◆ Result() [3/5]

template<typename E >
constexpr core_type::Result< void, E >::Result ( E &&  e)
inlineexplicitconstexprnoexcept

Construct a new Result from the specified error (given as rvalue)

Parameters
[in]eThe error to put into the Result

Definition at line 524 of file result.h.

524 : storage_{std::move(e)} {}

◆ Result() [4/5]

template<typename E >
core_type::Result< void, E >::Result ( const Result< void, E > &  other)
default

Copy-construct a new Result from another instance.

Parameters
[in]otherThe other instance

◆ Result() [5/5]

template<typename E >
core_type::Result< void, E >::Result ( Result< void, E > &&  other) const
defaultnoexcept

Move-construct a new Result from another instance.

Parameters
[in]otherThe other instance

◆ ~Result()

template<typename E >
core_type::Result< void, E >::~Result ( )
inlinenoexcept

Destruct an instance of Result.

Definition at line 562 of file result.h.

562 { static_assert(std::is_trivially_destructible<E>::value); }

Member Function Documentation

◆ AndThen()

template<typename E >
template<typename F >
Result core_type::Result< void, E >::AndThen ( F &&  fn) &&
inlinenoexcept

Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself.

Template Parameters
FFunctor type
Parameters
[in]fnCallable function
Returns
Result An Result

Definition at line 674 of file result.h.

674  {
675  if (HasValue()) { fn(); }
676  return Result{std::move(*this)};
677  }
constexpr Result() noexcept
Construct a new Result with a "void" value.
Definition: result.h:510
bool HasValue() const noexcept
Check whether *this contains a value.
Definition: result.h:586

References core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ CheckError()

template<typename E >
template<typename F , typename E2 = std::invoke_result_t<F, E>>
Result<void, E2> core_type::Result< void, E >::CheckError ( F &&  fn)
inline

Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself.

Template Parameters
FFunctor type
Parameters
[in]fnCallable function
Returns
Result An Result

Definition at line 659 of file result.h.

659  {
660  return HasValue() ? Result<void, E2>{} : Result<void, E2>{fn(Error())};
661  }
const E & Error() const &noexcept
Access the contained error.
Definition: result.h:601

References core_type::Result< T, E >::Error(), and core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ EmplaceError()

template<typename E >
template<typename... Args>
void core_type::Result< void, E >::EmplaceError ( Args &&...  args)
inlinenoexcept

Put a new error into this instance, constructed in-place from the given arguments.

Template Parameters
ArgsThe types of arguments given to this function
Parameters
[in]argsThe arguments used for constructing the error

Definition at line 577 of file result.h.

577  {
578  storage_.EmplaceError(std::forward<Args>(args)...);
579  }
void EmplaceError(Args &&...args) noexcept
Put a new error into this instance, constructed in-place from the given arguments.
Definition: result.h:199

References core_type::Result< T, E >::storage_.

◆ EmplaceValue()

template<typename E >
void core_type::Result< void, E >::EmplaceValue ( )
inlinenoexcept

Put a new value into this instance, constructed in-place from the given arguments.

Definition at line 567 of file result.h.

567 { storage_.EmplaceValue(empty_value{}); }
void EmplaceValue(Args &&...args) noexcept
Put a new value into this instance, constructed in-place from the given arguments.
Definition: result.h:187

References core_type::Result< T, E >::storage_.

◆ Err() [1/2]

template<typename E >
std::optional<E> core_type::Result< void, E >::Err ( ) &&
inlinenoexcept

Return the contained error as an Optional.

Returns
std::optional<E> An Optional with the error, if present

Definition at line 627 of file result.h.

627  {
628  std::optional<E> opt_err{};
629  if (!HasValue()) { opt_err.emplace(std::move(Error())); }
630  return opt_err;
631  }

References core_type::Result< T, E >::Error(), and core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ Err() [2/2]

template<typename E >
std::optional<E> core_type::Result< void, E >::Err ( ) const &
inlinenoexcept

Return the contained error as an Optional.

Returns
std::optional<E> An Optional with the error, if present

Definition at line 616 of file result.h.

616  {
617  std::optional<E> opt_err{};
618  if (!HasValue()) { opt_err.emplace(Error()); }
619  return opt_err;
620  }

References core_type::Result< T, E >::Error(), and core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ Error() [1/2]

template<typename E >
E&& core_type::Result< void, E >::Error ( ) &&
inlinenoexcept

Access the contained error.

This function’s behavior is undefined if *this does not contain an error

Returns
E && An rvalue reference to the contained error

Definition at line 609 of file result.h.

609 { return std::move(storage_.Error()); }
const E & Error() const &noexcept
Access the contained error.
Definition: result.h:263

References core_type::Result< T, E >::storage_.

◆ Error() [2/2]

template<typename E >
const E& core_type::Result< void, E >::Error ( ) const &
inlinenoexcept

Access the contained error.

This function’s behavior is undefined if *this does not contain an error

Returns
const E & A const reference to the contained error

Definition at line 601 of file result.h.

601 { return storage_.Error(); }

References core_type::Result< T, E >::storage_.

◆ ErrorOr() [1/2]

template<typename E >
template<typename G >
E core_type::Result< void, E >::ErrorOr ( G &&  defaultError) &&
inlinenoexcept

Return the contained error or the given default error.

If *this contains an error, it is returned. Otherwise, the specified default error is returned, static_cast’d to E

Template Parameters
GThe type of defaultError
Parameters
[in]defaultErrorThe error to use if *this does not contain an error
Returns
E The error

Definition at line 720 of file result.h.

720  {
721  return !HasValue() ? Result{std::move(*this)} : static_cast<E>(defaultError);
722  }

References core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ ErrorOr() [2/2]

template<typename E >
template<typename G >
E core_type::Result< void, E >::ErrorOr ( G &&  defaultError) const &
inlinenoexcept

Return the contained error or the given default error.

If *this contains an error, it is returned. Otherwise, the specified default error is returned, static_cast’d to E

Template Parameters
GThe type of defaultError
Parameters
[in]defaultErrorThe error to use if *this does not contain an error
Returns
E The error

Definition at line 705 of file result.h.

705  {
706  return !HasValue() ? Result{*this} : static_cast<E>(defaultError);
707  }

References core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ FromError() [1/3]

template<typename E >
template<typename... Args>
static Result core_type::Result< void, E >::FromError ( Args &&...  args)
inlinestaticnoexcept

Build a new Result from an error that is constructed in-place from the given arguments.

This function shall not participate in overload resolution unless: std::is_const Args&&...>::value is true, and the first type of the expanded parameter pack first type of the expanded parameter pack is not a specialization of Result

Template Parameters
ArgsThe types of arguments given to this function
Parameters
[in]argsThe arguments used for constructing the error
Returns
Result A Result that contains an error

Definition at line 503 of file result.h.

503  {
504  return Result{std::forward<Args>(args)...};
505  }

◆ FromError() [2/3]

template<typename E >
static Result core_type::Result< void, E >::FromError ( const E &  e)
inlinestaticnoexcept

Build a new Result from the specified error (given as lvalue)

Parameters
[in]eThe error to put into the Result
Returns
Result A Result that contains the error e

Definition at line 479 of file result.h.

479 { return Result{e}; }

◆ FromError() [3/3]

template<typename E >
static Result core_type::Result< void, E >::FromError ( E &&  e)
inlinestaticnoexcept

Build a new Result from the specified error (given as rvalue)

Parameters
[in]eThe error to put into the Result
Returns
Result A Result that contains the error e

Definition at line 488 of file result.h.

488 { return Result{std::move(e)}; }

◆ FromValue()

template<typename E >
static Result core_type::Result< void, E >::FromValue ( )
inlinestaticnoexcept

Build a new Result with "void" as value.

Parameters
[in]tThe value to put into the Result

Definition at line 470 of file result.h.

470 { return Result{}; }

◆ HasValue()

template<typename E >
bool core_type::Result< void, E >::HasValue ( ) const
inlinenoexcept

Check whether *this contains a value.

Returns
bool True if *this contains a value, false otherwise

Definition at line 586 of file result.h.

586 { return storage_.HasValue(); }
bool HasValue() const noexcept
Check whether *this contains a value.
Definition: result.h:208

References core_type::Result< T, E >::storage_.

◆ MapError()

template<typename E >
template<typename F , typename E2 = std::invoke_result_t<F, E>>
Result<void, E2> core_type::Result< void, E >::MapError ( F &&  fn)
inline

Returns the result of the given function on the contained value if it exists; otherwise, returns the result itself.

Template Parameters
FFunctor type
Parameters
[in]fnCallable function
Returns
Result An Result

Definition at line 644 of file result.h.

644  {
645  return HasValue() ? Result<void, E2>{} : Result<void, E2>{fn(Error())};
646  }

References core_type::Result< T, E >::Error(), and core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ operator bool()

template<typename E >
core_type::Result< void, E >::operator bool ( ) const
inlineexplicitnoexcept

Check whether *this contains a value.

Returns
bool True if *this contains a value, false otherwise

Definition at line 593 of file result.h.

593 { return HasValue(); }

References core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename E >
Result& core_type::Result< void, E >::operator= ( const Result< void, E > &  other)
default

Copy-assign another Result to this instance.

Parameters
[in]otherThe other instance
Returns
Result & *this, containing the contents of other

◆ operator=() [2/2]

template<typename E >
Result& core_type::Result< void, E >::operator= ( Result< void, E > &&  other) const &&
defaultnoexcept

Move-assign another Result to this instance.

Parameters
[in]otherThe other instance
Returns
Result & *this, containing the contents of other

◆ OrElse()

template<typename E >
template<typename F >
Result core_type::Result< void, E >::OrElse ( F &&  fn) &&
inlinenoexcept

Returns the result itself if it contains a value; otherwise, returns the result of the given function on the error value.

Template Parameters
FFunctor type
Parameters
[in]fnCallable function
Returns
Result An Result

Definition at line 690 of file result.h.

690  {
691  return HasValue() ? Result{std::move(*this)} : Result{fn(Error())};
692  }

References core_type::Result< T, E >::Error(), and core_type::Result< T, E >::HasValue().

Here is the call graph for this function:

◆ Resolve()

template<typename E >
template<typename F >
void core_type::Result< void, E >::Resolve ( F &&  f) const
inline

Do nothing or call a function.

If *this contains a value, this function does nothing. Otherwise, the specified callable is invoked. The Callable is expected to be compatible to this interface: void f(const E&);

Template Parameters
FThe type of the Callable f
Parameters
[in]fThe Callable
Returns
T The value

Definition at line 736 of file result.h.

736  {
737  f(Error());
738  }

References core_type::Result< T, E >::Error().

Here is the call graph for this function:

Member Data Documentation

◆ storage_

template<typename E >
Result<empty_value, E> core_type::Result< void, E >::storage_
private

Storage to contain an empty value or error of type E.

Definition at line 749 of file result.h.


The documentation for this class was generated from the following file: