std::experimental::optional<T>::operator->, std::experimental::optional<T>::operator*

Technical specifications
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
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


[edit] Parameters


[edit] Return value

Pointer or reference to the contained value.

[edit] Exceptions

Throws nothing.

[edit] Notes

This operator does not check whether the optional contains a value. If checked access is needed, value() or value_or() may be used.

[edit] Example

#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';



[edit] See also

returns the contained value
(public member function) [edit]
returns the contained value if available, another value otherwise
(public member function) [edit]