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
235 && _Alloc_traits::_S_always_equal())
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>
542 __enable_if_t<is_constructible<value_type, _Pair>::value, iterator>
544 {
return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); }
570 #if __cplusplus >= 201103L 571 insert(const_iterator __position,
const value_type& __x)
573 insert(iterator __position,
const value_type& __x)
575 {
return _M_t._M_insert_equal_(__position, __x); }
577 #if __cplusplus >= 201103L 581 insert(const_iterator __position, value_type&& __x)
582 {
return _M_t._M_insert_equal_(__position, std::move(__x)); }
584 template<
typename _Pair>
585 __enable_if_t<is_constructible<value_type, _Pair&&>::value, iterator>
586 insert(const_iterator __position, _Pair&& __x)
588 return _M_t._M_emplace_hint_equal(__position,
589 std::forward<_Pair>(__x));
603 template<
typename _InputIterator>
605 insert(_InputIterator __first, _InputIterator __last)
606 { _M_t._M_insert_equal(__first, __last); }
608 #if __cplusplus >= 201103L 618 { this->
insert(__l.begin(), __l.end()); }
621 #if __cplusplus > 201402L 624 extract(const_iterator __pos)
626 __glibcxx_assert(__pos !=
end());
627 return _M_t.extract(__pos);
632 extract(
const key_type& __x)
633 {
return _M_t.extract(__x); }
638 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
642 insert(const_iterator __hint, node_type&& __nh)
643 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
645 template<
typename,
typename>
646 friend class _Rb_tree_merge_helper;
648 template<
typename _C2>
652 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
653 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
656 template<
typename _C2>
661 template<
typename _C2>
665 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
666 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
669 template<
typename _C2>
675 #if __cplusplus >= 201103L 695 {
return _M_t.erase(__position); }
698 _GLIBCXX_ABI_TAG_CXX11
701 {
return _M_t.erase(__position); }
715 erase(iterator __position)
716 { _M_t.erase(__position); }
732 {
return _M_t.erase(__x); }
734 #if __cplusplus >= 201103L 752 erase(const_iterator __first, const_iterator __last)
753 {
return _M_t.erase(__first, __last); }
771 erase(iterator __first, iterator __last)
772 { _M_t.erase(__first, __last); }
790 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
791 { _M_t.swap(__x._M_t); }
810 {
return _M_t.key_comp(); }
818 {
return value_compare(_M_t.key_comp()); }
836 {
return _M_t.find(__x); }
838 #if __cplusplus > 201103L 839 template<
typename _Kt>
841 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
842 {
return _M_t._M_find_tr(__x); }
859 find(
const key_type& __x)
const 860 {
return _M_t.find(__x); }
862 #if __cplusplus > 201103L 863 template<
typename _Kt>
865 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
866 {
return _M_t._M_find_tr(__x); }
878 {
return _M_t.count(__x); }
880 #if __cplusplus > 201103L 881 template<
typename _Kt>
883 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
884 {
return _M_t._M_count_tr(__x); }
902 {
return _M_t.lower_bound(__x); }
904 #if __cplusplus > 201103L 905 template<
typename _Kt>
908 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
909 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
927 {
return _M_t.lower_bound(__x); }
929 #if __cplusplus > 201103L 930 template<
typename _Kt>
933 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
934 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
947 {
return _M_t.upper_bound(__x); }
949 #if __cplusplus > 201103L 950 template<
typename _Kt>
953 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
954 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
967 {
return _M_t.upper_bound(__x); }
969 #if __cplusplus > 201103L 970 template<
typename _Kt>
973 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
974 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
994 {
return _M_t.equal_range(__x); }
996 #if __cplusplus > 201103L 997 template<
typename _Kt>
1021 {
return _M_t.equal_range(__x); }
1023 #if __cplusplus > 201103L 1024 template<
typename _Kt>
1028 _M_t._M_equal_range_tr(__x)))
1031 _M_t._M_equal_range_tr(__x));
1036 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1041 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1043 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1057 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1061 {
return __x._M_t == __y._M_t; }
1074 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1076 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1078 {
return __x._M_t < __y._M_t; }
1081 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1085 {
return !(__x == __y); }
1088 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1092 {
return __y < __x; }
1095 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1097 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1099 {
return !(__y < __x); }
1102 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1106 {
return !(__x < __y); }
1109 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1113 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1116 _GLIBCXX_END_NAMESPACE_CONTAINER
1118 #if __cplusplus > 201402L 1119 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1121 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1124 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1128 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1131 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1132 {
return __map._M_t; }
1135 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1136 {
return __map._M_t; }
1138 _GLIBCXX_END_NAMESPACE_VERSION
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
key_compare key_comp() const
bool operator!=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
multimap & operator=(const multimap &)=default
Multimap assignment operator.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
const_reverse_iterator rbegin() 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.
reverse_iterator rend() noexcept
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
The standard allocator, as per [20.4].
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
multimap(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multimap from a range.
const_reverse_iterator crbegin() const noexcept
iterator insert(const_iterator __position, const value_type &__x)
Inserts a std::pair into the multimap.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
const_iterator begin() const noexcept
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
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.
One of the comparison functors.
Struct holding two objects of arbitrary type.
const_iterator cbegin() const noexcept
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
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
bool operator==(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Multimap equality comparison.
iterator emplace(_Args &&... __args)
Build and insert a std::pair into the multimap.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts a std::pair into the multimap.
value_compare value_comp() const
multimap()=default
Default constructor creates no elements.
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
bool operator>=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
bool empty() const noexcept
ISO C++ entities toplevel namespace is std.
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
Uniform interface to C++98 and C++11 allocators.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
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) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
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(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
const_reverse_iterator crend() const noexcept
iterator erase(const_iterator __position)
Erases an element from a multimap.
reverse_iterator rbegin() noexcept
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator end() const noexcept
bool operator>(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a multimap.
size_type size() const 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.
multimap(multimap &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
multimap(const allocator_type &__a)
Allocator-extended default constructor.
__enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert(const_iterator __position, _Pair &&__x)
Inserts a std::pair into the multimap.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
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 count(const key_type &__x) const
Finds the number of elements with given key.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
iterator begin() noexcept
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
iterator insert(value_type &&__x)
Inserts a std::pair into the multimap.
__enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert(_Pair &&__x)
Inserts a std::pair into the multimap.
const_reverse_iterator rend() const noexcept
const_iterator cend() const noexcept
iterator insert(const_iterator __position, value_type &&__x)
Inserts a std::pair into the multimap.