std::multiset<Key,Compare,Allocator>::insert_range
来自 cppreference.cn
template< container-compatible-range<value_type> R > void insert_range( R&& rg ); |
(C++23 起) | |
插入范围 rg 中每个元素的副本。
范围 rg 中的每个迭代器都恰好解引用一次。如果 rg 与容器重叠,则行为未定义。
迭代器或引用均未失效。
目录 |
[编辑] 参数
rg | - | 一个 容器兼容范围 (container compatible range),即一个其元素可转换为 T 的 input_range 。 |
类型要求 | ||
-value_type 必须能够从 *ranges::begin(rg) EmplaceConstructible 到 multiset 中。否则,行为未定义。 |
[编辑] 返回值
(无)
[编辑] 复杂度
N·log(a.size() + N),其中 N
是 ranges::distance(rg)。
[编辑] 注意
特性测试宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知(Ranges-aware)构造和插入 |
[编辑] 示例
运行此代码
#include <iostream> #include <set> void println(auto, auto const& container) { for (const auto& elem : container) std::cout << elem << ' '; std::cout << '\n'; } int main() { auto container = std::multiset{1, 3, 2, 4}; const auto rg = {-1, 3, -2}; #ifdef __cpp_lib_containers_ranges container.insert_range(rg); #else container.insert(rg.begin(), rg.end()); #endif println("{}", container); }
输出
-2 -1 1 2 3 3 4
[编辑] 另请参阅
插入元素 或节点(C++17 起) (public member function) |