56#ifndef _STL_MULTIMAP_H
57#define _STL_MULTIMAP_H 1
60#if __cplusplus >= 201103L
63#if __glibcxx_containers_ranges
67namespace std _GLIBCXX_VISIBILITY(default)
69_GLIBCXX_BEGIN_NAMESPACE_VERSION
70_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
72 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
101 template <
typename _Key,
typename _Tp,
102 typename _Compare = std::less<_Key>,
103 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
107 typedef _Key key_type;
108 typedef _Tp mapped_type;
110 typedef _Compare key_compare;
111 typedef _Alloc allocator_type;
114#ifdef _GLIBCXX_CONCEPT_CHECKS
116 typedef typename _Alloc::value_type _Alloc_value_type;
117# if __cplusplus < 201103L
118 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
120 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
121 _BinaryFunctionConcept)
122 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
125#if __cplusplus >= 201103L
126#if __cplusplus > 201703L || defined __STRICT_ANSI__
128 "std::multimap must have the same value_type as its allocator");
133#pragma GCC diagnostic push
134#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
138 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
142 value_compare(_Compare __c)
146 bool operator()(
const value_type& __x,
const value_type& __y)
const
149#pragma GCC diagnostic pop
154 rebind<value_type>::other _Pair_alloc_type;
156 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
157 key_compare, _Pair_alloc_type> _Rep_type;
166 typedef typename _Alloc_traits::pointer pointer;
167 typedef typename _Alloc_traits::const_pointer const_pointer;
168 typedef typename _Alloc_traits::reference reference;
169 typedef typename _Alloc_traits::const_reference const_reference;
170 typedef typename _Rep_type::iterator iterator;
171 typedef typename _Rep_type::const_iterator const_iterator;
172 typedef typename _Rep_type::size_type size_type;
173 typedef typename _Rep_type::difference_type difference_type;
174 typedef typename _Rep_type::reverse_iterator reverse_iterator;
175 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
177#ifdef __glibcxx_node_extract
178 using node_type =
typename _Rep_type::node_type;
187#if __cplusplus < 201103L
200 const allocator_type& __a = allocator_type())
201 : _M_t(__comp, _Pair_alloc_type(__a)) { }
208#if __cplusplus < 201103L
234 const _Compare& __comp = _Compare(),
235 const allocator_type& __a = allocator_type())
236 : _M_t(__comp, _Pair_alloc_type(__a))
237 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
242 : _M_t(_Pair_alloc_type(__a)) { }
246 const __type_identity_t<allocator_type>& __a)
247 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
252 && _Alloc_traits::_S_always_equal())
253 : _M_t(
std::
move(__m._M_t), _Pair_alloc_type(__a)) { }
257 : _M_t(_Pair_alloc_type(__a))
258 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
261 template<
typename _InputIterator>
262 multimap(_InputIterator __first, _InputIterator __last,
263 const allocator_type& __a)
264 : _M_t(_Pair_alloc_type(__a))
265 { _M_t._M_insert_range_equal(__first, __last); }
277 template<
typename _InputIterator>
278 multimap(_InputIterator __first, _InputIterator __last)
280 { _M_t._M_insert_range_equal(__first, __last); }
293 template<
typename _InputIterator>
294 multimap(_InputIterator __first, _InputIterator __last,
295 const _Compare& __comp,
296 const allocator_type& __a = allocator_type())
297 : _M_t(__comp, _Pair_alloc_type(__a))
298 { _M_t._M_insert_range_equal(__first, __last); }
300#if __glibcxx_containers_ranges
305 template<__detail::__container_compatible_range<value_type> _Rg>
307 const _Compare& __comp,
308 const _Alloc& __a = _Alloc())
309 : _M_t(__comp, _Pair_alloc_type(__a))
313 template<__detail::__container_compatible_range<value_type> _Rg>
314 multimap(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
315 : _M_t(_Pair_alloc_type(__a))
320#if __cplusplus >= 201103L
334#if __cplusplus < 201103L
363 _M_t._M_assign_equal(__l.begin(), __l.end());
371 {
return allocator_type(_M_t.get_allocator()); }
381 {
return _M_t.begin(); }
390 {
return _M_t.begin(); }
399 {
return _M_t.end(); }
407 end() const _GLIBCXX_NOEXCEPT
408 {
return _M_t.end(); }
417 {
return _M_t.rbegin(); }
424 const_reverse_iterator
426 {
return _M_t.rbegin(); }
435 {
return _M_t.rend(); }
442 const_reverse_iterator
444 {
return _M_t.rend(); }
446#if __cplusplus >= 201103L
454 {
return _M_t.begin(); }
463 {
return _M_t.end(); }
470 const_reverse_iterator
472 {
return _M_t.rbegin(); }
479 const_reverse_iterator
481 {
return _M_t.rend(); }
486 _GLIBCXX_NODISCARD
bool
488 {
return _M_t.empty(); }
493 {
return _M_t.size(); }
498 {
return _M_t.max_size(); }
501#if __cplusplus >= 201103L
518 template<
typename... _Args>
545 template<
typename... _Args>
549 return _M_t._M_emplace_hint_equal(__pos,
569 {
return _M_t._M_insert_equal(__x); }
571#if __cplusplus >= 201103L
576 {
return _M_t._M_insert_equal(
std::move(__x)); }
578 template<
typename _Pair>
579 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
607#if __cplusplus >= 201103L
608 insert(const_iterator __position,
const value_type& __x)
610 insert(iterator __position,
const value_type& __x)
612 {
return _M_t._M_insert_equal_(__position, __x); }
614#if __cplusplus >= 201103L
618 insert(const_iterator __position, value_type&& __x)
619 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
621 template<
typename _Pair>
622 __enable_if_t<is_constructible<value_type, _Pair&&>::value,
iterator>
623 insert(const_iterator __position, _Pair&& __x)
625 return _M_t._M_emplace_hint_equal(__position,
640 template<
typename _InputIterator>
642 insert(_InputIterator __first, _InputIterator __last)
643 { _M_t._M_insert_range_equal(__first, __last); }
645#if __cplusplus >= 201103L
655 { this->
insert(__l.begin(), __l.end()); }
658#if __glibcxx_containers_ranges
665 template<__detail::__container_compatible_range<value_type> _Rg>
667 insert_range(_Rg&& __rg)
669 auto __first = ranges::begin(__rg);
670 const auto __last = ranges::end(__rg);
671 for (; __first != __last; ++__first)
672 _M_t._M_emplace_equal(*__first);
677#ifdef __glibcxx_node_extract
680 extract(const_iterator __pos)
682 __glibcxx_assert(__pos !=
end());
683 return _M_t.extract(__pos);
688 extract(
const key_type& __x)
689 {
return _M_t.extract(__x); }
694 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
698 insert(const_iterator __hint, node_type&& __nh)
699 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
701 template<
typename,
typename>
702 friend struct std::_Rb_tree_merge_helper;
704 template<
typename _Cmp2>
708 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
709 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
712 template<
typename _Cmp2>
717 template<
typename _Cmp2>
719 merge(map<_Key, _Tp, _Cmp2, _Alloc>& __source)
721 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
722 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
725 template<
typename _Cmp2>
727 merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
731#if __cplusplus >= 201103L
751 {
return _M_t.erase(__position); }
754 _GLIBCXX_ABI_TAG_CXX11
757 {
return _M_t.erase(__position); }
772 { _M_t.erase(__position); }
788 {
return _M_t.erase(__x); }
790#if __cplusplus >= 201103L
808 erase(const_iterator __first, const_iterator __last)
809 {
return _M_t.erase(__first, __last); }
828 { _M_t.erase(__first, __last); }
846 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
847 { _M_t.swap(__x._M_t); }
866 {
return _M_t.key_comp(); }
874 {
return value_compare(_M_t.key_comp()); }
892 {
return _M_t.find(__x); }
894#if __cplusplus > 201103L
895 template<
typename _Kt>
897 find(
const _Kt& __x) ->
decltype(_M_t._M_find_tr(__x))
898 {
return _M_t._M_find_tr(__x); }
915 find(
const key_type& __x)
const
916 {
return _M_t.find(__x); }
918#if __cplusplus > 201103L
919 template<
typename _Kt>
921 find(
const _Kt& __x)
const ->
decltype(_M_t._M_find_tr(__x))
922 {
return _M_t._M_find_tr(__x); }
934 {
return _M_t.count(__x); }
936#if __cplusplus > 201103L
937 template<
typename _Kt>
939 count(
const _Kt& __x)
const ->
decltype(_M_t._M_count_tr(__x))
940 {
return _M_t._M_count_tr(__x); }
944#if __cplusplus > 201703L
953 {
return _M_t.find(__x) != _M_t.end(); }
955 template<
typename _Kt>
958 ->
decltype(_M_t._M_find_tr(__x),
void(),
true)
959 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
977 {
return _M_t.lower_bound(__x); }
979#if __cplusplus > 201103L
980 template<
typename _Kt>
983 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
984 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
1002 {
return _M_t.lower_bound(__x); }
1004#if __cplusplus > 201103L
1005 template<
typename _Kt>
1008 ->
decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
1009 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
1022 {
return _M_t.upper_bound(__x); }
1024#if __cplusplus > 201103L
1025 template<
typename _Kt>
1028 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
1029 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1042 {
return _M_t.upper_bound(__x); }
1044#if __cplusplus > 201103L
1045 template<
typename _Kt>
1048 ->
decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1049 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1069 {
return _M_t.equal_range(__x); }
1071#if __cplusplus > 201103L
1072 template<
typename _Kt>
1096 {
return _M_t.equal_range(__x); }
1098#if __cplusplus > 201103L
1099 template<
typename _Kt>
1103 _M_t._M_equal_range_tr(__x)))
1106 _M_t._M_equal_range_tr(__x));
1111 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1116#if __cpp_lib_three_way_comparison
1117 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1118 friend __detail::__synth3way_t<pair<const _K1, _T1>>
1122 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1129#if __cpp_deduction_guides >= 201606
1131 template<
typename _InputIterator,
1132 typename _Compare = less<__iter_key_t<_InputIterator>>,
1133 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1134 typename = _RequireInputIter<_InputIterator>,
1135 typename = _RequireNotAllocator<_Compare>,
1136 typename = _RequireAllocator<_Allocator>>
1137 multimap(_InputIterator, _InputIterator,
1138 _Compare = _Compare(), _Allocator = _Allocator())
1139 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1140 _Compare, _Allocator>;
1142 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1143 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1144 typename = _RequireNotAllocator<_Compare>,
1145 typename = _RequireAllocator<_Allocator>>
1147 _Compare = _Compare(), _Allocator = _Allocator())
1148 -> multimap<_Key, _Tp, _Compare, _Allocator>;
1150 template<
typename _InputIterator,
typename _Allocator,
1151 typename = _RequireInputIter<_InputIterator>,
1152 typename = _RequireAllocator<_Allocator>>
1153 multimap(_InputIterator, _InputIterator, _Allocator)
1154 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1155 less<__iter_key_t<_InputIterator>>, _Allocator>;
1157 template<
typename _Key,
typename _Tp,
typename _Allocator,
1158 typename = _RequireAllocator<_Allocator>>
1160 -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
1162#if __glibcxx_containers_ranges
1163 template<ranges::input_range _Rg,
1164 __not_allocator_like _Compare = less<__detail::__range_key_type<_Rg>>,
1165 __allocator_like _Alloc =
1167 multimap(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1168 -> multimap<__detail::__range_key_type<_Rg>,
1169 __detail::__range_mapped_type<_Rg>,
1172 template<ranges::input_range _Rg, __allocator_like _Alloc>
1173 multimap(from_range_t, _Rg&&, _Alloc)
1174 -> multimap<__detail::__range_key_type<_Rg>,
1175 __detail::__range_mapped_type<_Rg>,
1176 less<__detail::__range_key_type<_Rg>>,
1192 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1196 {
return __x._M_t == __y._M_t; }
1198#if __cpp_lib_three_way_comparison
1213 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1214 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1215 operator<=>(
const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1216 const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
1217 {
return __x._M_t <=> __y._M_t; }
1230 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1234 {
return __x._M_t < __y._M_t; }
1237 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1241 {
return !(__x == __y); }
1244 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1248 {
return __y < __x; }
1251 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1255 {
return !(__y < __x); }
1258 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1262 {
return !(__x < __y); }
1266 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1270 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
1273_GLIBCXX_END_NAMESPACE_CONTAINER
1275#if __cplusplus > 201402L
1277 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1280 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1284 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1287 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1288 {
return __map._M_t; }
1291 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1292 {
return __map._M_t; }
1296_GLIBCXX_END_NAMESPACE_VERSION
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
is_nothrow_copy_constructible
The standard allocator, as per C++03 [20.4.1].
Struct holding two objects of arbitrary type.
_T1 first
The first member.
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(const allocator_type &__a)
Allocator-extended default constructor.
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.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
bool empty() const noexcept
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
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.
__enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert(const_iterator __position, _Pair &&__x)
Inserts a std::pair into the 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.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
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.
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.
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.
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
multimap & operator=(multimap &&)=default
Move assignment operator.
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()=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.
value_compare value_comp() const
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
__enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert(_Pair &&__x)
Inserts a std::pair into the multimap.
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.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
Uniform interface to C++98 and C++11 allocators.