std::experimental::optional<T>::value (3) - Linux Manuals
std::experimental::optional<T>::value: std::experimental::optional<T>::value
Command to display std::experimental::optional<T>::value
manual in Linux: $ man 3 std::experimental::optional<T>::value
NAME
std::experimental::optional<T>::value - std::experimental::optional<T>::value
Synopsis
constexpr T& value() &; (1) (library fundamentals TS)
constexpr const T & value() const &;
constexpr T&& value() &&; (2) (library fundamentals TS)
constexpr const T&& value() const &&;
Returns the contained value.
1) Equivalent to return bool(*this) ? *val : throw bad_optional_access();
2) Equivalent to return bool(*this) ? std::move(*val) : throw bad_optional_access();
Parameters
(none)
Return value
A reference to the contained value.
Exceptions
std::experimental::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
#include <experimental/optional>
#include <iostream>
int main()
{
std::experimental::optional<int> opt = {};
try {
int n = opt.value();
} catch(const std::logic_error& e) {
std::cout << e.what() << '\n';
}
}
Possible output:
optional<T>::value: not engaged
See also
returns the contained value if available, another value otherwise
value_or (public member function)
accesses the contained value
operator-> (public member function)
operator*
bad_optional_access exception indicating checked access to an optional that doesn't contain a value
(class)
(library fundamentals TS)
Pages related to std::experimental::optional<T>::value
- std::experimental::optional<T>::value_or (3) - std::experimental::optional<T>::value_or
- std::experimental::optional<T>::emplace (3) - std::experimental::optional<T>::emplace
- std::experimental::optional<T>::operator->,std::experimental::optional<T>::operator* (3) - 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>::swap (3) - std::experimental::optional<T>::swap
- 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