名稱空間
變體
操作

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

來自 cppreference.com
< 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) [編輯]