std::experimental::optional<T>::optional
Min standard notice:
Constructs a new optional object.
# Declarations
constexpr optional() noexcept;
constexpr optional( std::experimental::nullopt_t ) noexcept;
(library fundamentals TS)
optional( const optional& other );
(library fundamentals TS)
optional( optional&& other ) noexcept(/* see below */);
(library fundamentals TS)
constexpr optional( const T& value );
(library fundamentals TS)
constexpr optional( T&& value );
(library fundamentals TS)
template< class... Args >
constexpr explicit optional( std::experimental::in_place_t, Args&&... args );
(library fundamentals TS)
template< class U, class... Args >
constexpr explicit optional( std::experimental::in_place_t,
std::initializer_list<U> ilist,
Args&&... args );
(library fundamentals TS)
# Parameters
other: another optional object whose contained value to copyvalue: value to initialize the contained value withargs...: arguments to initialize the contained value withilist: initializer list to initialize the contained value with
# Example
#include <experimental/optional>
#include <iostream>
#include <string>
int main()
{
std::experimental::optional<int> o1, // empty
o2 = 1, // init from rvalue
o3 = o2; // copy-constructor
std::experimental::optional<std::string> o4(std::experimental::in_place,
{'a', 'b', 'c'});
std::cout << *o2 << ' ' << *o3 << ' ' << *o4 << '\n';
}