命名空间
变体
操作

std::expected<T,E>::emplace

来自 cppreference.cn
< cpp‎ | 工具库‎ | expected
 
 
 
 
主模板
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 起)

在适当位置构造一个 expected 值。调用后,has_value() 返回 true。

1) 销毁包含的值,然后使用 std::forward<Args>(args)... 直接初始化 *this 中包含的 expected 值。
此重载仅当 std::is_nothrow_constructible_v<T, Args...>true 时参与重载决议。
2) 销毁包含的值,然后使用 ilstd::forward<Args>(args)... 直接初始化 *this 中包含的 expected 值。
此重载仅当 std::is_nothrow_constructible_v<T, std::initializer_list<U>&, Args...>true 时参与重载决议。
3) 如果 *this 包含一个非预期值,则销毁该值。

目录

[编辑] 参数

args - 要传递给构造函数的参数
il - 要传递给构造函数的初始化列表

[编辑] 返回值

[编辑] 注意

如果 T 的构造可能抛出异常,则可以使用 operator= 代替。

[编辑] 示例

[编辑] 参阅

赋值内容
(public member function) [编辑]