Class Acts::Result< void, E >

template<typename E>
class 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.

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

Move constructor.

Parameters

other – The other result object, rvalue ref

template<typename E2>
inline 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

inline 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

inline E error() && noexcept

Returns the error by-value.

Note

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

Returns

Reference to the error

inline bool ok() const noexcept

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

Returns

bool Whether result contains an error or not.

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

The (self) assignment operator is deleted.

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

Move assignment operator.

Parameters

other – The other result object, rvalue ref

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

Assignment operator from an error.

Template Parameters

E2 – The type of the actual error

Parameters

error – The instance of the actual error

Returns

The assigned instance

Public Static Functions

static inline Result<void, E> failure(E error)

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

Parameters

error – The errorr to initialize with.

Returns

Result object, in error state.

static inline Result<void, E> success()

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

Returns

Result object, in ok state