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_VERSION
67 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
96 template <
typename _Key,
typename _Tp,
102 typedef _Key key_type;
103 typedef _Tp mapped_type;
105 typedef _Compare key_compare;
106 typedef _Alloc allocator_type;
109 #ifdef _GLIBCXX_CONCEPT_CHECKS 111 typedef typename _Alloc::value_type _Alloc_value_type;
112 # if __cplusplus < 201103L 113 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
115 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
116 _BinaryFunctionConcept)
117 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
120 #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) 121 static_assert(is_same<typename _Alloc::value_type, value_type>::value,
122 "std::multimap must have the same value_type as its allocator");
129 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
133 value_compare(_Compare __c)
137 bool operator()(
const value_type& __x,
const value_type& __y)
const 138 {
return comp(__x.first, __y.first); }
144 rebind<value_type>::other _Pair_alloc_type;
146 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
147 key_compare, _Pair_alloc_type> _Rep_type;
156 typedef typename _Alloc_traits::pointer pointer;
157 typedef typename _Alloc_traits::const_pointer const_pointer;
158 typedef typename _Alloc_traits::reference reference;
159 typedef typename _Alloc_traits::const_reference const_reference;
160 typedef typename _Rep_type::iterator iterator;
161 typedef typename _Rep_type::const_iterator const_iterator;
162 typedef typename _Rep_type::size_type size_type;
163 typedef typename _Rep_type::difference_type difference_type;
164 typedef typename _Rep_type::reverse_iterator reverse_iterator;
165 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
167 #if __cplusplus > 201402L 168 using node_type =
typename _Rep_type::node_type;
177 #if __cplusplus < 201103L 190 const allocator_type& __a = allocator_type())
191 : _M_t(__comp, _Pair_alloc_type(__a)) { }
198 #if __cplusplus < 201103L 224 const _Compare& __comp = _Compare(),
225 const allocator_type& __a = allocator_type())
226 : _M_t(__comp, _Pair_alloc_type(__a))
227 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
232 : _M_t(_Pair_alloc_type(__a)) { }
236 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
241 && _Alloc_traits::_S_always_equal())
242 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
246 : _M_t(_Pair_alloc_type(__a))
247 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
250 template<
typename _InputIterator>
251 multimap(_InputIterator __first, _InputIterator __last,
252 const allocator_type& __a)
253 : _M_t(_Pair_alloc_type(__a))
254 { _M_t._M_insert_range_equal(__first, __last); }
266 template<
typename _InputIterator>
267 multimap(_InputIterator __first, _InputIterator __last)
269 { _M_t._M_insert_range_equal(__first, __last); }
282 template<
typename _InputIterator>
283 multimap(_InputIterator __first, _InputIterator __last,
284 const _Compare& __comp,
285 const allocator_type& __a = allocator_type())
286 : _M_t(__comp, _Pair_alloc_type(__a))
287 { _M_t._M_insert_range_equal(__first, __last); }
289 #if __cplusplus >= 201103L 303 #if __cplusplus < 201103L 332 _M_t._M_assign_equal(__l.begin(), __l.end());
340 {
return allocator_type(_M_t.get_allocator()); }
350 {
return _M_t.begin(); }
359 {
return _M_t.begin(); }
368 {
return _M_t.end(); }
376 end() const _GLIBCXX_NOEXCEPT
377 {
return _M_t.end(); }
386 {
return _M_t.rbegin(); }
393 const_reverse_iterator
395 {
return _M_t.rbegin(); }
404 {
return _M_t.rend(); }
411 const_reverse_iterator
413 {
return _M_t.rend(); }
415 #if __cplusplus >= 201103L 423 {
return _M_t.begin(); }
432 {
return _M_t.end(); }
439 const_reverse_iterator
441 {
return _M_t.rbegin(); }
448 const_reverse_iterator
450 {
return _M_t.rend(); }
455 _GLIBCXX_NODISCARD
bool 457 {
return _M_t.empty(); }
462 {
return _M_t.size(); }
467 {
return _M_t.max_size(); }
470 #if __cplusplus >= 201103L 487 template<
typename... _Args>
490 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
514 template<
typename... _Args>
518 return _M_t._M_emplace_hint_equal(__pos,
519 std::forward<_Args>(__args)...);
538 {
return _M_t._M_insert_equal(__x); }
540 #if __cplusplus >= 201103L 545 {
return _M_t._M_insert_equal(std::move(__x)); }
547 template<
typename _Pair>
548 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
550 {
return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); }
576 #if __cplusplus >= 201103L 581 {
return _M_t._M_insert_equal_(__position, __x); }
583 #if __cplusplus >= 201103L 588 {
return _M_t._M_insert_equal_(__position, std::move(__x)); }
590 template<
typename _Pair>
591 __enable_if_t<is_constructible<value_type, _Pair&&>::value,
iterator>
592 insert(const_iterator __position, _Pair&& __x)
594 return _M_t._M_emplace_hint_equal(__position,
595 std::forward<_Pair>(__x));
609 template<
typename _InputIterator>
611 insert(_InputIterator __first, _InputIterator __last)
612 { _M_t._M_insert_range_equal(__first, __last); }
614 #if __cplusplus >= 201103L 624 { this->
insert(__l.begin(), __l.end()); }
627 #if __cplusplus > 201402L 630 extract(const_iterator __pos)
632 __glibcxx_assert(__pos !=
end());
633 return _M_t.extract(__pos);
638 extract(
const key_type& __x)
639 {
return _M_t.extract(__x); }
644 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
648 insert(const_iterator __hint, node_type&& __nh)
649 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
651 template<
typename,
typename>
652 friend class std::_Rb_tree_merge_helper;
654 template<
typename _C2>
656 merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
658 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
659 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
662 template<
typename _C2>
664 merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
667 template<
typename _C2>
669 merge(map<_Key, _Tp, _C2, _Alloc>& __source)
671 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
672 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
675 template<
typename _C2>
677 merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
681 #if __cplusplus >= 201103L 701 {
return _M_t.erase(__position); }
704 _GLIBCXX_ABI_TAG_CXX11
707 {
return _M_t.erase(__position); }
722 { _M_t.erase(__position); }
738 {
return _M_t.erase(__x); }
740 #if __cplusplus >= 201103L 758 erase(const_iterator __first, const_iterator __last)
759 {
return _M_t.erase(__first, __last); }
778 { _M_t.erase(__first, __last); }
796 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
797 { _M_t.swap(__x._M_t); }
816 {
return _M_t.key_comp(); }
824 {
return value_compare(_M_t.key_comp()); }
842 {
return _M_t.find(__x); }
844 #if __cplusplus > 201103L 845 template<
typename _Kt>
847 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
848 {
return _M_t._M_find_tr(__x); }
865 find(
const key_type& __x)
const 866 {
return _M_t.find(__x); }
868 #if __cplusplus > 201103L 869 template<
typename _Kt>
871 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
872 {
return _M_t._M_find_tr(__x); }
884 {
return _M_t.count(__x); }
886 #if __cplusplus > 201103L 887 template<
typename _Kt>
889 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
890 {
return _M_t._M_count_tr(__x); }
894 #if __cplusplus > 201703L 902 contains(
const key_type& __x)
const 903 {
return _M_t.find(__x) != _M_t.end(); }
905 template<
typename _Kt>
907 contains(
const _Kt& __x)
const 908 -> decltype(_M_t._M_find_tr(__x), void(),
true)
909 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
927 {
return _M_t.lower_bound(__x); }
929 #if __cplusplus > 201103L 930 template<
typename _Kt>
933 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
934 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
952 {
return _M_t.lower_bound(__x); }
954 #if __cplusplus > 201103L 955 template<
typename _Kt>
958 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
959 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
972 {
return _M_t.upper_bound(__x); }
974 #if __cplusplus > 201103L 975 template<
typename _Kt>
978 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
979 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
992 {
return _M_t.upper_bound(__x); }
994 #if __cplusplus > 201103L 995 template<
typename _Kt>
998 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
999 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1019 {
return _M_t.equal_range(__x); }
1021 #if __cplusplus > 201103L 1022 template<
typename _Kt>
1046 {
return _M_t.equal_range(__x); }
1048 #if __cplusplus > 201103L 1049 template<
typename _Kt>
1053 _M_t._M_equal_range_tr(__x)))
1056 _M_t._M_equal_range_tr(__x));
1061 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1066 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1068 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1072 #if __cpp_deduction_guides >= 201606 1074 template<
typename _InputIterator,
1075 typename _Compare = less<__iter_key_t<_InputIterator>>,
1076 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1077 typename = _RequireInputIter<_InputIterator>,
1078 typename = _RequireNotAllocator<_Compare>,
1079 typename = _RequireAllocator<_Allocator>>
1080 multimap(_InputIterator, _InputIterator,
1081 _Compare = _Compare(), _Allocator = _Allocator())
1082 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1083 _Compare, _Allocator>;
1085 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1086 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1087 typename = _RequireNotAllocator<_Compare>,
1088 typename = _RequireAllocator<_Allocator>>
1089 multimap(initializer_list<pair<_Key, _Tp>>,
1090 _Compare = _Compare(), _Allocator = _Allocator())
1091 -> multimap<_Key, _Tp, _Compare, _Allocator>;
1093 template<
typename _InputIterator,
typename _Allocator,
1094 typename = _RequireInputIter<_InputIterator>,
1095 typename = _RequireAllocator<_Allocator>>
1096 multimap(_InputIterator, _InputIterator, _Allocator)
1097 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1098 less<__iter_key_t<_InputIterator>>, _Allocator>;
1100 template<
typename _Key,
typename _Tp,
typename _Allocator,
1101 typename = _RequireAllocator<_Allocator>>
1102 multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
1103 -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
1117 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1121 {
return __x._M_t == __y._M_t; }
1134 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1136 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1138 {
return __x._M_t < __y._M_t; }
1141 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1145 {
return !(__x == __y); }
1148 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1152 {
return __y < __x; }
1155 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1157 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1159 {
return !(__y < __x); }
1162 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1166 {
return !(__x < __y); }
1169 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1173 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1176 _GLIBCXX_END_NAMESPACE_CONTAINER
1178 #if __cplusplus > 201402L 1180 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1183 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1187 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1190 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1191 {
return __map._M_t; }
1194 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1195 {
return __map._M_t; }
1199 _GLIBCXX_END_NAMESPACE_VERSION
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
reverse_iterator rend() 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.
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
const_iterator begin() const noexcept
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.
_GLIBCXX_NODISCARD bool empty() const noexcept
const_iterator cbegin() const noexcept
ISO C++ entities toplevel namespace is std.
value_compare value_comp() const
size_type size() const noexcept
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
const_iterator lower_bound(const key_type &__x) const
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.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
__enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert(_Pair &&__x)
Inserts a std::pair into the multimap.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
multimap(const allocator_type &__a)
Allocator-extended default constructor.
iterator insert(value_type &&__x)
Inserts a std::pair into the multimap.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
const_iterator end() const noexcept
__enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert(const_iterator __position, _Pair &&__x)
Inserts a std::pair into the multimap.
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
multimap(multimap &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
The standard allocator, as per [20.4].
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
const_reverse_iterator crbegin() const noexcept
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
reverse_iterator rbegin() noexcept
iterator emplace(_Args &&... __args)
Build and insert a std::pair into the multimap.
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 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.
is_nothrow_copy_constructible
iterator insert(const_iterator __position, value_type &&__x)
Inserts a std::pair into the multimap.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
iterator begin() noexcept
iterator insert(const_iterator __position, const value_type &__x)
Inserts a std::pair into the multimap.
const_reverse_iterator crend() const noexcept
size_type max_size() const noexcept
const_iterator cend() const noexcept
const_reverse_iterator rbegin() 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.
auto find(const _Kt &__x) const -> 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.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
const_reverse_iterator rend() const noexcept
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
Uniform interface to C++98 and C++11 allocators.
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
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()=default
Default constructor creates no elements.
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
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.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
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.
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
One of the comparison functors.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
Struct holding two objects of arbitrary type.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts a std::pair into the multimap.