std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator* (3) - Linux Manuals
std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*: std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*
Command to display std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*
manual in Linux: $ man 3 std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*
NAME
std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator* - std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*
Synopsis
constexpr const T* operator->() const; (1) (library fundamentals TS)
constexpr T* operator->(); (1) (library fundamentals TS)
constexpr const T& operator*() const&; (2) (library fundamentals TS)
constexpr T& operator*() &; (2) (library fundamentals TS)
constexpr const T&& operator*() const&&; (2) (library fundamentals TS)
constexpr T&& operator*() &&; (2) (library fundamentals TS)
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. If checked access is needed, value() or value_or() may be used.
Example
// Run this code
#include <experimental/optional>
#include <iostream>
#include <string>
using namespace std::literals;
int main()
{
std::experimental::optional<int> opt1 = 1;
std::cout << *opt1 << '\n';
std::experimental::optional<std::string> opt2 = "abc"s;
std::cout << opt2->size() << '\n';
}
Output:
1
3
See also
returns the contained value
value (public member function)
returns the contained value if available, another value otherwise
value_or (public member function)
Pages related to std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator*
- std::experimental::optional<T>::operator= (3) - std::experimental::optional<T>::operator=
- std::experimental::optional<T>::operatorbool (3) - std::experimental::optional<T>::operatorbool
- std::experimental::optional<T>::optional (3) - std::experimental::optional<T>::optional
- std::experimental::optional<T>::emplace (3) - std::experimental::optional<T>::emplace
- std::experimental::optional<T>::swap (3) - std::experimental::optional<T>::swap
- std::experimental::optional<T>::value (3) - std::experimental::optional<T>::value
- std::experimental::optional<T>::value_or (3) - std::experimental::optional<T>::value_or
- std::experimental::optional<T>::~optional (3) - std::experimental::optional<T>::~optional
- std::experimental::optional (3) - std::experimental::optional
- std::experimental::observer_ptr (3) - std::experimental::observer_ptr
- std::experimental::observer_ptr<W>::get (3) - std::experimental::observer_ptr<W>::get
- std::experimental::observer_ptr<W>::observer_ptr (3) - std::experimental::observer_ptr<W>::observer_ptr
- std::experimental::observer_ptr<W>::operator*, (3) - std::experimental::observer_ptr<W>::operator*,
- std::experimental::observer_ptr<W>::operator*,std::experimental::observer_ptr<W>::operator-> (3) - std::experimental::observer_ptr<W>::operator*,std::experimental::observer_ptr<W>::operator->
- std::experimental::observer_ptr<W>::operatorbool (3) - std::experimental::observer_ptr<W>::operatorbool
- std::experimental::observer_ptr<W>::operatorelement_type* (3) - std::experimental::observer_ptr<W>::operatorelement_type*
- std::experimental::observer_ptr<W>::release (3) - std::experimental::observer_ptr<W>::release
- std::experimental::observer_ptr<W>::reset (3) - std::experimental::observer_ptr<W>::reset
- std::experimental::observer_ptr<W>::swap (3) - std::experimental::observer_ptr<W>::swap
- std::experimental::ostream_joiner (3) - std::experimental::ostream_joiner
- std::experimental::ostream_joiner<DelimT,CharT,Traits>::operator++ (3) - std::experimental::ostream_joiner<DelimT,CharT,Traits>::operator++
- std::experimental::ostream_joiner<DelimT,CharT,Traits>::operator= (3) - std::experimental::ostream_joiner<DelimT,CharT,Traits>::operator=
- std::experimental::ostream_joiner<DelimT,CharT,Traits>::ostream_joiner (3) - std::experimental::ostream_joiner<DelimT,CharT,Traits>::ostream_joiner
- std::experimental::overaligned_tag,std::experimental::overaligned (3) - std::experimental::overaligned_tag,std::experimental::overaligned