std::experimental::optional::optional - cppreference.com (original) (raw)
| constexpr optional() noexcept; constexpr optional( std::experimental::nullopt_t ) noexcept; | (1) | (library fundamentals TS) |
|---|---|---|
| optional( const optional& other ); | (2) | (library fundamentals TS) |
| optional( optional&& other ) noexcept(/* see below */); | (3) | (library fundamentals TS) |
| constexpr optional( const T& value ); | (4) | (library fundamentals TS) |
| constexpr optional( T&& value ); | (5) | (library fundamentals TS) |
| template< class... Args > constexpr explicit optional( std::experimental::in_place_t, Args&&... args ); | (6) | (library fundamentals TS) |
| template< class U, class... Args > constexpr explicit optional( std::experimental::in_place_t, std::initializer_list<U> ilist, Args&&... args ); | (7) | (library fundamentals TS) |
Constructs a new optional object.
Constructs the object that does not contain a value.
Copy constructor: If other contains a value, initializes the contained value as if direct-initializing (but not direct-list-initializing) an object of type
Twith the expression *other. If other does not contain a value, constructs an object that does not contain a value.Move constructor: If other contains a value, initializes the contained value as if direct-initializing (but not direct-list-initializing) an object of type
Twith the expression std::move(*other) and does not make other empty: a moved-from optional still contains a value, but the value itself is moved from. If other does not contain a value, constructs an object that does not contain a value.Constructs an optional object that contains a value, initialized as if direct-initializing (but not direct-list-initializing) an object of type
Twith the expression value. This constructor isconstexprif the constructor ofTselected by direct-initialization isconstexpr.Constructs an optional object that contains a value, initialized as if direct-initializing (but not direct-list-initializing) an object of type
Twith the expression std::move(value). This constructor isconstexprif the constructor ofTselected by direct-initialization isconstexpr.Constructs an optional object that contains a value, initialized as if direct-initializing (but not direct-list-initializing) an object of type
Tfrom the arguments std::forward<Args>(args)....Constructs an optional object that contains a value, initialized as if direct-initializing (but not direct-list-initializing) an object of type
Tfrom the arguments ilist, std::forward<Args>(args).... The function does not participate in the overload resolution if std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value != true.
[edit] Parameters
| other | - | another optional object whose contained value to copy |
|---|---|---|
| value | - | value to initialize the contained value with |
| args... | - | arguments to initialize the contained value with |
| ilist | - | initializer list to initialize the contained value with |
| Type requirements | ||
| -T must meet the requirements of CopyConstructible in order to use overloads (2,4). | ||
| -T must meet the requirements of MoveConstructible in order to use overloads (3,5). |
[edit] Exceptions
Throws any exception thrown by the constructor of
T.Throws any exception thrown by the constructor of
T. Has the followingnoexceptdeclaration:
4-7) Throws any exception thrown by the constructor of T.