1 // Multiset implementation -*- C++ -*-
3 // Copyright (C) 2001-2017 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_VERSION
67 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69 template<typename _Key
, typename _Compare
, typename _Alloc
>
73 * @brief A standard container made up of elements, which can be retrieved
74 * in logarithmic time.
76 * @ingroup associative_containers
79 * @tparam _Key Type of key objects.
80 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
81 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
83 * Meets the requirements of a <a href="tables.html#65">container</a>, a
84 * <a href="tables.html#66">reversible container</a>, and an
85 * <a href="tables.html#69">associative container</a> (using equivalent
86 * keys). For a @c multiset<Key> the key_type and value_type are Key.
88 * Multisets support bidirectional iterators.
90 * The private tree data is declared exactly the same way for set and
91 * multiset; the distinction is made entirely in how the tree functions are
92 * called (*_unique versus *_equal, same as the standard).
94 template <typename _Key
, typename _Compare
= std::less
<_Key
>,
95 typename _Alloc
= std::allocator
<_Key
> >
98 #ifdef _GLIBCXX_CONCEPT_CHECKS
99 // concept requirements
100 typedef typename
_Alloc::value_type _Alloc_value_type
;
101 # if __cplusplus < 201103L
102 __glibcxx_class_requires(_Key
, _SGIAssignableConcept
)
104 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
105 _BinaryFunctionConcept
)
106 __glibcxx_class_requires2(_Key
, _Alloc_value_type
, _SameTypeConcept
)
111 typedef _Key key_type
;
112 typedef _Key value_type
;
113 typedef _Compare key_compare
;
114 typedef _Compare value_compare
;
115 typedef _Alloc allocator_type
;
118 /// This turns a red-black tree into a [multi]set.
119 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
120 rebind
<_Key
>::other _Key_alloc_type
;
122 typedef _Rb_tree
<key_type
, value_type
, _Identity
<value_type
>,
123 key_compare
, _Key_alloc_type
> _Rep_type
;
124 /// The actual tree structure.
127 typedef __gnu_cxx::__alloc_traits
<_Key_alloc_type
> _Alloc_traits
;
130 typedef typename
_Alloc_traits::pointer pointer
;
131 typedef typename
_Alloc_traits::const_pointer const_pointer
;
132 typedef typename
_Alloc_traits::reference reference
;
133 typedef typename
_Alloc_traits::const_reference const_reference
;
134 // _GLIBCXX_RESOLVE_LIB_DEFECTS
135 // DR 103. set::iterator is required to be modifiable,
136 // but this allows modification of keys.
137 typedef typename
_Rep_type::const_iterator iterator
;
138 typedef typename
_Rep_type::const_iterator const_iterator
;
139 typedef typename
_Rep_type::const_reverse_iterator reverse_iterator
;
140 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
141 typedef typename
_Rep_type::size_type size_type
;
142 typedef typename
_Rep_type::difference_type difference_type
;
144 #if __cplusplus > 201402L
145 using node_type
= typename
_Rep_type::node_type
;
148 // allocation/deallocation
150 * @brief Default constructor creates no elements.
152 #if __cplusplus < 201103L
153 multiset() : _M_t() { }
155 multiset() = default;
159 * @brief Creates a %multiset with no elements.
160 * @param __comp Comparator to use.
161 * @param __a An allocator object.
164 multiset(const _Compare
& __comp
,
165 const allocator_type
& __a
= allocator_type())
166 : _M_t(__comp
, _Key_alloc_type(__a
)) { }
169 * @brief Builds a %multiset from a range.
170 * @param __first An input iterator.
171 * @param __last An input iterator.
173 * Create a %multiset consisting of copies of the elements from
174 * [first,last). This is linear in N if the range is already sorted,
175 * and NlogN otherwise (where N is distance(__first,__last)).
177 template<typename _InputIterator
>
178 multiset(_InputIterator __first
, _InputIterator __last
)
180 { _M_t
._M_insert_equal(__first
, __last
); }
183 * @brief Builds a %multiset from a range.
184 * @param __first An input iterator.
185 * @param __last An input iterator.
186 * @param __comp A comparison functor.
187 * @param __a An allocator object.
189 * Create a %multiset consisting of copies of the elements from
190 * [__first,__last). This is linear in N if the range is already sorted,
191 * and NlogN otherwise (where N is distance(__first,__last)).
193 template<typename _InputIterator
>
194 multiset(_InputIterator __first
, _InputIterator __last
,
195 const _Compare
& __comp
,
196 const allocator_type
& __a
= allocator_type())
197 : _M_t(__comp
, _Key_alloc_type(__a
))
198 { _M_t
._M_insert_equal(__first
, __last
); }
201 * @brief %Multiset copy constructor.
203 * Whether the allocator is copied depends on the allocator traits.
205 #if __cplusplus < 201103L
206 multiset(const multiset
& __x
)
209 multiset(const multiset
&) = default;
212 * @brief %Multiset move constructor.
214 * The newly-created %multiset contains the exact contents of the
215 * moved instance. The moved instance is a valid, but unspecified
218 multiset(multiset
&&) = default;
221 * @brief Builds a %multiset from an initializer_list.
222 * @param __l An initializer_list.
223 * @param __comp A comparison functor.
224 * @param __a An allocator object.
226 * Create a %multiset consisting of copies of the elements from
227 * the list. This is linear in N if the list is already sorted,
228 * and NlogN otherwise (where N is @a __l.size()).
230 multiset(initializer_list
<value_type
> __l
,
231 const _Compare
& __comp
= _Compare(),
232 const allocator_type
& __a
= allocator_type())
233 : _M_t(__comp
, _Key_alloc_type(__a
))
234 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
236 /// Allocator-extended default constructor.
238 multiset(const allocator_type
& __a
)
239 : _M_t(_Compare(), _Key_alloc_type(__a
)) { }
241 /// Allocator-extended copy constructor.
242 multiset(const multiset
& __m
, const allocator_type
& __a
)
243 : _M_t(__m
._M_t
, _Key_alloc_type(__a
)) { }
245 /// Allocator-extended move constructor.
246 multiset(multiset
&& __m
, const allocator_type
& __a
)
247 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
248 && _Alloc_traits::_S_always_equal())
249 : _M_t(std::move(__m
._M_t
), _Key_alloc_type(__a
)) { }
251 /// Allocator-extended initialier-list constructor.
252 multiset(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
253 : _M_t(_Compare(), _Key_alloc_type(__a
))
254 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
256 /// Allocator-extended range constructor.
257 template<typename _InputIterator
>
258 multiset(_InputIterator __first
, _InputIterator __last
,
259 const allocator_type
& __a
)
260 : _M_t(_Compare(), _Key_alloc_type(__a
))
261 { _M_t
._M_insert_equal(__first
, __last
); }
264 * The dtor only erases the elements, and note that if the elements
265 * themselves are pointers, the pointed-to memory is not touched in any
266 * way. Managing the pointer is the user's responsibility.
268 ~multiset() = default;
272 * @brief %Multiset assignment operator.
274 * Whether the allocator is copied depends on the allocator traits.
276 #if __cplusplus < 201103L
278 operator=(const multiset
& __x
)
285 operator=(const multiset
&) = default;
287 /// Move assignment operator.
289 operator=(multiset
&&) = default;
292 * @brief %Multiset list assignment operator.
293 * @param __l An initializer_list.
295 * This function fills a %multiset with copies of the elements in the
296 * initializer list @a __l.
298 * Note that the assignment completely changes the %multiset and
299 * that the resulting %multiset's size is the same as the number
300 * of elements assigned.
303 operator=(initializer_list
<value_type
> __l
)
305 _M_t
._M_assign_equal(__l
.begin(), __l
.end());
312 /// Returns the comparison object.
315 { return _M_t
.key_comp(); }
316 /// Returns the comparison object.
319 { return _M_t
.key_comp(); }
320 /// Returns the memory allocation object.
322 get_allocator() const _GLIBCXX_NOEXCEPT
323 { return allocator_type(_M_t
.get_allocator()); }
326 * Returns a read-only (constant) iterator that points to the first
327 * element in the %multiset. Iteration is done in ascending order
328 * according to the keys.
331 begin() const _GLIBCXX_NOEXCEPT
332 { return _M_t
.begin(); }
335 * Returns a read-only (constant) iterator that points one past the last
336 * element in the %multiset. Iteration is done in ascending order
337 * according to the keys.
340 end() const _GLIBCXX_NOEXCEPT
341 { return _M_t
.end(); }
344 * Returns a read-only (constant) reverse iterator that points to the
345 * last element in the %multiset. Iteration is done in descending order
346 * according to the keys.
349 rbegin() const _GLIBCXX_NOEXCEPT
350 { return _M_t
.rbegin(); }
353 * Returns a read-only (constant) reverse iterator that points to the
354 * last element in the %multiset. Iteration is done in descending order
355 * according to the keys.
358 rend() const _GLIBCXX_NOEXCEPT
359 { return _M_t
.rend(); }
361 #if __cplusplus >= 201103L
363 * Returns a read-only (constant) iterator that points to the first
364 * element in the %multiset. Iteration is done in ascending order
365 * according to the keys.
368 cbegin() const noexcept
369 { return _M_t
.begin(); }
372 * Returns a read-only (constant) iterator that points one past the last
373 * element in the %multiset. Iteration is done in ascending order
374 * according to the keys.
377 cend() const noexcept
378 { return _M_t
.end(); }
381 * Returns a read-only (constant) reverse iterator that points to the
382 * last element in the %multiset. Iteration is done in descending order
383 * according to the keys.
386 crbegin() const noexcept
387 { return _M_t
.rbegin(); }
390 * Returns a read-only (constant) reverse iterator that points to the
391 * last element in the %multiset. Iteration is done in descending order
392 * according to the keys.
395 crend() const noexcept
396 { return _M_t
.rend(); }
399 /// Returns true if the %set is empty.
401 empty() const _GLIBCXX_NOEXCEPT
402 { return _M_t
.empty(); }
404 /// Returns the size of the %set.
406 size() const _GLIBCXX_NOEXCEPT
407 { return _M_t
.size(); }
409 /// Returns the maximum size of the %set.
411 max_size() const _GLIBCXX_NOEXCEPT
412 { return _M_t
.max_size(); }
415 * @brief Swaps data with another %multiset.
416 * @param __x A %multiset of the same element and allocator types.
418 * This exchanges the elements between two multisets in constant time.
419 * (It is only swapping a pointer, an integer, and an instance of the @c
420 * Compare type (which itself is often stateless and empty), so it should
422 * Note that the global std::swap() function is specialized such that
423 * std::swap(s1,s2) will feed to this function.
425 * Whether the allocators are swapped depends on the allocator traits.
429 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable
<_Compare
>::value
)
430 { _M_t
.swap(__x
._M_t
); }
433 #if __cplusplus >= 201103L
435 * @brief Builds and inserts an element into the %multiset.
436 * @param __args Arguments used to generate the element instance to be
438 * @return An iterator that points to the inserted element.
440 * This function inserts an element into the %multiset. Contrary
441 * to a std::set the %multiset does not rely on unique keys and thus
442 * multiple copies of the same element can be inserted.
444 * Insertion requires logarithmic time.
446 template<typename
... _Args
>
448 emplace(_Args
&&... __args
)
449 { return _M_t
._M_emplace_equal(std::forward
<_Args
>(__args
)...); }
452 * @brief Builds and inserts an element into the %multiset.
453 * @param __pos An iterator that serves as a hint as to where the
454 * element should be inserted.
455 * @param __args Arguments used to generate the element instance to be
457 * @return An iterator that points to the inserted element.
459 * This function inserts an element into the %multiset. Contrary
460 * to a std::set the %multiset does not rely on unique keys and thus
461 * multiple copies of the same element can be inserted.
463 * Note that the first parameter is only a hint and can potentially
464 * improve the performance of the insertion process. A bad hint would
465 * cause no gains in efficiency.
467 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
468 * for more on @a hinting.
470 * Insertion requires logarithmic time (if the hint is not taken).
472 template<typename
... _Args
>
474 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
476 return _M_t
._M_emplace_hint_equal(__pos
,
477 std::forward
<_Args
>(__args
)...);
482 * @brief Inserts an element into the %multiset.
483 * @param __x Element to be inserted.
484 * @return An iterator that points to the inserted element.
486 * This function inserts an element into the %multiset. Contrary
487 * to a std::set the %multiset does not rely on unique keys and thus
488 * multiple copies of the same element can be inserted.
490 * Insertion requires logarithmic time.
493 insert(const value_type
& __x
)
494 { return _M_t
._M_insert_equal(__x
); }
496 #if __cplusplus >= 201103L
498 insert(value_type
&& __x
)
499 { return _M_t
._M_insert_equal(std::move(__x
)); }
503 * @brief Inserts an element into the %multiset.
504 * @param __position An iterator that serves as a hint as to where the
505 * element should be inserted.
506 * @param __x Element to be inserted.
507 * @return An iterator that points to the inserted element.
509 * This function inserts an element into the %multiset. Contrary
510 * to a std::set the %multiset does not rely on unique keys and thus
511 * multiple copies of the same element can be inserted.
513 * Note that the first parameter is only a hint and can potentially
514 * improve the performance of the insertion process. A bad hint would
515 * cause no gains in efficiency.
517 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
518 * for more on @a hinting.
520 * Insertion requires logarithmic time (if the hint is not taken).
523 insert(const_iterator __position
, const value_type
& __x
)
524 { return _M_t
._M_insert_equal_(__position
, __x
); }
526 #if __cplusplus >= 201103L
528 insert(const_iterator __position
, value_type
&& __x
)
529 { return _M_t
._M_insert_equal_(__position
, std::move(__x
)); }
533 * @brief A template function that tries to insert a range of elements.
534 * @param __first Iterator pointing to the start of the range to be
536 * @param __last Iterator pointing to the end of the range.
538 * Complexity similar to that of the range constructor.
540 template<typename _InputIterator
>
542 insert(_InputIterator __first
, _InputIterator __last
)
543 { _M_t
._M_insert_equal(__first
, __last
); }
545 #if __cplusplus >= 201103L
547 * @brief Attempts to insert a list of elements into the %multiset.
548 * @param __l A std::initializer_list<value_type> of elements
551 * Complexity similar to that of the range constructor.
554 insert(initializer_list
<value_type
> __l
)
555 { this->insert(__l
.begin(), __l
.end()); }
558 #if __cplusplus > 201402L
561 extract(const_iterator __pos
)
563 __glibcxx_assert(__pos
!= end());
564 return _M_t
.extract(__pos
);
569 extract(const key_type
& __x
)
570 { return _M_t
.extract(__x
); }
572 /// Re-insert an extracted node.
574 insert(node_type
&& __nh
)
575 { return _M_t
._M_reinsert_node_equal(std::move(__nh
)); }
577 /// Re-insert an extracted node.
579 insert(const_iterator __hint
, node_type
&& __nh
)
580 { return _M_t
._M_reinsert_node_hint_equal(__hint
, std::move(__nh
)); }
582 template<typename
, typename
>
583 friend class _Rb_tree_merge_helper
;
585 template<typename _Compare1
>
587 merge(multiset
<_Key
, _Compare1
, _Alloc
>& __source
)
589 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
590 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
593 template<typename _Compare1
>
595 merge(multiset
<_Key
, _Compare1
, _Alloc
>&& __source
)
598 template<typename _Compare1
>
600 merge(set
<_Key
, _Compare1
, _Alloc
>& __source
)
602 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
603 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
606 template<typename _Compare1
>
608 merge(set
<_Key
, _Compare1
, _Alloc
>&& __source
)
612 #if __cplusplus >= 201103L
613 // _GLIBCXX_RESOLVE_LIB_DEFECTS
614 // DR 130. Associative erase should return an iterator.
616 * @brief Erases an element from a %multiset.
617 * @param __position An iterator pointing to the element to be erased.
618 * @return An iterator pointing to the element immediately following
619 * @a position prior to the element being erased. If no such
620 * element exists, end() is returned.
622 * This function erases an element, pointed to by the given iterator,
623 * from a %multiset. Note that this function only erases the element,
624 * and that if the element is itself a pointer, the pointed-to memory is
625 * not touched in any way. Managing the pointer is the user's
628 _GLIBCXX_ABI_TAG_CXX11
630 erase(const_iterator __position
)
631 { return _M_t
.erase(__position
); }
634 * @brief Erases an element from a %multiset.
635 * @param __position An iterator pointing to the element to be erased.
637 * This function erases an element, pointed to by the given iterator,
638 * from a %multiset. Note that this function only erases the element,
639 * and that if the element is itself a pointer, the pointed-to memory is
640 * not touched in any way. Managing the pointer is the user's
644 erase(iterator __position
)
645 { _M_t
.erase(__position
); }
649 * @brief Erases elements according to the provided key.
650 * @param __x Key of element to be erased.
651 * @return The number of elements erased.
653 * This function erases all elements located by the given key from a
655 * Note that this function only erases the element, and that if
656 * the element is itself a pointer, the pointed-to memory is not touched
657 * in any way. Managing the pointer is the user's responsibility.
660 erase(const key_type
& __x
)
661 { return _M_t
.erase(__x
); }
663 #if __cplusplus >= 201103L
664 // _GLIBCXX_RESOLVE_LIB_DEFECTS
665 // DR 130. Associative erase should return an iterator.
667 * @brief Erases a [first,last) range of elements from a %multiset.
668 * @param __first Iterator pointing to the start of the range to be
670 * @param __last Iterator pointing to the end of the range to
672 * @return The iterator @a last.
674 * This function erases a sequence of elements from a %multiset.
675 * Note that this function only erases the elements, and that if
676 * the elements themselves are pointers, the pointed-to memory is not
677 * touched in any way. Managing the pointer is the user's
680 _GLIBCXX_ABI_TAG_CXX11
682 erase(const_iterator __first
, const_iterator __last
)
683 { return _M_t
.erase(__first
, __last
); }
686 * @brief Erases a [first,last) range of elements from a %multiset.
687 * @param first Iterator pointing to the start of the range to be
689 * @param last Iterator pointing to the end of the range to be erased.
691 * This function erases a sequence of elements from a %multiset.
692 * Note that this function only erases the elements, and that if
693 * the elements themselves are pointers, the pointed-to memory is not
694 * touched in any way. Managing the pointer is the user's
698 erase(iterator __first
, iterator __last
)
699 { _M_t
.erase(__first
, __last
); }
703 * Erases all elements in a %multiset. Note that this function only
704 * erases the elements, and that if the elements themselves are pointers,
705 * the pointed-to memory is not touched in any way. Managing the pointer
706 * is the user's responsibility.
709 clear() _GLIBCXX_NOEXCEPT
712 // multiset operations:
716 * @brief Finds the number of elements with given key.
717 * @param __x Key of elements to be located.
718 * @return Number of elements with specified key.
721 count(const key_type
& __x
) const
722 { return _M_t
.count(__x
); }
724 #if __cplusplus > 201103L
725 template<typename _Kt
>
727 count(const _Kt
& __x
) const -> decltype(_M_t
._M_count_tr(__x
))
728 { return _M_t
._M_count_tr(__x
); }
732 // _GLIBCXX_RESOLVE_LIB_DEFECTS
733 // 214. set::find() missing const overload
736 * @brief Tries to locate an element in a %set.
737 * @param __x Element to be located.
738 * @return Iterator pointing to sought-after element, or end() if not
741 * This function takes a key and tries to locate the element with which
742 * the key matches. If successful the function returns an iterator
743 * pointing to the sought after element. If unsuccessful it returns the
744 * past-the-end ( @c end() ) iterator.
747 find(const key_type
& __x
)
748 { return _M_t
.find(__x
); }
751 find(const key_type
& __x
) const
752 { return _M_t
.find(__x
); }
754 #if __cplusplus > 201103L
755 template<typename _Kt
>
758 -> decltype(iterator
{_M_t
._M_find_tr(__x
)})
759 { return iterator
{_M_t
._M_find_tr(__x
)}; }
761 template<typename _Kt
>
763 find(const _Kt
& __x
) const
764 -> decltype(const_iterator
{_M_t
._M_find_tr(__x
)})
765 { return const_iterator
{_M_t
._M_find_tr(__x
)}; }
771 * @brief Finds the beginning of a subsequence matching given key.
772 * @param __x Key to be located.
773 * @return Iterator pointing to first element equal to or greater
774 * than key, or end().
776 * This function returns the first element of a subsequence of elements
777 * that matches the given key. If unsuccessful it returns an iterator
778 * pointing to the first element that has a greater value than given key
779 * or end() if no such element exists.
782 lower_bound(const key_type
& __x
)
783 { return _M_t
.lower_bound(__x
); }
786 lower_bound(const key_type
& __x
) const
787 { return _M_t
.lower_bound(__x
); }
789 #if __cplusplus > 201103L
790 template<typename _Kt
>
792 lower_bound(const _Kt
& __x
)
793 -> decltype(iterator(_M_t
._M_lower_bound_tr(__x
)))
794 { return iterator(_M_t
._M_lower_bound_tr(__x
)); }
796 template<typename _Kt
>
798 lower_bound(const _Kt
& __x
) const
799 -> decltype(iterator(_M_t
._M_lower_bound_tr(__x
)))
800 { return iterator(_M_t
._M_lower_bound_tr(__x
)); }
806 * @brief Finds the end of a subsequence matching given key.
807 * @param __x Key to be located.
808 * @return Iterator pointing to the first element
809 * greater than key, or end().
812 upper_bound(const key_type
& __x
)
813 { return _M_t
.upper_bound(__x
); }
816 upper_bound(const key_type
& __x
) const
817 { return _M_t
.upper_bound(__x
); }
819 #if __cplusplus > 201103L
820 template<typename _Kt
>
822 upper_bound(const _Kt
& __x
)
823 -> decltype(iterator(_M_t
._M_upper_bound_tr(__x
)))
824 { return iterator(_M_t
._M_upper_bound_tr(__x
)); }
826 template<typename _Kt
>
828 upper_bound(const _Kt
& __x
) const
829 -> decltype(iterator(_M_t
._M_upper_bound_tr(__x
)))
830 { return iterator(_M_t
._M_upper_bound_tr(__x
)); }
836 * @brief Finds a subsequence matching given key.
837 * @param __x Key to be located.
838 * @return Pair of iterators that possibly points to the subsequence
839 * matching given key.
841 * This function is equivalent to
843 * std::make_pair(c.lower_bound(val),
844 * c.upper_bound(val))
846 * (but is faster than making the calls separately).
848 * This function probably only makes sense for multisets.
850 std::pair
<iterator
, iterator
>
851 equal_range(const key_type
& __x
)
852 { return _M_t
.equal_range(__x
); }
854 std::pair
<const_iterator
, const_iterator
>
855 equal_range(const key_type
& __x
) const
856 { return _M_t
.equal_range(__x
); }
858 #if __cplusplus > 201103L
859 template<typename _Kt
>
861 equal_range(const _Kt
& __x
)
862 -> decltype(pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)))
863 { return pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)); }
865 template<typename _Kt
>
867 equal_range(const _Kt
& __x
) const
868 -> decltype(pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)))
869 { return pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)); }
873 template<typename _K1
, typename _C1
, typename _A1
>
875 operator==(const multiset
<_K1
, _C1
, _A1
>&,
876 const multiset
<_K1
, _C1
, _A1
>&);
878 template<typename _K1
, typename _C1
, typename _A1
>
880 operator< (const multiset
<_K1
, _C1
, _A1
>&,
881 const multiset
<_K1
, _C1
, _A1
>&);
885 * @brief Multiset equality comparison.
886 * @param __x A %multiset.
887 * @param __y A %multiset of the same type as @a __x.
888 * @return True iff the size and elements of the multisets are equal.
890 * This is an equivalence relation. It is linear in the size of the
892 * Multisets are considered equivalent if their sizes are equal, and if
893 * corresponding elements compare equal.
895 template<typename _Key
, typename _Compare
, typename _Alloc
>
897 operator==(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
898 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
899 { return __x
._M_t
== __y
._M_t
; }
902 * @brief Multiset ordering relation.
903 * @param __x A %multiset.
904 * @param __y A %multiset of the same type as @a __x.
905 * @return True iff @a __x is lexicographically less than @a __y.
907 * This is a total ordering relation. It is linear in the size of the
908 * sets. The elements must be comparable with @c <.
910 * See std::lexicographical_compare() for how the determination is made.
912 template<typename _Key
, typename _Compare
, typename _Alloc
>
914 operator<(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
915 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
916 { return __x
._M_t
< __y
._M_t
; }
918 /// Returns !(x == y).
919 template<typename _Key
, typename _Compare
, typename _Alloc
>
921 operator!=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
922 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
923 { return !(__x
== __y
); }
926 template<typename _Key
, typename _Compare
, typename _Alloc
>
928 operator>(const multiset
<_Key
,_Compare
,_Alloc
>& __x
,
929 const multiset
<_Key
,_Compare
,_Alloc
>& __y
)
930 { return __y
< __x
; }
933 template<typename _Key
, typename _Compare
, typename _Alloc
>
935 operator<=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
936 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
937 { return !(__y
< __x
); }
940 template<typename _Key
, typename _Compare
, typename _Alloc
>
942 operator>=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
943 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
944 { return !(__x
< __y
); }
946 /// See std::multiset::swap().
947 template<typename _Key
, typename _Compare
, typename _Alloc
>
949 swap(multiset
<_Key
, _Compare
, _Alloc
>& __x
,
950 multiset
<_Key
, _Compare
, _Alloc
>& __y
)
951 _GLIBCXX_NOEXCEPT_IF(noexcept(__x
.swap(__y
)))
954 _GLIBCXX_END_NAMESPACE_CONTAINER
956 #if __cplusplus > 201402L
957 // Allow std::multiset access to internals of compatible sets.
958 template<typename _Val
, typename _Cmp1
, typename _Alloc
, typename _Cmp2
>
960 _Rb_tree_merge_helper
<_GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>,
964 friend class _GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>;
967 _S_get_tree(_GLIBCXX_STD_C::set
<_Val
, _Cmp2
, _Alloc
>& __set
)
968 { return __set
._M_t
; }
971 _S_get_tree(_GLIBCXX_STD_C::multiset
<_Val
, _Cmp2
, _Alloc
>& __set
)
972 { return __set
._M_t
; }
976 _GLIBCXX_END_NAMESPACE_VERSION
979 #endif /* _STL_MULTISET_H */