Optional type¶
-
template<typename
T
>
classoptional
¶ An optional object that may or may not contain a value.
-
constexpr
optional
() 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
-
constexpr
-
template<typename
T
, typenameU
>
constexpr booloperator==
(optional<T> const &lhs, optional<U> const &rhs) noexcept¶
-
template<typename
T
>
constexpr booloperator==
(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.