Template Class Result< void, E >

Class Documentation

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
  • E: The type of the error

Public 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.

Result(Result<void, E> &&other)

Move constructor.

Parameters
  • other: The other result object, rvalue ref

template<typename E2>
Result(E2 error) noexcept

Constructor from error.

This implicitly requires E2 to be convertible to E.

Template Parameters
  • E2: The type of the actual error

Parameters
  • error: The instance of the actual error

E &error() & noexcept

Returns a reference to the error stored in the result.

Note

If res.ok() this method will abort (noexcept)

Return

Reference to the error

E error() && noexcept

Returns the error by-value.

Note

If res.ok() this method will abort (noexcept)

Return

Reference to the error

bool ok() const noexcept

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

Return

bool Whether result contains an error or not.

Result<void, E> &operator=(const Result<void, E> &other) = default

The (self) assignment operator is deleted.

Result<void, E> &operator=(Result<void, E> &&other) noexcept

Move assignment operator.

Parameters
  • other: The other result object, rvalue ref

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

Assignment operator from an error.

Return

The assigned instance

Template Parameters
  • E2: The type of the actual error

Parameters
  • error: The instance of the actual error

Public Static Functions

Result<void, E> failure(E error)

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

Return

Result object, in error state.

Parameters
  • error: The errorr to initialize with.

Result<void, E> success()

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

Return

Result object, in ok state