- map
- (constructor)
- ~map
- operator=
- Iterators
- begin,rbegin,cbegin,crbegin
- end,rend,cend,crend
- Capacity
- empty
- size
- max_size
- Element access
- operator[]
- at(C++11)
- Modifiers
- insert
- erase
- swap
- clear
- emplace
- emplace_hint
- Observers
- key_comp
- value_comp
- Operations
- find
- count
- lower_bound
- upper_bound
- equal_range
- Allocator
- get_allocator
搜索、移除和插入操作具有对数复杂度。
通常被实现为红黑树或二叉搜索树
map 容器通常比 unordered_map 容器通过它们的键访问单个元素慢,但它们允许根据它们的顺序直接迭代子集。
map 容器中的 value_type 是 pair
empty (1) explicit map (const key_compare& comp = key_compare(),const allocator_type& alloc = allocator_type()); explicit map (const allocator_type& alloc); range (2) template~mapmap (InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const allocator_type& = allocator_type()); copy (3) map (const map& x); map (const map& x, const allocator_type& alloc); move (4) map (map&& x); map (map&& x, const allocator_type& alloc); initializer list (5) map (initializer_list il, const key_compare& comp = key_compare(), const allocator_type& alloc = allocator_type());
~map();operator=
新内容分配给容器,替换其当前内容
copy (1) map& operator= (const map& x); move (2) map& operator= (map&& x); initializer list (3) map& operator= (initializer_listIterators begin,rbegin,cbegin,crbegin end,rend,cend,crend Capacity emptyil);
bool empty() const noexcept;size
size_type size() const noexcept;max_size
size_type max_size() const noexcept;Element access operator[]
匹配则返回对应值引用,不匹配则插入新元素并返回对应映射值(值若无指定则是默认构造函数赋值)的引用。
mapped_type& operator[] (const key_type& k); mapped_type& operator[] (key_type&& k);at(C++11)
不匹配时与operator[]有相同的行为,只不过不匹配时会抛出异常。
mapped_type& at (const key_type& k); const mapped_type& at (const key_type& k) const;Modifiers insert
如果插入元素的键已存在则不插入,并返回现有元素的迭代器。
single element (1) paireraseinsert (const value_type& val); template pair insert (P&& val); with hint (2) iterator insert (const_iterator position, const value_type& val); template iterator insert (const_iterator position, P&& val); range (3) template void insert (InputIterator first, InputIterator last); initializer list (4) void insert (initializer_list il);
删除单个元素或一系列元素 [first,last)(左闭右开)
(1) iterator erase (const_iterator position); (2) size_type erase (const key_type& k); (3) iterator erase (const_iterator first, const_iterator last);swap
void swap (map& x);clear
void clear() noexcept;emplace
templateemplace_hintpair emplace (Args&&... args);
templateObservers key_compiterator emplace_hint (const_iterator position, Args&&... args);
key_compare key_comp() const;value_comp
value_compare value_comp() const;Operations find
找不到返回map::end
iterator find (const key_type& k); const_iterator find (const key_type& k) const;count
统计键相等的元素数量,由于键唯一所以只能是1和0
size_type count (const key_type& k) const;lower_bound
同set
iterator lower_bound (const key_type& k); const_iterator lower_bound (const key_type& k) const;upper_bound
同set
iterator upper_bound (const key_type& k); const_iterator upper_bound (const key_type& k) const;equal_range
同set
pairAllocator get_allocatorequal_range (const key_type& k) const; pair equal_range (const key_type& k);
allocator_type get_allocator() const noexcept;



