命名空间
变体 (Variants)
视图 (Views)
操作 (Actions)

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

来自 cppreference.cn
< cpp‎ | utility‎ | 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 partial specialization
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 包含 unexpected 值,则销毁该值。

目录

[编辑] 参数 (Parameters)

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

[编辑] 返回值 (Return value)

[编辑] 注解 (Notes)

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

[编辑] 示例 (Example)

[编辑] 参见 (See also)

赋值内容
(公共成员函数) [编辑]