std::optional<T>::value (3) - Linux Manuals
std::optional<T>::value: std::optional<T>::value
NAME
std::optional<T>::value - std::optional<T>::value
Synopsis
constexpr T& value() &; (1) (since C++17)
constexpr const T & value() const &;
constexpr T&& value() &&; (2) (since C++17)
constexpr const T&& value() const &&;
If *this contains a value, returns a reference to the contained value.
Otherwise, throws a std::bad_optional_access exception.
Parameters
(none)
Return value
A reference to the contained value.
Exceptions
std::bad_optional_access if *this does not contain a value.
Notes
The dereference operator operator*() does not check if this optional contains a value, which may be more efficient than value().
Example
// Run this code
Possible output:
See also
value_or (public member function)
operator-> (public member function)
operator*
bad_optional_access exception indicating checked access to an optional that doesn't contain a value
(C++17)