std::optional<T>::operator->,std::optional<T>::operator* (3) - Linux Manuals
std::optional<T>::operator->,std::optional<T>::operator*: std::optional<T>::operator->,std::optional<T>::operator*
NAME
std::optional<T>::operator->,std::optional<T>::operator* - std::optional<T>::operator->,std::optional<T>::operator*
Synopsis
constexpr const T* operator->() const; (1) (since C++17)
constexpr T* operator->(); (1) (since C++17)
constexpr const T& operator*() const&; (2) (since C++17)
constexpr T& operator*() &; (2) (since C++17)
constexpr const T&& operator*() const&&; (2) (since C++17)
constexpr T&& operator*() &&; (2) (since C++17)
Accesses the contained value.
1) Returns a pointer to the contained value.
2) Returns a reference to the contained value.
The behavior is undefined if *this does not contain a value.
Parameters
(none)
Return value
Pointer or reference to the contained value.
Exceptions
(none)
Notes
This operator does not check whether the optional contains a value! You can do so manually by using has_value() or simply operator_bool(). Alternatively, if checked access is needed, value() or value_or() may be used.
Example
// Run this code
Output:
See also
value (public member function)
value_or (public member function)