20 General utilities library [utilities]

20.6 Optional objects [optional]

20.6.3 Class template optional [optional.optional]

20.6.3.5 Observers [optional.observe]

constexpr const T* operator->() const; constexpr T* operator->();
Preconditions: *this contains a value.
Returns: val.
Throws: Nothing.
Remarks: These functions are constexpr functions.
constexpr const T& operator*() const&; constexpr T& operator*() &;
Preconditions: *this contains a value.
Returns: *val.
Throws: Nothing.
Remarks: These functions are constexpr functions.
constexpr T&& operator*() &&; constexpr const T&& operator*() const&&;
Preconditions: *this contains a value.
Effects: Equivalent to: return std​::​move(*val);
constexpr explicit operator bool() const noexcept;
Returns: true if and only if *this contains a value.
Remarks: This function is a constexpr function.
constexpr bool has_value() const noexcept;
Returns: true if and only if *this contains a value.
Remarks: This function is a constexpr function.
constexpr const T& value() const&; constexpr T& value() &;
Effects: Equivalent to:
return bool(*this) ? *val : throw bad_optional_access();
constexpr T&& value() &&; constexpr const T&& value() const&&;
Effects: Equivalent to:
return bool(*this) ? std::move(*val) : throw bad_optional_access();
template<class U> constexpr T value_or(U&& v) const&;
Mandates: is_­copy_­constructible_­v<T> && is_­convertible_­v<U&&, T> is true.
Effects: Equivalent to:
return bool(*this) ? **this : static_cast<T>(std::forward<U>(v));
template<class U> constexpr T value_or(U&& v) &&;
Mandates: is_­move_­constructible_­v<T> && is_­convertible_­v<U&&, T> is true.
Effects: Equivalent to:
return bool(*this) ? std::move(**this) : static_cast<T>(std::forward<U>(v));