std::expected<T,E>:: emplace
From cppreference.net
|
主模板
|
||
|
template
<
class
...
Args
>
constexpr T & emplace ( Args && ... args ) noexcept ; |
(1) | (自 C++23 起) |
|
template
<
class
U,
class
...
Args
>
constexpr T & emplace ( std:: initializer_list < U > il, Args && ... args ) noexcept ; |
(2) | (自 C++23 起) |
|
void
部分特化
|
||
|
constexpr
void
emplace
(
)
noexcept
;
|
(3) | (自 C++23 起) |
构造一个期望值的原位构造版本。调用后,
has_value()
将返回 true。
此重载仅当
std::
is_nothrow_constructible_v
<
T,
std::
initializer_list
<
U
>
&
, Args...
>
为
true
时参与重载决议。
3)
若
*
this
包含意外值,则销毁该值。
目录 |
参数
| args | - | 传递给构造函数的参数 |
| il | - | 传递给构造函数的初始化列表 |
返回值
1)
*
std::
construct_at
(
std::
addressof
(
val
)
,
std::
forward
<
Args
>
(
args
)
...
)
2)
*
std::
construct_at
(
std::
addressof
(
val
)
, il,
std::
forward
<
Args
>
(
args
)
...
)
注释
如果
T
的构造可能抛出异常,可以使用
operator=
作为替代方案。
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
赋值内容
(公开成员函数) |