56#ifndef _STL_MULTIMAP_H
57#define _STL_MULTIMAP_H 1
60#if __cplusplus >= 201103L
64namespace std _GLIBCXX_VISIBILITY(default)
66_GLIBCXX_BEGIN_NAMESPACE_VERSION
67_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
98 template <
typename _Key,
typename _Tp,
104 typedef _Key key_type;
105 typedef _Tp mapped_type;
107 typedef _Compare key_compare;
108 typedef _Alloc allocator_type;
111#ifdef _GLIBCXX_CONCEPT_CHECKS
113 typedef typename _Alloc::value_type _Alloc_value_type;
114# if __cplusplus < 201103L
115 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
117 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
118 _BinaryFunctionConcept)
119 __glibcxx_class_requires2(
value_type, _Alloc_value_type, _SameTypeConcept)
122#if __cplusplus >= 201103L
123#if __cplusplus > 201703L || defined __STRICT_ANSI__
125 "std::multimap must have the same value_type as its allocator");
130#pragma GCC diagnostic push
131#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
135 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
139 value_compare(_Compare __c)
146#pragma GCC diagnostic pop
151 rebind<value_type>::other _Pair_alloc_type;
153 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
154 key_compare, _Pair_alloc_type> _Rep_type;
163 typedef typename _Alloc_traits::pointer pointer;
164 typedef typename _Alloc_traits::const_pointer const_pointer;
165 typedef typename _Alloc_traits::reference reference;
166 typedef typename _Alloc_traits::const_reference const_reference;
167 typedef typename _Rep_type::iterator iterator;
168 typedef typename _Rep_type::const_iterator const_iterator;
169 typedef typename _Rep_type::size_type size_type;
170 typedef typename _Rep_type::difference_type difference_type;
174#if __cplusplus > 201402L
184#if __cplusplus < 201103L
197 const allocator_type& __a = allocator_type())
198 : _M_t(__comp, _Pair_alloc_type(__a)) { }
205#if __cplusplus < 201103L
231 const _Compare& __comp = _Compare(),
232 const allocator_type& __a = allocator_type())
233 : _M_t(__comp, _Pair_alloc_type(__a))
234 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
239 : _M_t(_Pair_alloc_type(__a)) { }
243 const __type_identity_t<allocator_type>& __a)
244 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
249 && _Alloc_traits::_S_always_equal())
250 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
254 : _M_t(_Pair_alloc_type(__a))
255 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
258 template<
typename _InputIterator>
259 multimap(_InputIterator __first, _InputIterator __last,
260 const allocator_type& __a)
261 : _M_t(_Pair_alloc_type(__a))
262 { _M_t._M_insert_range_equal(__first, __last); }
274 template<
typename _InputIterator>
275 multimap(_InputIterator __first, _InputIterator __last)
277 { _M_t._M_insert_range_equal(__first, __last); }
290 template<
typename _InputIterator>
291 multimap(_InputIterator __first, _InputIterator __last,
292 const _Compare& __comp,
293 const allocator_type& __a = allocator_type())
294 : _M_t(__comp, _Pair_alloc_type(__a))
295 { _M_t._M_insert_range_equal(__first, __last); }
297#if __cplusplus >= 201103L
311#if __cplusplus < 201103L
340 _M_t._M_assign_equal(__l.begin(), __l.end());
348 {
return allocator_type(_M_t.get_allocator()); }
358 {
return _M_t.begin(); }
367 {
return _M_t.begin(); }
376 {
return _M_t.end(); }
384 end() const _GLIBCXX_NOEXCEPT
385 {
return _M_t.end(); }
394 {
return _M_t.rbegin(); }
401 const_reverse_iterator
403 {
return _M_t.rbegin(); }
412 {
return _M_t.rend(); }
419 const_reverse_iterator
421 {
return _M_t.rend(); }
423#if __cplusplus >= 201103L
431 {
return _M_t.begin(); }
440 {
return _M_t.end(); }
447 const_reverse_iterator
449 {
return _M_t.rbegin(); }
456 const_reverse_iterator
458 {
return _M_t.rend(); }
463 _GLIBCXX_NODISCARD
bool
465 {
return _M_t.empty(); }
470 {
return _M_t.size(); }
475 {
return _M_t.max_size(); }
478#if __cplusplus >= 201103L
495 template<
typename... _Args>
498 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
522 template<
typename... _Args>
526 return _M_t._M_emplace_hint_equal(__pos,
527 std::forward<_Args>(__args)...);
546 {
return _M_t._M_insert_equal(__x); }
548#if __cplusplus >= 201103L
553 {
return _M_t._M_insert_equal(
std::move(__x)); }
555 template<
typename _Pair>
556 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
558 {
return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); }
584#if __cplusplus >= 201103L
589 {
return _M_t._M_insert_equal_(__position, __x); }
591#if __cplusplus >= 201103L
596 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
598 template<
typename _Pair>
599 __enable_if_t<is_constructible<value_type, _Pair&&>::value,
iterator>
600 insert(const_iterator __position, _Pair&& __x)
602 return _M_t._M_emplace_hint_equal(__position,
603 std::forward<_Pair>(__x));
617 template<
typename _InputIterator>
619 insert(_InputIterator __first, _InputIterator __last)
620 { _M_t._M_insert_range_equal(__first, __last); }
622#if __cplusplus >= 201103L
632 { this->
insert(__l.begin(), __l.end()); }
635#if __cplusplus > 201402L
640 __glibcxx_assert(__pos !=
end());
641 return _M_t.extract(__pos);
647 {
return _M_t.extract(__x); }
652 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
656 insert(const_iterator __hint, node_type&& __nh)
657 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
659 template<
typename,
typename>
660 friend struct std::_Rb_tree_merge_helper;
662 template<
typename _Cmp2>
666 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
667 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
670 template<
typename _Cmp2>
672 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>&& __source)
675 template<
typename _Cmp2>
677 merge(map<_Key, _Tp, _Cmp2, _Alloc>& __source)
679 using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
680 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
683 template<
typename _Cmp2>
685 merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
689#if __cplusplus >= 201103L
709 {
return _M_t.erase(__position); }
712 _GLIBCXX_ABI_TAG_CXX11
715 {
return _M_t.erase(__position); }
730 { _M_t.erase(__position); }
746 {
return _M_t.erase(__x); }
748#if __cplusplus >= 201103L
766 erase(const_iterator __first, const_iterator __last)
767 {
return _M_t.erase(__first, __last); }
786 { _M_t.erase(__first, __last); }
804 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
805 { _M_t.swap(__x._M_t); }
824 {
return _M_t.key_comp(); }
832 {
return value_compare(_M_t.key_comp()); }
850 {
return _M_t.find(__x); }
852#if __cplusplus > 201103L
853 template<
typename _Kt>
855 find(
const _Kt& __x) ->
decltype(_M_t._M_find_tr(__x))
856 {
return _M_t._M_find_tr(__x); }
873 find(
const key_type& __x)
const
874 {
return _M_t.find(__x); }
876#if __cplusplus > 201103L
877 template<
typename _Kt>
879 find(
const _Kt& __x)
const ->
decltype(_M_t._M_find_tr(__x))
880 {
return _M_t._M_find_tr(__x); }
892 {
return _M_t.count(__x); }
894#if __cplusplus > 201103L
895 template<
typename _Kt>
897 count(
const _Kt& __x)
const ->
decltype(_M_t._M_count_tr(__x))
898 {
return _M_t._M_count_tr(__x); }
902#if __cplusplus > 201703L
911 {
return _M_t.find(__x) != _M_t.end(); }
913 template<
typename _Kt>
916 ->
decltype(_M_t._M_find_tr(__x), void(),
true)
917 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
935 {
return _M_t.lower_bound(__x); }
937#if __cplusplus > 201103L
938 template<
typename _Kt>
941 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
942 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
960 {
return _M_t.lower_bound(__x); }
962#if __cplusplus > 201103L
963 template<
typename _Kt>
966 ->
decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
967 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
980 {
return _M_t.upper_bound(__x); }
982#if __cplusplus > 201103L
983 template<
typename _Kt>
986 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
987 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1000 {
return _M_t.upper_bound(__x); }
1002#if __cplusplus > 201103L
1003 template<
typename _Kt>
1006 ->
decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1007 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1027 {
return _M_t.equal_range(__x); }
1029#if __cplusplus > 201103L
1030 template<
typename _Kt>
1054 {
return _M_t.equal_range(__x); }
1056#if __cplusplus > 201103L
1057 template<
typename _Kt>
1061 _M_t._M_equal_range_tr(__x)))
1064 _M_t._M_equal_range_tr(__x));
1069 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1074#if __cpp_lib_three_way_comparison
1075 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1076 friend __detail::__synth3way_t<pair<const _K1, _T1>>
1080 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1087#if __cpp_deduction_guides >= 201606
1089 template<
typename _InputIterator,
1090 typename _Compare = less<__iter_key_t<_InputIterator>>,
1091 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1092 typename = _RequireInputIter<_InputIterator>,
1093 typename = _RequireNotAllocator<_Compare>,
1094 typename = _RequireAllocator<_Allocator>>
1095 multimap(_InputIterator, _InputIterator,
1096 _Compare = _Compare(), _Allocator = _Allocator())
1097 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1098 _Compare, _Allocator>;
1100 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1101 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1102 typename = _RequireNotAllocator<_Compare>,
1103 typename = _RequireAllocator<_Allocator>>
1104 multimap(initializer_list<pair<_Key, _Tp>>,
1105 _Compare = _Compare(), _Allocator = _Allocator())
1106 -> multimap<_Key, _Tp, _Compare, _Allocator>;
1108 template<
typename _InputIterator,
typename _Allocator,
1109 typename = _RequireInputIter<_InputIterator>,
1110 typename = _RequireAllocator<_Allocator>>
1111 multimap(_InputIterator, _InputIterator, _Allocator)
1112 -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1113 less<__iter_key_t<_InputIterator>>, _Allocator>;
1115 template<
typename _Key,
typename _Tp,
typename _Allocator,
1116 typename = _RequireAllocator<_Allocator>>
1117 multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
1118 -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
1132 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1136 {
return __x._M_t == __y._M_t; }
1138#if __cpp_lib_three_way_comparison
1153 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1154 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1155 operator<=>(
const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1156 const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
1157 {
return __x._M_t <=> __y._M_t; }
1170 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1174 {
return __x._M_t < __y._M_t; }
1177 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1181 {
return !(__x == __y); }
1184 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1188 {
return __y < __x; }
1191 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1195 {
return !(__y < __x); }
1198 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1202 {
return !(__x < __y); }
1206 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1210 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.
swap(__y)))
1213_GLIBCXX_END_NAMESPACE_CONTAINER
1215#if __cplusplus > 201402L
1217 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1220 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1224 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1227 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1228 {
return __map._M_t; }
1231 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1232 {
return __map._M_t; }
1236_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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.
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.
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.
node_type extract(const key_type &__x)
Extract a node.
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.
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.
__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.
Uniform interface to C++98 and C++11 allocators.