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;
109 typedef typename _Alloc::value_type _Alloc_value_type;
110 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
111 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
112 _BinaryFunctionConcept)
113 __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
117 : public
std::binary_function<value_type, value_type,
bool>
119 friend class multimap<_Key, _Tp, _Compare, _Alloc>;
123 value_compare(_Compare __c)
127 bool operator()(
const value_type& __x,
const value_type& __y)
const 128 {
return comp(__x.first, __y.first); }
134 rebind<value_type>::other _Pair_alloc_type;
136 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
137 key_compare, _Pair_alloc_type> _Rep_type;
146 typedef typename _Alloc_traits::pointer pointer;
147 typedef typename _Alloc_traits::const_pointer const_pointer;
148 typedef typename _Alloc_traits::reference reference;
149 typedef typename _Alloc_traits::const_reference const_reference;
150 typedef typename _Rep_type::iterator iterator;
151 typedef typename _Rep_type::const_iterator const_iterator;
152 typedef typename _Rep_type::size_type size_type;
153 typedef typename _Rep_type::difference_type difference_type;
154 typedef typename _Rep_type::reverse_iterator reverse_iterator;
155 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
157 #if __cplusplus > 201402L 158 using node_type =
typename _Rep_type::node_type;
167 #if __cplusplus < 201103L 180 const allocator_type& __a = allocator_type())
181 : _M_t(__comp, _Pair_alloc_type(__a)) { }
193 #if __cplusplus >= 201103L 202 noexcept(is_nothrow_copy_constructible<_Compare>::value)
203 : _M_t(
std::move(__x._M_t)) { }
216 const _Compare& __comp = _Compare(),
217 const allocator_type& __a = allocator_type())
218 : _M_t(__comp, _Pair_alloc_type(__a))
219 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
224 : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
228 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
232 noexcept(is_nothrow_copy_constructible<_Compare>::value
233 && _Alloc_traits::_S_always_equal())
234 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
238 : _M_t(_Compare(), _Pair_alloc_type(__a))
239 { _M_t._M_insert_equal(__l.begin(), __l.end()); }
242 template<
typename _InputIterator>
243 multimap(_InputIterator __first, _InputIterator __last,
244 const allocator_type& __a)
245 : _M_t(_Compare(), _Pair_alloc_type(__a))
246 { _M_t._M_insert_equal(__first, __last); }
258 template<
typename _InputIterator>
259 multimap(_InputIterator __first, _InputIterator __last)
261 { _M_t._M_insert_equal(__first, __last); }
274 template<
typename _InputIterator>
275 multimap(_InputIterator __first, _InputIterator __last,
276 const _Compare& __comp,
277 const allocator_type& __a = allocator_type())
278 : _M_t(__comp, _Pair_alloc_type(__a))
279 { _M_t._M_insert_equal(__first, __last); }
305 #if __cplusplus >= 201103L 324 _M_t._M_assign_equal(__l.begin(), __l.end());
332 {
return allocator_type(_M_t.get_allocator()); }
342 {
return _M_t.begin(); }
351 {
return _M_t.begin(); }
360 {
return _M_t.end(); }
368 end() const _GLIBCXX_NOEXCEPT
369 {
return _M_t.end(); }
378 {
return _M_t.rbegin(); }
385 const_reverse_iterator
387 {
return _M_t.rbegin(); }
396 {
return _M_t.rend(); }
403 const_reverse_iterator
405 {
return _M_t.rend(); }
407 #if __cplusplus >= 201103L 415 {
return _M_t.begin(); }
424 {
return _M_t.end(); }
431 const_reverse_iterator
433 {
return _M_t.rbegin(); }
440 const_reverse_iterator
442 {
return _M_t.rend(); }
449 {
return _M_t.empty(); }
454 {
return _M_t.size(); }
459 {
return _M_t.max_size(); }
462 #if __cplusplus >= 201103L 479 template<
typename... _Args>
482 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
506 template<
typename... _Args>
510 return _M_t._M_emplace_hint_equal(__pos,
511 std::forward<_Args>(__args)...);
529 {
return _M_t._M_insert_equal(__x); }
531 #if __cplusplus >= 201103L 532 template<
typename _Pair,
typename =
typename 533 std::enable_if<std::is_constructible<value_type,
534 _Pair&&>::value>::type>
537 {
return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
561 #if __cplusplus >= 201103L 562 insert(const_iterator __position,
const value_type& __x)
564 insert(iterator __position,
const value_type& __x)
566 {
return _M_t._M_insert_equal_(__position, __x); }
568 #if __cplusplus >= 201103L 569 template<
typename _Pair,
typename =
typename 570 std::enable_if<std::is_constructible<value_type,
571 _Pair&&>::value>::type>
573 insert(const_iterator __position, _Pair&& __x)
574 {
return _M_t._M_insert_equal_(__position,
575 std::forward<_Pair>(__x)); }
587 template<
typename _InputIterator>
589 insert(_InputIterator __first, _InputIterator __last)
590 { _M_t._M_insert_equal(__first, __last); }
592 #if __cplusplus >= 201103L 602 { this->
insert(__l.begin(), __l.end()); }
605 #if __cplusplus > 201402L 608 extract(const_iterator __pos)
610 __glibcxx_assert(__pos !=
end());
611 return _M_t.extract(__pos);
616 extract(
const key_type& __x)
617 {
return _M_t.extract(__x); }
622 {
return _M_t._M_reinsert_node_equal(std::move(__nh)); }
626 insert(const_iterator __hint, node_type&& __nh)
627 {
return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
629 template<
typename,
typename>
630 friend class _Rb_tree_merge_helper;
632 template<
typename _C2>
636 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
637 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
640 template<
typename _C2>
645 template<
typename _C2>
649 using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>;
650 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
653 template<
typename _C2>
659 #if __cplusplus >= 201103L 677 {
return _M_t.erase(__position); }
680 _GLIBCXX_ABI_TAG_CXX11
682 erase(iterator __position)
683 {
return _M_t.erase(__position); }
696 erase(iterator __position)
697 { _M_t.erase(__position); }
713 {
return _M_t.erase(__x); }
715 #if __cplusplus >= 201103L 733 erase(const_iterator __first, const_iterator __last)
734 {
return _M_t.erase(__first, __last); }
752 erase(iterator __first, iterator __last)
753 { _M_t.erase(__first, __last); }
771 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
772 { _M_t.swap(__x._M_t); }
791 {
return _M_t.key_comp(); }
799 {
return value_compare(_M_t.key_comp()); }
817 {
return _M_t.find(__x); }
819 #if __cplusplus > 201103L 820 template<
typename _Kt>
822 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
823 {
return _M_t._M_find_tr(__x); }
840 find(
const key_type& __x)
const 841 {
return _M_t.find(__x); }
843 #if __cplusplus > 201103L 844 template<
typename _Kt>
846 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
847 {
return _M_t._M_find_tr(__x); }
859 {
return _M_t.count(__x); }
861 #if __cplusplus > 201103L 862 template<
typename _Kt>
864 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
865 {
return _M_t._M_count_tr(__x); }
883 {
return _M_t.lower_bound(__x); }
885 #if __cplusplus > 201103L 886 template<
typename _Kt>
889 -> decltype(_M_t._M_lower_bound_tr(__x))
890 {
return _M_t._M_lower_bound_tr(__x); }
908 {
return _M_t.lower_bound(__x); }
910 #if __cplusplus > 201103L 911 template<
typename _Kt>
914 -> decltype(_M_t._M_lower_bound_tr(__x))
915 {
return _M_t._M_lower_bound_tr(__x); }
928 {
return _M_t.upper_bound(__x); }
930 #if __cplusplus > 201103L 931 template<
typename _Kt>
934 -> decltype(_M_t._M_upper_bound_tr(__x))
935 {
return _M_t._M_upper_bound_tr(__x); }
948 {
return _M_t.upper_bound(__x); }
950 #if __cplusplus > 201103L 951 template<
typename _Kt>
954 -> decltype(_M_t._M_upper_bound_tr(__x))
955 {
return _M_t._M_upper_bound_tr(__x); }
975 {
return _M_t.equal_range(__x); }
977 #if __cplusplus > 201103L 978 template<
typename _Kt>
981 -> decltype(_M_t._M_equal_range_tr(__x))
982 {
return _M_t._M_equal_range_tr(__x); }
1002 {
return _M_t.equal_range(__x); }
1004 #if __cplusplus > 201103L 1005 template<
typename _Kt>
1008 -> decltype(_M_t._M_equal_range_tr(__x))
1009 {
return _M_t._M_equal_range_tr(__x); }
1013 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1018 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1020 operator<(const multimap<_K1, _T1, _C1, _A1>&,
1034 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1038 {
return __x._M_t == __y._M_t; }
1051 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1053 operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1055 {
return __x._M_t < __y._M_t; }
1058 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1062 {
return !(__x == __y); }
1065 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1069 {
return __y < __x; }
1072 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1074 operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1076 {
return !(__y < __x); }
1079 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1083 {
return !(__x < __y); }
1086 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1090 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1093 _GLIBCXX_END_NAMESPACE_CONTAINER
1095 #if __cplusplus > 201402L 1096 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1098 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1101 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
1105 friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
1108 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1109 {
return __map._M_t; }
1112 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1113 {
return __map._M_t; }
1115 _GLIBCXX_END_NAMESPACE_VERSION
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
multimap(const multimap &__m, const allocator_type &__a)
Allocator-extended copy constructor.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts a std::pair into the multimap.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
bool operator!=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator==.
multimap(multimap &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multimap.
multimap & operator=(const multimap &__x)
Multimap assignment operator.
reverse_iterator rend() noexcept
Uniform interface to C++98 and C++11 allocators.
multimap(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multimap with no elements.
multimap(_InputIterator __first, _InputIterator __last)
Builds a multimap from a range.
auto lower_bound(const _Kt &__x) const -> decltype(_M_t._M_lower_bound_tr(__x))
Finds the beginning of a subsequence matching given key.
ISO C++ entities toplevel namespace is std.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
const_iterator end() const noexcept
multimap(const allocator_type &__a)
Allocator-extended default constructor.
multimap & operator=(initializer_list< value_type > __l)
Multimap list assignment operator.
multimap(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multimap from a range.
auto upper_bound(const _Kt &__x) const -> decltype(_M_t._M_upper_bound_tr(__x))
Finds the end of a subsequence matching given key.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
size_type max_size() const noexcept
size_type count(const key_type &__x) const
Finds the number of elements with given key.
iterator insert(const value_type &__x)
Inserts a std::pair into the multimap.
iterator erase(const_iterator __position)
Erases an element from a multimap.
multimap(multimap &&__x) noexcept(is_nothrow_copy_constructible< _Compare >::value)
Multimap move constructor.
void swap(multimap &__x) noexcept(/*conditional */)
Swaps data with another multimap.
multimap(const multimap &__x)
Multimap copy constructor.
multimap(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multimap from an initializer_list.
const_reverse_iterator rbegin() const noexcept
auto equal_range(const _Kt &__x) -> decltype(_M_t._M_equal_range_tr(__x))
Finds a subsequence matching given key.
bool operator>(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
auto upper_bound(const _Kt &__x) -> decltype(_M_t._M_upper_bound_tr(__x))
Finds the end of a subsequence matching given key.
bool empty() const noexcept
const_iterator begin() const noexcept
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a multimap.
key_compare key_comp() const
reverse_iterator rbegin() noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
multimap()=default
Default constructor creates no elements.
A standard container made up of (key,value) pairs, which can be retrieved based on a key...
Struct holding two objects of arbitrary type.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
bool operator==(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Multimap equality comparison.
const_reverse_iterator rend() const noexcept
bool operator>=(const multimap< _Key, _Tp, _Compare, _Alloc > &__x, const multimap< _Key, _Tp, _Compare, _Alloc > &__y)
Based on operator<.
One of the comparison functors.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of std::pairs into the multimap.
auto equal_range(const _Kt &__x) const -> decltype(_M_t._M_equal_range_tr(__x))
Finds a subsequence matching given key.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
const_iterator cbegin() const noexcept
const_iterator cend() const noexcept
const_reverse_iterator crend() const noexcept
iterator insert(const_iterator __position, const value_type &__x)
Inserts a std::pair into the multimap.
iterator find(const key_type &__x)
Tries to locate an element in a multimap.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
multimap(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
multimap(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
iterator emplace(_Args &&... __args)
Build and insert a std::pair into the multimap.
iterator begin() noexcept
auto lower_bound(const _Kt &__x) -> decltype(_M_t._M_lower_bound_tr(__x))
Finds the beginning of 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.
size_type size() const noexcept
value_compare value_comp() const
const_iterator find(const key_type &__x) const
Tries to locate an element in a multimap.
const_reverse_iterator crbegin() const noexcept
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
The standard allocator, as per [20.4].