首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::optional::emplace

template< class... Args > T& emplace( Args&&... args );

?

(since C++17)

template< class U, class... Args > T& emplace( std::initializer_list<U> ilist, Args&&... args );

?

(since C++17)

构造就地包含的值。如果*this在调用之前已经包含了一个值,所包含的值将通过调用其析构函数来销毁。

1%29将包含的值初始化为直接初始化%28但不是直接列表-使用std::forward<Args>(args)...作为参数。

2%29通过调用包含的值的构造函数来初始化包含的值。ilist,std::forward<Args>(args)...作为参数。此重载只参与在下列情况下的重载解决方案:std::is_constructible<T,std::initializer_list<U>&, Args&&...>::valuetrue...

参数

args...

-

the arguments to pass to the constructor

ilist

-

the initializer list to pass to the constructor

类型要求

-T必须是由ARGS构成的...

-T必须是可从STD::初始化器构造的[医]名单和ARGS..。

返回值

对新包含值的引用。

例外

对象的选定构造函数引发的任何异常。T如果抛出异常,*this在此调用%28之后不包含值,以前包含的值(如果有的话)已被销毁%29。

另见

operator=

assigns contents (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com