std::any::emplace (3) - Linux Man Pages

std::any::emplace: std::any::emplace

NAME

std::any::emplace - std::any::emplace

Synopsis


template< class ValueType, class... Args > (1) (since C++17)
std::decay_t<ValueType>& emplace( Args&&... args );
template< class ValueType, class U, class... Args > (2) (since C++17)
std::decay_t<ValueType>& emplace( std::initializer_list<U> il, Args&&... args );


Changes the contained object to one of type std::decay_t<ValueType> constructed from the arguments.
First destroys the current contained object (if any) by reset(), then:
1) constructs an object of type std::decay_t<ValueType>, direct-non-list-initialized from std::forward<Args>(args)..., as the contained object. This overload only participates in overload resolution if std::is_constructible_v<std::decay_t<ValueType>, Args...> and std::is_copy_constructible_v<std::decay_t<ValueType>> are both true.
2) constructs an object of type std::decay_t<ValueType>, direct-non-list-initialized from il, std::forward<Args>(args)..., as the contained object. This overload only participates in overload resolution if std::is_constructible_v<std::decay_t<ValueType>, std::initializer_list<U>&, Args...> and std::is_copy_constructible_v<std::decay_t<ValueType>> are both true.

Template parameters


ValueType - contained value type

Type requirements


-
std::decay_t<ValueType> must meet the requirements of CopyConstructible.

Return value


A reference to the new contained object.

Exceptions


Throws any exception thrown by T's constructor. If an exception is thrown, the previously contained object (if any) has been destroyed, and *this does not contain a value.

Example


 This section is incomplete
 Reason: no example

See also


              constructs an any object
constructor (public member function)
              destroys contained object
reset (public member function)