std::optional::optional
From cppreference.com
constexpr optional(); |
(1) | (since C++14) |
constexpr optional( std::nullopt_t ); |
(1) | (since C++14) |
optional( const optional& other); |
(2) | (since C++14) |
optional( optional&& other ); |
(3) | (since C++14) |
constexpr optional( const T& value ); |
(4) | (since C++14) |
constexpr optional( T&& value ); |
(5) | (since C++14) |
template< class... Args > constexpr explicit optional( std::in_place_t, Args&&... args ); |
(6) | (since C++14) |
template< class U, class... Args > constexpr explicit optional( std::in_place_t, std::initializer_list<U> ilist, |
(7) | (since C++14) |
Constructs a new optional
object.
1) Constructs the object without initializing the contained value. The object is in disengaged state after the call.
2-3) Initializes the contained value by copying (2) or moving(3) the contained value of
other
, but only if other
is engaged. other
is still in engaged state if it was in engaged state before the call.4-7) Initializes the contained value from various sources. *this is in engaged state after the call.
4) Initializes the contained value by copying
value
.5) Initializes the contained value by moving
value
.6) Initializes the contained value by constructing it in-place and passing
args...
to the constructor.7) Initializes the contained value by constructing it in-place and passing the initializer list
ilist
and arguments args...
to the constructor. 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
1)
2) Throws any exception thrown by the constructor of
T
.3) Throws any exception thrown by the constructor of
T
. Has the following noexcept
declaration: .4-5) Throws any exception thrown by the constructor of
T
.[edit] See also
creates an optional object (function template) |