std::expected<T,E>::emplace
来自 cppreference.cn
主模板 |
||
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。
仅当 std::is_nothrow_constructible_v<T, Args...> 为 true 时,此重载才参与重载决议。
仅当 std::is_nothrow_constructible_v<T, std::initializer_list<U>&, Args...> 为 true 时,此重载才参与重载决议。
3) 如果 *this 包含 unexpected 值,则销毁该值。
目录 |
[编辑] 参数 (Parameters)
args | - | 传递给构造函数的参数 |
il | - | 传递给构造函数的初始化器列表 |
[编辑] 返回值 (Return value)
1) *std::construct_at(std::addressof(
val
), std::forward<Args>(args)...)2) *std::construct_at(std::addressof(
val
), il, std::forward<Args>(args)...)[编辑] 注解 (Notes)
如果 T
的构造可能抛出异常,则可以使用 operator=
代替。
[编辑] 示例 (Example)
本节不完整 原因:没有示例 |
[编辑] 参见 (See also)
赋值内容 (公共成员函数) |