Optional type

class none_t

The unit type of the none constant.

constexpr none_t none

A constant used to create empty optional objects.

template<typename T>
class optional

An optional object that may or may not contain a value.

constexpr optional() noexcept

Creates a new empty optional object.

constexpr optional(none_t) noexcept

Creates a new empty optional object.

constexpr optional(T t) noexcept

Creates a new optional object.

Parameters:t – the value of the new optional object
constexpr T operator*() const noexcept
Requires:this optional isn’t empty.
Returns:the value of this optional.
explicit constexpr operator bool() const noexcept
Returns:true if this optional has a value; false if it’s empty.

Note

This feature is only available when compiling with C++17 support.

constexpr optional(std::optional<T> o) noexcept

Creates a new optional from a std::optional.

Parameters:o – the source
Returns:an optional with the same value as o
constexpr operator std::optional<T>() const noexcept

Converts an optional to std::optional.

Returns:a std::optional with the same value as this optional

Note

This feature is only available if the OGONEK_USE_BOOST macro is set.

constexpr optional(boost::optional<T> o) noexcept

Creates a new optional from a boost::optional.

Parameters:o – the source
Returns:an optional with the same value as o
constexpr operator boost::optional<T>() const noexcept

Converts an optional to boost::optional.

Returns:a boost::optional with the same value as this optional
template<typename T, typename U>
constexpr bool operator==(optional<T> const &lhs, optional<U> const &rhs) noexcept
template<typename T>
constexpr bool operator==(optional<T> const &lhs, T const &rhs) noexcept
template<typename T>
constexpr bool operator==(T const &lhs, optional<T> const &rhs) noexcept
template<typename T>
constexpr bool operator==(optional<T> const &lhs, none_t) noexcept
template<typename T>
constexpr bool operator==(none_t, optional<T> const &rhs) noexcept

Compares optional for equality.

Returns:true if both sides have the same value, or if neither side has a value; false otherwise.
template<typename T, typename U>
constexpr bool operator!=(optional<T> const &lhs, optional<U> const &rhs) noexcept
template<typename T>
constexpr bool operator!=(optional<T> const &lhs, T const &rhs) noexcept
template<typename T>
constexpr bool operator!=(T const &lhs, optional<T> const &rhs) noexcept
template<typename T>
constexpr bool operator!=(optional<T> const &lhs, none_t) noexcept
template<typename T>
constexpr bool operator!=(none_t, optional<T> const &rhs) noexcept

Compares optional for inequality.

Returns:!(lhs == rhs)