56 #ifndef _STL_MULTIMAP_H 57 #define _STL_MULTIMAP_H 1 60 #if __cplusplus >= 201103L 64 namespace std _GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
95 template <
typename _Key,
typename _Tp,
101 typedef _Key key_type;
102 typedef _Tp mapped_type;
104 typedef _Compare key_compare;
105 typedef _Alloc allocator_type;
108 #ifdef _GLIBCXX_CONCEPT_CHECKS 110 typedef typename _Alloc::value_type _Alloc_value_type;
111 # if __cplusplus < 201103L 112 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
114 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
115 _BinaryFunctionConcept)
116 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
123 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
127 value_compare(_Compare __c)
131 bool operator()(
const value_type& __x,
const value_type& __y)
const 132 {
return comp(__x.first, __y.first); }
138 rebind<value_type>::other _Pair_alloc_type;
140 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
141 key_compare, _Pair_alloc_type> _Rep_type;
150 typedef typename _Alloc_traits::pointer pointer;
151 typedef typename _Alloc_traits::const_pointer const_pointer;
152 typedef typename _Alloc_traits::reference reference;
153 typedef typename _Alloc_traits::const_reference const_reference;
154 typedef typename _Rep_type::iterator iterator;
155 typedef typename _Rep_type::const_iterator const_iterator;
156 typedef typename _Rep_type::size_type size_type;
157 typedef typename _Rep_type::difference_type difference_type;
158 typedef typename _Rep_type::reverse_iterator reverse_iterator;
159 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
161 #if __cplusplus > 201402L 162 using node_type =
typename _Rep_type::node_type;
171 #if __cplusplus < 201103L 184 const allocator_type& __a = allocator_type())
185 : _M_t(__comp, _Pair_alloc_type(__a)) { }
192 #if __cplusplus < 201103L 218 const _Compare& __comp = _Compare(),
219 const allocator_type& __a = allocator_type())
220 : _M_t(__comp, _Pair_alloc_type(__a))
221 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
226 : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
230 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
234 noexcept(is_nothrow_copy_constructible<_Compare>::value
235 && _Alloc_traits::_S_always_equal())
236 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
240 : _M_t(_Compare(), _Pair_alloc_type(__a))
241 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
244 template<
typename _InputIterator>
245 multimap(_InputIterator __first, _InputIterator __last,
246 const allocator_type& __a)
247 : _M_t(_Compare(), _Pair_alloc_type(__a))
248 { _M_t._M_insert_equal(__first, __last); }
260 template<
typename _InputIterator>
261 multimap(_InputIterator __first, _InputIterator __last)
263 { _M_t._M_insert_equal(__first, __last); }
276 template<
typename _InputIterator>
277 multimap(_InputIterator __first, _InputIterator __last,
278 const _Compare& __comp,
279 const allocator_type& __a = allocator_type())
280 : _M_t(__comp, _Pair_alloc_type(__a))
281 { _M_t._M_insert_equal(__first, __last); }
283 #if __cplusplus >= 201103L 297 #if __cplusplus < 201103L 326 _M_t._M_assign_equal(__l.begin(), __l.end());
334 {
return allocator_type(_M_t.get_allocator()); }
344 {
return _M_t.begin(); }
353 {
return _M_t.begin(); }
362 {
return _M_t.end(); }
370 end() const _GLIBCXX_NOEXCEPT
371 {
return _M_t.end(); }
380 {
return _M_t.rbegin(); }
387 const_reverse_iterator
389 {
return _M_t.rbegin(); }
398 {
return _M_t.rend(); }
405 const_reverse_iterator
407 {
return _M_t.rend(); }
409 #if __cplusplus >= 201103L 417 {
return _M_t.begin(); }
426 {
return _M_t.end(); }
433 const_reverse_iterator
435 {
return _M_t.rbegin(); }
442 const_reverse_iterator
444 {
return _M_t.rend(); }
451 {
return _M_t.empty(); }
456 {
return _M_t.size(); }
461 {
return _M_t.max_size(); }
464 #if __cplusplus >= 201103L 481 template<
typename... _Args>
484 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
508 template<
typename... _Args>
512 return _M_t._M_emplace_hint_equal(__pos,
513 std::forward<_Args>(__args)...);
531 {
return _M_t._M_insert_equal(__x); }
533 #if __cplusplus >= 201103L 534 template<
typename _Pair,
typename =
typename 535 std::enable_if<std::is_constructible<value_type,
536 _Pair&&>::value>::type>
539 {
return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
563 #if __cplusplus >= 201103L 564 insert(const_iterator __position,
const value_type& __x)
566 insert(iterator __position,
const value_type& __x)
568 {
return _M_t._M_insert_equal_(__position, __x); }
570 #if __cplusplus >= 201103L 571 template<
typename _Pair,
typename =
typename 572 std::enable_if<std::is_constructible<value_type,
573 _Pair&&>::value>::type>
575 insert(const_iterator __position, _Pair&& __x)
576 {
return _M_t._M_insert_equal_(__position,
577 std::forward<_Pair>(__x)); }
589 template<
typename _InputIterator>
591 insert(_InputIterator __first, _InputIterator __last)
592 { _M_t._M_insert_equal(__first, __last); }
594 #if __cplusplus >= 201103L 604 { this->
insert(__l.begin(), __l.end()); }
607 #if __cplusplus > 201402L 610 extract(const_iterator __pos)
612 __glibcxx_assert(__pos !=
end());
613 return _M_t.extract(__pos);
618 extract(
const key_type& __x)
619 {
return _M_t.extract(__x); }
624 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
628 insert(const_iterator __hint, node_type&& __nh)
629 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
631 template<
typename,
typename>
632 friend class _Rb_tree_merge_helper;
634 template<
typename _C2>
638 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
639 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
642 template<
typename _C2>
647 template<
typename _C2>
651 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
652 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
655 template<
typename _C2>
661 #if __cplusplus >= 201103L 681 {
return _M_t.erase(__position); }
684 _GLIBCXX_ABI_TAG_CXX11
687 {
return _M_t.erase(__position); }
701 erase(iterator __position)
702 { _M_t.erase(__position); }
718 {
return _M_t.erase(__x); }
720 #if __cplusplus >= 201103L 738 erase(const_iterator __first, const_iterator __last)
739 {
return _M_t.erase(__first, __last); }
757 erase(iterator __first, iterator __last)
758 { _M_t.erase(__first, __last); }
776 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
777 { _M_t.swap(__x._M_t); }
796 {
return _M_t.key_comp(); }
804 {
return value_compare(_M_t.key_comp()); }
822 {
return _M_t.find(__x); }
824 #if __cplusplus > 201103L 825 template<
typename _Kt>
827 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
828 {
return _M_t._M_find_tr(__x); }
845 find(
const key_type& __x)
const 846 {
return _M_t.find(__x); }
848 #if __cplusplus > 201103L 849 template<
typename _Kt>
851 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
852 {
return _M_t._M_find_tr(__x); }
864 {
return _M_t.count(__x); }
866 #if __cplusplus > 201103L 867 template<
typename _Kt>
869 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
870 {
return _M_t._M_count_tr(__x); }
888 {
return _M_t.lower_bound(__x); }
890 #if __cplusplus > 201103L 891 template<
typename _Kt>
894 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
895 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
913 {
return _M_t.lower_bound(__x); }
915 #if __cplusplus > 201103L 916 template<
typename _Kt>
919 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
920 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
933 {
return _M_t.upper_bound(__x); }
935 #if __cplusplus > 201103L 936 template<
typename _Kt>
939 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
940 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
953 {
return _M_t.upper_bound(__x); }
955 #if __cplusplus > 201103L 956 template<
typename _Kt>
959 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
960 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
980 {
return _M_t.equal_range(__x); }
982 #if __cplusplus > 201103L 983 template<
typename _Kt>
1007 {
return _M_t.equal_range(__x); }
1009 #if __cplusplus > 201103L 1010 template<
typename _Kt>
1014 _M_t._M_equal_range_tr(__x)))
1017 _M_t._M_equal_range_tr(__x));
1022 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1027 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1029 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1043 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1047 {
return __x._M_t == __y._M_t; }
1060 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1062 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1064 {
return __x._M_t < __y._M_t; }
1067 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1071 {
return !(__x == __y); }
1074 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1078 {
return __y < __x; }
1081 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1083 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1085 {
return !(__y < __x); }
1088 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1092 {
return !(__x < __y); }
1095 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1099 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1102 _GLIBCXX_END_NAMESPACE_CONTAINER
1104 #if __cplusplus > 201402L 1105 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1107 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1110 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1114 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1117 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1118 {
return __map._M_t; }
1121 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1122 {
return __map._M_t; }
1124 _GLIBCXX_END_NAMESPACE_VERSION
multimap(multimap &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Builds and inserts a std::pair into the multimap.
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
reverse_iterator rend() noexcept
The standard allocator, as per [20.4].
Uniform interface to C++98 and C++11 allocators.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
size_type size() const noexcept
bool operator>(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
value_compare value_comp() const
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
auto upper_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
iterator emplace(_Args &&...__args)
Build and insert a std::pair into the multimap.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
const_iterator begin() const noexcept
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
iterator erase(const_iterator __position)
Erases an element from a multimap.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
const_reverse_iterator crbegin() const noexcept
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
const_reverse_iterator rend() const noexcept
const_iterator cend() const noexcept
size_type count(const key_type &__x) const
Finds the number of elements with given key.
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
ISO C++ entities toplevel namespace is std.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
const_iterator cbegin() const noexcept
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
const_reverse_iterator crend() const noexcept
multimap(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multimap from an initializer_list.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
iterator insert(const_iterator __position, const value_type &__x)
Inserts a std::pair into the multimap.
reverse_iterator rbegin() noexcept
Struct holding two objects of arbitrary type.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
multimap(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multimap from a range.
bool operator==(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Multimap equality comparison.
const_iterator end() const noexcept
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
One of the comparison functors.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
bool empty() const noexcept
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
iterator begin() noexcept
bool operator>=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
auto upper_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
auto equal_range(const _Kt &__x) const -> decltype(pair< const_iterator, const_iterator >( _M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
const_reverse_iterator rbegin() const noexcept
key_compare key_comp() const
multimap()=default
Default constructor creates no elements.
multimap(const allocator_type &__a)
Allocator-extended default constructor.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
auto lower_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
bool operator!=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
size_type max_size() const noexcept