Optional values
Experimental
Collaboration diagram for Optional values:

## Classes

struct | std::experimental::fundamentals_v1::_Has_addressof< _Tp >
class | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >
class | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >
class | std::experimental::fundamentals_v1::bad_optional_access
struct | std::experimental::fundamentals_v1::in_place_t
struct | std::experimental::fundamentals_v1::nullopt_t
class | std::experimental::fundamentals_v1::optional< _Tp >

## Macros

#define | __cpp_lib_experimental_optional

## Typedefs

template<typename _Tp , typename _Up >
using | std::experimental::__assigns_from_optional = __or_< is_assignable< _Tp &, const optional< _Up > & >, is_assignable< _Tp &, optional< _Up > & >, is_assignable< _Tp &, const optional< _Up > && >, is_assignable< _Tp &, optional< _Up > && > >
template<typename _Tp , typename _Up >

using

std::experimental::__converts_from_optional = __or_< is_constructible< _Tp, const optional< _Up > & >, is_constructible< _Tp, optional< _Up > & >, is_constructible< _Tp, const optional< _Up > && >, is_constructible< _Tp, optional< _Up > && >, is_convertible< const optional< _Up > &, _Tp >, is_convertible< optional< _Up > &, _Tp >, is_convertible< const optional< _Up > &&, _Tp >, is_convertible< optional< _Up > &&, _Tp > >

using | std::hash< experimental::optional< _Tp > >::argument_type = experimental::optional< _Tp >
using | std::hash< experimental::optional< _Tp > >::result_type = size_t
using | std::experimental::fundamentals_v1::optional< _Tp >::value_type = _Tp

## Enumerations

enum | _Construct { _Token }

## Functions

| std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_Optional_base (_Optional_base &&__other) noexcept(is_nothrow_move_constructible< _Tp >())
| std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_Optional_base (_Optional_base &&__other) noexcept(is_nothrow_move_constructible< _Tp >())
| std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_Optional_base (const _Optional_base &__other)
| std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_Optional_base (const _Optional_base &__other)
template<typename... _Args>
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_Optional_base (in_place_t, _Args &&... __args)
template<typename... _Args>
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_Optional_base (in_place_t, _Args &&... __args)
template<typename _Up , typename... _Args, enable_if_t< is_constructible< _Tp, initializer_list< _Up > &, _Args &&... >::value, int > ...>
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_Optional_base (in_place_t, initializer_list< _Up > __il, _Args &&... __args)
template<typename _Up , typename... _Args, enable_if_t< is_constructible< _Tp, initializer_list< _Up > &, _Args &&... >::value, int > ...>
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_Optional_base (in_place_t, initializer_list< _Up > __il, _Args &&... __args)
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_Optional_base (nullopt_t) noexcept
constexpr | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_Optional_base (nullopt_t) noexcept
| std::experimental::fundamentals_v1::bad_optional_access::bad_optional_access (const char *__arg)
constexpr | std::experimental::fundamentals_v1::nullopt_t::nullopt_t (_Construct)
template<typename _Up = _Tp, enable_if_t< __and_< __not_< is_same< optional< _Tp >, decay_t< _Up >>>, is_constructible< _Tp, _Up && >, is_convertible< _Up &&, _Tp > >::value, bool > = true>
constexpr | std::experimental::fundamentals_v1::optional< _Tp >::optional (_Up &&__t)
template<typename _Up , enable_if_t< __and_< __not_< is_same< _Tp, _Up >>, is_constructible< _Tp, const _Up & >, is_convertible< const _Up &, _Tp >, __not_< __converts_from_optional< _Tp, _Up >> >::value, bool > = true>
constexpr | std::experimental::fundamentals_v1::optional< _Tp >::optional (const optional< _Up > &__t)
template<typename _Up , enable_if_t< __and_< __not_< is_same< _Tp, _Up >>, is_constructible< _Tp, _Up && >, is_convertible< _Up &&, _Tp >, __not_< __converts_from_optional< _Tp, _Up >> >::value, bool > = true>
constexpr | std::experimental::fundamentals_v1::optional< _Tp >::optional (optional< _Up > &&__t)
template<typename _Tp >
constexpr enable_if_t<!_Has_addressof< _Tp >::value, _Tp * > | std::experimental::__constexpr_addressof (_Tp &__t)
void | std::experimental::__throw_bad_optional_access (const char *) __attribute__((__noreturn__))
template<typename... _Args>
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_construct (_Args &&... __args) noexcept(is_nothrow_constructible< _Stored_type, _Args... >())
template<typename... _Args>
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_construct (_Args &&... __args) noexcept(is_nothrow_constructible< _Stored_type, _Args... >())
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_destruct ()
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_destruct ()
constexpr const _Tp & | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_get () const noexcept
constexpr const _Tp & | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_get () const noexcept
constexpr _Tp & | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_get () noexcept
_Tp & | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_get () noexcept
constexpr bool | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_is_engaged () const noexcept
constexpr bool | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_is_engaged () const noexcept
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_reset ()
void | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_reset ()
template<typename... _Args>
enable_if_t< is_constructible< _Tp, _Args &&... >::value > | std::experimental::fundamentals_v1::optional< _Tp >::emplace (_Args &&... __args)
template<typename _Up , typename... _Args>
enable_if_t< is_constructible< _Tp, initializer_list< _Up > &, _Args &&... >::value > | std::experimental::fundamentals_v1::optional< _Tp >::emplace (initializer_list< _Up > __il, _Args &&... __args)
template<typename _Tp >
constexpr optional< decay_t< _Tp > > | std::experimental::make_optional (_Tp &&__t)
constexpr | std::experimental::fundamentals_v1::optional< _Tp >::operator bool () const noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator!= (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator!= (const optional< _Tp > &__lhs, _Tp const &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator!= (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator!= (const optional< _Tp > &__lhs, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator!= (nullopt_t, const optional< _Tp > &__rhs) noexcept
size_t | std::hash< experimental::optional< _Tp > >::operator() (const experimental::optional< _Tp > &__t) const noexcept(noexcept(hash< _Tp > {}(*__t)))
constexpr _Tp & | std::experimental::fundamentals_v1::optional< _Tp >::operator* () &
constexpr _Tp && | std::experimental::fundamentals_v1::optional< _Tp >::operator* () &&
constexpr const _Tp & | std::experimental::fundamentals_v1::optional< _Tp >::operator* () const &
constexpr const _Tp && | std::experimental::fundamentals_v1::optional< _Tp >::operator* () const &&
_Tp * | std::experimental::fundamentals_v1::optional< _Tp >::operator-> ()
constexpr const _Tp * | std::experimental::fundamentals_v1::optional< _Tp >::operator-> () const
template<typename _Tp >
constexpr bool | std::experimental::operator< (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator< (const optional< _Tp > &, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator< (const optional< _Tp > &__lhs, const _Tp &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator< (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator< (nullopt_t, const optional< _Tp > &__rhs) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator<= (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator<= (const optional< _Tp > &__lhs, const _Tp &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator<= (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator<= (const optional< _Tp > &__lhs, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator<= (nullopt_t, const optional< _Tp > &) noexcept
_Optional_base & | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::operator= (_Optional_base &&__other) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>())
_Optional_base & | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::operator= (_Optional_base &&__other) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>())
template<typename _Up = _Tp>
enable_if_t< __and_< __not_< is_same< optional< _Tp >, decay_t< _Up > > >, is_constructible< _Tp, _Up >, __not_< __and_< is_scalar< _Tp >, is_same< _Tp, decay_t< _Up > > > >, is_assignable< _Tp &, _Up > >::value, optional & > | std::experimental::fundamentals_v1::optional< _Tp >::operator= (_Up &&__u)
_Optional_base & | std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::operator= (const _Optional_base &__other)
_Optional_base & | std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::operator= (const _Optional_base &__other)
template<typename _Up >
enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, const _Up & >, is_assignable< _Tp &, _Up >, __not_< __converts_from_optional< _Tp, _Up > >, __not_< __assigns_from_optional< _Tp, _Up > > >::value, optional & > | std::experimental::fundamentals_v1::optional< _Tp >::operator= (const optional< _Up > &__u)
optional & | std::experimental::fundamentals_v1::optional< _Tp >::operator= (nullopt_t) noexcept
template<typename _Up >
enable_if_t< __and_< __not_< is_same< _Tp, _Up > >, is_constructible< _Tp, _Up >, is_assignable< _Tp &, _Up >, __not_< __converts_from_optional< _Tp, _Up > >, __not_< __assigns_from_optional< _Tp, _Up > > >::value, optional & > | std::experimental::fundamentals_v1::optional< _Tp >::operator= (optional< _Up > &&__u)
template<typename _Tp >
constexpr bool | std::experimental::operator== (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator== (const optional< _Tp > &__lhs, const _Tp &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator== (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator== (const optional< _Tp > &__lhs, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator== (nullopt_t, const optional< _Tp > &__rhs) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator> (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator> (const optional< _Tp > &__lhs, const _Tp &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator> (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator> (const optional< _Tp > &__lhs, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator> (nullopt_t, const optional< _Tp > &) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator>= (const _Tp &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator>= (const optional< _Tp > &, nullopt_t) noexcept
template<typename _Tp >
constexpr bool | std::experimental::operator>= (const optional< _Tp > &__lhs, const _Tp &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator>= (const optional< _Tp > &__lhs, const optional< _Tp > &__rhs)
template<typename _Tp >
constexpr bool | std::experimental::operator>= (nullopt_t, const optional< _Tp > &__rhs) noexcept
void | std::experimental::fundamentals_v1::optional< _Tp >::swap (optional &__other) noexcept(is_nothrow_move_constructible< _Tp >() &&noexcept(swap(declval< _Tp & >(), declval< _Tp & >())))
template<typename _Tp >
void | std::experimental::swap (optional< _Tp > &__lhs, optional< _Tp > &__rhs) noexcept(noexcept(__lhs.swap(__rhs)))
constexpr _Tp & | std::experimental::fundamentals_v1::optional< _Tp >::value () &
constexpr _Tp && | std::experimental::fundamentals_v1::optional< _Tp >::value () &&
constexpr const _Tp & | std::experimental::fundamentals_v1::optional< _Tp >::value () const &
constexpr const _Tp && | std::experimental::fundamentals_v1::optional< _Tp >::value () const &&
template<typename _Up >
_Tp | std::experimental::fundamentals_v1::optional< _Tp >::value_or (_Up &&__u) &&
template<typename _Up >
constexpr _Tp | std::experimental::fundamentals_v1::optional< _Tp >::value_or (_Up &&__u) const &

## Variables

_Empty_byte std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_empty
_Empty_byte std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_empty
_Stored_type std::experimental::fundamentals_v1::_Optional_base< _Tp, _ShouldProvideDestructor >::_M_payload
_Stored_type std::experimental::fundamentals_v1::_Optional_base< _Tp, false >::_M_payload
constexpr in_place_t | std::experimental::in_place
constexpr nullopt_t | std::experimental::nullopt

## Detailed Description

Class template for optional values and surrounding facilities, as described in n3793 "A proposal to add a utility class to represent optional objects (Revision 5)".

## Function Documentation

## __constexpr_addressof()

template<typename _Tp >

constexpr enable_if_t<!_Has_addressof<_Tp>::value, _Tp*> std::experimental::fundamentals_v1::__constexpr_addressof | ( | _Tp & | __t | ) |

constexpr

An overload that attempts to take the address of an lvalue as a constant expression. Falls back to __addressof in the presence of an overloaded addressof operator (unary operator&), in which case the call will not be a constant expression.

Definition at line 175 of file optional.

## Variable Documentation

## in_place

constexpr in_place_t std::experimental::fundamentals_v1::in_place

constexpr

Tag for in-place construction.

Definition at line 88 of file optional.

## nullopt

constexpr nullopt_t std::experimental::fundamentals_v1::nullopt

constexpr

Tag to disengage optional objects.

Definition at line 107 of file optional.