56#ifndef _STL_MULTISET_H
57#define _STL_MULTISET_H 1
60#if __cplusplus >= 201103L
63#if __glibcxx_containers_ranges
68namespace std _GLIBCXX_VISIBILITY(default)
70_GLIBCXX_BEGIN_NAMESPACE_VERSION
71_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
73 template<
typename _Key,
typename _Compare,
typename _Alloc>
99 template <
typename _Key,
typename _Compare = std::less<_Key>,
100 typename _Alloc = std::allocator<_Key> >
103#ifdef _GLIBCXX_CONCEPT_CHECKS
105 typedef typename _Alloc::value_type _Alloc_value_type;
106# if __cplusplus < 201103L
107 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
109 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
110 _BinaryFunctionConcept)
111 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
114#if __cplusplus >= 201103L
116 "std::multiset must have a non-const, non-volatile value_type");
117# if __cplusplus > 201703L || defined __STRICT_ANSI__
119 "std::multiset must have the same value_type as its allocator");
125 typedef _Key key_type;
126 typedef _Key value_type;
127 typedef _Compare key_compare;
128 typedef _Compare value_compare;
129 typedef _Alloc allocator_type;
134 rebind<_Key>::other _Key_alloc_type;
136 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
137 key_compare, _Key_alloc_type> _Rep_type;
144 typedef typename _Alloc_traits::pointer pointer;
145 typedef typename _Alloc_traits::const_pointer const_pointer;
146 typedef typename _Alloc_traits::reference reference;
147 typedef typename _Alloc_traits::const_reference const_reference;
151 typedef typename _Rep_type::const_iterator iterator;
152 typedef typename _Rep_type::const_iterator const_iterator;
153 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
154 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
155 typedef typename _Rep_type::size_type size_type;
156 typedef typename _Rep_type::difference_type difference_type;
158#ifdef __glibcxx_node_extract
159 using node_type =
typename _Rep_type::node_type;
166#if __cplusplus < 201103L
179 const allocator_type& __a = allocator_type())
180 : _M_t(__comp, _Key_alloc_type(__a)) { }
191 template<
typename _InputIterator>
192 multiset(_InputIterator __first, _InputIterator __last)
194 { _M_t._M_insert_range_equal(__first, __last); }
207 template<
typename _InputIterator>
208 multiset(_InputIterator __first, _InputIterator __last,
209 const _Compare& __comp,
210 const allocator_type& __a = allocator_type())
211 : _M_t(__comp, _Key_alloc_type(__a))
212 { _M_t._M_insert_range_equal(__first, __last); }
219#if __cplusplus < 201103L
245 const _Compare& __comp = _Compare(),
246 const allocator_type& __a = allocator_type())
247 : _M_t(__comp, _Key_alloc_type(__a))
248 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
253 : _M_t(_Key_alloc_type(__a)) { }
257 const __type_identity_t<allocator_type>& __a)
258 : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
263 && _Alloc_traits::_S_always_equal())
264 : _M_t(
std::
move(__m._M_t), _Key_alloc_type(__a)) { }
268 : _M_t(_Key_alloc_type(__a))
269 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
272 template<
typename _InputIterator>
273 multiset(_InputIterator __first, _InputIterator __last,
274 const allocator_type& __a)
275 : _M_t(_Key_alloc_type(__a))
276 { _M_t._M_insert_range_equal(__first, __last); }
278#if __glibcxx_containers_ranges
283 template<__detail::__container_compatible_range<_Key> _Rg>
285 const _Compare& __comp,
286 const _Alloc& __a = _Alloc())
287 : _M_t(__comp, _Key_alloc_type(__a))
291 template<__detail::__container_compatible_range<_Key> _Rg>
292 multiset(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
293 : _M_t(_Key_alloc_type(__a))
310#if __cplusplus < 201103L
339 _M_t._M_assign_equal(__l.begin(), __l.end());
349 {
return _M_t.key_comp(); }
353 {
return _M_t.key_comp(); }
357 {
return allocator_type(_M_t.get_allocator()); }
366 {
return _M_t.begin(); }
374 end() const _GLIBCXX_NOEXCEPT
375 {
return _M_t.end(); }
384 {
return _M_t.rbegin(); }
393 {
return _M_t.rend(); }
395#if __cplusplus >= 201103L
403 {
return _M_t.begin(); }
412 {
return _M_t.end(); }
421 {
return _M_t.rbegin(); }
430 {
return _M_t.rend(); }
434 _GLIBCXX_NODISCARD
bool
436 {
return _M_t.empty(); }
441 {
return _M_t.size(); }
446 {
return _M_t.max_size(); }
463 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
464 { _M_t.swap(__x._M_t); }
467#if __cplusplus >= 201103L
480 template<
typename... _Args>
506 template<
typename... _Args>
510 return _M_t._M_emplace_hint_equal(__pos,
528 {
return _M_t._M_insert_equal(__x); }
530#if __cplusplus >= 201103L
533 {
return _M_t._M_insert_equal(
std::move(__x)); }
557 insert(const_iterator __position,
const value_type& __x)
558 {
return _M_t._M_insert_equal_(__position, __x); }
560#if __cplusplus >= 201103L
563 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
574 template<
typename _InputIterator>
576 insert(_InputIterator __first, _InputIterator __last)
577 { _M_t._M_insert_range_equal(__first, __last); }
579#if __cplusplus >= 201103L
589 { this->
insert(__l.begin(), __l.end()); }
592#if __glibcxx_containers_ranges
599 template<__detail::__container_compatible_range<_Key> _Rg>
601 insert_range(_Rg&& __rg)
603 auto __first = ranges::begin(__rg);
604 const auto __last = ranges::end(__rg);
605 for (; __first != __last; ++__first)
606 _M_t._M_emplace_equal(*__first);
611#ifdef __glibcxx_node_extract
614 extract(const_iterator __pos)
616 __glibcxx_assert(__pos !=
end());
617 return _M_t.extract(__pos);
622 extract(
const key_type& __x)
623 {
return _M_t.extract(__x); }
625#ifdef __glibcxx_associative_heterogeneous_erasure
626 template <__heterogeneous_tree_key<multiset> _Kt>
629 {
return _M_t._M_extract_tr(__key); }
635 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
639 insert(const_iterator __hint, node_type&& __nh)
640 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
642 template<
typename,
typename>
643 friend struct std::_Rb_tree_merge_helper;
645 template<
typename _Compare1>
649 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
650 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
653 template<
typename _Compare1>
658 template<
typename _Compare1>
660 merge(set<_Key, _Compare1, _Alloc>& __source)
662 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
663 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
666 template<
typename _Compare1>
668 merge(set<_Key, _Compare1, _Alloc>&& __source)
672#if __cplusplus >= 201103L
688 _GLIBCXX_ABI_TAG_CXX11
691 {
return _M_t.erase(__position); }
705 { _M_t.erase(__position); }
721 {
return _M_t.erase(__x); }
723#ifdef __glibcxx_associative_heterogeneous_erasure
724 template <__heterogeneous_tree_key<multiset> _Kt>
727 {
return _M_t._M_erase_tr(__key); }
730#if __cplusplus >= 201103L
747 _GLIBCXX_ABI_TAG_CXX11
749 erase(const_iterator __first, const_iterator __last)
750 {
return _M_t.erase(__first, __last); }
766 { _M_t.erase(__first, __last); }
789 {
return _M_t.count(__x); }
791#ifdef __glibcxx_generic_associative_lookup
792 template<
typename _Kt>
794 count(
const _Kt& __x)
const ->
decltype(_M_t._M_count_tr(__x))
795 {
return _M_t._M_count_tr(__x); }
799#if __cplusplus > 201703L
808 {
return _M_t.find(__x) != _M_t.end(); }
810 template<
typename _Kt>
813 ->
decltype(_M_t._M_find_tr(__x),
void(),
true)
814 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
834 {
return _M_t.find(__x); }
837 find(
const key_type& __x)
const
838 {
return _M_t.find(__x); }
840#ifdef __glibcxx_generic_associative_lookup
841 template<
typename _Kt>
844 ->
decltype(
iterator{_M_t._M_find_tr(__x)})
845 {
return iterator{_M_t._M_find_tr(__x)}; }
847 template<
typename _Kt>
849 find(
const _Kt& __x)
const
850 ->
decltype(const_iterator{_M_t._M_find_tr(__x)})
851 {
return const_iterator{_M_t._M_find_tr(__x)}; }
869 {
return _M_t.lower_bound(__x); }
873 {
return _M_t.lower_bound(__x); }
875#ifdef __glibcxx_generic_associative_lookup
876 template<
typename _Kt>
879 ->
decltype(
iterator(_M_t._M_lower_bound_tr(__x)))
880 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
882 template<
typename _Kt>
885 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
886 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
899 {
return _M_t.upper_bound(__x); }
903 {
return _M_t.upper_bound(__x); }
905#ifdef __glibcxx_generic_associative_lookup
906 template<
typename _Kt>
909 ->
decltype(
iterator(_M_t._M_upper_bound_tr(__x)))
910 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
912 template<
typename _Kt>
915 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
916 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
938 {
return _M_t.equal_range(__x); }
942 {
return _M_t.equal_range(__x); }
944#ifdef __glibcxx_generic_associative_lookup
945 template<
typename _Kt>
951 template<
typename _Kt>
959 template<
typename _K1,
typename _C1,
typename _A1>
964#if __cpp_lib_three_way_comparison
965 template<
typename _K1,
typename _C1,
typename _A1>
966 friend __detail::__synth3way_t<_K1>
970 template<
typename _K1,
typename _C1,
typename _A1>
977#if __cpp_deduction_guides >= 201606
979 template<
typename _InputIterator,
982 typename _Allocator =
984 typename = _RequireInputIter<_InputIterator>,
985 typename = _RequireNotAllocator<_Compare>,
986 typename = _RequireAllocator<_Allocator>>
987 multiset(_InputIterator, _InputIterator,
988 _Compare = _Compare(), _Allocator = _Allocator())
990 _Compare, _Allocator>;
992 template<
typename _Key,
995 typename = _RequireNotAllocator<_Compare>,
996 typename = _RequireAllocator<_Allocator>>
998 _Compare = _Compare(), _Allocator = _Allocator())
1001 template<
typename _InputIterator,
typename _Allocator,
1002 typename = _RequireInputIter<_InputIterator>,
1003 typename = _RequireAllocator<_Allocator>>
1004 multiset(_InputIterator, _InputIterator, _Allocator)
1009 template<
typename _Key,
typename _Allocator,
1010 typename = _RequireAllocator<_Allocator>>
1014#if __glibcxx_containers_ranges
1017 __allocator_like _Alloc = std::allocator<ranges::range_value_t<_Rg>>>
1018 multiset(from_range_t, _Rg&&, _Compare = _Compare(), _Alloc = _Alloc())
1021 template<ranges::input_range _Rg, __allocator_like _Alloc>
1022 multiset(from_range_t, _Rg&&, _Alloc)
1038 template<
typename _Key,
typename _Compare,
typename _Alloc>
1042 {
return __x._M_t == __y._M_t; }
1044#if __cpp_lib_three_way_comparison
1059 template<
typename _Key,
typename _Compare,
typename _Alloc>
1060 inline __detail::__synth3way_t<_Key>
1061 operator<=>(
const multiset<_Key, _Compare, _Alloc>& __x,
1062 const multiset<_Key, _Compare, _Alloc>& __y)
1063 {
return __x._M_t <=> __y._M_t; }
1076 template<
typename _Key,
typename _Compare,
typename _Alloc>
1080 {
return __x._M_t < __y._M_t; }
1083 template<
typename _Key,
typename _Compare,
typename _Alloc>
1087 {
return !(__x == __y); }
1090 template<
typename _Key,
typename _Compare,
typename _Alloc>
1094 {
return __y < __x; }
1097 template<
typename _Key,
typename _Compare,
typename _Alloc>
1101 {
return !(__y < __x); }
1104 template<
typename _Key,
typename _Compare,
typename _Alloc>
1108 {
return !(__x < __y); }
1112 template<
typename _Key,
typename _Compare,
typename _Alloc>
1116 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
1119_GLIBCXX_END_NAMESPACE_CONTAINER
1121#ifdef __glibcxx_node_extract
1123 template<
typename _Val,
typename _Cmp1,
typename _Alloc,
typename _Cmp2>
1125 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>,
1129 friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>;
1132 _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1133 {
return __set._M_t; }
1136 _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1137 {
return __set._M_t; }
1141_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].
One of the comparison functors.
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
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.
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.
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.
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.
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.
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.
const_iterator find(const key_type &__x) const
Tries to locate an element in a set.
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.
A range for which ranges::begin returns an input iterator.