Namespaces
Variants

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

From cppreference.net

template < class ... Args >
iterator emplace ( Args && ... args ) ;
(自 C++23 起)
(自 C++26 起为 constexpr)

在容器中就地构造一个新元素并插入,使用给定的 args

First, initializes an object t of type value_type with std:: forward < Args > ( args ) ... , then inserts t as if by
auto it = ranges::upper_bound(c, t, compare);
c.insert(it, std::move(t));

此重载仅当 std:: is_constructible_v < value_type, Args... > true 时参与重载决议。

如果 value_type 不能通过 args 实现 EmplaceConstructible flat_multiset 中,则行为未定义。

目录

参数

args - 要转发给元素构造函数的参数

返回值

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

异常

若因任何原因抛出异常,此函数不产生任何效果( 强异常安全保证 )。

复杂度

与容器大小呈对数关系。

注释

谨慎使用 emplace 可以在构造新元素的同时避免不必要的复制或移动操作。

示例

参见

使用提示原位构造元素
(公开成员函数)
插入元素
(公开成员函数)