Skip to content

Engine → Core → result.h

result

Syntax

template <typename ValueType> class [[nodiscard]] result

Constructors

AccessSignatureDescription
publicresult( const ValueType &value);
publicresult( ValueType &&value) noexcept(std::is_nothrow_move_constructible_v<ValueType>);
publicresult( error failure) noexcept;
publicresult( const result &) = default;
publicresult( result &&) noexcept = default;

Destructors

AccessSignatureDescription
public~result() = default;

Variables

AccessNameTypeDefaultDescription
privatemStoragestd::variant<ValueType, error>—

Functions

Public

get_error

[[nodiscard]] const error &get_error() const & noexcept;

The held error. Calling this on a value result is a fatal programmer error.

[[nodiscard]] error &&get_error() && noexcept;

has_value

[[nodiscard]] bool has_value() const noexcept;

True when this result holds a value rather than an error.

value

[[nodiscard]] ValueType &value() & noexcept;

The held value. Calling this on an error result is a fatal programmer error.

[[nodiscard]] const ValueType &value() const & noexcept;
[[nodiscard]] ValueType &&value() && noexcept;

value_or

template <typename FallbackType> [[nodiscard]] ValueType value_or(
    FallbackType &&fallback) const &;

The value, or fallback when this result holds an error.

template <typename FallbackType> [[nodiscard]] ValueType value_or(
    FallbackType &&fallback) &&;

Operator Overloads

Public

operator bool

[[nodiscard]] explicit operator bool() const noexcept;

operator*

[[nodiscard]] ValueType &operator*() & noexcept;
[[nodiscard]] const ValueType &operator*() const & noexcept;
[[nodiscard]] ValueType &&operator*() && noexcept;

operator->

[[nodiscard]] ValueType *operator->() noexcept;
[[nodiscard]] const ValueType *operator->() const noexcept;

operator=

result &operator=(
    const result &) = default;
result &operator=(
    result &&) noexcept = default;