template<typename T>
cubos::core::memory::Opt class

Wrapper for reference types to indicate that the given argument type is optional.

Template parameters
T Argument type.

Constructors, destructors, conversion operators

Opt()
Constructs without a value.
Opt(T value)
Constructs with a value.
Opt(const Opt<T>& other)
Copy constructor.
operator bool() const
Checks if the optional contains a value.
template<typename U = T>
requires(requires(const U&a, const U&b) { a==b;}) bool operator
Compares with another optional value.

Public functions

void replace(T value)
Moves the given value into the optional, destroying any previously stored value.
void reset()
Destroys the value, if any.
auto contains() const -> bool
Checks if the optional contains a value.
auto value() -> T&
Gets the underlying value.
auto value() const -> const T&
Gets the underlying value.
auto operator*() -> T&
Gets the underlying value.
auto operator->() -> T*
Gets the underlying value.

Function documentation

template<typename T>
cubos::core::memory::Opt<T>::Opt(T value)

Constructs with a value.

Parameters
value Value.

template<typename T>
cubos::core::memory::Opt<T>::Opt(const Opt<T>& other)

Copy constructor.

Parameters
other Other optional.

template<typename T>
cubos::core::memory::Opt<T>::operator bool() const

Checks if the optional contains a value.

Returns Whether the optional contains a value.

template<typename T> template<typename U = T>
cubos::core::memory::Opt<T>::requires(requires(const U&a, const U&b) { a==b;}) bool operator

Compares with another optional value.

Returns Whether they're equal.

template<typename T>
void cubos::core::memory::Opt<T>::replace(T value)

Moves the given value into the optional, destroying any previously stored value.

Parameters
value Value.

template<typename T>
bool cubos::core::memory::Opt<T>::contains() const

Checks if the optional contains a value.

Returns Whether the optional contains a value.

template<typename T>
T& cubos::core::memory::Opt<T>::value()

Gets the underlying value.

Returns Reference to value.

Aborts if there's no value.

template<typename T>
const T& cubos::core::memory::Opt<T>::value() const

Gets the underlying value.

Returns Reference to value.

Aborts if there's no value.

template<typename T>
T& cubos::core::memory::Opt<T>::operator*()

Gets the underlying value.

Returns Reference to value.

Aborts if there's no value.

template<typename T>
T* cubos::core::memory::Opt<T>::operator->()

Gets the underlying value.

Returns Reference to value.

Aborts if there's no value.