版权声明:本文为博主原创文章,博客地址:https://blog.csdn.net/qq_41855420,未经博主允许不得转载。 https://blog.csdn.net/qq_41855420/article/details/89765519
C++ multimap 容器
定义于头文件 <map>
,申明:
template< class Key, class T, class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T> >> class multimap;
multimap 是关联容器,含有关键-值 pair 的已排序列表,同时容许多个入口拥有同一关键。按照应用到关键的比较函数 Compare 排序。搜索、插入和移除操作拥有对数复杂度。
拥有等价关键的关键-值 pair 的顺序就是插入顺序,且不会更改。(C++11 起)
凡在标准库使用比较 (Compare) 概念出,都用描述于比较 (Compare) 上的等价关系确定等价性。不精确地说,若二个对象 a 和 b 互不小于对方: !comp(a, b) && !comp(b, a) ,则认为它们等价。
std::multimap 满足容器 (Container) 、具分配器容器 (AllocatorAwareContainer) 、关联容器 (AssociativeContainer) 和可逆容器 (ReversibleContainer) 的要求。
成员类型
成员类型 |
定义 |
key_type |
Key |
mapped_type |
T |
value_type |
std::pair<const Key, T> |
size_type |
无符号整数类型(通常是 std::size_t ) |
difference_type |
有符号整数类型(通常是 std::ptrdiff_t ) |
key_compare |
Compare |
allocator_type |
Allocator |
reference |
Allocator::reference (C++11 前) value_type& (C++11 起) |
const_reference |
Allocator::const_reference (C++11 前) const value_type& (C++11 起) |
pointer |
Allocator::pointer (C++11 前) std::allocator_traits::pointer (C++11 起) |
const_pointer |
Allocator::const_pointer (C++11 前) std::allocator_traits::const_pointer (C++11 起) |
iterator |
双向迭代器 (LegacyBidirectionalIterator) |
const_iterator |
常双向迭代器 |
reverse_iterator |
std::reverse_iterator |
const_reverse_iterator |
std::reverse_iterator<const_iterator> |
node_type(C++17 起) |
表示容器结点的结点把柄特化 |
成员类
|
|
value_compare |
比较类型为value_type的对象 (类) |
成员函数
|
|
(构造函数) |
构造 multimap (公开成员函数) |
(析构函数) |
析构 multimap (公开成员函数) |
operator= |
赋值给容器 (公开成员函数) |
get_allocator |
返回相关的分配器 (公开成员函数) |
迭代器
|
|
begin、cbegin |
返回指向容器第一个元素的迭代器 (公开成员函数) |
end、cend |
返回指向容器尾端的迭代器 (公开成员函数) |
rbegin、crbegin |
返回指向容器最后元素的逆向迭代器 (公开成员函数) |
rend、crend |
返回指向前端的逆向迭代器 (公开成员函数) |
容量
|
|
empty |
检查容器是否为空 (公开成员函数) |
size |
返回容纳的元素数 (公开成员函数) |
max_size |
返回可容纳的最大元素数 (公开成员函数) |
修改器
|
|
clear |
清除内容 (公开成员函数) |
insert |
插入元素或结点 (C++17 起) (公开成员函数) |
emplace(C++11) |
原位构造元素 (公开成员函数) |
emplace_hint (C++11) |
使用提示原位构造元素 (公开成员函数) |
erase 擦除元素 |
(公开成员函数) |
swap 交换内容 |
(公开成员函数) |
extract(C++17) |
从另一容器释出结点 (公开成员函数) |
merge (C++17) |
从另一容器接合结点 (公开成员函数) |
查找
|
|
count |
返回匹配特定键的元素数量 (公开成员函数) |
find |
寻找带有特定键的元素 (公开成员函数) |
contains(C++20) |
检查容器是否含有带特定关键的元素 (公开成员函数) |
equal_range |
返回匹配特定键的元素范围 (公开成员函数) |
lower_bound |
返回指向首个不小于给定键的元素的迭代器 (公开成员函数) |
upper_bound |
返回指向首个大于给定键的元素的迭代器 (公开成员函数) |
观察器
|
|
key_comp |
返回用于比较键的函数 (公开成员函数) |
value_comp |
返回用于在value_type类型的对象中比较键的函数。 (公开成员函数) |