1 // Multiset implementation -*- C++ -*-
3 // Copyright (C) 2001-2016 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/stl_multiset.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{set}
56 #ifndef _STL_MULTISET_H
57 #define _STL_MULTISET_H 1
59 #include <bits/concept_check.h>
60 #if __cplusplus >= 201103L
61 #include <initializer_list>
64 namespace std
_GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68 template<typename _Key
, typename _Compare
, typename _Alloc
>
72 * @brief A standard container made up of elements, which can be retrieved
73 * in logarithmic time.
75 * @ingroup associative_containers
78 * @tparam _Key Type of key objects.
79 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
80 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
82 * Meets the requirements of a <a href="tables.html#65">container</a>, a
83 * <a href="tables.html#66">reversible container</a>, and an
84 * <a href="tables.html#69">associative container</a> (using equivalent
85 * keys). For a @c multiset<Key> the key_type and value_type are Key.
87 * Multisets support bidirectional iterators.
89 * The private tree data is declared exactly the same way for set and
90 * multiset; the distinction is made entirely in how the tree functions are
91 * called (*_unique versus *_equal, same as the standard).
93 template <typename _Key
, typename _Compare
= std::less
<_Key
>,
94 typename _Alloc
= std::allocator
<_Key
> >
97 // concept requirements
98 typedef typename
_Alloc::value_type _Alloc_value_type
;
99 __glibcxx_class_requires(_Key
, _SGIAssignableConcept
)
100 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
101 _BinaryFunctionConcept
)
102 __glibcxx_class_requires2(_Key
, _Alloc_value_type
, _SameTypeConcept
)
106 typedef _Key key_type
;
107 typedef _Key value_type
;
108 typedef _Compare key_compare
;
109 typedef _Compare value_compare
;
110 typedef _Alloc allocator_type
;
113 /// This turns a red-black tree into a [multi]set.
114 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
115 rebind
<_Key
>::other _Key_alloc_type
;
117 typedef _Rb_tree
<key_type
, value_type
, _Identity
<value_type
>,
118 key_compare
, _Key_alloc_type
> _Rep_type
;
119 /// The actual tree structure.
122 typedef __gnu_cxx::__alloc_traits
<_Key_alloc_type
> _Alloc_traits
;
125 typedef typename
_Alloc_traits::pointer pointer
;
126 typedef typename
_Alloc_traits::const_pointer const_pointer
;
127 typedef typename
_Alloc_traits::reference reference
;
128 typedef typename
_Alloc_traits::const_reference const_reference
;
129 // _GLIBCXX_RESOLVE_LIB_DEFECTS
130 // DR 103. set::iterator is required to be modifiable,
131 // but this allows modification of keys.
132 typedef typename
_Rep_type::const_iterator iterator
;
133 typedef typename
_Rep_type::const_iterator const_iterator
;
134 typedef typename
_Rep_type::const_reverse_iterator reverse_iterator
;
135 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
136 typedef typename
_Rep_type::size_type size_type
;
137 typedef typename
_Rep_type::difference_type difference_type
;
139 #if __cplusplus > 201402L
140 using node_type
= typename
_Rep_type::node_type
;
143 // allocation/deallocation
145 * @brief Default constructor creates no elements.
147 #if __cplusplus < 201103L
148 multiset() : _M_t() { }
150 multiset() = default;
154 * @brief Creates a %multiset with no elements.
155 * @param __comp Comparator to use.
156 * @param __a An allocator object.
159 multiset(const _Compare
& __comp
,
160 const allocator_type
& __a
= allocator_type())
161 : _M_t(__comp
, _Key_alloc_type(__a
)) { }
164 * @brief Builds a %multiset from a range.
165 * @param __first An input iterator.
166 * @param __last An input iterator.
168 * Create a %multiset consisting of copies of the elements from
169 * [first,last). This is linear in N if the range is already sorted,
170 * and NlogN otherwise (where N is distance(__first,__last)).
172 template<typename _InputIterator
>
173 multiset(_InputIterator __first
, _InputIterator __last
)
175 { _M_t
._M_insert_equal(__first
, __last
); }
178 * @brief Builds a %multiset from a range.
179 * @param __first An input iterator.
180 * @param __last An input iterator.
181 * @param __comp A comparison functor.
182 * @param __a An allocator object.
184 * Create a %multiset consisting of copies of the elements from
185 * [__first,__last). This is linear in N if the range is already sorted,
186 * and NlogN otherwise (where N is distance(__first,__last)).
188 template<typename _InputIterator
>
189 multiset(_InputIterator __first
, _InputIterator __last
,
190 const _Compare
& __comp
,
191 const allocator_type
& __a
= allocator_type())
192 : _M_t(__comp
, _Key_alloc_type(__a
))
193 { _M_t
._M_insert_equal(__first
, __last
); }
196 * @brief %Multiset copy constructor.
198 * Whether the allocator is copied depends on the allocator traits.
200 #if __cplusplus < 201103L
201 multiset(const multiset
& __x
)
204 multiset(const multiset
&) = default;
207 * @brief %Multiset move constructor.
209 * The newly-created %multiset contains the exact contents of the
210 * moved instance. The moved instance is a valid, but unspecified
213 multiset(multiset
&&) = default;
216 * @brief Builds a %multiset from an initializer_list.
217 * @param __l An initializer_list.
218 * @param __comp A comparison functor.
219 * @param __a An allocator object.
221 * Create a %multiset consisting of copies of the elements from
222 * the list. This is linear in N if the list is already sorted,
223 * and NlogN otherwise (where N is @a __l.size()).
225 multiset(initializer_list
<value_type
> __l
,
226 const _Compare
& __comp
= _Compare(),
227 const allocator_type
& __a
= allocator_type())
228 : _M_t(__comp
, _Key_alloc_type(__a
))
229 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
231 /// Allocator-extended default constructor.
233 multiset(const allocator_type
& __a
)
234 : _M_t(_Compare(), _Key_alloc_type(__a
)) { }
236 /// Allocator-extended copy constructor.
237 multiset(const multiset
& __m
, const allocator_type
& __a
)
238 : _M_t(__m
._M_t
, _Key_alloc_type(__a
)) { }
240 /// Allocator-extended move constructor.
241 multiset(multiset
&& __m
, const allocator_type
& __a
)
242 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
243 && _Alloc_traits::_S_always_equal())
244 : _M_t(std::move(__m
._M_t
), _Key_alloc_type(__a
)) { }
246 /// Allocator-extended initialier-list constructor.
247 multiset(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
248 : _M_t(_Compare(), _Key_alloc_type(__a
))
249 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
251 /// Allocator-extended range constructor.
252 template<typename _InputIterator
>
253 multiset(_InputIterator __first
, _InputIterator __last
,
254 const allocator_type
& __a
)
255 : _M_t(_Compare(), _Key_alloc_type(__a
))
256 { _M_t
._M_insert_equal(__first
, __last
); }
259 * The dtor only erases the elements, and note that if the elements
260 * themselves are pointers, the pointed-to memory is not touched in any
261 * way. Managing the pointer is the user's responsibility.
263 ~multiset() = default;
267 * @brief %Multiset assignment operator.
269 * Whether the allocator is copied depends on the allocator traits.
271 #if __cplusplus < 201103L
273 operator=(const multiset
& __x
)
280 operator=(const multiset
&) = default;
282 /// Move assignment operator.
284 operator=(multiset
&&) = default;
287 * @brief %Multiset list assignment operator.
288 * @param __l An initializer_list.
290 * This function fills a %multiset with copies of the elements in the
291 * initializer list @a __l.
293 * Note that the assignment completely changes the %multiset and
294 * that the resulting %multiset's size is the same as the number
295 * of elements assigned.
298 operator=(initializer_list
<value_type
> __l
)
300 _M_t
._M_assign_equal(__l
.begin(), __l
.end());
307 /// Returns the comparison object.
310 { return _M_t
.key_comp(); }
311 /// Returns the comparison object.
314 { return _M_t
.key_comp(); }
315 /// Returns the memory allocation object.
317 get_allocator() const _GLIBCXX_NOEXCEPT
318 { return allocator_type(_M_t
.get_allocator()); }
321 * Returns a read-only (constant) iterator that points to the first
322 * element in the %multiset. Iteration is done in ascending order
323 * according to the keys.
326 begin() const _GLIBCXX_NOEXCEPT
327 { return _M_t
.begin(); }
330 * Returns a read-only (constant) iterator that points one past the last
331 * element in the %multiset. Iteration is done in ascending order
332 * according to the keys.
335 end() const _GLIBCXX_NOEXCEPT
336 { return _M_t
.end(); }
339 * Returns a read-only (constant) reverse iterator that points to the
340 * last element in the %multiset. Iteration is done in descending order
341 * according to the keys.
344 rbegin() const _GLIBCXX_NOEXCEPT
345 { return _M_t
.rbegin(); }
348 * Returns a read-only (constant) reverse iterator that points to the
349 * last element in the %multiset. Iteration is done in descending order
350 * according to the keys.
353 rend() const _GLIBCXX_NOEXCEPT
354 { return _M_t
.rend(); }
356 #if __cplusplus >= 201103L
358 * Returns a read-only (constant) iterator that points to the first
359 * element in the %multiset. Iteration is done in ascending order
360 * according to the keys.
363 cbegin() const noexcept
364 { return _M_t
.begin(); }
367 * Returns a read-only (constant) iterator that points one past the last
368 * element in the %multiset. Iteration is done in ascending order
369 * according to the keys.
372 cend() const noexcept
373 { return _M_t
.end(); }
376 * Returns a read-only (constant) reverse iterator that points to the
377 * last element in the %multiset. Iteration is done in descending order
378 * according to the keys.
381 crbegin() const noexcept
382 { return _M_t
.rbegin(); }
385 * Returns a read-only (constant) reverse iterator that points to the
386 * last element in the %multiset. Iteration is done in descending order
387 * according to the keys.
390 crend() const noexcept
391 { return _M_t
.rend(); }
394 /// Returns true if the %set is empty.
396 empty() const _GLIBCXX_NOEXCEPT
397 { return _M_t
.empty(); }
399 /// Returns the size of the %set.
401 size() const _GLIBCXX_NOEXCEPT
402 { return _M_t
.size(); }
404 /// Returns the maximum size of the %set.
406 max_size() const _GLIBCXX_NOEXCEPT
407 { return _M_t
.max_size(); }
410 * @brief Swaps data with another %multiset.
411 * @param __x A %multiset of the same element and allocator types.
413 * This exchanges the elements between two multisets in constant time.
414 * (It is only swapping a pointer, an integer, and an instance of the @c
415 * Compare type (which itself is often stateless and empty), so it should
417 * Note that the global std::swap() function is specialized such that
418 * std::swap(s1,s2) will feed to this function.
420 * Whether the allocators are swapped depends on the allocator traits.
424 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable
<_Compare
>::value
)
425 { _M_t
.swap(__x
._M_t
); }
428 #if __cplusplus >= 201103L
430 * @brief Builds and inserts an element into the %multiset.
431 * @param __args Arguments used to generate the element instance to be
433 * @return An iterator that points to the inserted element.
435 * This function inserts an element into the %multiset. Contrary
436 * to a std::set the %multiset does not rely on unique keys and thus
437 * multiple copies of the same element can be inserted.
439 * Insertion requires logarithmic time.
441 template<typename
... _Args
>
443 emplace(_Args
&&... __args
)
444 { return _M_t
._M_emplace_equal(std::forward
<_Args
>(__args
)...); }
447 * @brief Builds and inserts an element into the %multiset.
448 * @param __pos An iterator that serves as a hint as to where the
449 * element should be inserted.
450 * @param __args Arguments used to generate the element instance to be
452 * @return An iterator that points to the inserted element.
454 * This function inserts an element into the %multiset. Contrary
455 * to a std::set the %multiset does not rely on unique keys and thus
456 * multiple copies of the same element can be inserted.
458 * Note that the first parameter is only a hint and can potentially
459 * improve the performance of the insertion process. A bad hint would
460 * cause no gains in efficiency.
462 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
463 * for more on @a hinting.
465 * Insertion requires logarithmic time (if the hint is not taken).
467 template<typename
... _Args
>
469 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
471 return _M_t
._M_emplace_hint_equal(__pos
,
472 std::forward
<_Args
>(__args
)...);
477 * @brief Inserts an element into the %multiset.
478 * @param __x Element to be inserted.
479 * @return An iterator that points to the inserted element.
481 * This function inserts an element into the %multiset. Contrary
482 * to a std::set the %multiset does not rely on unique keys and thus
483 * multiple copies of the same element can be inserted.
485 * Insertion requires logarithmic time.
488 insert(const value_type
& __x
)
489 { return _M_t
._M_insert_equal(__x
); }
491 #if __cplusplus >= 201103L
493 insert(value_type
&& __x
)
494 { return _M_t
._M_insert_equal(std::move(__x
)); }
498 * @brief Inserts an element into the %multiset.
499 * @param __position An iterator that serves as a hint as to where the
500 * element should be inserted.
501 * @param __x Element to be inserted.
502 * @return An iterator that points to the inserted element.
504 * This function inserts an element into the %multiset. Contrary
505 * to a std::set the %multiset does not rely on unique keys and thus
506 * multiple copies of the same element can be inserted.
508 * Note that the first parameter is only a hint and can potentially
509 * improve the performance of the insertion process. A bad hint would
510 * cause no gains in efficiency.
512 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
513 * for more on @a hinting.
515 * Insertion requires logarithmic time (if the hint is not taken).
518 insert(const_iterator __position
, const value_type
& __x
)
519 { return _M_t
._M_insert_equal_(__position
, __x
); }
521 #if __cplusplus >= 201103L
523 insert(const_iterator __position
, value_type
&& __x
)
524 { return _M_t
._M_insert_equal_(__position
, std::move(__x
)); }
528 * @brief A template function that tries to insert a range of elements.
529 * @param __first Iterator pointing to the start of the range to be
531 * @param __last Iterator pointing to the end of the range.
533 * Complexity similar to that of the range constructor.
535 template<typename _InputIterator
>
537 insert(_InputIterator __first
, _InputIterator __last
)
538 { _M_t
._M_insert_equal(__first
, __last
); }
540 #if __cplusplus >= 201103L
542 * @brief Attempts to insert a list of elements into the %multiset.
543 * @param __l A std::initializer_list<value_type> of elements
546 * Complexity similar to that of the range constructor.
549 insert(initializer_list
<value_type
> __l
)
550 { this->insert(__l
.begin(), __l
.end()); }
553 #if __cplusplus > 201402L
556 extract(const_iterator __pos
)
558 __glibcxx_assert(__pos
!= end());
559 return _M_t
.extract(__pos
);
564 extract(const key_type
& __x
)
565 { return _M_t
.extract(__x
); }
567 /// Re-insert an extracted node.
569 insert(node_type
&& __nh
)
570 { return _M_t
._M_reinsert_node_equal(std::move(__nh
)); }
572 /// Re-insert an extracted node.
574 insert(const_iterator __hint
, node_type
&& __nh
)
575 { return _M_t
._M_reinsert_node_hint_equal(__hint
, std::move(__nh
)); }
577 template<typename
, typename
>
578 friend class _Rb_tree_merge_helper
;
580 template<typename _Compare1
>
582 merge(multiset
<_Key
, _Compare1
, _Alloc
>& __source
)
584 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
585 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
588 template<typename _Compare1
>
590 merge(multiset
<_Key
, _Compare1
, _Alloc
>&& __source
)
593 template<typename _Compare1
>
595 merge(set
<_Key
, _Compare1
, _Alloc
>& __source
)
597 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
598 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
601 template<typename _Compare1
>
603 merge(set
<_Key
, _Compare1
, _Alloc
>&& __source
)
607 #if __cplusplus >= 201103L
608 // _GLIBCXX_RESOLVE_LIB_DEFECTS
609 // DR 130. Associative erase should return an iterator.
611 * @brief Erases an element from a %multiset.
612 * @param __position An iterator pointing to the element to be erased.
613 * @return An iterator pointing to the element immediately following
614 * @a position prior to the element being erased. If no such
615 * element exists, end() is returned.
617 * This function erases an element, pointed to by the given iterator,
618 * from a %multiset. Note that this function only erases the element,
619 * and that if the element is itself a pointer, the pointed-to memory is
620 * not touched in any way. Managing the pointer is the user's
623 _GLIBCXX_ABI_TAG_CXX11
625 erase(const_iterator __position
)
626 { return _M_t
.erase(__position
); }
629 * @brief Erases an element from a %multiset.
630 * @param __position An iterator pointing to the element to be erased.
632 * This function erases an element, pointed to by the given iterator,
633 * from a %multiset. Note that this function only erases the element,
634 * and that if the element is itself a pointer, the pointed-to memory is
635 * not touched in any way. Managing the pointer is the user's
639 erase(iterator __position
)
640 { _M_t
.erase(__position
); }
644 * @brief Erases elements according to the provided key.
645 * @param __x Key of element to be erased.
646 * @return The number of elements erased.
648 * This function erases all elements located by the given key from a
650 * Note that this function only erases the element, and that if
651 * the element is itself a pointer, the pointed-to memory is not touched
652 * in any way. Managing the pointer is the user's responsibility.
655 erase(const key_type
& __x
)
656 { return _M_t
.erase(__x
); }
658 #if __cplusplus >= 201103L
659 // _GLIBCXX_RESOLVE_LIB_DEFECTS
660 // DR 130. Associative erase should return an iterator.
662 * @brief Erases a [first,last) range of elements from a %multiset.
663 * @param __first Iterator pointing to the start of the range to be
665 * @param __last Iterator pointing to the end of the range to
667 * @return The iterator @a last.
669 * This function erases a sequence of elements from a %multiset.
670 * Note that this function only erases the elements, and that if
671 * the elements themselves are pointers, the pointed-to memory is not
672 * touched in any way. Managing the pointer is the user's
675 _GLIBCXX_ABI_TAG_CXX11
677 erase(const_iterator __first
, const_iterator __last
)
678 { return _M_t
.erase(__first
, __last
); }
681 * @brief Erases a [first,last) range of elements from a %multiset.
682 * @param first Iterator pointing to the start of the range to be
684 * @param last Iterator pointing to the end of the range to be erased.
686 * This function erases a sequence of elements from a %multiset.
687 * Note that this function only erases the elements, and that if
688 * the elements themselves are pointers, the pointed-to memory is not
689 * touched in any way. Managing the pointer is the user's
693 erase(iterator __first
, iterator __last
)
694 { _M_t
.erase(__first
, __last
); }
698 * Erases all elements in a %multiset. Note that this function only
699 * erases the elements, and that if the elements themselves are pointers,
700 * the pointed-to memory is not touched in any way. Managing the pointer
701 * is the user's responsibility.
704 clear() _GLIBCXX_NOEXCEPT
707 // multiset operations:
711 * @brief Finds the number of elements with given key.
712 * @param __x Key of elements to be located.
713 * @return Number of elements with specified key.
716 count(const key_type
& __x
) const
717 { return _M_t
.count(__x
); }
719 #if __cplusplus > 201103L
720 template<typename _Kt
>
722 count(const _Kt
& __x
) const -> decltype(_M_t
._M_count_tr(__x
))
723 { return _M_t
._M_count_tr(__x
); }
727 // _GLIBCXX_RESOLVE_LIB_DEFECTS
728 // 214. set::find() missing const overload
731 * @brief Tries to locate an element in a %set.
732 * @param __x Element to be located.
733 * @return Iterator pointing to sought-after element, or end() if not
736 * This function takes a key and tries to locate the element with which
737 * the key matches. If successful the function returns an iterator
738 * pointing to the sought after element. If unsuccessful it returns the
739 * past-the-end ( @c end() ) iterator.
742 find(const key_type
& __x
)
743 { return _M_t
.find(__x
); }
746 find(const key_type
& __x
) const
747 { return _M_t
.find(__x
); }
749 #if __cplusplus > 201103L
750 template<typename _Kt
>
753 -> decltype(iterator
{_M_t
._M_find_tr(__x
)})
754 { return iterator
{_M_t
._M_find_tr(__x
)}; }
756 template<typename _Kt
>
758 find(const _Kt
& __x
) const
759 -> decltype(const_iterator
{_M_t
._M_find_tr(__x
)})
760 { return const_iterator
{_M_t
._M_find_tr(__x
)}; }
766 * @brief Finds the beginning of a subsequence matching given key.
767 * @param __x Key to be located.
768 * @return Iterator pointing to first element equal to or greater
769 * than key, or end().
771 * This function returns the first element of a subsequence of elements
772 * that matches the given key. If unsuccessful it returns an iterator
773 * pointing to the first element that has a greater value than given key
774 * or end() if no such element exists.
777 lower_bound(const key_type
& __x
)
778 { return _M_t
.lower_bound(__x
); }
781 lower_bound(const key_type
& __x
) const
782 { return _M_t
.lower_bound(__x
); }
784 #if __cplusplus > 201103L
785 template<typename _Kt
>
787 lower_bound(const _Kt
& __x
)
788 -> decltype(_M_t
._M_lower_bound_tr(__x
))
789 { return _M_t
._M_lower_bound_tr(__x
); }
791 template<typename _Kt
>
793 lower_bound(const _Kt
& __x
) const
794 -> decltype(_M_t
._M_lower_bound_tr(__x
))
795 { return _M_t
._M_lower_bound_tr(__x
); }
801 * @brief Finds the end of a subsequence matching given key.
802 * @param __x Key to be located.
803 * @return Iterator pointing to the first element
804 * greater than key, or end().
807 upper_bound(const key_type
& __x
)
808 { return _M_t
.upper_bound(__x
); }
811 upper_bound(const key_type
& __x
) const
812 { return _M_t
.upper_bound(__x
); }
814 #if __cplusplus > 201103L
815 template<typename _Kt
>
817 upper_bound(const _Kt
& __x
)
818 -> decltype(_M_t
._M_upper_bound_tr(__x
))
819 { return _M_t
._M_upper_bound_tr(__x
); }
821 template<typename _Kt
>
823 upper_bound(const _Kt
& __x
) const
824 -> decltype(_M_t
._M_upper_bound_tr(__x
))
825 { return _M_t
._M_upper_bound_tr(__x
); }
831 * @brief Finds a subsequence matching given key.
832 * @param __x Key to be located.
833 * @return Pair of iterators that possibly points to the subsequence
834 * matching given key.
836 * This function is equivalent to
838 * std::make_pair(c.lower_bound(val),
839 * c.upper_bound(val))
841 * (but is faster than making the calls separately).
843 * This function probably only makes sense for multisets.
845 std::pair
<iterator
, iterator
>
846 equal_range(const key_type
& __x
)
847 { return _M_t
.equal_range(__x
); }
849 std::pair
<const_iterator
, const_iterator
>
850 equal_range(const key_type
& __x
) const
851 { return _M_t
.equal_range(__x
); }
853 #if __cplusplus > 201103L
854 template<typename _Kt
>
856 equal_range(const _Kt
& __x
)
857 -> decltype(_M_t
._M_equal_range_tr(__x
))
858 { return _M_t
._M_equal_range_tr(__x
); }
860 template<typename _Kt
>
862 equal_range(const _Kt
& __x
) const
863 -> decltype(_M_t
._M_equal_range_tr(__x
))
864 { return _M_t
._M_equal_range_tr(__x
); }
868 template<typename _K1
, typename _C1
, typename _A1
>
870 operator==(const multiset
<_K1
, _C1
, _A1
>&,
871 const multiset
<_K1
, _C1
, _A1
>&);
873 template<typename _K1
, typename _C1
, typename _A1
>
875 operator< (const multiset
<_K1
, _C1
, _A1
>&,
876 const multiset
<_K1
, _C1
, _A1
>&);
880 * @brief Multiset equality comparison.
881 * @param __x A %multiset.
882 * @param __y A %multiset of the same type as @a __x.
883 * @return True iff the size and elements of the multisets are equal.
885 * This is an equivalence relation. It is linear in the size of the
887 * Multisets are considered equivalent if their sizes are equal, and if
888 * corresponding elements compare equal.
890 template<typename _Key
, typename _Compare
, typename _Alloc
>
892 operator==(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
893 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
894 { return __x
._M_t
== __y
._M_t
; }
897 * @brief Multiset ordering relation.
898 * @param __x A %multiset.
899 * @param __y A %multiset of the same type as @a __x.
900 * @return True iff @a __x is lexicographically less than @a __y.
902 * This is a total ordering relation. It is linear in the size of the
903 * sets. The elements must be comparable with @c <.
905 * See std::lexicographical_compare() for how the determination is made.
907 template<typename _Key
, typename _Compare
, typename _Alloc
>
909 operator<(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
910 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
911 { return __x
._M_t
< __y
._M_t
; }
913 /// Returns !(x == y).
914 template<typename _Key
, typename _Compare
, typename _Alloc
>
916 operator!=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
917 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
918 { return !(__x
== __y
); }
921 template<typename _Key
, typename _Compare
, typename _Alloc
>
923 operator>(const multiset
<_Key
,_Compare
,_Alloc
>& __x
,
924 const multiset
<_Key
,_Compare
,_Alloc
>& __y
)
925 { return __y
< __x
; }
928 template<typename _Key
, typename _Compare
, typename _Alloc
>
930 operator<=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
931 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
932 { return !(__y
< __x
); }
935 template<typename _Key
, typename _Compare
, typename _Alloc
>
937 operator>=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
938 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
939 { return !(__x
< __y
); }
941 /// See std::multiset::swap().
942 template<typename _Key
, typename _Compare
, typename _Alloc
>
944 swap(multiset
<_Key
, _Compare
, _Alloc
>& __x
,
945 multiset
<_Key
, _Compare
, _Alloc
>& __y
)
946 _GLIBCXX_NOEXCEPT_IF(noexcept(__x
.swap(__y
)))
949 _GLIBCXX_END_NAMESPACE_CONTAINER
951 #if __cplusplus > 201402L
952 _GLIBCXX_BEGIN_NAMESPACE_VERSION
953 // Allow std::multiset access to internals of compatible sets.
954 template<typename _Val
, typename _Cmp1
, typename _Alloc
, typename _Cmp2
>
956 _Rb_tree_merge_helper
<_GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>,
960 friend class _GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>;
963 _S_get_tree(_GLIBCXX_STD_C::set
<_Val
, _Cmp2
, _Alloc
>& __set
)
964 { return __set
._M_t
; }
967 _S_get_tree(_GLIBCXX_STD_C::multiset
<_Val
, _Cmp2
, _Alloc
>& __set
)
968 { return __set
._M_t
; }
970 _GLIBCXX_END_NAMESPACE_VERSION
975 #endif /* _STL_MULTISET_H */