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
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)...);
532 {
return _M_t._M_insert_equal(__x); }
534 #if __cplusplus >= 201103L
539 {
return _M_t._M_insert_equal(std::move(__x)); }
541 template<
typename _Pair,
typename =
typename
542 std::enable_if<std::is_constructible<value_type,
543 _Pair&&>::value>::type>
546 {
return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
572 #if __cplusplus >= 201103L
573 insert(const_iterator __position,
const value_type& __x)
577 {
return _M_t._M_insert_equal_(__position, __x); }
579 #if __cplusplus >= 201103L
583 insert(const_iterator __position, value_type&& __x)
584 {
return _M_t._M_insert_equal_(__position, std::move(__x)); }
586 template<
typename _Pair,
typename =
typename
587 std::enable_if<std::is_constructible<value_type,
588 _Pair&&>::value>::type>
590 insert(const_iterator __position, _Pair&& __x)
591 {
return _M_t._M_insert_equal_(__position,
592 std::forward<_Pair>(__x)); }
605 template<
typename _InputIterator>
607 insert(_InputIterator __first, _InputIterator __last)
608 { _M_t._M_insert_equal(__first, __last); }
610 #if __cplusplus >= 201103L
620 { this->
insert(__l.begin(), __l.end()); }
623 #if __cplusplus > 201402L
626 extract(const_iterator __pos)
628 __glibcxx_assert(__pos !=
end());
629 return _M_t.extract(__pos);
634 extract(
const key_type& __x)
635 {
return _M_t.extract(__x); }
640 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
644 insert(const_iterator __hint, node_type&& __nh)
645 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
647 template<
typename,
typename>
648 friend class _Rb_tree_merge_helper;
650 template<
typename _C2>
652 merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
654 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
655 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
658 template<
typename _C2>
660 merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
663 template<
typename _C2>
665 merge(map<_Key, _Tp, _C2, _Alloc>& __source)
667 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
668 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
671 template<
typename _C2>
673 merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
677 #if __cplusplus >= 201103L
697 {
return _M_t.erase(__position); }
700 _GLIBCXX_ABI_TAG_CXX11
703 {
return _M_t.erase(__position); }
718 { _M_t.erase(__position); }
734 {
return _M_t.erase(__x); }
736 #if __cplusplus >= 201103L
754 erase(const_iterator __first, const_iterator __last)
755 {
return _M_t.erase(__first, __last); }
774 { _M_t.erase(__first, __last); }
792 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
793 { _M_t.swap(__x._M_t); }
812 {
return _M_t.key_comp(); }
820 {
return value_compare(_M_t.key_comp()); }
838 {
return _M_t.find(__x); }
840 #if __cplusplus > 201103L
841 template<
typename _Kt>
843 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
844 {
return _M_t._M_find_tr(__x); }
861 find(
const key_type& __x)
const
862 {
return _M_t.find(__x); }
864 #if __cplusplus > 201103L
865 template<
typename _Kt>
867 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
868 {
return _M_t._M_find_tr(__x); }
880 {
return _M_t.count(__x); }
882 #if __cplusplus > 201103L
883 template<
typename _Kt>
885 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
886 {
return _M_t._M_count_tr(__x); }
904 {
return _M_t.lower_bound(__x); }
906 #if __cplusplus > 201103L
907 template<
typename _Kt>
910 -> decltype(
iterator(_M_t._M_lower_bound_tr(__x)))
911 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
929 {
return _M_t.lower_bound(__x); }
931 #if __cplusplus > 201103L
932 template<
typename _Kt>
935 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
936 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
949 {
return _M_t.upper_bound(__x); }
951 #if __cplusplus > 201103L
952 template<
typename _Kt>
955 -> decltype(
iterator(_M_t._M_upper_bound_tr(__x)))
956 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
969 {
return _M_t.upper_bound(__x); }
971 #if __cplusplus > 201103L
972 template<
typename _Kt>
975 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
976 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
996 {
return _M_t.equal_range(__x); }
998 #if __cplusplus > 201103L
999 template<
typename _Kt>
1023 {
return _M_t.equal_range(__x); }
1025 #if __cplusplus > 201103L
1026 template<
typename _Kt>
1030 _M_t._M_equal_range_tr(__x)))
1033 _M_t._M_equal_range_tr(__x));
1038 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1043 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1045 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1059 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1063 {
return __x._M_t == __y._M_t; }
1076 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1078 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1080 {
return __x._M_t < __y._M_t; }
1083 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1087 {
return !(__x == __y); }
1090 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1094 {
return __y < __x; }
1097 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1099 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1101 {
return !(__y < __x); }
1104 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1108 {
return !(__x < __y); }
1111 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1115 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1118 _GLIBCXX_END_NAMESPACE_CONTAINER
1120 #if __cplusplus > 201402L
1121 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1123 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1126 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1130 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1133 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1134 {
return __map._M_t; }
1137 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1138 {
return __map._M_t; }
1140 _GLIBCXX_END_NAMESPACE_VERSION
const_reverse_iterator rbegin() const noexcept
const_iterator cend() const noexcept
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
const_reverse_iterator rend() const noexcept
value_compare value_comp() const
const_iterator begin() const noexcept
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.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
const_iterator cbegin() const noexcept
multimap()=default
Default constructor creates no elements.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
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.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
iterator emplace_hint(const_iterator __pos, _Args &&...__args)
Builds and inserts a std::pair into the 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.
iterator erase(const_iterator __position)
Erases an element from a multimap.
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
The standard allocator, as per [20.4].
iterator emplace(_Args &&...__args)
Build and insert a std::pair into the multimap.
size_type size() const noexcept
bool empty() const noexcept
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.
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
const_reverse_iterator crend() const noexcept
const_reverse_iterator crbegin() const noexcept
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
iterator insert(_Pair &&__x)
Inserts a std::pair into the multimap.
iterator insert(const_iterator __position, _Pair &&__x)
Inserts a std::pair into the multimap.
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.
multimap(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multimap from an initializer_list.
size_type max_size() const noexcept
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
iterator insert(value_type &&__x)
Inserts a std::pair into the multimap.
reverse_iterator rbegin() noexcept
iterator insert(const_iterator __position, value_type &&__x)
Inserts a std::pair into the multimap.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
void noexcept()
Swaps data with another multimap.
iterator begin() noexcept
const_iterator end() const noexcept
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
Struct holding two objects of arbitrary type.
reverse_iterator rend() noexcept
key_compare key_comp() const
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
One of the comparison functors.
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.
Uniform interface to C++98 and C++11 allocators.
multimap(const allocator_type &__a)
Allocator-extended default constructor.