C++ Reference: Standard C++ Library reference: Containers: map: multimap

C++官网参考链接:https://cplusplus.com/reference/map/multimap/

类模板 
<map>
std::multimap
template < class Key,// multimap::key_type           
class T,// multimap::mapped_type           
class Compare = less<Key>,// multimap::key_compare           
class Alloc = allocator<pair<const Key,T> >// multimap::allocator_type
> class multimap;
multimap
multimap是关联容器,它存储由键值和映射值按特定顺序组合而成的元素,其中多个元素可以具有等价的键。
在multimap中,键值通常用于对元素进行排序和唯一标识,而映射值存储与此键相关的内容。键和映射值的类型可能不同,并被分组在成员类型value_type中,这是一个组合了两者的pair类型: 
typedef pair<const Key, T> value_type;
在内部,multimap中的元素总是按其键排序,并遵循由其内部比较对象(comparison object)(类型Compare)指示的特定严格弱排序标准。
在按键访问单个元素时,multimap容器通常比unordered_multimap容器慢,但它们允许基于顺序对子集进行直接迭代。
multimap通常实现为二叉搜索树。

容器的属性
有关联的
关联容器中的元素是通过它们的键来引用的,而不是通过它们在容器中的绝对位置。
有顺序的 
容器中的元素始终遵循严格的顺序。所有插入的元素都按此顺序给出一个位置。
映射 
每个元素都将一个键与映射值关联:键用于标识其主要内容为映射值的元素。
多个等价键
容器中的多个元素可以具有等价的键。
能够感知的allocator 
容器使用allocator对象动态处理其存储需求。

模板形参 
Key 
键的类型。映射中的每个元素都由其键值标识。
别名为成员类型multimap::key_type。
T
映射值的类型。multimap中的每个元素都存储一些数据作为其映射值。
别名为成员类型multimap::mapped_type。
Compare
一个二元谓词,接受两个元素键作为实参并返回bool值。表达式comp(a,b),其中comp是这种类型的对象,a和b是元素键,如果按照函数定义的严格弱顺序,a被认为在b之前,则返回true。
multimap对象使用这个表达式来确定元素在容器中的顺序以及两个元素键是否等价(通过条件反射式比较:if(!comp(a,b) && !comp(b,a)))。
这可以是函数指针或函数对象(参见构造函数(constructor)的示例)。它默认为less<T>,返回的结果与应用less-than操作符(a<b)相同。
别名为成员类型multimap::key_compare。
Alloc
用于定义存储分配模型的allocator对象的类型。默认情况下,使用allocator类模板,它定义了最简单的内存分配模型,并且与值无关。
别名为成员类型multimap::allocator_type。

成员类型

C++98

member typedefinitionnotes
key_typeThe first template parameter (Key)
mapped_typeThe second template parameter (T)
value_typepair<const key_type,mapped_type>
key_compareThe third template parameter (Compare)defaults to: less<key_type>
value_compareNested function class to compare elementssee value_comp
allocator_typeThe fourth template parameter (Alloc)defaults to: allocator<value_type>
referenceallocator_type::referencefor the default allocator: value_type&
const_referenceallocator_type::const_referencefor the default allocator: const value_type&
pointerallocator_type::pointerfor the default allocator: value_type*
const_pointerallocator_type::const_pointerfor the default allocator: const value_type*
iteratorbidirectional iterator to value_typeconvertible to const_iterator
const_iteratorbidirectional iterator to const value_type
reverse_iteratorreverse_iterator<iterator>
const_reverse_iteratorreverse_iterator<const_iterator>
difference_typea signed integral type, identical to: iterator_traits<iterator>::difference_typeusually the same as ptrdiff_t
size_typean unsigned integral type that can represent any non-negative value of difference_typeusually the same as size_t

C++11

member typedefinitionnotes
key_typeThe first template parameter (Key)
mapped_typeThe second template parameter (T)
value_typepair<const key_type,mapped_type>
key_compareThe third template parameter (Compare)defaults to: less<key_type>
value_compareNested function class to compare elementssee value_comp
allocator_typeThe fourth template parameter (Alloc)defaults to: allocator<value_type>
referencevalue_type&
const_referenceconst value_type&
pointerallocator_traits<allocator_type>::pointerfor the default allocator: value_type*
const_pointerallocator_traits<allocator_type>::const_pointerfor the default allocator: const value_type*
iteratorbidirectional iterator to value_typeconvertible to const_iterator
const_iteratorbidirectional iterator to const value_type
reverse_iteratorreverse_iterator<iterator>
const_reverse_iteratorreverse_iterator<const_iterator>
difference_typea signed integral type, identical to:
iterator_traits<iterator>::difference_type
usually the same as ptrdiff_t
size_typean unsigned integral type that can represent any non-negative value of difference_typeusually the same as size_t

成员函数 
(constructor)    Construct multimap (public member function)
(destructor)    Multimap destructor (public member function)
operator=    Copy container content (public member function)

iterator: 
begin    Return iterator to beginning (public member function)
end    Return iterator to end (public member function)
rbegin    Return reverse iterator to reverse beginning (public member function)
rend    Return reverse iterator to reverse end (public member function)
cbegin    Return const_iterator to beginning (public member function)
cend    Return const_iterator to end (public member function)
crbegin    Return const_reverse_iterator to reverse beginning (public member function)
crend    Return const_reverse_iterator to reverse end (public member function)

容量: 
empty    Test whether container is empty (public member function)
size    Return container size (public member function)
max_size    Return maximum size (public member function)

修改器: 
insert    Insert element (public member function)
erase    Erase elements (public member function)
swap    Swap content (public member function)
clear    Clear content (public member function)
emplace    Construct and insert element (public member function)
emplace_hint    Construct and insert element with hint (public member function)

观测器: 
key_comp    Return key comparison object (public member function)
value_comp    Return value comparison object (public member function)

操作: 
find    Get iterator to element (public member function)
count    Count elements with a specific key (public member function)
lower_bound    Return iterator to lower bound (public member function)
upper_bound    Return iterator to upper bound (public member function)
equal_range    Get range of equal elements (public member function)

allocator: 
get_allocator    Get allocator (public member function) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值