A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../ranges/../utility/optional/value.html below:

std::optional<T>::value - cppreference.com

constexpr T& value() &;
constexpr const T& value() const &;

(1) (since C++17)

constexpr T&& value() &&;
constexpr const T&& value() const &&;

(2) (since C++17)

If *this contains a value, returns a reference to the contained value.

Otherwise, throws a std::bad_optional_access exception.

[edit] Parameters

(none)

[edit] Return value

A reference to the contained value.

[edit] Exceptions

std::bad_optional_access if *this does not contain a value.

[edit] Notes

The dereference operator operator*() does not check if this optional contains a value, which may be more efficient than value().

[edit] Example

Output:

bad optional access
bad optional access
43
44
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4