1 // Set 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.
39 * Copyright (c) 1996,1997
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_set.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{set}
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 unique keys, which can be
73 * retrieved in logarithmic time.
75 * @ingroup associative_containers
77 * @tparam _Key Type of key objects.
78 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
79 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
81 * Meets the requirements of a <a href="tables.html#65">container</a>, a
82 * <a href="tables.html#66">reversible container</a>, and an
83 * <a href="tables.html#69">associative container</a> (using unique keys).
85 * Sets support bidirectional iterators.
87 * The private tree data is declared exactly the same way for set and
88 * multiset; the distinction is made entirely in how the tree functions are
89 * called (*_unique versus *_equal, same as the standard).
91 template<typename _Key
, typename _Compare
= std::less
<_Key
>,
92 typename _Alloc
= std::allocator
<_Key
> >
95 // concept requirements
96 typedef typename
_Alloc::value_type _Alloc_value_type
;
97 __glibcxx_class_requires(_Key
, _SGIAssignableConcept
)
98 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
99 _BinaryFunctionConcept
)
100 __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
;
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 _Rep_type _M_t
; // Red-black tree representing set.
121 typedef __gnu_cxx::__alloc_traits
<_Key_alloc_type
> _Alloc_traits
;
125 /// Iterator-related typedefs.
126 typedef typename
_Alloc_traits::pointer pointer
;
127 typedef typename
_Alloc_traits::const_pointer const_pointer
;
128 typedef typename
_Alloc_traits::reference reference
;
129 typedef typename
_Alloc_traits::const_reference const_reference
;
130 // _GLIBCXX_RESOLVE_LIB_DEFECTS
131 // DR 103. set::iterator is required to be modifiable,
132 // but this allows modification of keys.
133 typedef typename
_Rep_type::const_iterator iterator
;
134 typedef typename
_Rep_type::const_iterator const_iterator
;
135 typedef typename
_Rep_type::const_reverse_iterator reverse_iterator
;
136 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
137 typedef typename
_Rep_type::size_type size_type
;
138 typedef typename
_Rep_type::difference_type difference_type
;
141 #if __cplusplus > 201402L
142 using node_type
= typename
_Rep_type::node_type
;
143 using insert_return_type
= typename
_Rep_type::insert_return_type
;
146 // allocation/deallocation
148 * @brief Default constructor creates no elements.
150 #if __cplusplus < 201103L
157 * @brief Creates a %set with no elements.
158 * @param __comp Comparator to use.
159 * @param __a An allocator object.
162 set(const _Compare
& __comp
,
163 const allocator_type
& __a
= allocator_type())
164 : _M_t(__comp
, _Key_alloc_type(__a
)) { }
167 * @brief Builds a %set from a range.
168 * @param __first An input iterator.
169 * @param __last An input iterator.
171 * Create a %set consisting of copies of the elements from
172 * [__first,__last). This is linear in N if the range is
173 * already sorted, and NlogN otherwise (where N is
174 * distance(__first,__last)).
176 template<typename _InputIterator
>
177 set(_InputIterator __first
, _InputIterator __last
)
179 { _M_t
._M_insert_unique(__first
, __last
); }
182 * @brief Builds a %set from a range.
183 * @param __first An input iterator.
184 * @param __last An input iterator.
185 * @param __comp A comparison functor.
186 * @param __a An allocator object.
188 * Create a %set consisting of copies of the elements from
189 * [__first,__last). This is linear in N if the range is
190 * already sorted, and NlogN otherwise (where N is
191 * distance(__first,__last)).
193 template<typename _InputIterator
>
194 set(_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_unique(__first
, __last
); }
201 * @brief %Set copy constructor.
202 * @param __x A %set of identical element and allocator types.
204 * The newly-created %set uses a copy of the allocator object used
205 * by @a __x (unless the allocator traits dictate a different object).
210 #if __cplusplus >= 201103L
212 * @brief %Set move constructor
213 * @param __x A %set of identical element and allocator types.
215 * The newly-created %set contains the exact contents of @a x.
216 * The contents of @a x are a valid, but unspecified %set.
219 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
)
220 : _M_t(std::move(__x
._M_t
)) { }
223 * @brief Builds a %set from an initializer_list.
224 * @param __l An initializer_list.
225 * @param __comp A comparison functor.
226 * @param __a An allocator object.
228 * Create a %set consisting of copies of the elements in the list.
229 * This is linear in N if the list is already sorted, and NlogN
230 * otherwise (where N is @a __l.size()).
232 set(initializer_list
<value_type
> __l
,
233 const _Compare
& __comp
= _Compare(),
234 const allocator_type
& __a
= allocator_type())
235 : _M_t(__comp
, _Key_alloc_type(__a
))
236 { _M_t
._M_insert_unique(__l
.begin(), __l
.end()); }
238 /// Allocator-extended default constructor.
240 set(const allocator_type
& __a
)
241 : _M_t(_Compare(), _Key_alloc_type(__a
)) { }
243 /// Allocator-extended copy constructor.
244 set(const set
& __x
, const allocator_type
& __a
)
245 : _M_t(__x
._M_t
, _Key_alloc_type(__a
)) { }
247 /// Allocator-extended move constructor.
248 set(set
&& __x
, const allocator_type
& __a
)
249 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
250 && _Alloc_traits::_S_always_equal())
251 : _M_t(std::move(__x
._M_t
), _Key_alloc_type(__a
)) { }
253 /// Allocator-extended initialier-list constructor.
254 set(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
255 : _M_t(_Compare(), _Key_alloc_type(__a
))
256 { _M_t
._M_insert_unique(__l
.begin(), __l
.end()); }
258 /// Allocator-extended range constructor.
259 template<typename _InputIterator
>
260 set(_InputIterator __first
, _InputIterator __last
,
261 const allocator_type
& __a
)
262 : _M_t(_Compare(), _Key_alloc_type(__a
))
263 { _M_t
._M_insert_unique(__first
, __last
); }
267 * @brief %Set assignment operator.
268 * @param __x A %set of identical element and allocator types.
270 * All the elements of @a __x are copied.
272 * Whether the allocator is copied depends on the allocator traits.
275 operator=(const set
& __x
)
281 #if __cplusplus >= 201103L
282 /// Move assignment operator.
284 operator=(set
&&) = default;
287 * @brief %Set list assignment operator.
288 * @param __l An initializer_list.
290 * This function fills a %set with copies of the elements in the
291 * initializer list @a __l.
293 * Note that the assignment completely changes the %set and
294 * that the resulting %set's size is the same as the number
295 * of elements assigned.
298 operator=(initializer_list
<value_type
> __l
)
300 _M_t
._M_assign_unique(__l
.begin(), __l
.end());
307 /// Returns the comparison object with which the %set was constructed.
310 { return _M_t
.key_comp(); }
311 /// Returns the comparison object with which the %set was constructed.
314 { return _M_t
.key_comp(); }
315 /// Returns the allocator object with which the %set was constructed.
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 %set. Iteration is done in ascending order according
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 %set. Iteration is done in ascending order according
335 end() const _GLIBCXX_NOEXCEPT
336 { return _M_t
.end(); }
339 * Returns a read-only (constant) iterator that points to the last
340 * element in the %set. Iteration is done in descending order according
344 rbegin() const _GLIBCXX_NOEXCEPT
345 { return _M_t
.rbegin(); }
348 * Returns a read-only (constant) reverse iterator that points to the
349 * last pair in the %set. 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 %set. Iteration is done in ascending order according
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 %set. Iteration is done in ascending order according
372 cend() const noexcept
373 { return _M_t
.end(); }
376 * Returns a read-only (constant) iterator that points to the last
377 * element in the %set. Iteration is done in descending order according
381 crbegin() const noexcept
382 { return _M_t
.rbegin(); }
385 * Returns a read-only (constant) reverse iterator that points to the
386 * last pair in the %set. 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 %set.
411 * @param __x A %set of the same element and allocator types.
413 * This exchanges the elements between two sets in constant
414 * time. (It is only swapping a pointer, an integer, and an
415 * instance of the @c Compare type (which itself is often
416 * stateless and empty), so it should be quite fast.) Note
417 * that the global std::swap() function is specialized such
418 * that 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 Attempts to build and insert an element into the %set.
431 * @param __args Arguments used to generate an element.
432 * @return A pair, of which the first element is an iterator that points
433 * to the possibly inserted element, and the second is a bool
434 * that is true if the element was actually inserted.
436 * This function attempts to build and insert an element into the %set.
437 * A %set relies on unique keys and thus an element is only inserted if
438 * it is not already present in the %set.
440 * Insertion requires logarithmic time.
442 template<typename
... _Args
>
443 std::pair
<iterator
, bool>
444 emplace(_Args
&&... __args
)
445 { return _M_t
._M_emplace_unique(std::forward
<_Args
>(__args
)...); }
448 * @brief Attempts to insert an element into the %set.
449 * @param __pos An iterator that serves as a hint as to where the
450 * element should be inserted.
451 * @param __args Arguments used to generate the element to be
453 * @return An iterator that points to the element with key equivalent to
454 * the one generated from @a __args (may or may not be the
457 * This function is not concerned about whether the insertion took place,
458 * and thus does not return a boolean like the single-argument emplace()
459 * does. Note that the first parameter is only a hint and can
460 * potentially improve the performance of the insertion process. A bad
461 * hint would cause no gains in efficiency.
463 * For more on @a hinting, see:
464 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
466 * Insertion requires logarithmic time (if the hint is not taken).
468 template<typename
... _Args
>
470 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
472 return _M_t
._M_emplace_hint_unique(__pos
,
473 std::forward
<_Args
>(__args
)...);
478 * @brief Attempts to insert an element into the %set.
479 * @param __x Element to be inserted.
480 * @return A pair, of which the first element is an iterator that points
481 * to the possibly inserted element, and the second is a bool
482 * that is true if the element was actually inserted.
484 * This function attempts to insert an element into the %set. A %set
485 * relies on unique keys and thus an element is only inserted if it is
486 * not already present in the %set.
488 * Insertion requires logarithmic time.
490 std::pair
<iterator
, bool>
491 insert(const value_type
& __x
)
493 std::pair
<typename
_Rep_type::iterator
, bool> __p
=
494 _M_t
._M_insert_unique(__x
);
495 return std::pair
<iterator
, bool>(__p
.first
, __p
.second
);
498 #if __cplusplus >= 201103L
499 std::pair
<iterator
, bool>
500 insert(value_type
&& __x
)
502 std::pair
<typename
_Rep_type::iterator
, bool> __p
=
503 _M_t
._M_insert_unique(std::move(__x
));
504 return std::pair
<iterator
, bool>(__p
.first
, __p
.second
);
509 * @brief Attempts to insert an element into the %set.
510 * @param __position An iterator that serves as a hint as to where the
511 * element should be inserted.
512 * @param __x Element to be inserted.
513 * @return An iterator that points to the element with key of
514 * @a __x (may or may not be the element passed in).
516 * This function is not concerned about whether the insertion took place,
517 * and thus does not return a boolean like the single-argument insert()
518 * does. Note that the first parameter is only a hint and can
519 * potentially improve the performance of the insertion process. A bad
520 * hint would cause no gains in efficiency.
522 * For more on @a hinting, see:
523 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
525 * Insertion requires logarithmic time (if the hint is not taken).
528 insert(const_iterator __position
, const value_type
& __x
)
529 { return _M_t
._M_insert_unique_(__position
, __x
); }
531 #if __cplusplus >= 201103L
533 insert(const_iterator __position
, value_type
&& __x
)
534 { return _M_t
._M_insert_unique_(__position
, std::move(__x
)); }
538 * @brief A template function that attempts to insert a range
540 * @param __first Iterator pointing to the start of the range to be
542 * @param __last Iterator pointing to the end of the range.
544 * Complexity similar to that of the range constructor.
546 template<typename _InputIterator
>
548 insert(_InputIterator __first
, _InputIterator __last
)
549 { _M_t
._M_insert_unique(__first
, __last
); }
551 #if __cplusplus >= 201103L
553 * @brief Attempts to insert a list of elements into the %set.
554 * @param __l A std::initializer_list<value_type> of elements
557 * Complexity similar to that of the range constructor.
560 insert(initializer_list
<value_type
> __l
)
561 { this->insert(__l
.begin(), __l
.end()); }
564 #if __cplusplus > 201402L
567 extract(const_iterator __pos
)
569 __glibcxx_assert(__pos
!= end());
570 return _M_t
.extract(__pos
);
575 extract(const key_type
& __x
)
576 { return _M_t
.extract(__x
); }
578 /// Re-insert an extracted node.
580 insert(node_type
&& __nh
)
581 { return _M_t
._M_reinsert_node_unique(std::move(__nh
)); }
583 /// Re-insert an extracted node.
585 insert(const_iterator __hint
, node_type
&& __nh
)
586 { return _M_t
._M_reinsert_node_hint_unique(__hint
, std::move(__nh
)); }
588 template<typename
, typename
>
589 friend class _Rb_tree_merge_helper
;
591 template<typename _Compare1
>
593 merge(set
<_Key
, _Compare1
, _Alloc
>& __source
)
595 using _Merge_helper
= _Rb_tree_merge_helper
<set
, _Compare1
>;
596 _M_t
._M_merge_unique(_Merge_helper::_S_get_tree(__source
));
599 template<typename _Compare1
>
601 merge(set
<_Key
, _Compare1
, _Alloc
>&& __source
)
604 template<typename _Compare1
>
606 merge(multiset
<_Key
, _Compare1
, _Alloc
>& __source
)
608 using _Merge_helper
= _Rb_tree_merge_helper
<set
, _Compare1
>;
609 _M_t
._M_merge_unique(_Merge_helper::_S_get_tree(__source
));
612 template<typename _Compare1
>
614 merge(multiset
<_Key
, _Compare1
, _Alloc
>&& __source
)
618 #if __cplusplus >= 201103L
619 // _GLIBCXX_RESOLVE_LIB_DEFECTS
620 // DR 130. Associative erase should return an iterator.
622 * @brief Erases an element from a %set.
623 * @param __position An iterator pointing to the element to be erased.
624 * @return An iterator pointing to the element immediately following
625 * @a __position prior to the element being erased. If no such
626 * element exists, end() is returned.
628 * This function erases an element, pointed to by the given iterator,
629 * from a %set. Note that this function only erases the element, and
630 * that if the element is itself a pointer, the pointed-to memory is not
631 * touched in any way. Managing the pointer is the user's
634 _GLIBCXX_ABI_TAG_CXX11
636 erase(const_iterator __position
)
637 { return _M_t
.erase(__position
); }
640 * @brief Erases an element from a %set.
641 * @param position An iterator pointing to the element to be erased.
643 * This function erases an element, pointed to by the given iterator,
644 * from a %set. Note that this function only erases the element, and
645 * that if the element is itself a pointer, the pointed-to memory is not
646 * touched in any way. Managing the pointer is the user's
650 erase(iterator __position
)
651 { _M_t
.erase(__position
); }
655 * @brief Erases elements according to the provided key.
656 * @param __x Key of element to be erased.
657 * @return The number of elements erased.
659 * This function erases all the elements located by the given key from
661 * Note that this function only erases the element, and that if
662 * the element is itself a pointer, the pointed-to memory is not touched
663 * in any way. Managing the pointer is the user's responsibility.
666 erase(const key_type
& __x
)
667 { return _M_t
.erase(__x
); }
669 #if __cplusplus >= 201103L
670 // _GLIBCXX_RESOLVE_LIB_DEFECTS
671 // DR 130. Associative erase should return an iterator.
673 * @brief Erases a [__first,__last) range of elements from a %set.
674 * @param __first Iterator pointing to the start of the range to be
677 * @param __last Iterator pointing to the end of the range to
679 * @return The iterator @a __last.
681 * This function erases a sequence of elements from a %set.
682 * Note that this function only erases the element, and that if
683 * the element is itself a pointer, the pointed-to memory is not touched
684 * in any way. Managing the pointer is the user's responsibility.
686 _GLIBCXX_ABI_TAG_CXX11
688 erase(const_iterator __first
, const_iterator __last
)
689 { return _M_t
.erase(__first
, __last
); }
692 * @brief Erases a [first,last) range of elements from a %set.
693 * @param __first Iterator pointing to the start of the range to be
695 * @param __last Iterator pointing to the end of the range to
698 * This function erases a sequence of elements from a %set.
699 * Note that this function only erases the element, and that if
700 * the element is itself a pointer, the pointed-to memory is not touched
701 * in any way. Managing the pointer is the user's responsibility.
704 erase(iterator __first
, iterator __last
)
705 { _M_t
.erase(__first
, __last
); }
709 * Erases all elements in a %set. Note that this function only erases
710 * the elements, and that if the elements themselves are pointers, the
711 * pointed-to memory is not touched in any way. Managing the pointer is
712 * the user's responsibility.
715 clear() _GLIBCXX_NOEXCEPT
722 * @brief Finds the number of elements.
723 * @param __x Element to located.
724 * @return Number of elements with specified key.
726 * This function only makes sense for multisets; for set the result will
727 * either be 0 (not present) or 1 (present).
730 count(const key_type
& __x
) const
731 { return _M_t
.find(__x
) == _M_t
.end() ? 0 : 1; }
733 #if __cplusplus > 201103L
734 template<typename _Kt
>
736 count(const _Kt
& __x
) const
737 -> decltype(_M_t
._M_count_tr(__x
))
738 { return _M_t
._M_find_tr(__x
) == _M_t
.end() ? 0 : 1; }
742 // _GLIBCXX_RESOLVE_LIB_DEFECTS
743 // 214. set::find() missing const overload
746 * @brief Tries to locate an element in a %set.
747 * @param __x Element to be located.
748 * @return Iterator pointing to sought-after element, or end() if not
751 * This function takes a key and tries to locate the element with which
752 * the key matches. If successful the function returns an iterator
753 * pointing to the sought after element. If unsuccessful it returns the
754 * past-the-end ( @c end() ) iterator.
757 find(const key_type
& __x
)
758 { return _M_t
.find(__x
); }
761 find(const key_type
& __x
) const
762 { return _M_t
.find(__x
); }
764 #if __cplusplus > 201103L
765 template<typename _Kt
>
768 -> decltype(iterator
{_M_t
._M_find_tr(__x
)})
769 { return iterator
{_M_t
._M_find_tr(__x
)}; }
771 template<typename _Kt
>
773 find(const _Kt
& __x
) const
774 -> decltype(const_iterator
{_M_t
._M_find_tr(__x
)})
775 { return const_iterator
{_M_t
._M_find_tr(__x
)}; }
781 * @brief Finds the beginning of a subsequence matching given key.
782 * @param __x Key to be located.
783 * @return Iterator pointing to first element equal to or greater
784 * than key, or end().
786 * This function returns the first element of a subsequence of elements
787 * that matches the given key. If unsuccessful it returns an iterator
788 * pointing to the first element that has a greater value than given key
789 * or end() if no such element exists.
792 lower_bound(const key_type
& __x
)
793 { return _M_t
.lower_bound(__x
); }
796 lower_bound(const key_type
& __x
) const
797 { return _M_t
.lower_bound(__x
); }
799 #if __cplusplus > 201103L
800 template<typename _Kt
>
802 lower_bound(const _Kt
& __x
)
803 -> decltype(_M_t
._M_lower_bound_tr(__x
))
804 { return _M_t
._M_lower_bound_tr(__x
); }
806 template<typename _Kt
>
808 lower_bound(const _Kt
& __x
) const
809 -> decltype(_M_t
._M_lower_bound_tr(__x
))
810 { return _M_t
._M_lower_bound_tr(__x
); }
816 * @brief Finds the end of a subsequence matching given key.
817 * @param __x Key to be located.
818 * @return Iterator pointing to the first element
819 * greater than key, or end().
822 upper_bound(const key_type
& __x
)
823 { return _M_t
.upper_bound(__x
); }
826 upper_bound(const key_type
& __x
) const
827 { return _M_t
.upper_bound(__x
); }
829 #if __cplusplus > 201103L
830 template<typename _Kt
>
832 upper_bound(const _Kt
& __x
)
833 -> decltype(_M_t
._M_upper_bound_tr(__x
))
834 { return _M_t
._M_upper_bound_tr(__x
); }
836 template<typename _Kt
>
838 upper_bound(const _Kt
& __x
) const
839 -> decltype(_M_t
._M_upper_bound_tr(__x
))
840 { return _M_t
._M_upper_bound_tr(__x
); }
846 * @brief Finds a subsequence matching given key.
847 * @param __x Key to be located.
848 * @return Pair of iterators that possibly points to the subsequence
849 * matching given key.
851 * This function is equivalent to
853 * std::make_pair(c.lower_bound(val),
854 * c.upper_bound(val))
856 * (but is faster than making the calls separately).
858 * This function probably only makes sense for multisets.
860 std::pair
<iterator
, iterator
>
861 equal_range(const key_type
& __x
)
862 { return _M_t
.equal_range(__x
); }
864 std::pair
<const_iterator
, const_iterator
>
865 equal_range(const key_type
& __x
) const
866 { return _M_t
.equal_range(__x
); }
868 #if __cplusplus > 201103L
869 template<typename _Kt
>
871 equal_range(const _Kt
& __x
)
872 -> decltype(_M_t
._M_equal_range_tr(__x
))
873 { return _M_t
._M_equal_range_tr(__x
); }
875 template<typename _Kt
>
877 equal_range(const _Kt
& __x
) const
878 -> decltype(_M_t
._M_equal_range_tr(__x
))
879 { return _M_t
._M_equal_range_tr(__x
); }
883 template<typename _K1
, typename _C1
, typename _A1
>
885 operator==(const set
<_K1
, _C1
, _A1
>&, const set
<_K1
, _C1
, _A1
>&);
887 template<typename _K1
, typename _C1
, typename _A1
>
889 operator<(const set
<_K1
, _C1
, _A1
>&, const set
<_K1
, _C1
, _A1
>&);
894 * @brief Set equality comparison.
896 * @param __y A %set of the same type as @a x.
897 * @return True iff the size and elements of the sets are equal.
899 * This is an equivalence relation. It is linear in the size of the sets.
900 * Sets are considered equivalent if their sizes are equal, and if
901 * corresponding elements compare equal.
903 template<typename _Key
, typename _Compare
, typename _Alloc
>
905 operator==(const set
<_Key
, _Compare
, _Alloc
>& __x
,
906 const set
<_Key
, _Compare
, _Alloc
>& __y
)
907 { return __x
._M_t
== __y
._M_t
; }
910 * @brief Set ordering relation.
912 * @param __y A %set of the same type as @a x.
913 * @return True iff @a __x is lexicographically less than @a __y.
915 * This is a total ordering relation. It is linear in the size of the
916 * sets. The elements must be comparable with @c <.
918 * See std::lexicographical_compare() for how the determination is made.
920 template<typename _Key
, typename _Compare
, typename _Alloc
>
922 operator<(const set
<_Key
, _Compare
, _Alloc
>& __x
,
923 const set
<_Key
, _Compare
, _Alloc
>& __y
)
924 { return __x
._M_t
< __y
._M_t
; }
926 /// Returns !(x == y).
927 template<typename _Key
, typename _Compare
, typename _Alloc
>
929 operator!=(const set
<_Key
, _Compare
, _Alloc
>& __x
,
930 const set
<_Key
, _Compare
, _Alloc
>& __y
)
931 { return !(__x
== __y
); }
934 template<typename _Key
, typename _Compare
, typename _Alloc
>
936 operator>(const set
<_Key
, _Compare
, _Alloc
>& __x
,
937 const set
<_Key
, _Compare
, _Alloc
>& __y
)
938 { return __y
< __x
; }
941 template<typename _Key
, typename _Compare
, typename _Alloc
>
943 operator<=(const set
<_Key
, _Compare
, _Alloc
>& __x
,
944 const set
<_Key
, _Compare
, _Alloc
>& __y
)
945 { return !(__y
< __x
); }
948 template<typename _Key
, typename _Compare
, typename _Alloc
>
950 operator>=(const set
<_Key
, _Compare
, _Alloc
>& __x
,
951 const set
<_Key
, _Compare
, _Alloc
>& __y
)
952 { return !(__x
< __y
); }
954 /// See std::set::swap().
955 template<typename _Key
, typename _Compare
, typename _Alloc
>
957 swap(set
<_Key
, _Compare
, _Alloc
>& __x
, set
<_Key
, _Compare
, _Alloc
>& __y
)
958 _GLIBCXX_NOEXCEPT_IF(noexcept(__x
.swap(__y
)))
961 _GLIBCXX_END_NAMESPACE_CONTAINER
963 #if __cplusplus > 201402L
964 _GLIBCXX_BEGIN_NAMESPACE_VERSION
965 // Allow std::set access to internals of compatible sets.
966 template<typename _Val
, typename _Cmp1
, typename _Alloc
, typename _Cmp2
>
968 _Rb_tree_merge_helper
<_GLIBCXX_STD_C::set
<_Val
, _Cmp1
, _Alloc
>, _Cmp2
>
971 friend class _GLIBCXX_STD_C::set
<_Val
, _Cmp1
, _Alloc
>;
974 _S_get_tree(_GLIBCXX_STD_C::set
<_Val
, _Cmp2
, _Alloc
>& __set
)
975 { return __set
._M_t
; }
978 _S_get_tree(_GLIBCXX_STD_C::multiset
<_Val
, _Cmp2
, _Alloc
>& __set
)
979 { return __set
._M_t
; }
981 _GLIBCXX_END_NAMESPACE_VERSION
985 #endif /* _STL_SET_H */