std::map<Key,T,Compare,Allocator>::merge
来自cppreference.com
template< class C2 > void merge( std::map<Key, T, C2, Allocator>& source ); |
(1) | (C++17 起) (C++26 起为 constexpr) |
template< class C2 > void merge( std::map<Key, T, C2, Allocator>&& source ); |
(2) | (C++17 起) (C++26 起为 constexpr) |
template< class C2 > void merge( std::multimap<Key, T, C2, Allocator>& source ); |
(3) | (C++17 起) (C++26 起为 constexpr) |
template< class C2 > void merge( std::multimap<Key, T, C2, Allocator>&& source ); |
(4) | (C++17 起) (C++26 起为 constexpr) |
尝试提取(“接合”)source 中的每个元素,并用 *this 的比较对象插入到 *this。 如果 *this 中有元素的键等价于来自 source 中某元素的键,那么就不会从 source 提取该元素。 如果 get_allocator() == source.get_allocator() 是 false,那么行为未定义。
不复制或移动元素,只会重指向容器节点的内部指针。指向被转移元素的所有指针和引用保持有效,但现在指代到 *this 中而非到 source 中。
目录 |
[编辑] 参数
source | - | 传递节点来源的兼容容器 |
异常
不抛异常,除非比较操作有抛出。
[编辑] 复杂度
给定 S 为 size(),N 为 source.size():
1-4) S·log(S+N)
[编辑] 示例
运行此代码
#include <iostream> #include <map> #include <string> int main() { std::map<int, std::string> ma{{1, "apple"}, {5, "pear"}, {10, "banana"}}; std::map<int, std::string> mb{{2, "zorro"}, {4, "batman"}, {5, "X"}, {8, "alpaca"}};