Standard library header <map>
From cppreference.net
此头文件是 容器 库的组成部分。
包含文件 |
||
|
(C++20)
|
三路比较运算符支持 | |
|
(C++11)
|
std::initializer_list 类模板 | |
类 |
||
|
按键排序的键值对集合,键唯一
(类模板) |
||
|
按键排序的键值对集合
(类模板) |
||
函数 |
||
|
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20)
|
按字典序比较两个
map
的值
(函数模板) |
|
|
特化
std::swap
算法
(函数模板) |
||
|
(C++20)
|
擦除所有满足特定条件的元素
(函数模板) |
|
|
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20 中移除)
(C++20)
|
按字典序比较两个
multimap
的值
(函数模板) |
|
|
特化
std::swap
算法
(函数模板) |
||
|
(C++20)
|
擦除所有满足特定条件的元素
(函数模板) |
|
范围访问 |
||
|
(C++11)
(C++14)
|
返回指向容器或数组起始的迭代器
(函数模板) |
|
|
(C++11)
(C++14)
|
返回指向容器或数组末尾的迭代器
(函数模板) |
|
|
(C++14)
|
返回指向容器或数组起始的反向迭代器
(函数模板) |
|
|
(C++14)
|
返回指向容器或数组末尾的反向迭代器
(函数模板) |
|
|
(C++17)
(C++20)
|
返回容器或数组的大小 < | |
概要
#include <compare> #include <initializer_list> namespace std { // 类模板 map template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T>>> class map; template<class Key, class T, class Compare, class Allocator> bool operator==(const map<Key, T, Compare, Allocator>& x, const map<Key, T, Compare, Allocator>& y); template<class Key, class T, class Compare, class Allocator> /*synth-three-way-result*/<pair<const Key, T>> operator<=>( const map<Key, T, Compare, Allocator>& x, const map<Key, T, Compare, Allocator>& y); template<class Key, class T, class Compare, class Allocator> void swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y) noexcept(noexcept(x.swap(y))); // map 的擦除操作 template<class Key, class T, class Compare, class Allocator, class Predicate> typename map<Key, T, Compare, Allocator>::size_type erase_if( map<Key, T, Compare, Allocator>& c, Predicate pred); // 类模板 multimap template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T>>> class multimap; template<class Key, class T, class Compare, class Allocator> bool operator==(const multimap<Key, T, Compare, Allocator>& x, const multimap<Key, T, Compare, Allocator>& y); template<class Key, class T, class Compare, class Allocator> /*synth-three-way-result*/<pair<const Key, T>> operator<=>( const multimap<Key, T, Compare, Allocator>& x, const multimap<Key, T, Compare, Allocator>& y); template<class Key, class T, class Compare, class Allocator> void swap(multimap<Key, T, Compare, Allocator>& x, multimap<Key, T, Compare, Allocator>& y) noexcept(noexcept(x.swap(y))); // multimap 的擦除操作 template<class Key, class T, class Compare, class Allocator, class Predicate> typename multimap<Key, T, Compare, Allocator>::size_type erase_if( multimap<Key, T, Compare, Allocator>& c, Predicate pred); namespace pmr { template<class Key, class T, class Compare = less<Key>> using map = std::map<Key, T, Compare, polymorphic_allocator<pair<const Key, T>>>; template<class Key, class T, class Compare = less<Key>> using multimap = std::multimap<Key, T, Compare, polymorphic_allocator<pair<const Key, T>>>; } }
类模板 std::map
namespace std { template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T>>> class map { public: // 类型定义 using key_type = Key; using mapped_type = T; using value_type = pair<const Key, T>; using key_compare = Compare; using allocator_type = Allocator; using pointer = typename allocator_traits<Allocator>::pointer; using const_pointer = typename allocator_traits<Allocator>::const_pointer; using reference = value_type&; using const_reference = const value_type&; using size_type = /* 实现定义 */; using difference_type = /* 实现定义 */; using iterator = /* 实现定义 */; using const_iterator = /* 实现定义 */; using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>; using node_type = /* 未指定 */; using insert_return_type = /*插入返回类型*/<iterator, node_type>; class value_compare { protected: Compare comp; value_compare(Compare c) : comp(c) { } public: bool operator()(const value_type& x, const value_type& y) const { return comp(x.first, y.first); } }; // 构造/复制/销毁 map() : map(Compare()) { } explicit map(const Compare& comp, const Allocator& = Allocator()); template<class InputIter> map(InputIter first, InputIter last, const Compare& comp = Compare(), const Allocator& = Allocator()); template<container-compatible-range<value_type> R> map(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); map(const map& x); map(map&& x); explicit map(const Allocator&); map(const map&, const type_identity_t<Allocator>&); map(map&&, const type_identity_t<Allocator>&); map(initializer_list<value_type>, const Compare& = Compare(), const Allocator& = Allocator()); template<class InputIter> map(InputIter first, InputIter last, const Allocator& a) : map(first, last, Compare(), a) { } template<container-compatible-range<value_type> R> map(from_range_t, R&& rg, const Allocator& a)) : map(from_range, std::forward<R>(rg), Compare(), a) { } map(initializer_list<value_type> il, const Allocator& a) : map(il, Compare(), a) { } ~map(); map& operator=(const map& x); map& operator=(map&& x) noexcept(allocator_traits<Allocator>::is_always_equal::value&& is_nothrow_move_assignable_v<Compare>); map& operator=(initializer_list<value_type>); allocator_type get_allocator() const noexcept; // 迭代器 iterator begin() noexcept; const_iterator begin() const noexcept; iterator end()</
类模板 std::multimap
namespace std { template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T>>> class multimap { public: // 类型定义 using key_type = Key; using mapped_type = T; using value_type = pair<const Key, T>; using key_compare = Compare; using allocator_type = Allocator; using pointer = typename allocator_traits<Allocator>::pointer; using const_pointer = typename allocator_traits<Allocator>::const_pointer; using reference = value_type&; using const_reference = const value_type&; using size_type = /* 实现定义 */; using difference_type = /* 实现定义 */; using iterator = /* 实现定义 */; using const_iterator = /* 实现定义 */; using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>; using node_type = /* 未指定 */; class value_compare { protected: Compare comp; value_compare(Compare c) : comp(c) { } public: bool operator()(const value_type& x, const value_type& y) const { return comp(x.first, y.first); } }; // 构造/复制/销毁 multimap() : multimap(Compare()) { } explicit multimap(const Compare& comp, const Allocator& = Allocator()); template<class InputIter> multimap(InputIter first, InputIter last, const Compare& comp = Compare(), const Allocator& = Allocator()); template<container-compatible-range<value_type> R> multimap(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); multimap(const multimap& x); multimap(multimap&& x); explicit multimap(const Allocator&); multimap(const multimap&, const type_identity_t<Allocator>&); multimap(multimap&&, const type_identity_t<Allocator>&); multimap(initializer_list<value_type>, const Compare& = Compare(), const Allocator& = Allocator()); template<class InputIter> multimap(InputIter first, InputIter last, const Allocator& a) : multimap(first, last, Compare(), a) { } template<container-compatible-range<value_type> R> multimap(from_range_t, R&& rg, const Allocator& a)) : multimap(from_range, std::forward<R>(rg), Compare(), a) { } multimap(initializer_list<value_type> il, const Allocator& a) : multimap(il, Compare(), a) { } ~multimap(); multimap& operator=(const multimap& x); multimap& operator=(multimap&& x) noexcept( allocator_traits<Allocator>::is_always_equal::value&& is_nothrow_move_assignable_v<Compare>); multimap& operator=(initializer_list<value_type>); allocator_type get_allocator() const noexcept; // 迭代器 iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end()</
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时的行为 | 正确行为 |
|---|---|---|---|
| LWG 133 | C++98 | map::get_allocator 在概要中缺失 | 已添加 |