ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::Result< void, E > Class Template Reference

Template specialization for the void case. More...

#include <Acts/Utilities/Result.hpp>

Inheritance diagram for Acts::Result< void, E >:
[legend]
Collaboration diagram for Acts::Result< void, E >:
[legend]

Public Types

using ErrorType = E
 Type alias for the error type contained in failed result.
using ValueType = void
 Type alias for the value type (void) in successful result.

Public Member Functions

 Result ()=default
 Default constructor which initializes the result in the ok state.
 Result (const Result< void, E > &other)=default
 The copy constructor is deleted.
template<typename E2>
 Result (E2 error) noexcept
 Constructor from error.
 Result (Result< void, E > &&other) noexcept
 Move constructor.
auto and_then (C &&callable) const &
 Bind a function to this result monadically.
error () &&noexcept
 Returns the error by-value.
E & error () &noexcept
 Returns a reference to the error stored in the result.
const E & error () const &noexcept
 Returns a reference to the error stored in the result.
bool ok () const noexcept
 Checks whether this result is in the ok state, and no error.
void & operator* () noexcept
 Returns a reference into the variant to the valid value.
void * operator-> () noexcept
 Allows to access members of the stored object with res->foo similar to std::optional.
Result< void, E > & operator= (const Result< void, E > &other)=default
 The (self) assignment operator is deleted.
template<typename E2>
Result< void, E > & operator= (E2 error)
 Assignment operator from an error.
Result< void, E > & operator= (Result< void, E > &&other) noexcept
 Move assignment operator.
auto transform (C &&callable) const &
 Transforms the value contained in this result.
void value () const
 Validates this void result and throws if an error is present.
std::conditional_t< std::is_reference_v< U >, const void &, void > value_or (U &&v) const &
 Retrieves the valid value from the result object, or returns a default value if no valid value exists.

Static Public Member Functions

static Result< void, E > failure (E error)
 Static factory function to initialize the result in the error state.
static Result< void, E > success ()
 Static factory function to initialize the result in the ok state.

Detailed Description

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

Template specialization for the void case.

This specialization handles the case where there is no actual return value, but an error might be returned. Returning the error directly would make handling different from other functions using the Result<T, E> mechanism. Result<void, E> does not have the dereference operator, and value methods. The static success factory does not accept a value.

Note
To ease usage, this Result<void, E> is default constructible in the ok state, whereas Result<T, E> is not.
Template Parameters
EThe type of the error

Member Typedef Documentation

◆ ErrorType

template<typename E>
using Acts::Result< void, E >::ErrorType = E

Type alias for the error type contained in failed result.

◆ ValueType

template<typename E>
using Acts::Result< void, E >::ValueType = void

Type alias for the value type (void) in successful result.

Constructor & Destructor Documentation

◆ Result() [1/4]

template<typename E>
Acts::Result< void, E >::Result ( )
default

Default constructor which initializes the result in the ok state.

◆ Result() [2/4]

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

The copy constructor is deleted.

Parameters
otherThe other result instance to copy from

◆ Result() [3/4]

template<typename E>
Acts::Result< void, E >::Result ( Result< void, E > && other)
noexcept

Move constructor.

Parameters
otherThe other result object, rvalue ref

◆ Result() [4/4]

template<typename E>
template<typename E2>
Acts::Result< void, E >::Result ( E2 error)
noexcept

Constructor from error.

This implicitly requires E2 to be convertible to E.

Template Parameters
E2The type of the actual error
Parameters
errorThe instance of the actual error

Member Function Documentation

◆ and_then()

auto Acts::Result< void, E >::and_then ( C && callable) const &

Bind a function to this result monadically.

This function takes a function f and, if this result contains a valid value x, returns f(x). If the type of x is T, then f is expected to accept type T and return Result<U>. In this case, transform would return the unhelpful type Result<Result<U>>, so and_then strips away the outer layer to return Result<U>. If the value is invalid, this returns an invalid value in Result<U>.

Parameters
[in]callableThe transformation function to apply.
Note
This is the lvalue version.
This functions is >>= on the functor in A of Result<A, E>.
Returns
The modified valid value if exists, or an error otherwise.

◆ error() [1/3]

template<typename E>
E Acts::Result< void, E >::error ( ) &&
noexcept

Returns the error by-value.

Note
If res.ok() this method will abort (noexcept)
Returns
The error by value

◆ error() [2/3]

template<typename E>
E & Acts::Result< void, E >::error ( ) &
noexcept

Returns a reference to the error stored in the result.

Note
If res.ok() this method will abort (noexcept)
Returns
Reference to the error

◆ error() [3/3]

template<typename E>
const E & Acts::Result< void, E >::error ( ) const &
noexcept

Returns a reference to the error stored in the result.

Note
If res.ok() this method will abort (noexcept)
Returns
Reference to the error

◆ failure()

template<typename E>
Result< void, E > Acts::Result< void, E >::failure ( E error)
static

Static factory function to initialize the result in the error state.

Parameters
errorThe error to initialize with.
Returns
Result object, in error state.

◆ ok()

template<typename E>
bool Acts::Result< void, E >::ok ( ) const
noexcept

Checks whether this result is in the ok state, and no error.

Returns
bool Whether result contains an error or not.

◆ operator*()

void & Acts::Result< void, E >::operator* ( )
noexcept

Returns a reference into the variant to the valid value.

Note
If !res.ok(), this method will abort (noexcept)
Returns
Reference to value stored in the variant.

◆ operator->()

void * Acts::Result< void, E >::operator-> ( )
noexcept

Allows to access members of the stored object with res->foo similar to std::optional.

Note
If !res.ok(), this method will abort (noexcept)
Returns
Pointer to value stored in the variant.

◆ operator=() [1/3]

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

The (self) assignment operator is deleted.

Parameters
otherThe other result instance to assign from
Returns
Reference to this result instance

◆ operator=() [2/3]

template<typename E>
template<typename E2>
Result< void, E > & Acts::Result< void, E >::operator= ( E2 error)

Assignment operator from an error.

Template Parameters
E2The type of the actual error
Parameters
errorThe instance of the actual error
Returns
The assigned instance

◆ operator=() [3/3]

template<typename E>
Result< void, E > & Acts::Result< void, E >::operator= ( Result< void, E > && other)
noexcept

Move assignment operator.

Parameters
otherThe other result object, rvalue ref
Returns
Reference to this result for assignment chaining

◆ success()

template<typename E>
Result< void, E > Acts::Result< void, E >::success ( )
static

Static factory function to initialize the result in the ok state.

Returns
Result object, in ok state

◆ transform()

auto Acts::Result< void, E >::transform ( C && callable) const &

Transforms the value contained in this result.

Applying a function f to a valid value x returns f(x), while applying f to an invalid value returns another invalid value.

Parameters
[in]callableThe transformation function to apply.
Note
This is the lvalue version.
This functions is fmap on the functor in A of Result<A, E>.
Returns
The modified valid value if exists, or an error otherwise.

◆ value()

template<typename E>
void Acts::Result< void, E >::value ( ) const

Validates this void result and throws if an error is present.

This method checks if the result contains an error and throws an exception if one is found. For void results, there is no value to return - this method only performs validation.

Exceptions
std::runtime_errorif the result contains an error

◆ value_or()

std::conditional_t< std::is_reference_v< U >, const void &, void > Acts::Result< void, E >::value_or ( U && v) const &

Retrieves the valid value from the result object, or returns a default value if no valid value exists.

Parameters
[in]vThe default value to use if no valid value exists.
Note
This is the lvalue version.
This function always returns by value.
Returns
Either the valid value, or the given substitute.