std::map
Defined in header <map> | ? | ? |
---|---|---|
template< class Key, class T, class Compare = std::less<Key>, class Allocator = std::allocator<std::pair<const Key, T> > > class map; | (1) | ? |
namespace pmr { template <class Key, class T, class Compare = std::less<Key>> using map = std::map<Key, T, Compare, std::pmr::polymorphic_allocator<std::pair<const Key,T>>> } | (2) | (since C++17) |
std::map
是一个排序关联容器,它包含具有唯一键的键值对。通过使用比较函数对键进行排序。Compare
搜索、删除和插入操作具有对数复杂度。映射通常实现为红黑树...
标准库在任何地方使用Compare
概念、唯一性是利用等价关系来确定的。用不精确的术语来说,有两个对象a
和b
如果两者都没有比其他的要小,则视为等效%28不唯一%29:!comp(a, b) &&?!comp(b, a)
...
std::map
满足…的要求Container
,,,AllocatorAwareContainer
,,,AssociativeContainer
和ReversibleContainer
...
成员类型
Member type | Definition | ||||
---|---|---|---|---|---|
key_type | Key | ||||
mapped_type | T | ||||
value_type | std::pair<const Key, T> | ||||
size_type | Unsigned integer type (usually std::size_t) | ||||
difference_type | Signed integer type (usually std::ptrdiff_t) | ||||
key_compare | Compare | ||||
allocator_type | Allocator | ||||
reference | Allocator::reference (until C++11) value_type& (since C++11) | Allocator::reference | (until C++11) | value_type& | (since C++11) |
Allocator::reference | (until C++11) | ||||
value_type& | (since C++11) | ||||
const_reference | Allocator::const_reference (until C++11) const value_type& (since C++11) | Allocator::const_reference | (until C++11) | const value_type& | (since C++11) |
Allocator::const_reference | (until C++11) | ||||
const value_type& | (since C++11) | ||||
pointer | Allocator::pointer (until C++11) std::allocator_traits<Allocator>::pointer (since C++11) | Allocator::pointer | (until C++11) | std::allocator_traits<Allocator>::pointer | (since C++11) |
Allocator::pointer | (until C++11) | ||||
std::allocator_traits<Allocator>::pointer | (since C++11) | ||||
const_pointer | Allocator::const_pointer (until C++11) std::allocator_traits<Allocator>::const_pointer (since C++11) | Allocator::const_pointer | (until C++11) | std::allocator_traits<Allocator>::const_pointer | (since C++11) |
Allocator::const_pointer | (until C++11) | ||||
std::allocator_traits<Allocator>::const_pointer | (since C++11) | ||||
iterator | BidirectionalIterator | ||||
const_iterator | Constant bidirectional iterator | ||||
reverse_iterator | std::reverse_iterator<iterator> | ||||
const_reverse_iterator | std::reverse_iterator<const_iterator> | ||||
node_type | a specialization of node handle representing a container node (since C++17) | ||||
insert_return_type | type describing the result of inserting a node_type, a specialization of template <class Iterator, class NodeType> struct /*unspecified*/ { Iterator position; bool inserted; NodeType node; }; instantiated with template arguments iterator and node_type. (since C++17) |
成员类
value_compare | compares objects of type value_type (class) |
---|
成员函数
(constructor) | constructs the map (public member function) |
---|---|
(destructor) | destructs the map (public member function) |
operator= | assigns values to the container (public member function) |
get_allocator | returns the associated allocator (public member function) |
元素存取
在%28C++11%29访问指定元素中,边界检查%28公共成员函数%29
操作者。[]访问指定元素%28公共成员函数%29
迭代器
BEGINCBEGIN将迭代器返回到开头%28的公共成员函数%29
End cend将迭代器返回到End%28公共成员函数%29
将反向迭代器返回到开头%28的公共成员函数%29
rend crend将反向迭代器返回到End%28公共成员函数%29
容量
空检查容器是否为空%28公共成员函数%29
Size返回元素数%28公共成员函数%29
马克斯[医]Size返回元素的最大可能数%28公共成员函数%29
修饰符
清除内容%28公共成员功能%29
插入元素或节点%28,因为C++17%29%28公共成员函数%29
插入[医]或[医]如果键已经存在,则指定%28C++17%29插入一个元素或分配给当前元素
嵌入%28C++11%29构造元素就地%28公共成员函数%29
座落[医]提示%28C++11%29使用提示%28公共成员函数%29就地构造元素
试一试[医]嵌入%28C++17%29如果密钥不存在,则插入就地;如果密钥存在%28公共成员函数%29,则不执行任何操作。
擦除元素%28公共成员函数%29
交换交换内容%28公共成员函数%29
提取%28C++17%29从容器中提取节点%28公共成员函数%29
从另一个容器合并%28C++17%29个连接节点%28公共成员函数%29
查找
Count返回匹配特定键的元素数%28公共成员函数%29
查找具有特定密钥%28公共成员函数%29的查找元素
平等[医]范围返回匹配特定键%28公共成员函数%29的元素的范围
较低[医]绑定将迭代器返回给第一个元素,不少于给定的键%28公共成员函数%29。
上层[医]绑定将迭代器返回给大于给定键%28公共成员函数%29的第一个元素。
观察员
键[医]COMP返回比较键%28公共成员函数%29的函数
价值[医]COMP返回比较值类型对象中键的函数。[医]类型%28公共成员功能%29
非会员职能
operator==operator!=operator<operator<=operator>operator>= | lexicographically compares the values in the map (function template) |
---|---|
std::swap(std::map) | specializes the std::swap algorithm (function template) |
? cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com