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;
109 typedef typename _Alloc::value_type _Alloc_value_type;
110 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
111 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
112 _BinaryFunctionConcept)
113 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
119 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
123 value_compare(_Compare __c)
127 bool operator()(
const value_type& __x,
const value_type& __y)
const 128 {
return comp(__x.first, __y.first); }
134 rebind<value_type>::other _Pair_alloc_type;
136 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
137 key_compare, _Pair_alloc_type> _Rep_type;
146 typedef typename _Alloc_traits::pointer pointer;
147 typedef typename _Alloc_traits::const_pointer const_pointer;
148 typedef typename _Alloc_traits::reference reference;
149 typedef typename _Alloc_traits::const_reference const_reference;
150 typedef typename _Rep_type::iterator iterator;
151 typedef typename _Rep_type::const_iterator const_iterator;
152 typedef typename _Rep_type::size_type size_type;
153 typedef typename _Rep_type::difference_type difference_type;
154 typedef typename _Rep_type::reverse_iterator reverse_iterator;
155 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
157 #if __cplusplus > 201402L 158 using node_type =
typename _Rep_type::node_type;
167 #if __cplusplus < 201103L 180 const allocator_type& __a = allocator_type())
181 : _M_t(__comp, _Pair_alloc_type(__a)) { }
188 #if __cplusplus < 201103L 214 const _Compare& __comp = _Compare(),
215 const allocator_type& __a = allocator_type())
216 : _M_t(__comp, _Pair_alloc_type(__a))
217 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
222 : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
226 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
230 noexcept(is_nothrow_copy_constructible<_Compare>::value
231 && _Alloc_traits::_S_always_equal())
232 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
236 : _M_t(_Compare(), _Pair_alloc_type(__a))
237 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
240 template<
typename _InputIterator>
241 multimap(_InputIterator __first, _InputIterator __last,
242 const allocator_type& __a)
243 : _M_t(_Compare(), _Pair_alloc_type(__a))
244 { _M_t._M_insert_equal(__first, __last); }
256 template<
typename _InputIterator>
257 multimap(_InputIterator __first, _InputIterator __last)
259 { _M_t._M_insert_equal(__first, __last); }
272 template<
typename _InputIterator>
273 multimap(_InputIterator __first, _InputIterator __last,
274 const _Compare& __comp,
275 const allocator_type& __a = allocator_type())
276 : _M_t(__comp, _Pair_alloc_type(__a))
277 { _M_t._M_insert_equal(__first, __last); }
279 #if __cplusplus >= 201103L 293 #if __cplusplus < 201103L 322 _M_t._M_assign_equal(__l.begin(), __l.end());
330 {
return allocator_type(_M_t.get_allocator()); }
340 {
return _M_t.begin(); }
349 {
return _M_t.begin(); }
358 {
return _M_t.end(); }
366 end() const _GLIBCXX_NOEXCEPT
367 {
return _M_t.end(); }
376 {
return _M_t.rbegin(); }
383 const_reverse_iterator
385 {
return _M_t.rbegin(); }
394 {
return _M_t.rend(); }
401 const_reverse_iterator
403 {
return _M_t.rend(); }
405 #if __cplusplus >= 201103L 413 {
return _M_t.begin(); }
422 {
return _M_t.end(); }
429 const_reverse_iterator
431 {
return _M_t.rbegin(); }
438 const_reverse_iterator
440 {
return _M_t.rend(); }
447 {
return _M_t.empty(); }
452 {
return _M_t.size(); }
457 {
return _M_t.max_size(); }
460 #if __cplusplus >= 201103L 477 template<
typename... _Args>
480 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
504 template<
typename... _Args>
508 return _M_t._M_emplace_hint_equal(__pos,
509 std::forward<_Args>(__args)...);
527 {
return _M_t._M_insert_equal(__x); }
529 #if __cplusplus >= 201103L 530 template<
typename _Pair,
typename =
typename 531 std::enable_if<std::is_constructible<value_type,
532 _Pair&&>::value>::type>
535 {
return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
559 #if __cplusplus >= 201103L 560 insert(const_iterator __position,
const value_type& __x)
562 insert(iterator __position,
const value_type& __x)
564 {
return _M_t._M_insert_equal_(__position, __x); }
566 #if __cplusplus >= 201103L 567 template<
typename _Pair,
typename =
typename 568 std::enable_if<std::is_constructible<value_type,
569 _Pair&&>::value>::type>
571 insert(const_iterator __position, _Pair&& __x)
572 {
return _M_t._M_insert_equal_(__position,
573 std::forward<_Pair>(__x)); }
585 template<
typename _InputIterator>
587 insert(_InputIterator __first, _InputIterator __last)
588 { _M_t._M_insert_equal(__first, __last); }
590 #if __cplusplus >= 201103L 600 { this->
insert(__l.begin(), __l.end()); }
603 #if __cplusplus > 201402L 606 extract(const_iterator __pos)
608 __glibcxx_assert(__pos !=
end());
609 return _M_t.extract(__pos);
614 extract(
const key_type& __x)
615 {
return _M_t.extract(__x); }
620 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
624 insert(const_iterator __hint, node_type&& __nh)
625 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
627 template<
typename,
typename>
628 friend class _Rb_tree_merge_helper;
630 template<
typename _C2>
634 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
635 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
638 template<
typename _C2>
643 template<
typename _C2>
647 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
648 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
651 template<
typename _C2>
657 #if __cplusplus >= 201103L 677 {
return _M_t.erase(__position); }
680 _GLIBCXX_ABI_TAG_CXX11
683 {
return _M_t.erase(__position); }
697 erase(iterator __position)
698 { _M_t.erase(__position); }
714 {
return _M_t.erase(__x); }
716 #if __cplusplus >= 201103L 734 erase(const_iterator __first, const_iterator __last)
735 {
return _M_t.erase(__first, __last); }
753 erase(iterator __first, iterator __last)
754 { _M_t.erase(__first, __last); }
772 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
773 { _M_t.swap(__x._M_t); }
792 {
return _M_t.key_comp(); }
800 {
return value_compare(_M_t.key_comp()); }
818 {
return _M_t.find(__x); }
820 #if __cplusplus > 201103L 821 template<
typename _Kt>
823 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
824 {
return _M_t._M_find_tr(__x); }
841 find(
const key_type& __x)
const 842 {
return _M_t.find(__x); }
844 #if __cplusplus > 201103L 845 template<
typename _Kt>
847 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
848 {
return _M_t._M_find_tr(__x); }
860 {
return _M_t.count(__x); }
862 #if __cplusplus > 201103L 863 template<
typename _Kt>
865 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
866 {
return _M_t._M_count_tr(__x); }
884 {
return _M_t.lower_bound(__x); }
886 #if __cplusplus > 201103L 887 template<
typename _Kt>
890 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
891 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
909 {
return _M_t.lower_bound(__x); }
911 #if __cplusplus > 201103L 912 template<
typename _Kt>
915 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
916 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
929 {
return _M_t.upper_bound(__x); }
931 #if __cplusplus > 201103L 932 template<
typename _Kt>
935 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
936 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
949 {
return _M_t.upper_bound(__x); }
951 #if __cplusplus > 201103L 952 template<
typename _Kt>
955 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
956 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
976 {
return _M_t.equal_range(__x); }
978 #if __cplusplus > 201103L 979 template<
typename _Kt>
1003 {
return _M_t.equal_range(__x); }
1005 #if __cplusplus > 201103L 1006 template<
typename _Kt>
1010 _M_t._M_equal_range_tr(__x)))
1013 _M_t._M_equal_range_tr(__x));
1018 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1023 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1025 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1039 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1043 {
return __x._M_t == __y._M_t; }
1056 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1058 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1060 {
return __x._M_t < __y._M_t; }
1063 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1067 {
return !(__x == __y); }
1070 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1074 {
return __y < __x; }
1077 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1079 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1081 {
return !(__y < __x); }
1084 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1088 {
return !(__x < __y); }
1091 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1095 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1098 _GLIBCXX_END_NAMESPACE_CONTAINER
1100 #if __cplusplus > 201402L 1101 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1103 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1106 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1110 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1113 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1114 {
return __map._M_t; }
1117 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1118 {
return __map._M_t; }
1120 _GLIBCXX_END_NAMESPACE_VERSION
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
reverse_iterator rbegin() noexcept
bool empty() const noexcept
const_iterator cend() const noexcept
bool operator!=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
size_type size() const noexcept
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
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.
const_iterator end() const noexcept
ISO C++ entities toplevel namespace is std.
const_reverse_iterator crend() const noexcept
multimap(multimap &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
const_iterator begin() const noexcept
multimap(const allocator_type &__a)
Allocator-extended default constructor.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator cbegin() const noexcept
multimap()=default
Default constructor creates no elements.
const_iterator upper_bound(const key_type &__x) const
Finds the end 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<.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
iterator begin() noexcept
const_reverse_iterator rend() const noexcept
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
multimap(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multimap from an initializer_list.
const_reverse_iterator rbegin() const noexcept
size_type erase(const key_type &__x)
Erases elements according to the provided key.
The standard allocator, as per [20.4].
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
bool operator==(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Multimap equality comparison.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
bool operator>=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
key_compare key_comp() const
multimap(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multimap from a range.
const_reverse_iterator crbegin() const noexcept
iterator insert(const_iterator __position, const value_type &__x)
Inserts a std::pair into the multimap.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
value_compare value_comp() const
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
iterator emplace(_Args &&... __args)
Build and insert a std::pair into the multimap.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given 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.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts a std::pair into the multimap.
reverse_iterator rend() noexcept
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Struct holding two objects of arbitrary type.
size_type max_size() const noexcept
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__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.
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
Uniform interface to C++98 and C++11 allocators.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
iterator erase(const_iterator __position)
Erases an element from a multimap.
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
One of the comparison functors.
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.