56#ifndef _STL_MULTISET_H
57#define _STL_MULTISET_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 _Compare,
typename _Alloc>
98 template <
typename _Key,
typename _Compare = std::less<_Key>,
99 typename _Alloc = std::allocator<_Key> >
102#ifdef _GLIBCXX_CONCEPT_CHECKS
104 typedef typename _Alloc::value_type _Alloc_value_type;
105# if __cplusplus < 201103L
106 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
108 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
109 _BinaryFunctionConcept)
110 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
113#if __cplusplus >= 201103L
115 "std::multiset must have a non-const, non-volatile value_type");
116# if __cplusplus > 201703L || defined __STRICT_ANSI__
118 "std::multiset must have the same value_type as its allocator");
124 typedef _Key key_type;
125 typedef _Key value_type;
126 typedef _Compare key_compare;
127 typedef _Compare value_compare;
128 typedef _Alloc allocator_type;
133 rebind<_Key>::other _Key_alloc_type;
135 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
136 key_compare, _Key_alloc_type> _Rep_type;
143 typedef typename _Alloc_traits::pointer pointer;
144 typedef typename _Alloc_traits::const_pointer const_pointer;
145 typedef typename _Alloc_traits::reference reference;
146 typedef typename _Alloc_traits::const_reference const_reference;
150 typedef typename _Rep_type::const_iterator iterator;
151 typedef typename _Rep_type::const_iterator const_iterator;
152 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
153 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
154 typedef typename _Rep_type::size_type size_type;
155 typedef typename _Rep_type::difference_type difference_type;
157#ifdef __glibcxx_node_extract
158 using node_type =
typename _Rep_type::node_type;
165#if __cplusplus < 201103L
178 const allocator_type& __a = allocator_type())
179 : _M_t(__comp, _Key_alloc_type(__a)) { }
190 template<
typename _InputIterator>
191 multiset(_InputIterator __first, _InputIterator __last)
193 { _M_t._M_insert_range_equal(__first, __last); }
206 template<
typename _InputIterator>
207 multiset(_InputIterator __first, _InputIterator __last,
208 const _Compare& __comp,
209 const allocator_type& __a = allocator_type())
210 : _M_t(__comp, _Key_alloc_type(__a))
211 { _M_t._M_insert_range_equal(__first, __last); }
218#if __cplusplus < 201103L
244 const _Compare& __comp = _Compare(),
245 const allocator_type& __a = allocator_type())
246 : _M_t(__comp, _Key_alloc_type(__a))
247 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
252 : _M_t(_Key_alloc_type(__a)) { }
256 const __type_identity_t<allocator_type>& __a)
257 : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
262 && _Alloc_traits::_S_always_equal())
263 : _M_t(
std::
move(__m._M_t), _Key_alloc_type(__a)) { }
267 : _M_t(_Key_alloc_type(__a))
268 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
271 template<
typename _InputIterator>
272 multiset(_InputIterator __first, _InputIterator __last,
273 const allocator_type& __a)
274 : _M_t(_Key_alloc_type(__a))
275 { _M_t._M_insert_range_equal(__first, __last); }
277#if __glibcxx_containers_ranges
282 template<__detail::__container_compatible_range<_Key> _Rg>
284 const _Compare& __comp,
285 const _Alloc& __a = _Alloc())
286 : _M_t(__comp, _Key_alloc_type(__a))
290 template<__detail::__container_compatible_range<_Key> _Rg>
291 multiset(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
292 : _M_t(_Key_alloc_type(__a))
309#if __cplusplus < 201103L
338 _M_t._M_assign_equal(__l.begin(), __l.end());
348 {
return _M_t.key_comp(); }
352 {
return _M_t.key_comp(); }
356 {
return allocator_type(_M_t.get_allocator()); }
365 {
return _M_t.begin(); }
373 end() const _GLIBCXX_NOEXCEPT
374 {
return _M_t.end(); }
383 {
return _M_t.rbegin(); }
392 {
return _M_t.rend(); }
394#if __cplusplus >= 201103L
402 {
return _M_t.begin(); }
411 {
return _M_t.end(); }
420 {
return _M_t.rbegin(); }
429 {
return _M_t.rend(); }
433 _GLIBCXX_NODISCARD
bool
435 {
return _M_t.empty(); }
440 {
return _M_t.size(); }
445 {
return _M_t.max_size(); }
462 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
463 { _M_t.swap(__x._M_t); }
466#if __cplusplus >= 201103L
479 template<
typename... _Args>
505 template<
typename... _Args>
509 return _M_t._M_emplace_hint_equal(__pos,
527 {
return _M_t._M_insert_equal(__x); }
529#if __cplusplus >= 201103L
532 {
return _M_t._M_insert_equal(
std::move(__x)); }
556 insert(const_iterator __position,
const value_type& __x)
557 {
return _M_t._M_insert_equal_(__position, __x); }
559#if __cplusplus >= 201103L
562 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
573 template<
typename _InputIterator>
575 insert(_InputIterator __first, _InputIterator __last)
576 { _M_t._M_insert_range_equal(__first, __last); }
578#if __cplusplus >= 201103L
588 { this->
insert(__l.begin(), __l.end()); }
591#if __glibcxx_containers_ranges
598 template<__detail::__container_compatible_range<_Key> _Rg>
600 insert_range(_Rg&& __rg)
602 auto __first = ranges::begin(__rg);
603 const auto __last = ranges::end(__rg);
604 for (; __first != __last; ++__first)
605 _M_t._M_emplace_equal(*__first);
610#ifdef __glibcxx_node_extract
613 extract(const_iterator __pos)
615 __glibcxx_assert(__pos !=
end());
616 return _M_t.extract(__pos);
621 extract(
const key_type& __x)
622 {
return _M_t.extract(__x); }
627 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
631 insert(const_iterator __hint, node_type&& __nh)
632 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
634 template<
typename,
typename>
635 friend struct std::_Rb_tree_merge_helper;
637 template<
typename _Compare1>
641 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
642 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
645 template<
typename _Compare1>
650 template<
typename _Compare1>
652 merge(set<_Key, _Compare1, _Alloc>& __source)
654 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
655 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
658 template<
typename _Compare1>
660 merge(set<_Key, _Compare1, _Alloc>&& __source)
664#if __cplusplus >= 201103L
680 _GLIBCXX_ABI_TAG_CXX11
683 {
return _M_t.erase(__position); }
697 { _M_t.erase(__position); }
713 {
return _M_t.erase(__x); }
715#if __cplusplus >= 201103L
732 _GLIBCXX_ABI_TAG_CXX11
734 erase(const_iterator __first, const_iterator __last)
735 {
return _M_t.erase(__first, __last); }
751 { _M_t.erase(__first, __last); }
774 {
return _M_t.count(__x); }
776#if __cplusplus > 201103L
777 template<
typename _Kt>
779 count(
const _Kt& __x)
const ->
decltype(_M_t._M_count_tr(__x))
780 {
return _M_t._M_count_tr(__x); }
784#if __cplusplus > 201703L
793 {
return _M_t.find(__x) != _M_t.end(); }
795 template<
typename _Kt>
798 ->
decltype(_M_t._M_find_tr(__x),
void(),
true)
799 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
819 {
return _M_t.find(__x); }
822 find(
const key_type& __x)
const
823 {
return _M_t.find(__x); }
825#if __cplusplus > 201103L
826 template<
typename _Kt>
829 ->
decltype(iterator{_M_t._M_find_tr(__x)})
830 {
return iterator{_M_t._M_find_tr(__x)}; }
832 template<
typename _Kt>
835 ->
decltype(const_iterator{_M_t._M_find_tr(__x)})
836 {
return const_iterator{_M_t._M_find_tr(__x)}; }
854 {
return _M_t.lower_bound(__x); }
858 {
return _M_t.lower_bound(__x); }
860#if __cplusplus > 201103L
861 template<
typename _Kt>
864 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
865 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
867 template<
typename _Kt>
870 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
871 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
884 {
return _M_t.upper_bound(__x); }
888 {
return _M_t.upper_bound(__x); }
890#if __cplusplus > 201103L
891 template<
typename _Kt>
894 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
895 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
897 template<
typename _Kt>
900 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
901 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
923 {
return _M_t.equal_range(__x); }
927 {
return _M_t.equal_range(__x); }
929#if __cplusplus > 201103L
930 template<
typename _Kt>
936 template<
typename _Kt>
944 template<
typename _K1,
typename _C1,
typename _A1>
949#if __cpp_lib_three_way_comparison
950 template<
typename _K1,
typename _C1,
typename _A1>
951 friend __detail::__synth3way_t<_K1>
955 template<
typename _K1,
typename _C1,
typename _A1>
962#if __cpp_deduction_guides >= 201606
964 template<
typename _InputIterator,
966 less<typename iterator_traits<_InputIterator>::value_type>,
967 typename _Allocator =
968 allocator<typename iterator_traits<_InputIterator>::value_type>,
969 typename = _RequireInputIter<_InputIterator>,
970 typename = _RequireNotAllocator<_Compare>,
971 typename = _RequireAllocator<_Allocator>>
972 multiset(_InputIterator, _InputIterator,
973 _Compare = _Compare(), _Allocator = _Allocator())
974 -> multiset<typename iterator_traits<_InputIterator>::value_type,
975 _Compare, _Allocator>;
977 template<
typename _Key,
978 typename _Compare = less<_Key>,
979 typename _Allocator = allocator<_Key>,
980 typename = _RequireNotAllocator<_Compare>,
981 typename = _RequireAllocator<_Allocator>>
982 multiset(initializer_list<_Key>,
983 _Compare = _Compare(), _Allocator = _Allocator())
984 -> multiset<_Key, _Compare, _Allocator>;
986 template<
typename _InputIterator,
typename _Allocator,
987 typename = _RequireInputIter<_InputIterator>,
988 typename = _RequireAllocator<_Allocator>>
989 multiset(_InputIterator, _InputIterator, _Allocator)
990 -> multiset<typename iterator_traits<_InputIterator>::value_type,
991 less<typename iterator_traits<_InputIterator>::value_type>,
994 template<
typename _Key,
typename _Allocator,
995 typename = _RequireAllocator<_Allocator>>
996 multiset(initializer_list<_Key>, _Allocator)
997 -> multiset<_Key, less<_Key>, _Allocator>;
999#if __glibcxx_containers_ranges
1000 template<ranges::input_range _Rg,
1001 __not_allocator_like _Compare = less<ranges::range_value_t<_Rg>>,
1003 multiset(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1004 -> multiset<ranges::range_value_t<_Rg>, _Compare, _Alloc>;
1006 template<ranges::input_range _Rg, __allocator_like _Alloc>
1007 multiset(from_range_t, _Rg&&, _Alloc)
1008 -> multiset<ranges::range_value_t<_Rg>, less<ranges::range_value_t<_Rg>>, _Alloc>;
1023 template<
typename _Key,
typename _Compare,
typename _Alloc>
1027 {
return __x._M_t == __y._M_t; }
1029#if __cpp_lib_three_way_comparison
1044 template<
typename _Key,
typename _Compare,
typename _Alloc>
1045 inline __detail::__synth3way_t<_Key>
1046 operator<=>(
const multiset<_Key, _Compare, _Alloc>& __x,
1047 const multiset<_Key, _Compare, _Alloc>& __y)
1048 {
return __x._M_t <=> __y._M_t; }
1061 template<
typename _Key,
typename _Compare,
typename _Alloc>
1065 {
return __x._M_t < __y._M_t; }
1068 template<
typename _Key,
typename _Compare,
typename _Alloc>
1072 {
return !(__x == __y); }
1075 template<
typename _Key,
typename _Compare,
typename _Alloc>
1079 {
return __y < __x; }
1082 template<
typename _Key,
typename _Compare,
typename _Alloc>
1086 {
return !(__y < __x); }
1089 template<
typename _Key,
typename _Compare,
typename _Alloc>
1093 {
return !(__x < __y); }
1097 template<
typename _Key,
typename _Compare,
typename _Alloc>
1101 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
1104_GLIBCXX_END_NAMESPACE_CONTAINER
1106#if __cplusplus > 201402L
1108 template<
typename _Val,
typename _Cmp1,
typename _Alloc,
typename _Cmp2>
1110 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>,
1114 friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>;
1117 _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1118 {
return __set._M_t; }
1121 _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1122 {
return __set._M_t; }
1126_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.
A standard container made up of unique keys, which can be retrieved in logarithmic time.
A standard container made up of elements, which can be retrieved in logarithmic time.
iterator emplace(_Args &&... __args)
Builds and inserts an element into the multiset.
multiset(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Builds and inserts an element into the multiset.
reverse_iterator crend() const noexcept
auto find(const _Kt &__x) const -> decltype(const_iterator{_M_t._M_find_tr(__x)})
Tries to locate an element in a set.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
multiset & operator=(const multiset &)=default
Multiset assignment operator.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a multiset.
reverse_iterator crbegin() const noexcept
multiset(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a multiset with no elements.
auto contains(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x), void(), true)
Finds whether an element with the given key exists.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
void swap(multiset &__x) noexcept(/*conditional */)
Swaps data with another multiset.
iterator cbegin() const noexcept
value_compare value_comp() const
Returns the comparison object.
multiset(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
multiset(const multiset &__m, const __type_identity_t< allocator_type > &__a)
Allocator-extended copy constructor.
auto upper_bound(const _Kt &__x) const -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
bool empty() const noexcept
Returns true if the set is empty.
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
multiset()=default
Default constructor creates no elements.
iterator insert(const value_type &__x)
Inserts an element into the multiset.
reverse_iterator rbegin() const noexcept
reverse_iterator rend() const noexcept
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the multiset.
void insert(_InputIterator __first, _InputIterator __last)
A template function that tries to insert a range of elements.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
multiset(multiset &&)=default
Multiset move constructor.
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 find(const key_type &__x)
Tries to locate an element in a set.
multiset & operator=(initializer_list< value_type > __l)
Multiset list assignment operator.
auto find(const _Kt &__x) -> decltype(iterator{_M_t._M_find_tr(__x)})
Tries to locate an element in a set.
auto lower_bound(const _Kt &__x) const -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
size_type size() const noexcept
Returns the size of the set.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
_GLIBCXX_ABI_TAG_CXX11 iterator erase(const_iterator __position)
Erases an element from a multiset.
iterator cend() const noexcept
multiset & operator=(multiset &&)=default
Move assignment operator.
multiset(multiset &&__m, const __type_identity_t< allocator_type > &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
allocator_type get_allocator() const noexcept
Returns the memory allocation object.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
auto equal_range(const _Kt &__x) const -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
key_compare key_comp() const
Returns the comparison object.
multiset(_InputIterator __first, _InputIterator __last)
Builds a multiset from a range.
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 an element into the multiset.
bool contains(const key_type &__x) const
Finds whether an element with the given key exists.
iterator begin() const noexcept
multiset(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a multiset from an initializer_list.
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
const_iterator find(const key_type &__x) const
Tries to locate an element in a set.
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
multiset(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a multiset from a range.
multiset(const allocator_type &__a)
Allocator-extended default constructor.
size_type max_size() const noexcept
Returns the maximum size of the set.
multiset(const multiset &)=default
Multiset copy constructor.
iterator end() const noexcept
Uniform interface to C++98 and C++11 allocators.