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.
148 #if __cplusplus >= 201103L
149 noexcept(is_nothrow_default_constructible
<allocator_type
>::value
)
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.
197 * @param __x A %multiset of identical element and allocator types.
199 * The newly-created %multiset uses a copy of the allocator object used
200 * by @a __x (unless the allocator traits dictate a different object).
202 multiset(const multiset
& __x
)
205 #if __cplusplus >= 201103L
207 * @brief %Multiset move constructor.
208 * @param __x A %multiset of identical element and allocator types.
210 * The newly-created %multiset contains the exact contents of @a __x.
211 * The contents of @a __x are a valid, but unspecified %multiset.
213 multiset(multiset
&& __x
)
214 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
)
215 : _M_t(std::move(__x
._M_t
)) { }
218 * @brief Builds a %multiset from an initializer_list.
219 * @param __l An initializer_list.
220 * @param __comp A comparison functor.
221 * @param __a An allocator object.
223 * Create a %multiset consisting of copies of the elements from
224 * the list. This is linear in N if the list is already sorted,
225 * and NlogN otherwise (where N is @a __l.size()).
227 multiset(initializer_list
<value_type
> __l
,
228 const _Compare
& __comp
= _Compare(),
229 const allocator_type
& __a
= allocator_type())
230 : _M_t(__comp
, _Key_alloc_type(__a
))
231 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
233 /// Allocator-extended default constructor.
235 multiset(const allocator_type
& __a
)
236 : _M_t(_Compare(), _Key_alloc_type(__a
)) { }
238 /// Allocator-extended copy constructor.
239 multiset(const multiset
& __m
, const allocator_type
& __a
)
240 : _M_t(__m
._M_t
, _Key_alloc_type(__a
)) { }
242 /// Allocator-extended move constructor.
243 multiset(multiset
&& __m
, const allocator_type
& __a
)
244 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
245 && _Alloc_traits::_S_always_equal())
246 : _M_t(std::move(__m
._M_t
), _Key_alloc_type(__a
)) { }
248 /// Allocator-extended initialier-list constructor.
249 multiset(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
250 : _M_t(_Compare(), _Key_alloc_type(__a
))
251 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
253 /// Allocator-extended range constructor.
254 template<typename _InputIterator
>
255 multiset(_InputIterator __first
, _InputIterator __last
,
256 const allocator_type
& __a
)
257 : _M_t(_Compare(), _Key_alloc_type(__a
))
258 { _M_t
._M_insert_equal(__first
, __last
); }
262 * @brief %Multiset assignment operator.
263 * @param __x A %multiset of identical element and allocator types.
265 * All the elements of @a __x are copied.
267 * Whether the allocator is copied depends on the allocator traits.
270 operator=(const multiset
& __x
)
276 #if __cplusplus >= 201103L
277 /// Move assignment operator.
279 operator=(multiset
&&) = default;
282 * @brief %Multiset list assignment operator.
283 * @param __l An initializer_list.
285 * This function fills a %multiset with copies of the elements in the
286 * initializer list @a __l.
288 * Note that the assignment completely changes the %multiset and
289 * that the resulting %multiset's size is the same as the number
290 * of elements assigned.
293 operator=(initializer_list
<value_type
> __l
)
295 _M_t
._M_assign_equal(__l
.begin(), __l
.end());
302 /// Returns the comparison object.
305 { return _M_t
.key_comp(); }
306 /// Returns the comparison object.
309 { return _M_t
.key_comp(); }
310 /// Returns the memory allocation object.
312 get_allocator() const _GLIBCXX_NOEXCEPT
313 { return allocator_type(_M_t
.get_allocator()); }
316 * Returns a read-only (constant) iterator that points to the first
317 * element in the %multiset. Iteration is done in ascending order
318 * according to the keys.
321 begin() const _GLIBCXX_NOEXCEPT
322 { return _M_t
.begin(); }
325 * Returns a read-only (constant) iterator that points one past the last
326 * element in the %multiset. Iteration is done in ascending order
327 * according to the keys.
330 end() const _GLIBCXX_NOEXCEPT
331 { return _M_t
.end(); }
334 * Returns a read-only (constant) reverse iterator that points to the
335 * last element in the %multiset. Iteration is done in descending order
336 * according to the keys.
339 rbegin() const _GLIBCXX_NOEXCEPT
340 { return _M_t
.rbegin(); }
343 * Returns a read-only (constant) reverse iterator that points to the
344 * last element in the %multiset. Iteration is done in descending order
345 * according to the keys.
348 rend() const _GLIBCXX_NOEXCEPT
349 { return _M_t
.rend(); }
351 #if __cplusplus >= 201103L
353 * Returns a read-only (constant) iterator that points to the first
354 * element in the %multiset. Iteration is done in ascending order
355 * according to the keys.
358 cbegin() const noexcept
359 { return _M_t
.begin(); }
362 * Returns a read-only (constant) iterator that points one past the last
363 * element in the %multiset. Iteration is done in ascending order
364 * according to the keys.
367 cend() const noexcept
368 { return _M_t
.end(); }
371 * Returns a read-only (constant) reverse iterator that points to the
372 * last element in the %multiset. Iteration is done in descending order
373 * according to the keys.
376 crbegin() const noexcept
377 { return _M_t
.rbegin(); }
380 * Returns a read-only (constant) reverse iterator that points to the
381 * last element in the %multiset. Iteration is done in descending order
382 * according to the keys.
385 crend() const noexcept
386 { return _M_t
.rend(); }
389 /// Returns true if the %set is empty.
391 empty() const _GLIBCXX_NOEXCEPT
392 { return _M_t
.empty(); }
394 /// Returns the size of the %set.
396 size() const _GLIBCXX_NOEXCEPT
397 { return _M_t
.size(); }
399 /// Returns the maximum size of the %set.
401 max_size() const _GLIBCXX_NOEXCEPT
402 { return _M_t
.max_size(); }
405 * @brief Swaps data with another %multiset.
406 * @param __x A %multiset of the same element and allocator types.
408 * This exchanges the elements between two multisets in constant time.
409 * (It is only swapping a pointer, an integer, and an instance of the @c
410 * Compare type (which itself is often stateless and empty), so it should
412 * Note that the global std::swap() function is specialized such that
413 * std::swap(s1,s2) will feed to this function.
415 * Whether the allocators are swapped depends on the allocator traits.
419 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable
<_Compare
>::value
)
420 { _M_t
.swap(__x
._M_t
); }
423 #if __cplusplus >= 201103L
425 * @brief Builds and inserts an element into the %multiset.
426 * @param __args Arguments used to generate the element instance to be
428 * @return An iterator that points to the inserted element.
430 * This function inserts an element into the %multiset. Contrary
431 * to a std::set the %multiset does not rely on unique keys and thus
432 * multiple copies of the same element can be inserted.
434 * Insertion requires logarithmic time.
436 template<typename
... _Args
>
438 emplace(_Args
&&... __args
)
439 { return _M_t
._M_emplace_equal(std::forward
<_Args
>(__args
)...); }
442 * @brief Builds and inserts an element into the %multiset.
443 * @param __pos An iterator that serves as a hint as to where the
444 * element should be inserted.
445 * @param __args Arguments used to generate the element instance to be
447 * @return An iterator that points to the inserted element.
449 * This function inserts an element into the %multiset. Contrary
450 * to a std::set the %multiset does not rely on unique keys and thus
451 * multiple copies of the same element can be inserted.
453 * Note that the first parameter is only a hint and can potentially
454 * improve the performance of the insertion process. A bad hint would
455 * cause no gains in efficiency.
457 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
458 * for more on @a hinting.
460 * Insertion requires logarithmic time (if the hint is not taken).
462 template<typename
... _Args
>
464 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
466 return _M_t
._M_emplace_hint_equal(__pos
,
467 std::forward
<_Args
>(__args
)...);
472 * @brief Inserts an element into the %multiset.
473 * @param __x Element to be inserted.
474 * @return An iterator that points to the inserted element.
476 * This function inserts an element into the %multiset. Contrary
477 * to a std::set the %multiset does not rely on unique keys and thus
478 * multiple copies of the same element can be inserted.
480 * Insertion requires logarithmic time.
483 insert(const value_type
& __x
)
484 { return _M_t
._M_insert_equal(__x
); }
486 #if __cplusplus >= 201103L
488 insert(value_type
&& __x
)
489 { return _M_t
._M_insert_equal(std::move(__x
)); }
493 * @brief Inserts an element into the %multiset.
494 * @param __position An iterator that serves as a hint as to where the
495 * element should be inserted.
496 * @param __x Element to be inserted.
497 * @return An iterator that points to the inserted element.
499 * This function inserts an element into the %multiset. Contrary
500 * to a std::set the %multiset does not rely on unique keys and thus
501 * multiple copies of the same element can be inserted.
503 * Note that the first parameter is only a hint and can potentially
504 * improve the performance of the insertion process. A bad hint would
505 * cause no gains in efficiency.
507 * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
508 * for more on @a hinting.
510 * Insertion requires logarithmic time (if the hint is not taken).
513 insert(const_iterator __position
, const value_type
& __x
)
514 { return _M_t
._M_insert_equal_(__position
, __x
); }
516 #if __cplusplus >= 201103L
518 insert(const_iterator __position
, value_type
&& __x
)
519 { return _M_t
._M_insert_equal_(__position
, std::move(__x
)); }
523 * @brief A template function that tries to insert a range of elements.
524 * @param __first Iterator pointing to the start of the range to be
526 * @param __last Iterator pointing to the end of the range.
528 * Complexity similar to that of the range constructor.
530 template<typename _InputIterator
>
532 insert(_InputIterator __first
, _InputIterator __last
)
533 { _M_t
._M_insert_equal(__first
, __last
); }
535 #if __cplusplus >= 201103L
537 * @brief Attempts to insert a list of elements into the %multiset.
538 * @param __l A std::initializer_list<value_type> of elements
541 * Complexity similar to that of the range constructor.
544 insert(initializer_list
<value_type
> __l
)
545 { this->insert(__l
.begin(), __l
.end()); }
548 #if __cplusplus > 201402L
551 extract(const_iterator __pos
)
553 __glibcxx_assert(__pos
!= end());
554 return _M_t
.extract(__pos
);
559 extract(const key_type
& __x
)
560 { return _M_t
.extract(__x
); }
562 /// Re-insert an extracted node.
564 insert(node_type
&& __nh
)
565 { return _M_t
._M_reinsert_node_equal(std::move(__nh
)); }
567 /// Re-insert an extracted node.
569 insert(const_iterator __hint
, node_type
&& __nh
)
570 { return _M_t
._M_reinsert_node_hint_equal(__hint
, std::move(__nh
)); }
572 template<typename
, typename
>
573 friend class _Rb_tree_merge_helper
;
575 template<typename _Compare1
>
577 merge(multiset
<_Key
, _Compare1
, _Alloc
>& __source
)
579 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
580 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
583 template<typename _Compare1
>
585 merge(multiset
<_Key
, _Compare1
, _Alloc
>&& __source
)
588 template<typename _Compare1
>
590 merge(set
<_Key
, _Compare1
, _Alloc
>& __source
)
592 using _Merge_helper
= _Rb_tree_merge_helper
<multiset
, _Compare1
>;
593 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
596 template<typename _Compare1
>
598 merge(set
<_Key
, _Compare1
, _Alloc
>&& __source
)
602 #if __cplusplus >= 201103L
603 // _GLIBCXX_RESOLVE_LIB_DEFECTS
604 // DR 130. Associative erase should return an iterator.
606 * @brief Erases an element from a %multiset.
607 * @param __position An iterator pointing to the element to be erased.
608 * @return An iterator pointing to the element immediately following
609 * @a position prior to the element being erased. If no such
610 * element exists, end() is returned.
612 * This function erases an element, pointed to by the given iterator,
613 * from a %multiset. Note that this function only erases the element,
614 * and that if the element is itself a pointer, the pointed-to memory is
615 * not touched in any way. Managing the pointer is the user's
618 _GLIBCXX_ABI_TAG_CXX11
620 erase(const_iterator __position
)
621 { return _M_t
.erase(__position
); }
624 * @brief Erases an element from a %multiset.
625 * @param __position An iterator pointing to the element to be erased.
627 * This function erases an element, pointed to by the given iterator,
628 * from a %multiset. Note that this function only erases the element,
629 * and that if the element is itself a pointer, the pointed-to memory is
630 * not touched in any way. Managing the pointer is the user's
634 erase(iterator __position
)
635 { _M_t
.erase(__position
); }
639 * @brief Erases elements according to the provided key.
640 * @param __x Key of element to be erased.
641 * @return The number of elements erased.
643 * This function erases all elements located by the given key from a
645 * Note that this function only erases the element, and that if
646 * the element is itself a pointer, the pointed-to memory is not touched
647 * in any way. Managing the pointer is the user's responsibility.
650 erase(const key_type
& __x
)
651 { return _M_t
.erase(__x
); }
653 #if __cplusplus >= 201103L
654 // _GLIBCXX_RESOLVE_LIB_DEFECTS
655 // DR 130. Associative erase should return an iterator.
657 * @brief Erases a [first,last) range of elements from a %multiset.
658 * @param __first Iterator pointing to the start of the range to be
660 * @param __last Iterator pointing to the end of the range to
662 * @return The iterator @a last.
664 * This function erases a sequence of elements from a %multiset.
665 * Note that this function only erases the elements, and that if
666 * the elements themselves are pointers, the pointed-to memory is not
667 * touched in any way. Managing the pointer is the user's
670 _GLIBCXX_ABI_TAG_CXX11
672 erase(const_iterator __first
, const_iterator __last
)
673 { return _M_t
.erase(__first
, __last
); }
676 * @brief Erases a [first,last) range of elements from a %multiset.
677 * @param first Iterator pointing to the start of the range to be
679 * @param last Iterator pointing to the end of the range to be erased.
681 * This function erases a sequence of elements from a %multiset.
682 * Note that this function only erases the elements, and that if
683 * the elements themselves are pointers, the pointed-to memory is not
684 * touched in any way. Managing the pointer is the user's
688 erase(iterator __first
, iterator __last
)
689 { _M_t
.erase(__first
, __last
); }
693 * Erases all elements in a %multiset. Note that this function only
694 * erases the elements, and that if the elements themselves are pointers,
695 * the pointed-to memory is not touched in any way. Managing the pointer
696 * is the user's responsibility.
699 clear() _GLIBCXX_NOEXCEPT
702 // multiset operations:
706 * @brief Finds the number of elements with given key.
707 * @param __x Key of elements to be located.
708 * @return Number of elements with specified key.
711 count(const key_type
& __x
) const
712 { return _M_t
.count(__x
); }
714 #if __cplusplus > 201103L
715 template<typename _Kt
>
717 count(const _Kt
& __x
) const -> decltype(_M_t
._M_count_tr(__x
))
718 { return _M_t
._M_count_tr(__x
); }
722 // _GLIBCXX_RESOLVE_LIB_DEFECTS
723 // 214. set::find() missing const overload
726 * @brief Tries to locate an element in a %set.
727 * @param __x Element to be located.
728 * @return Iterator pointing to sought-after element, or end() if not
731 * This function takes a key and tries to locate the element with which
732 * the key matches. If successful the function returns an iterator
733 * pointing to the sought after element. If unsuccessful it returns the
734 * past-the-end ( @c end() ) iterator.
737 find(const key_type
& __x
)
738 { return _M_t
.find(__x
); }
741 find(const key_type
& __x
) const
742 { return _M_t
.find(__x
); }
744 #if __cplusplus > 201103L
745 template<typename _Kt
>
748 -> decltype(iterator
{_M_t
._M_find_tr(__x
)})
749 { return iterator
{_M_t
._M_find_tr(__x
)}; }
751 template<typename _Kt
>
753 find(const _Kt
& __x
) const
754 -> decltype(const_iterator
{_M_t
._M_find_tr(__x
)})
755 { return const_iterator
{_M_t
._M_find_tr(__x
)}; }
761 * @brief Finds the beginning of a subsequence matching given key.
762 * @param __x Key to be located.
763 * @return Iterator pointing to first element equal to or greater
764 * than key, or end().
766 * This function returns the first element of a subsequence of elements
767 * that matches the given key. If unsuccessful it returns an iterator
768 * pointing to the first element that has a greater value than given key
769 * or end() if no such element exists.
772 lower_bound(const key_type
& __x
)
773 { return _M_t
.lower_bound(__x
); }
776 lower_bound(const key_type
& __x
) const
777 { return _M_t
.lower_bound(__x
); }
779 #if __cplusplus > 201103L
780 template<typename _Kt
>
782 lower_bound(const _Kt
& __x
)
783 -> decltype(_M_t
._M_lower_bound_tr(__x
))
784 { return _M_t
._M_lower_bound_tr(__x
); }
786 template<typename _Kt
>
788 lower_bound(const _Kt
& __x
) const
789 -> decltype(_M_t
._M_lower_bound_tr(__x
))
790 { return _M_t
._M_lower_bound_tr(__x
); }
796 * @brief Finds the end of a subsequence matching given key.
797 * @param __x Key to be located.
798 * @return Iterator pointing to the first element
799 * greater than key, or end().
802 upper_bound(const key_type
& __x
)
803 { return _M_t
.upper_bound(__x
); }
806 upper_bound(const key_type
& __x
) const
807 { return _M_t
.upper_bound(__x
); }
809 #if __cplusplus > 201103L
810 template<typename _Kt
>
812 upper_bound(const _Kt
& __x
)
813 -> decltype(_M_t
._M_upper_bound_tr(__x
))
814 { return _M_t
._M_upper_bound_tr(__x
); }
816 template<typename _Kt
>
818 upper_bound(const _Kt
& __x
) const
819 -> decltype(_M_t
._M_upper_bound_tr(__x
))
820 { return _M_t
._M_upper_bound_tr(__x
); }
826 * @brief Finds a subsequence matching given key.
827 * @param __x Key to be located.
828 * @return Pair of iterators that possibly points to the subsequence
829 * matching given key.
831 * This function is equivalent to
833 * std::make_pair(c.lower_bound(val),
834 * c.upper_bound(val))
836 * (but is faster than making the calls separately).
838 * This function probably only makes sense for multisets.
840 std::pair
<iterator
, iterator
>
841 equal_range(const key_type
& __x
)
842 { return _M_t
.equal_range(__x
); }
844 std::pair
<const_iterator
, const_iterator
>
845 equal_range(const key_type
& __x
) const
846 { return _M_t
.equal_range(__x
); }
848 #if __cplusplus > 201103L
849 template<typename _Kt
>
851 equal_range(const _Kt
& __x
)
852 -> decltype(_M_t
._M_equal_range_tr(__x
))
853 { return _M_t
._M_equal_range_tr(__x
); }
855 template<typename _Kt
>
857 equal_range(const _Kt
& __x
) const
858 -> decltype(_M_t
._M_equal_range_tr(__x
))
859 { return _M_t
._M_equal_range_tr(__x
); }
863 template<typename _K1
, typename _C1
, typename _A1
>
865 operator==(const multiset
<_K1
, _C1
, _A1
>&,
866 const multiset
<_K1
, _C1
, _A1
>&);
868 template<typename _K1
, typename _C1
, typename _A1
>
870 operator< (const multiset
<_K1
, _C1
, _A1
>&,
871 const multiset
<_K1
, _C1
, _A1
>&);
875 * @brief Multiset equality comparison.
876 * @param __x A %multiset.
877 * @param __y A %multiset of the same type as @a __x.
878 * @return True iff the size and elements of the multisets are equal.
880 * This is an equivalence relation. It is linear in the size of the
882 * Multisets are considered equivalent if their sizes are equal, and if
883 * corresponding elements compare equal.
885 template<typename _Key
, typename _Compare
, typename _Alloc
>
887 operator==(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
888 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
889 { return __x
._M_t
== __y
._M_t
; }
892 * @brief Multiset ordering relation.
893 * @param __x A %multiset.
894 * @param __y A %multiset of the same type as @a __x.
895 * @return True iff @a __x is lexicographically less than @a __y.
897 * This is a total ordering relation. It is linear in the size of the
898 * sets. The elements must be comparable with @c <.
900 * See std::lexicographical_compare() for how the determination is made.
902 template<typename _Key
, typename _Compare
, typename _Alloc
>
904 operator<(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
905 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
906 { return __x
._M_t
< __y
._M_t
; }
908 /// Returns !(x == y).
909 template<typename _Key
, typename _Compare
, typename _Alloc
>
911 operator!=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
912 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
913 { return !(__x
== __y
); }
916 template<typename _Key
, typename _Compare
, typename _Alloc
>
918 operator>(const multiset
<_Key
,_Compare
,_Alloc
>& __x
,
919 const multiset
<_Key
,_Compare
,_Alloc
>& __y
)
920 { return __y
< __x
; }
923 template<typename _Key
, typename _Compare
, typename _Alloc
>
925 operator<=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
926 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
927 { return !(__y
< __x
); }
930 template<typename _Key
, typename _Compare
, typename _Alloc
>
932 operator>=(const multiset
<_Key
, _Compare
, _Alloc
>& __x
,
933 const multiset
<_Key
, _Compare
, _Alloc
>& __y
)
934 { return !(__x
< __y
); }
936 /// See std::multiset::swap().
937 template<typename _Key
, typename _Compare
, typename _Alloc
>
939 swap(multiset
<_Key
, _Compare
, _Alloc
>& __x
,
940 multiset
<_Key
, _Compare
, _Alloc
>& __y
)
941 _GLIBCXX_NOEXCEPT_IF(noexcept(__x
.swap(__y
)))
944 _GLIBCXX_END_NAMESPACE_CONTAINER
946 #if __cplusplus > 201402L
947 _GLIBCXX_BEGIN_NAMESPACE_VERSION
948 // Allow std::multiset access to internals of compatible sets.
949 template<typename _Val
, typename _Cmp1
, typename _Alloc
, typename _Cmp2
>
951 _Rb_tree_merge_helper
<_GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>,
955 friend class _GLIBCXX_STD_C::multiset
<_Val
, _Cmp1
, _Alloc
>;
958 _S_get_tree(_GLIBCXX_STD_C::set
<_Val
, _Cmp2
, _Alloc
>& __set
)
959 { return __set
._M_t
; }
962 _S_get_tree(_GLIBCXX_STD_C::multiset
<_Val
, _Cmp2
, _Alloc
>& __set
)
963 { return __set
._M_t
; }
965 _GLIBCXX_END_NAMESPACE_VERSION
970 #endif /* _STL_MULTISET_H */