std::optional::emplace (3) Linux Manual Page
std::optional<T>::emplace – std::optional<T>::emplace
Synopsis
template< class... Args > (since C++17)
T& emplace( Args&&... args );
template< class U, class... Args > (since C++17)
T& emplace( std::initializer_list<U> ilist, Args&&... args );
Constructs the contained value in-place. If *this already contains a value before the call, the contained value is destroyed by calling its destructor.
1) Initializes the contained value by direct-initializing (but not direct-list-initializing) with std::forward<Args>(args)… as parameters.
2) Initializes the contained value by calling its constructor with ilist, std::forward<Args>(args)… as parameters. This overload only participates in overload resolution if std::is_constructible<T, std::initializer_list<U>&, Args&&…>::value is true.
Parameters
args… – the arguments to pass to the constructor
ilist – the initializer list to pass to the constructor
Type requirements
–
T must be constructible from Args… for overload (1)
–
T must be constructible from std::initializer_list and Args… for overload (2)
Return value
A reference to the new contained value.
Exceptions
Any exception thrown by the selected constructor of T. If an exception is thrown, *this does not contain a value after this call (the previously contained value, if any, had been destroyed).
See also
assigns contents
operator= (public member function)
