56#ifndef _STL_MULTISET_H
57#define _STL_MULTISET_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 _Compare,
typename _Alloc>
95 template <
typename _Key,
typename _Compare = std::less<_Key>,
96 typename _Alloc = std::allocator<_Key> >
99#ifdef _GLIBCXX_CONCEPT_CHECKS
101 typedef typename _Alloc::value_type _Alloc_value_type;
102# if __cplusplus < 201103L
103 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
105 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
106 _BinaryFunctionConcept)
107 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
110#if __cplusplus >= 201103L
112 "std::multiset must have a non-const, non-volatile value_type");
113# if __cplusplus > 201703L || defined __STRICT_ANSI__
115 "std::multiset must have the same value_type as its allocator");
121 typedef _Key key_type;
122 typedef _Key value_type;
123 typedef _Compare key_compare;
124 typedef _Compare value_compare;
125 typedef _Alloc allocator_type;
130 rebind<_Key>::other _Key_alloc_type;
132 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
133 key_compare, _Key_alloc_type> _Rep_type;
140 typedef typename _Alloc_traits::pointer pointer;
141 typedef typename _Alloc_traits::const_pointer const_pointer;
142 typedef typename _Alloc_traits::reference reference;
143 typedef typename _Alloc_traits::const_reference const_reference;
147 typedef typename _Rep_type::const_iterator iterator;
148 typedef typename _Rep_type::const_iterator const_iterator;
151 typedef typename _Rep_type::size_type size_type;
152 typedef typename _Rep_type::difference_type difference_type;
154#if __cplusplus > 201402L
162#if __cplusplus < 201103L
175 const allocator_type& __a = allocator_type())
176 : _M_t(__comp, _Key_alloc_type(__a)) { }
187 template<
typename _InputIterator>
188 multiset(_InputIterator __first, _InputIterator __last)
190 { _M_t._M_insert_range_equal(__first, __last); }
203 template<
typename _InputIterator>
204 multiset(_InputIterator __first, _InputIterator __last,
205 const _Compare& __comp,
206 const allocator_type& __a = allocator_type())
207 : _M_t(__comp, _Key_alloc_type(__a))
208 { _M_t._M_insert_range_equal(__first, __last); }
215#if __cplusplus < 201103L
241 const _Compare& __comp = _Compare(),
242 const allocator_type& __a = allocator_type())
243 : _M_t(__comp, _Key_alloc_type(__a))
244 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
249 : _M_t(_Key_alloc_type(__a)) { }
253 const __type_identity_t<allocator_type>& __a)
254 : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
259 && _Alloc_traits::_S_always_equal())
260 : _M_t(
std::
move(__m._M_t), _Key_alloc_type(__a)) { }
264 : _M_t(_Key_alloc_type(__a))
265 { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
268 template<
typename _InputIterator>
269 multiset(_InputIterator __first, _InputIterator __last,
270 const allocator_type& __a)
271 : _M_t(_Key_alloc_type(__a))
272 { _M_t._M_insert_range_equal(__first, __last); }
287#if __cplusplus < 201103L
316 _M_t._M_assign_equal(__l.begin(), __l.end());
326 {
return _M_t.key_comp(); }
330 {
return _M_t.key_comp(); }
334 {
return allocator_type(_M_t.get_allocator()); }
343 {
return _M_t.begin(); }
351 end() const _GLIBCXX_NOEXCEPT
352 {
return _M_t.end(); }
361 {
return _M_t.rbegin(); }
370 {
return _M_t.rend(); }
372#if __cplusplus >= 201103L
380 {
return _M_t.begin(); }
389 {
return _M_t.end(); }
398 {
return _M_t.rbegin(); }
407 {
return _M_t.rend(); }
411 _GLIBCXX_NODISCARD
bool
413 {
return _M_t.empty(); }
418 {
return _M_t.size(); }
423 {
return _M_t.max_size(); }
440 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
441 { _M_t.swap(__x._M_t); }
444#if __cplusplus >= 201103L
457 template<
typename... _Args>
460 {
return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
483 template<
typename... _Args>
487 return _M_t._M_emplace_hint_equal(__pos,
488 std::forward<_Args>(__args)...);
505 {
return _M_t._M_insert_equal(__x); }
507#if __cplusplus >= 201103L
510 {
return _M_t._M_insert_equal(
std::move(__x)); }
534 insert(const_iterator __position,
const value_type& __x)
535 {
return _M_t._M_insert_equal_(__position, __x); }
537#if __cplusplus >= 201103L
539 insert(const_iterator __position, value_type&& __x)
540 {
return _M_t._M_insert_equal_(__position,
std::move(__x)); }
551 template<
typename _InputIterator>
553 insert(_InputIterator __first, _InputIterator __last)
554 { _M_t._M_insert_range_equal(__first, __last); }
556#if __cplusplus >= 201103L
566 { this->
insert(__l.begin(), __l.end()); }
569#if __cplusplus > 201402L
574 __glibcxx_assert(__pos !=
end());
575 return _M_t.extract(__pos);
581 {
return _M_t.extract(__x); }
586 {
return _M_t._M_reinsert_node_equal(
std::move(__nh)); }
590 insert(const_iterator __hint, node_type&& __nh)
591 {
return _M_t._M_reinsert_node_hint_equal(__hint,
std::move(__nh)); }
593 template<
typename,
typename>
594 friend struct std::_Rb_tree_merge_helper;
596 template<
typename _Compare1>
600 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
601 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
604 template<
typename _Compare1>
606 merge(multiset<_Key, _Compare1, _Alloc>&& __source)
609 template<
typename _Compare1>
611 merge(set<_Key, _Compare1, _Alloc>& __source)
613 using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
614 _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
617 template<
typename _Compare1>
619 merge(set<_Key, _Compare1, _Alloc>&& __source)
623#if __cplusplus >= 201103L
639 _GLIBCXX_ABI_TAG_CXX11
642 {
return _M_t.erase(__position); }
656 { _M_t.erase(__position); }
672 {
return _M_t.erase(__x); }
674#if __cplusplus >= 201103L
691 _GLIBCXX_ABI_TAG_CXX11
693 erase(const_iterator __first, const_iterator __last)
694 {
return _M_t.erase(__first, __last); }
710 { _M_t.erase(__first, __last); }
733 {
return _M_t.count(__x); }
735#if __cplusplus > 201103L
736 template<
typename _Kt>
738 count(
const _Kt& __x)
const ->
decltype(_M_t._M_count_tr(__x))
739 {
return _M_t._M_count_tr(__x); }
743#if __cplusplus > 201703L
752 {
return _M_t.find(__x) != _M_t.end(); }
754 template<
typename _Kt>
757 ->
decltype(_M_t._M_find_tr(__x), void(),
true)
758 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
778 {
return _M_t.find(__x); }
781 find(
const key_type& __x)
const
782 {
return _M_t.find(__x); }
784#if __cplusplus > 201103L
785 template<
typename _Kt>
788 ->
decltype(iterator{_M_t._M_find_tr(__x)})
789 {
return iterator{_M_t._M_find_tr(__x)}; }
791 template<
typename _Kt>
794 ->
decltype(const_iterator{_M_t._M_find_tr(__x)})
795 {
return const_iterator{_M_t._M_find_tr(__x)}; }
813 {
return _M_t.lower_bound(__x); }
817 {
return _M_t.lower_bound(__x); }
819#if __cplusplus > 201103L
820 template<
typename _Kt>
823 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
824 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
826 template<
typename _Kt>
829 ->
decltype(iterator(_M_t._M_lower_bound_tr(__x)))
830 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
843 {
return _M_t.upper_bound(__x); }
847 {
return _M_t.upper_bound(__x); }
849#if __cplusplus > 201103L
850 template<
typename _Kt>
853 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
854 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
856 template<
typename _Kt>
859 ->
decltype(iterator(_M_t._M_upper_bound_tr(__x)))
860 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
882 {
return _M_t.equal_range(__x); }
886 {
return _M_t.equal_range(__x); }
888#if __cplusplus > 201103L
889 template<
typename _Kt>
895 template<
typename _Kt>
903 template<
typename _K1,
typename _C1,
typename _A1>
908#if __cpp_lib_three_way_comparison
909 template<
typename _K1,
typename _C1,
typename _A1>
910 friend __detail::__synth3way_t<_K1>
914 template<
typename _K1,
typename _C1,
typename _A1>
921#if __cpp_deduction_guides >= 201606
923 template<
typename _InputIterator,
925 less<typename iterator_traits<_InputIterator>::value_type>,
926 typename _Allocator =
927 allocator<typename iterator_traits<_InputIterator>::value_type>,
928 typename = _RequireInputIter<_InputIterator>,
929 typename = _RequireNotAllocator<_Compare>,
930 typename = _RequireAllocator<_Allocator>>
931 multiset(_InputIterator, _InputIterator,
932 _Compare = _Compare(), _Allocator = _Allocator())
933 -> multiset<typename iterator_traits<_InputIterator>::value_type,
934 _Compare, _Allocator>;
936 template<
typename _Key,
937 typename _Compare = less<_Key>,
938 typename _Allocator = allocator<_Key>,
939 typename = _RequireNotAllocator<_Compare>,
940 typename = _RequireAllocator<_Allocator>>
941 multiset(initializer_list<_Key>,
942 _Compare = _Compare(), _Allocator = _Allocator())
943 -> multiset<_Key, _Compare, _Allocator>;
945 template<
typename _InputIterator,
typename _Allocator,
946 typename = _RequireInputIter<_InputIterator>,
947 typename = _RequireAllocator<_Allocator>>
948 multiset(_InputIterator, _InputIterator, _Allocator)
949 -> multiset<typename iterator_traits<_InputIterator>::value_type,
950 less<typename iterator_traits<_InputIterator>::value_type>,
953 template<
typename _Key,
typename _Allocator,
954 typename = _RequireAllocator<_Allocator>>
955 multiset(initializer_list<_Key>, _Allocator)
956 -> multiset<_Key, less<_Key>, _Allocator>;
971 template<
typename _Key,
typename _Compare,
typename _Alloc>
975 {
return __x._M_t == __y._M_t; }
977#if __cpp_lib_three_way_comparison
992 template<
typename _Key,
typename _Compare,
typename _Alloc>
993 inline __detail::__synth3way_t<_Key>
994 operator<=>(
const multiset<_Key, _Compare, _Alloc>& __x,
995 const multiset<_Key, _Compare, _Alloc>& __y)
996 {
return __x._M_t <=> __y._M_t; }
1009 template<
typename _Key,
typename _Compare,
typename _Alloc>
1013 {
return __x._M_t < __y._M_t; }
1016 template<
typename _Key,
typename _Compare,
typename _Alloc>
1020 {
return !(__x == __y); }
1023 template<
typename _Key,
typename _Compare,
typename _Alloc>
1027 {
return __y < __x; }
1030 template<
typename _Key,
typename _Compare,
typename _Alloc>
1034 {
return !(__y < __x); }
1037 template<
typename _Key,
typename _Compare,
typename _Alloc>
1041 {
return !(__x < __y); }
1045 template<
typename _Key,
typename _Compare,
typename _Alloc>
1049 _GLIBCXX_NOEXCEPT_IF(
noexcept(__x.swap(__y)))
1052_GLIBCXX_END_NAMESPACE_CONTAINER
1054#if __cplusplus > 201402L
1056 template<
typename _Val,
typename _Cmp1,
typename _Alloc,
typename _Cmp2>
1058 _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>,
1062 friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>;
1065 _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1066 {
return __set._M_t; }
1069 _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1070 {
return __set._M_t; }
1074_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
Node handle type for maps.
Struct holding two objects of arbitrary type.
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.
iterator insert(node_type &&__nh)
Re-insert an extracted node.
_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.
node_type extract(const_iterator __pos)
Extract a node.
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.
node_type extract(const key_type &__x)
Extract a node.
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 __hint, node_type &&__nh)
Re-insert an extracted node.
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.