名稱空間
變體
操作

std::flat_multiset<Key,Compare,KeyContainer>::emplace

來自 cppreference.com
 
 
 
 
template< class... Args >
iterator emplace( Args&&... args );
(C++23 起)

使用給定的 args 在容器中就地構造新元素。

首先,使用 std::forward<Args>(args)... 初始化一個型別為 value_type 的物件 t,然後插入 t,如同透過
auto it = ranges::upper_bound(c, t, compare);
c.insert(it, std::move(t));

此過載僅在 std::is_constructible_v<value_type, Args...>true 時參與過載決議。

謹慎使用 emplace 允許構造新元素,同時避免不必要的複製或移動操作。

目錄

[編輯] 引數

args - 轉發給元素建構函式的引數

[編輯] 返回值

指向已插入元素的迭代器。

[編輯] 異常

如果由於任何原因丟擲異常,此函式無效果(強異常安全保證)。

[編輯] 複雜度

容器大小的對數級別。

[編輯] 示例

[編輯] 參閱

使用提示就地構造元素
(public member function) [編輯]
插入元素
(public member function) [編輯]