Namespaces
Variants

std::optional

From cppreference.com
Revision as of 04:16, 1 June 2013 by P12bot (talk | contribs) (Shorten template names. Use {{lc}} where appropriate.)
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
 
Defined in header <optional>
template< class T >
class optional;
(since C++14)

The class template optional manages an optional contained value. The value may be in either initialized or uninitialized state during the lifetime of the optional object. The class manages the initialization state of the contained value and its lifetime. The value is guaranteed to be allocated within the optional object itself, i.e. no dynamic memory allocation ever takes place.

The optional object is in initialized state on the following conditions:

  • The object is initialized with a value of type T
  • The object is assigned an optional in initialized state.

The object is in uninitialized state on the following conditions:

  • The object is default-initialized.
  • The object is initialized with a value of std::nullopt_t or a optional object in uninitialized state.
  • The object is assigned a value of std::nullopt_t or a optional object in uninitialized state.

Template parameters

T - the type of the value to manage initialization state for. The type must meet the requirements of Template:concept

Member types

Member type Definition
value_type T

Member functions

Template:cpp/utility/optional/dcl list constructorTemplate:cpp/utility/optional/dcl list destructorTemplate:cpp/utility/optional/dcl list operator=Template:cpp/utility/optional/dcl list operator*Template:cpp/utility/optional/dcl list operator boolTemplate:cpp/utility/optional/dcl list valueTemplate:cpp/utility/optional/dcl list value orTemplate:cpp/utility/optional/dcl list swapTemplate:cpp/utility/optional/dcl list emplace
Observers
Modifiers

Non-member functions

Template:cpp/utility/optional/dcl list operator cmpTemplate:cpp/utility/optional/dcl list make optionalTemplate:cpp/utility/optional/dcl list swap2

Helper classes

Template:cpp/utility/optional/dcl list hash