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
121 #if __cplusplus > 201703L || defined __STRICT_ANSI__
123 "std::multimap must have the same value_type as its allocator");
131 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
135 value_compare(_Compare __c)
146 rebind<value_type>::other _Pair_alloc_type;
148 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
149 key_compare, _Pair_alloc_type> _Rep_type;
158 typedef typename _Alloc_traits::pointer pointer;
159 typedef typename _Alloc_traits::const_pointer const_pointer;
160 typedef typename _Alloc_traits::reference reference;
161 typedef typename _Alloc_traits::const_reference const_reference;
162 typedef typename _Rep_type::iterator iterator;
163 typedef typename _Rep_type::const_iterator const_iterator;
164 typedef typename _Rep_type::size_type size_type;
165 typedef typename _Rep_type::difference_type difference_type;
169 #if __cplusplus > 201402L
179 #if __cplusplus < 201103L
192 const allocator_type& __a = allocator_type())
193 : _M_t(__comp, _Pair_alloc_type(__a)) { }
200 #if __cplusplus < 201103L
226 const _Compare& __comp = _Compare(),
227 const allocator_type& __a = allocator_type())
228 : _M_t(__comp, _Pair_alloc_type(__a))
229 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
234 : _M_t(_Pair_alloc_type(__a)) { }
238 const __type_identity_t<allocator_type>& __a)
239 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
244 && _Alloc_traits::_S_always_equal())
245 : _M_t(
std::
move(__m._M_t), _Pair_alloc_type(__a)) { }
249 : _M_t(_Pair_alloc_type(__a))
250 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
253 template<
typename _InputIterator>
254 multimap(_InputIterator __first, _InputIterator __last,
255 const allocator_type& __a)
256 : _M_t(_Pair_alloc_type(__a))
257 { _M_t._M_insert_range_equal(__first, __last); }
269 template<
typename _InputIterator>
270 multimap(_InputIterator __first, _InputIterator __last)
272 { _M_t._M_insert_range_equal(__first, __last); }
285 template<
typename _InputIterator>
286 multimap(_InputIterator __first, _InputIterator __last,
287 const _Compare& __comp,
288 const allocator_type& __a = allocator_type())
289 : _M_t(__comp, _Pair_alloc_type(__a))
290 { _M_t._M_insert_range_equal(__first, __last); }
292 #if __cplusplus >= 201103L
306 #if __cplusplus < 201103L
335 _M_t._M_assign_equal(__l.begin(), __l.end());
343 {
return allocator_type(_M_t.get_allocator()); }
353 {
return _M_t.begin(); }
362 {
return _M_t.begin(); }
371 {
return _M_t.end(); }
379 end() const _GLIBCXX_NOEXCEPT
380 {
return _M_t.end(); }
389 {
return _M_t.rbegin(); }
396 const_reverse_iterator
398 {
return _M_t.rbegin(); }
407 {
return _M_t.rend(); }
414 const_reverse_iterator
416 {
return _M_t.rend(); }
418 #if __cplusplus >= 201103L
426 {
return _M_t.begin(); }
435 {
return _M_t.end(); }
442 const_reverse_iterator
444 {
return _M_t.rbegin(); }
451 const_reverse_iterator
453 {
return _M_t.rend(); }
458 _GLIBCXX_NODISCARD
bool
460 {
return _M_t.empty(); }
465 {
return _M_t.size(); }
470 {
return _M_t.max_size(); }
473 #if __cplusplus >= 201103L
490 template<
typename... _Args>
493 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
517 template<
typename... _Args>
521 return _M_t._M_emplace_hint_equal(__pos,
522 std::forward<_Args>(__args)...);
541 {
return _M_t._M_insert_equal(__x); }
543 #if __cplusplus >= 201103L
548 {
return _M_t._M_insert_equal(
std::move(__x)); }
550 template<
typename _Pair>
551 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
553 {
return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); }
579 #if __cplusplus >= 201103L
584 {
return _M_t._M_insert_equal_(__position, __x); }
586 #if __cplusplus >= 201103L
591 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
593 template<
typename _Pair>
594 __enable_if_t<is_constructible<value_type, _Pair&&>::value,
iterator>
595 insert(const_iterator __position, _Pair&& __x)
597 return _M_t._M_emplace_hint_equal(__position,
598 std::forward<_Pair>(__x));
612 template<
typename _InputIterator>
614 insert(_InputIterator __first, _InputIterator __last)
615 { _M_t._M_insert_range_equal(__first, __last); }
617 #if __cplusplus >= 201103L
627 { this->
insert(__l.begin(), __l.end()); }
630 #if __cplusplus > 201402L
635 __glibcxx_assert(__pos !=
end());
636 return _M_t.extract(__pos);
642 {
return _M_t.extract(__x); }
647 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
651 insert(const_iterator __hint, node_type&& __nh)
652 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
654 template<
typename,
typename>
655 friend struct std::_Rb_tree_merge_helper;
657 template<
typename _Cmp2>
661 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
662 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
665 template<
typename _Cmp2>
667 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>&& __source)
670 template<
typename _Cmp2>
672 merge(map<_Key, _Tp, _Cmp2, _Alloc>& __source)
674 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
675 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
678 template<
typename _Cmp2>
680 merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
684 #if __cplusplus >= 201103L
704 {
return _M_t.erase(__position); }
707 _GLIBCXX_ABI_TAG_CXX11
710 {
return _M_t.erase(__position); }
725 { _M_t.erase(__position); }
741 {
return _M_t.erase(__x); }
743 #if __cplusplus >= 201103L
761 erase(const_iterator __first, const_iterator __last)
762 {
return _M_t.erase(__first, __last); }
781 { _M_t.erase(__first, __last); }
799 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
800 { _M_t.swap(__x._M_t); }
819 {
return _M_t.key_comp(); }
827 {
return value_compare(_M_t.key_comp()); }
845 {
return _M_t.find(__x); }
847 #if __cplusplus > 201103L
848 template<
typename _Kt>
850 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
851 {
return _M_t._M_find_tr(__x); }
868 find(
const key_type& __x)
const
869 {
return _M_t.find(__x); }
871 #if __cplusplus > 201103L
872 template<
typename _Kt>
874 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
875 {
return _M_t._M_find_tr(__x); }
887 {
return _M_t.count(__x); }
889 #if __cplusplus > 201103L
890 template<
typename _Kt>
892 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
893 {
return _M_t._M_count_tr(__x); }
897 #if __cplusplus > 201703L
906 {
return _M_t.find(__x) != _M_t.end(); }
908 template<
typename _Kt>
911 -> decltype(_M_t._M_find_tr(__x),
void(),
true)
912 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
930 {
return _M_t.lower_bound(__x); }
932 #if __cplusplus > 201103L
933 template<
typename _Kt>
936 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
937 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
955 {
return _M_t.lower_bound(__x); }
957 #if __cplusplus > 201103L
958 template<
typename _Kt>
961 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
962 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
975 {
return _M_t.upper_bound(__x); }
977 #if __cplusplus > 201103L
978 template<
typename _Kt>
981 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
982 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
995 {
return _M_t.upper_bound(__x); }
997 #if __cplusplus > 201103L
998 template<
typename _Kt>
1001 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1002 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1022 {
return _M_t.equal_range(__x); }
1024 #if __cplusplus > 201103L
1025 template<
typename _Kt>
1049 {
return _M_t.equal_range(__x); }
1051 #if __cplusplus > 201103L
1052 template<
typename _Kt>
1056 _M_t._M_equal_range_tr(__x)))
1059 _M_t._M_equal_range_tr(__x));
1064 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1069 #if __cpp_lib_three_way_comparison
1070 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1071 friend __detail::__synth3way_t<pair<const _K1, _T1>>
1075 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1082 #if __cpp_deduction_guides >= 201606
1084 template<
typename _InputIterator,
1085 typename _Compare = less<__iter_key_t<_InputIterator>>,
1086 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1087 typename = _RequireInputIter<_InputIterator>,
1088 typename = _RequireNotAllocator<_Compare>,
1089 typename = _RequireAllocator<_Allocator>>
1090 multimap(_InputIterator, _InputIterator,
1091 _Compare = _Compare(), _Allocator = _Allocator())
1092 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1093 _Compare, _Allocator>;
1095 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1096 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1097 typename = _RequireNotAllocator<_Compare>,
1098 typename = _RequireAllocator<_Allocator>>
1099 multimap(initializer_list<pair<_Key, _Tp>>,
1100 _Compare = _Compare(), _Allocator = _Allocator())
1101 -> multimap<_Key, _Tp, _Compare, _Allocator>;
1103 template<
typename _InputIterator,
typename _Allocator,
1104 typename = _RequireInputIter<_InputIterator>,
1105 typename = _RequireAllocator<_Allocator>>
1106 multimap(_InputIterator, _InputIterator, _Allocator)
1107 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1108 less<__iter_key_t<_InputIterator>>, _Allocator>;
1110 template<
typename _Key,
typename _Tp,
typename _Allocator,
1111 typename = _RequireAllocator<_Allocator>>
1112 multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
1113 -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
1127 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1131 {
return __x._M_t == __y._M_t; }
1133 #if __cpp_lib_three_way_comparison
1148 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1149 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1150 operator<=>(
const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1151 const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
1152 {
return __x._M_t <=> __y._M_t; }
1165 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1169 {
return __x._M_t < __y._M_t; }
1172 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1176 {
return !(__x == __y); }
1179 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1183 {
return __y < __x; }
1186 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1190 {
return !(__y < __x); }
1193 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1197 {
return !(__x < __y); }
1201 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1205 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.
swap(__y)))
1208 _GLIBCXX_END_NAMESPACE_CONTAINER
1210 #if __cplusplus > 201402L
1212 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1215 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1219 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1222 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1223 {
return __map._M_t; }
1226 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1227 {
return __map._M_t; }
1231 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
ISO C++ entities toplevel namespace is std.
is_nothrow_copy_constructible
The standard allocator, as per C++03 [20.4.1].
Node handle type for maps.
One of the comparison functors.
Struct holding two objects of arbitrary type.
_T1 first
The first member.
constexpr void swap(pair &__p) noexcept(__and_< __is_nothrow_swappable< _T1 >, __is_nothrow_swappable< _T2 >>::value)
Swap the first members and then the second members.
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
iterator insert(node_type &&__nh)
Re-insert an extracted node.
multimap(const allocator_type &__a)
Allocator-extended default constructor.
iterator insert(const_iterator __hint, node_type &&__nh)
Re-insert an extracted node.
__enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert(_Pair &&__x)
Inserts a std::pair into the multimap.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
iterator emplace(_Args &&... __args)
Build and insert a std::pair into the multimap.
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
iterator insert(const_iterator __position, value_type &&__x)
Inserts a std::pair into the multimap.
bool empty() const noexcept
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.
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.
iterator begin() noexcept
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
const_iterator end() const noexcept
iterator erase(const_iterator __position)
Erases an element from a multimap.
const_reverse_iterator rend() const noexcept
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
const_reverse_iterator crend() const noexcept
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 erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
multimap(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multimap from an initializer_list.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
size_type max_size() const noexcept
const_reverse_iterator rbegin() const noexcept
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
multimap(multimap &&__m, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
const_iterator cbegin() const noexcept
multimap(const multimap &)=default
Multimap copy constructor.
key_compare key_comp() const
iterator insert(value_type &&__x)
Inserts a std::pair into the multimap.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
reverse_iterator rend() noexcept
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts a std::pair into the multimap.
bool contains(const key_type &__x) const
Finds whether an element with the given key exists.
size_type size() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
const_reverse_iterator crbegin() const noexcept
auto contains(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x), void(), true)
Finds whether an element with the given key exists.
multimap(const multimap &__m, const __type_identity_t< allocator_type > &__a)
Allocator-extended copy constructor.
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
const_iterator cend() const noexcept
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
reverse_iterator rbegin() noexcept
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
node_type extract(const key_type &__x)
Extract a node.
__enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert(const_iterator __position, _Pair &&__x)
Inserts a std::pair into the 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.
const_iterator begin() 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.
multimap(multimap &&)=default
Multimap move constructor.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
multimap()=default
Default constructor creates no elements.
multimap(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multimap from a range.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
node_type extract(const_iterator __pos)
Extract a node.
value_compare value_comp() const
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
iterator insert(const_iterator __position, const value_type &__x)
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.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
multimap & operator=(multimap &&)=default
Move assignment operator.
Uniform interface to C++98 and C++11 allocators.