xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/bits/stl_set.h (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
11debfc3dSmrg // Set implementation -*- C++ -*-
21debfc3dSmrg 
3*8feb0f0bSmrg // Copyright (C) 2001-2020 Free Software Foundation, Inc.
41debfc3dSmrg //
51debfc3dSmrg // This file is part of the GNU ISO C++ Library.  This library is free
61debfc3dSmrg // software; you can redistribute it and/or modify it under the
71debfc3dSmrg // terms of the GNU General Public License as published by the
81debfc3dSmrg // Free Software Foundation; either version 3, or (at your option)
91debfc3dSmrg // any later version.
101debfc3dSmrg 
111debfc3dSmrg // This library is distributed in the hope that it will be useful,
121debfc3dSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
131debfc3dSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141debfc3dSmrg // GNU General Public License for more details.
151debfc3dSmrg 
161debfc3dSmrg // Under Section 7 of GPL version 3, you are granted additional
171debfc3dSmrg // permissions described in the GCC Runtime Library Exception, version
181debfc3dSmrg // 3.1, as published by the Free Software Foundation.
191debfc3dSmrg 
201debfc3dSmrg // You should have received a copy of the GNU General Public License and
211debfc3dSmrg // a copy of the GCC Runtime Library Exception along with this program;
221debfc3dSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
231debfc3dSmrg // <http://www.gnu.org/licenses/>.
241debfc3dSmrg 
251debfc3dSmrg /*
261debfc3dSmrg  *
271debfc3dSmrg  * Copyright (c) 1994
281debfc3dSmrg  * Hewlett-Packard Company
291debfc3dSmrg  *
301debfc3dSmrg  * Permission to use, copy, modify, distribute and sell this software
311debfc3dSmrg  * and its documentation for any purpose is hereby granted without fee,
321debfc3dSmrg  * provided that the above copyright notice appear in all copies and
331debfc3dSmrg  * that both that copyright notice and this permission notice appear
341debfc3dSmrg  * in supporting documentation.  Hewlett-Packard Company makes no
351debfc3dSmrg  * representations about the suitability of this software for any
361debfc3dSmrg  * purpose.  It is provided "as is" without express or implied warranty.
371debfc3dSmrg  *
381debfc3dSmrg  *
391debfc3dSmrg  * Copyright (c) 1996,1997
401debfc3dSmrg  * Silicon Graphics Computer Systems, Inc.
411debfc3dSmrg  *
421debfc3dSmrg  * Permission to use, copy, modify, distribute and sell this software
431debfc3dSmrg  * and its documentation for any purpose is hereby granted without fee,
441debfc3dSmrg  * provided that the above copyright notice appear in all copies and
451debfc3dSmrg  * that both that copyright notice and this permission notice appear
461debfc3dSmrg  * in supporting documentation.  Silicon Graphics makes no
471debfc3dSmrg  * representations about the suitability of this software for any
481debfc3dSmrg  * purpose.  It is provided "as is" without express or implied warranty.
491debfc3dSmrg  */
501debfc3dSmrg 
511debfc3dSmrg /** @file bits/stl_set.h
521debfc3dSmrg  *  This is an internal header file, included by other library headers.
531debfc3dSmrg  *  Do not attempt to use it directly. @headername{set}
541debfc3dSmrg  */
551debfc3dSmrg 
561debfc3dSmrg #ifndef _STL_SET_H
571debfc3dSmrg #define _STL_SET_H 1
581debfc3dSmrg 
591debfc3dSmrg #include <bits/concept_check.h>
601debfc3dSmrg #if __cplusplus >= 201103L
611debfc3dSmrg #include <initializer_list>
621debfc3dSmrg #endif
631debfc3dSmrg 
_GLIBCXX_VISIBILITY(default)641debfc3dSmrg namespace std _GLIBCXX_VISIBILITY(default)
651debfc3dSmrg {
66a2dc1f3fSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
671debfc3dSmrg _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
681debfc3dSmrg 
691debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
701debfc3dSmrg     class multiset;
711debfc3dSmrg 
721debfc3dSmrg   /**
731debfc3dSmrg    *  @brief A standard container made up of unique keys, which can be
741debfc3dSmrg    *  retrieved in logarithmic time.
751debfc3dSmrg    *
761debfc3dSmrg    *  @ingroup associative_containers
771debfc3dSmrg    *
781debfc3dSmrg    *  @tparam _Key  Type of key objects.
791debfc3dSmrg    *  @tparam _Compare  Comparison function object type, defaults to less<_Key>.
801debfc3dSmrg    *  @tparam _Alloc  Allocator type, defaults to allocator<_Key>.
811debfc3dSmrg    *
821debfc3dSmrg    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
831debfc3dSmrg    *  <a href="tables.html#66">reversible container</a>, and an
841debfc3dSmrg    *  <a href="tables.html#69">associative container</a> (using unique keys).
851debfc3dSmrg    *
861debfc3dSmrg    *  Sets support bidirectional iterators.
871debfc3dSmrg    *
881debfc3dSmrg    *  The private tree data is declared exactly the same way for set and
891debfc3dSmrg    *  multiset; the distinction is made entirely in how the tree functions are
901debfc3dSmrg    *  called (*_unique versus *_equal, same as the standard).
911debfc3dSmrg   */
921debfc3dSmrg   template<typename _Key, typename _Compare = std::less<_Key>,
931debfc3dSmrg 	   typename _Alloc = std::allocator<_Key> >
941debfc3dSmrg     class set
951debfc3dSmrg     {
961debfc3dSmrg #ifdef _GLIBCXX_CONCEPT_CHECKS
971debfc3dSmrg       // concept requirements
981debfc3dSmrg       typedef typename _Alloc::value_type		_Alloc_value_type;
991debfc3dSmrg # if __cplusplus < 201103L
1001debfc3dSmrg       __glibcxx_class_requires(_Key, _SGIAssignableConcept)
1011debfc3dSmrg # endif
1021debfc3dSmrg       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
1031debfc3dSmrg 				_BinaryFunctionConcept)
1041debfc3dSmrg       __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
1051debfc3dSmrg #endif
1061debfc3dSmrg 
107a2dc1f3fSmrg #if __cplusplus >= 201103L
108a2dc1f3fSmrg       static_assert(is_same<typename remove_cv<_Key>::type, _Key>::value,
109a2dc1f3fSmrg 	  "std::set must have a non-const, non-volatile value_type");
110*8feb0f0bSmrg # if __cplusplus > 201703L || defined __STRICT_ANSI__
111a2dc1f3fSmrg       static_assert(is_same<typename _Alloc::value_type, _Key>::value,
112a2dc1f3fSmrg 	  "std::set must have the same value_type as its allocator");
113a2dc1f3fSmrg # endif
114a2dc1f3fSmrg #endif
115a2dc1f3fSmrg 
1161debfc3dSmrg     public:
1171debfc3dSmrg       // typedefs:
118*8feb0f0bSmrg       ///@{
1191debfc3dSmrg       /// Public typedefs.
1201debfc3dSmrg       typedef _Key     key_type;
1211debfc3dSmrg       typedef _Key     value_type;
1221debfc3dSmrg       typedef _Compare key_compare;
1231debfc3dSmrg       typedef _Compare value_compare;
1241debfc3dSmrg       typedef _Alloc   allocator_type;
125*8feb0f0bSmrg       ///@}
1261debfc3dSmrg 
1271debfc3dSmrg     private:
1281debfc3dSmrg       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
1291debfc3dSmrg 	rebind<_Key>::other _Key_alloc_type;
1301debfc3dSmrg 
1311debfc3dSmrg       typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
1321debfc3dSmrg 		       key_compare, _Key_alloc_type> _Rep_type;
1331debfc3dSmrg       _Rep_type _M_t;  // Red-black tree representing set.
1341debfc3dSmrg 
1351debfc3dSmrg       typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
1361debfc3dSmrg 
1371debfc3dSmrg     public:
138*8feb0f0bSmrg       ///@{
1391debfc3dSmrg       ///  Iterator-related typedefs.
1401debfc3dSmrg       typedef typename _Alloc_traits::pointer		 pointer;
1411debfc3dSmrg       typedef typename _Alloc_traits::const_pointer	 const_pointer;
1421debfc3dSmrg       typedef typename _Alloc_traits::reference		 reference;
1431debfc3dSmrg       typedef typename _Alloc_traits::const_reference	 const_reference;
1441debfc3dSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
1451debfc3dSmrg       // DR 103. set::iterator is required to be modifiable,
1461debfc3dSmrg       // but this allows modification of keys.
1471debfc3dSmrg       typedef typename _Rep_type::const_iterator	 iterator;
1481debfc3dSmrg       typedef typename _Rep_type::const_iterator	 const_iterator;
1491debfc3dSmrg       typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
1501debfc3dSmrg       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
1511debfc3dSmrg       typedef typename _Rep_type::size_type		 size_type;
1521debfc3dSmrg       typedef typename _Rep_type::difference_type	 difference_type;
153*8feb0f0bSmrg       ///@}
1541debfc3dSmrg 
1551debfc3dSmrg #if __cplusplus > 201402L
1561debfc3dSmrg       using node_type = typename _Rep_type::node_type;
1571debfc3dSmrg       using insert_return_type = typename _Rep_type::insert_return_type;
1581debfc3dSmrg #endif
1591debfc3dSmrg 
1601debfc3dSmrg       // allocation/deallocation
1611debfc3dSmrg       /**
1621debfc3dSmrg        *  @brief  Default constructor creates no elements.
1631debfc3dSmrg        */
1641debfc3dSmrg #if __cplusplus < 201103L
1651debfc3dSmrg       set() : _M_t() { }
1661debfc3dSmrg #else
1671debfc3dSmrg       set() = default;
1681debfc3dSmrg #endif
1691debfc3dSmrg 
1701debfc3dSmrg       /**
1711debfc3dSmrg        *  @brief  Creates a %set with no elements.
1721debfc3dSmrg        *  @param  __comp  Comparator to use.
1731debfc3dSmrg        *  @param  __a  An allocator object.
1741debfc3dSmrg        */
1751debfc3dSmrg       explicit
1761debfc3dSmrg       set(const _Compare& __comp,
1771debfc3dSmrg 	  const allocator_type& __a = allocator_type())
1781debfc3dSmrg       : _M_t(__comp, _Key_alloc_type(__a)) { }
1791debfc3dSmrg 
1801debfc3dSmrg       /**
1811debfc3dSmrg        *  @brief  Builds a %set from a range.
1821debfc3dSmrg        *  @param  __first  An input iterator.
1831debfc3dSmrg        *  @param  __last  An input iterator.
1841debfc3dSmrg        *
1851debfc3dSmrg        *  Create a %set consisting of copies of the elements from
1861debfc3dSmrg        *  [__first,__last).  This is linear in N if the range is
1871debfc3dSmrg        *  already sorted, and NlogN otherwise (where N is
1881debfc3dSmrg        *  distance(__first,__last)).
1891debfc3dSmrg        */
1901debfc3dSmrg       template<typename _InputIterator>
1911debfc3dSmrg 	set(_InputIterator __first, _InputIterator __last)
1921debfc3dSmrg 	: _M_t()
193c0a68be4Smrg 	{ _M_t._M_insert_range_unique(__first, __last); }
1941debfc3dSmrg 
1951debfc3dSmrg       /**
1961debfc3dSmrg        *  @brief  Builds a %set from a range.
1971debfc3dSmrg        *  @param  __first  An input iterator.
1981debfc3dSmrg        *  @param  __last  An input iterator.
1991debfc3dSmrg        *  @param  __comp  A comparison functor.
2001debfc3dSmrg        *  @param  __a  An allocator object.
2011debfc3dSmrg        *
2021debfc3dSmrg        *  Create a %set consisting of copies of the elements from
2031debfc3dSmrg        *  [__first,__last).  This is linear in N if the range is
2041debfc3dSmrg        *  already sorted, and NlogN otherwise (where N is
2051debfc3dSmrg        *  distance(__first,__last)).
2061debfc3dSmrg        */
2071debfc3dSmrg       template<typename _InputIterator>
2081debfc3dSmrg 	set(_InputIterator __first, _InputIterator __last,
2091debfc3dSmrg 	    const _Compare& __comp,
2101debfc3dSmrg 	    const allocator_type& __a = allocator_type())
2111debfc3dSmrg 	: _M_t(__comp, _Key_alloc_type(__a))
212c0a68be4Smrg 	{ _M_t._M_insert_range_unique(__first, __last); }
2131debfc3dSmrg 
2141debfc3dSmrg       /**
2151debfc3dSmrg        *  @brief  %Set copy constructor.
2161debfc3dSmrg        *
2171debfc3dSmrg        *  Whether the allocator is copied depends on the allocator traits.
2181debfc3dSmrg        */
2191debfc3dSmrg #if __cplusplus < 201103L
2201debfc3dSmrg       set(const set& __x)
2211debfc3dSmrg       : _M_t(__x._M_t) { }
2221debfc3dSmrg #else
2231debfc3dSmrg       set(const set&) = default;
2241debfc3dSmrg 
2251debfc3dSmrg      /**
2261debfc3dSmrg        *  @brief %Set move constructor
2271debfc3dSmrg        *
2281debfc3dSmrg        *  The newly-created %set contains the exact contents of the moved
2291debfc3dSmrg        *  instance. The moved instance is a valid, but unspecified, %set.
2301debfc3dSmrg        */
2311debfc3dSmrg       set(set&&) = default;
2321debfc3dSmrg 
2331debfc3dSmrg       /**
2341debfc3dSmrg        *  @brief  Builds a %set from an initializer_list.
2351debfc3dSmrg        *  @param  __l  An initializer_list.
2361debfc3dSmrg        *  @param  __comp  A comparison functor.
2371debfc3dSmrg        *  @param  __a  An allocator object.
2381debfc3dSmrg        *
2391debfc3dSmrg        *  Create a %set consisting of copies of the elements in the list.
2401debfc3dSmrg        *  This is linear in N if the list is already sorted, and NlogN
2411debfc3dSmrg        *  otherwise (where N is @a __l.size()).
2421debfc3dSmrg        */
2431debfc3dSmrg       set(initializer_list<value_type> __l,
2441debfc3dSmrg 	  const _Compare& __comp = _Compare(),
2451debfc3dSmrg 	  const allocator_type& __a = allocator_type())
2461debfc3dSmrg       : _M_t(__comp, _Key_alloc_type(__a))
247c0a68be4Smrg       { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
2481debfc3dSmrg 
2491debfc3dSmrg       /// Allocator-extended default constructor.
2501debfc3dSmrg       explicit
2511debfc3dSmrg       set(const allocator_type& __a)
252c0a68be4Smrg       : _M_t(_Key_alloc_type(__a)) { }
2531debfc3dSmrg 
2541debfc3dSmrg       /// Allocator-extended copy constructor.
2551debfc3dSmrg       set(const set& __x, const allocator_type& __a)
2561debfc3dSmrg       : _M_t(__x._M_t, _Key_alloc_type(__a)) { }
2571debfc3dSmrg 
2581debfc3dSmrg       /// Allocator-extended move constructor.
2591debfc3dSmrg       set(set&& __x, const allocator_type& __a)
2601debfc3dSmrg       noexcept(is_nothrow_copy_constructible<_Compare>::value
2611debfc3dSmrg 	       && _Alloc_traits::_S_always_equal())
2621debfc3dSmrg       : _M_t(std::move(__x._M_t), _Key_alloc_type(__a)) { }
2631debfc3dSmrg 
2641debfc3dSmrg       /// Allocator-extended initialier-list constructor.
2651debfc3dSmrg       set(initializer_list<value_type> __l, const allocator_type& __a)
266c0a68be4Smrg       : _M_t(_Key_alloc_type(__a))
267c0a68be4Smrg       { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
2681debfc3dSmrg 
2691debfc3dSmrg       /// Allocator-extended range constructor.
2701debfc3dSmrg       template<typename _InputIterator>
2711debfc3dSmrg 	set(_InputIterator __first, _InputIterator __last,
2721debfc3dSmrg 	    const allocator_type& __a)
273c0a68be4Smrg 	: _M_t(_Key_alloc_type(__a))
274c0a68be4Smrg 	{ _M_t._M_insert_range_unique(__first, __last); }
2751debfc3dSmrg 
2761debfc3dSmrg       /**
2771debfc3dSmrg        *  The dtor only erases the elements, and note that if the elements
2781debfc3dSmrg        *  themselves are pointers, the pointed-to memory is not touched in any
2791debfc3dSmrg        *  way. Managing the pointer is the user's responsibility.
2801debfc3dSmrg        */
2811debfc3dSmrg       ~set() = default;
2821debfc3dSmrg #endif
2831debfc3dSmrg 
2841debfc3dSmrg       /**
2851debfc3dSmrg        *  @brief  %Set assignment operator.
2861debfc3dSmrg        *
2871debfc3dSmrg        *  Whether the allocator is copied depends on the allocator traits.
2881debfc3dSmrg        */
2891debfc3dSmrg #if __cplusplus < 201103L
2901debfc3dSmrg       set&
2911debfc3dSmrg       operator=(const set& __x)
2921debfc3dSmrg       {
2931debfc3dSmrg 	_M_t = __x._M_t;
2941debfc3dSmrg 	return *this;
2951debfc3dSmrg       }
2961debfc3dSmrg #else
2971debfc3dSmrg       set&
2981debfc3dSmrg       operator=(const set&) = default;
2991debfc3dSmrg 
3001debfc3dSmrg       /// Move assignment operator.
3011debfc3dSmrg       set&
3021debfc3dSmrg       operator=(set&&) = default;
3031debfc3dSmrg 
3041debfc3dSmrg       /**
3051debfc3dSmrg        *  @brief  %Set list assignment operator.
3061debfc3dSmrg        *  @param  __l  An initializer_list.
3071debfc3dSmrg        *
3081debfc3dSmrg        *  This function fills a %set with copies of the elements in the
3091debfc3dSmrg        *  initializer list @a __l.
3101debfc3dSmrg        *
3111debfc3dSmrg        *  Note that the assignment completely changes the %set and
3121debfc3dSmrg        *  that the resulting %set's size is the same as the number
3131debfc3dSmrg        *  of elements assigned.
3141debfc3dSmrg        */
3151debfc3dSmrg       set&
3161debfc3dSmrg       operator=(initializer_list<value_type> __l)
3171debfc3dSmrg       {
3181debfc3dSmrg 	_M_t._M_assign_unique(__l.begin(), __l.end());
3191debfc3dSmrg 	return *this;
3201debfc3dSmrg       }
3211debfc3dSmrg #endif
3221debfc3dSmrg 
3231debfc3dSmrg       // accessors:
3241debfc3dSmrg 
3251debfc3dSmrg       ///  Returns the comparison object with which the %set was constructed.
3261debfc3dSmrg       key_compare
3271debfc3dSmrg       key_comp() const
3281debfc3dSmrg       { return _M_t.key_comp(); }
3291debfc3dSmrg       ///  Returns the comparison object with which the %set was constructed.
3301debfc3dSmrg       value_compare
3311debfc3dSmrg       value_comp() const
3321debfc3dSmrg       { return _M_t.key_comp(); }
3331debfc3dSmrg       ///  Returns the allocator object with which the %set was constructed.
3341debfc3dSmrg       allocator_type
3351debfc3dSmrg       get_allocator() const _GLIBCXX_NOEXCEPT
3361debfc3dSmrg       { return allocator_type(_M_t.get_allocator()); }
3371debfc3dSmrg 
3381debfc3dSmrg       /**
3391debfc3dSmrg        *  Returns a read-only (constant) iterator that points to the first
3401debfc3dSmrg        *  element in the %set.  Iteration is done in ascending order according
3411debfc3dSmrg        *  to the keys.
3421debfc3dSmrg        */
3431debfc3dSmrg       iterator
3441debfc3dSmrg       begin() const _GLIBCXX_NOEXCEPT
3451debfc3dSmrg       { return _M_t.begin(); }
3461debfc3dSmrg 
3471debfc3dSmrg       /**
3481debfc3dSmrg        *  Returns a read-only (constant) iterator that points one past the last
3491debfc3dSmrg        *  element in the %set.  Iteration is done in ascending order according
3501debfc3dSmrg        *  to the keys.
3511debfc3dSmrg        */
3521debfc3dSmrg       iterator
3531debfc3dSmrg       end() const _GLIBCXX_NOEXCEPT
3541debfc3dSmrg       { return _M_t.end(); }
3551debfc3dSmrg 
3561debfc3dSmrg       /**
3571debfc3dSmrg        *  Returns a read-only (constant) iterator that points to the last
3581debfc3dSmrg        *  element in the %set.  Iteration is done in descending order according
3591debfc3dSmrg        *  to the keys.
3601debfc3dSmrg        */
3611debfc3dSmrg       reverse_iterator
3621debfc3dSmrg       rbegin() const _GLIBCXX_NOEXCEPT
3631debfc3dSmrg       { return _M_t.rbegin(); }
3641debfc3dSmrg 
3651debfc3dSmrg       /**
3661debfc3dSmrg        *  Returns a read-only (constant) reverse iterator that points to the
3671debfc3dSmrg        *  last pair in the %set.  Iteration is done in descending order
3681debfc3dSmrg        *  according to the keys.
3691debfc3dSmrg        */
3701debfc3dSmrg       reverse_iterator
3711debfc3dSmrg       rend() const _GLIBCXX_NOEXCEPT
3721debfc3dSmrg       { return _M_t.rend(); }
3731debfc3dSmrg 
3741debfc3dSmrg #if __cplusplus >= 201103L
3751debfc3dSmrg       /**
3761debfc3dSmrg        *  Returns a read-only (constant) iterator that points to the first
3771debfc3dSmrg        *  element in the %set.  Iteration is done in ascending order according
3781debfc3dSmrg        *  to the keys.
3791debfc3dSmrg        */
3801debfc3dSmrg       iterator
3811debfc3dSmrg       cbegin() const noexcept
3821debfc3dSmrg       { return _M_t.begin(); }
3831debfc3dSmrg 
3841debfc3dSmrg       /**
3851debfc3dSmrg        *  Returns a read-only (constant) iterator that points one past the last
3861debfc3dSmrg        *  element in the %set.  Iteration is done in ascending order according
3871debfc3dSmrg        *  to the keys.
3881debfc3dSmrg        */
3891debfc3dSmrg       iterator
3901debfc3dSmrg       cend() const noexcept
3911debfc3dSmrg       { return _M_t.end(); }
3921debfc3dSmrg 
3931debfc3dSmrg       /**
3941debfc3dSmrg        *  Returns a read-only (constant) iterator that points to the last
3951debfc3dSmrg        *  element in the %set.  Iteration is done in descending order according
3961debfc3dSmrg        *  to the keys.
3971debfc3dSmrg        */
3981debfc3dSmrg       reverse_iterator
3991debfc3dSmrg       crbegin() const noexcept
4001debfc3dSmrg       { return _M_t.rbegin(); }
4011debfc3dSmrg 
4021debfc3dSmrg       /**
4031debfc3dSmrg        *  Returns a read-only (constant) reverse iterator that points to the
4041debfc3dSmrg        *  last pair in the %set.  Iteration is done in descending order
4051debfc3dSmrg        *  according to the keys.
4061debfc3dSmrg        */
4071debfc3dSmrg       reverse_iterator
4081debfc3dSmrg       crend() const noexcept
4091debfc3dSmrg       { return _M_t.rend(); }
4101debfc3dSmrg #endif
4111debfc3dSmrg 
4121debfc3dSmrg       ///  Returns true if the %set is empty.
413c0a68be4Smrg       _GLIBCXX_NODISCARD bool
4141debfc3dSmrg       empty() const _GLIBCXX_NOEXCEPT
4151debfc3dSmrg       { return _M_t.empty(); }
4161debfc3dSmrg 
4171debfc3dSmrg       ///  Returns the size of the %set.
4181debfc3dSmrg       size_type
4191debfc3dSmrg       size() const _GLIBCXX_NOEXCEPT
4201debfc3dSmrg       { return _M_t.size(); }
4211debfc3dSmrg 
4221debfc3dSmrg       ///  Returns the maximum size of the %set.
4231debfc3dSmrg       size_type
4241debfc3dSmrg       max_size() const _GLIBCXX_NOEXCEPT
4251debfc3dSmrg       { return _M_t.max_size(); }
4261debfc3dSmrg 
4271debfc3dSmrg       /**
4281debfc3dSmrg        *  @brief  Swaps data with another %set.
4291debfc3dSmrg        *  @param  __x  A %set of the same element and allocator types.
4301debfc3dSmrg        *
4311debfc3dSmrg        *  This exchanges the elements between two sets in constant
4321debfc3dSmrg        *  time.  (It is only swapping a pointer, an integer, and an
4331debfc3dSmrg        *  instance of the @c Compare type (which itself is often
4341debfc3dSmrg        *  stateless and empty), so it should be quite fast.)  Note
4351debfc3dSmrg        *  that the global std::swap() function is specialized such
4361debfc3dSmrg        *  that std::swap(s1,s2) will feed to this function.
4371debfc3dSmrg        *
4381debfc3dSmrg        *  Whether the allocators are swapped depends on the allocator traits.
4391debfc3dSmrg        */
4401debfc3dSmrg       void
4411debfc3dSmrg       swap(set& __x)
4421debfc3dSmrg       _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
4431debfc3dSmrg       { _M_t.swap(__x._M_t); }
4441debfc3dSmrg 
4451debfc3dSmrg       // insert/erase
4461debfc3dSmrg #if __cplusplus >= 201103L
4471debfc3dSmrg       /**
4481debfc3dSmrg        *  @brief Attempts to build and insert an element into the %set.
4491debfc3dSmrg        *  @param __args  Arguments used to generate an element.
4501debfc3dSmrg        *  @return  A pair, of which the first element is an iterator that points
4511debfc3dSmrg        *           to the possibly inserted element, and the second is a bool
4521debfc3dSmrg        *           that is true if the element was actually inserted.
4531debfc3dSmrg        *
4541debfc3dSmrg        *  This function attempts to build and insert an element into the %set.
4551debfc3dSmrg        *  A %set relies on unique keys and thus an element is only inserted if
4561debfc3dSmrg        *  it is not already present in the %set.
4571debfc3dSmrg        *
4581debfc3dSmrg        *  Insertion requires logarithmic time.
4591debfc3dSmrg        */
4601debfc3dSmrg       template<typename... _Args>
4611debfc3dSmrg 	std::pair<iterator, bool>
4621debfc3dSmrg 	emplace(_Args&&... __args)
4631debfc3dSmrg 	{ return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
4641debfc3dSmrg 
4651debfc3dSmrg       /**
4661debfc3dSmrg        *  @brief Attempts to insert an element into the %set.
4671debfc3dSmrg        *  @param  __pos  An iterator that serves as a hint as to where the
4681debfc3dSmrg        *                element should be inserted.
4691debfc3dSmrg        *  @param  __args  Arguments used to generate the element to be
4701debfc3dSmrg        *                 inserted.
4711debfc3dSmrg        *  @return An iterator that points to the element with key equivalent to
4721debfc3dSmrg        *          the one generated from @a __args (may or may not be the
4731debfc3dSmrg        *          element itself).
4741debfc3dSmrg        *
4751debfc3dSmrg        *  This function is not concerned about whether the insertion took place,
4761debfc3dSmrg        *  and thus does not return a boolean like the single-argument emplace()
4771debfc3dSmrg        *  does.  Note that the first parameter is only a hint and can
4781debfc3dSmrg        *  potentially improve the performance of the insertion process.  A bad
4791debfc3dSmrg        *  hint would cause no gains in efficiency.
4801debfc3dSmrg        *
4811debfc3dSmrg        *  For more on @a hinting, see:
4821debfc3dSmrg        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
4831debfc3dSmrg        *
4841debfc3dSmrg        *  Insertion requires logarithmic time (if the hint is not taken).
4851debfc3dSmrg        */
4861debfc3dSmrg       template<typename... _Args>
4871debfc3dSmrg 	iterator
4881debfc3dSmrg 	emplace_hint(const_iterator __pos, _Args&&... __args)
4891debfc3dSmrg 	{
4901debfc3dSmrg 	  return _M_t._M_emplace_hint_unique(__pos,
4911debfc3dSmrg 					     std::forward<_Args>(__args)...);
4921debfc3dSmrg 	}
4931debfc3dSmrg #endif
4941debfc3dSmrg 
4951debfc3dSmrg       /**
4961debfc3dSmrg        *  @brief Attempts to insert an element into the %set.
4971debfc3dSmrg        *  @param  __x  Element to be inserted.
4981debfc3dSmrg        *  @return  A pair, of which the first element is an iterator that points
4991debfc3dSmrg        *           to the possibly inserted element, and the second is a bool
5001debfc3dSmrg        *           that is true if the element was actually inserted.
5011debfc3dSmrg        *
5021debfc3dSmrg        *  This function attempts to insert an element into the %set.  A %set
5031debfc3dSmrg        *  relies on unique keys and thus an element is only inserted if it is
5041debfc3dSmrg        *  not already present in the %set.
5051debfc3dSmrg        *
5061debfc3dSmrg        *  Insertion requires logarithmic time.
5071debfc3dSmrg        */
5081debfc3dSmrg       std::pair<iterator, bool>
5091debfc3dSmrg       insert(const value_type& __x)
5101debfc3dSmrg       {
5111debfc3dSmrg 	std::pair<typename _Rep_type::iterator, bool> __p =
5121debfc3dSmrg 	  _M_t._M_insert_unique(__x);
5131debfc3dSmrg 	return std::pair<iterator, bool>(__p.first, __p.second);
5141debfc3dSmrg       }
5151debfc3dSmrg 
5161debfc3dSmrg #if __cplusplus >= 201103L
5171debfc3dSmrg       std::pair<iterator, bool>
5181debfc3dSmrg       insert(value_type&& __x)
5191debfc3dSmrg       {
5201debfc3dSmrg 	std::pair<typename _Rep_type::iterator, bool> __p =
5211debfc3dSmrg 	  _M_t._M_insert_unique(std::move(__x));
5221debfc3dSmrg 	return std::pair<iterator, bool>(__p.first, __p.second);
5231debfc3dSmrg       }
5241debfc3dSmrg #endif
5251debfc3dSmrg 
5261debfc3dSmrg       /**
5271debfc3dSmrg        *  @brief Attempts to insert an element into the %set.
5281debfc3dSmrg        *  @param  __position  An iterator that serves as a hint as to where the
5291debfc3dSmrg        *                    element should be inserted.
5301debfc3dSmrg        *  @param  __x  Element to be inserted.
5311debfc3dSmrg        *  @return An iterator that points to the element with key of
5321debfc3dSmrg        *           @a __x (may or may not be the element passed in).
5331debfc3dSmrg        *
5341debfc3dSmrg        *  This function is not concerned about whether the insertion took place,
5351debfc3dSmrg        *  and thus does not return a boolean like the single-argument insert()
5361debfc3dSmrg        *  does.  Note that the first parameter is only a hint and can
5371debfc3dSmrg        *  potentially improve the performance of the insertion process.  A bad
5381debfc3dSmrg        *  hint would cause no gains in efficiency.
5391debfc3dSmrg        *
5401debfc3dSmrg        *  For more on @a hinting, see:
5411debfc3dSmrg        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
5421debfc3dSmrg        *
5431debfc3dSmrg        *  Insertion requires logarithmic time (if the hint is not taken).
5441debfc3dSmrg        */
5451debfc3dSmrg       iterator
5461debfc3dSmrg       insert(const_iterator __position, const value_type& __x)
5471debfc3dSmrg       { return _M_t._M_insert_unique_(__position, __x); }
5481debfc3dSmrg 
5491debfc3dSmrg #if __cplusplus >= 201103L
5501debfc3dSmrg       iterator
5511debfc3dSmrg       insert(const_iterator __position, value_type&& __x)
5521debfc3dSmrg       { return _M_t._M_insert_unique_(__position, std::move(__x)); }
5531debfc3dSmrg #endif
5541debfc3dSmrg 
5551debfc3dSmrg       /**
5561debfc3dSmrg        *  @brief A template function that attempts to insert a range
5571debfc3dSmrg        *  of elements.
5581debfc3dSmrg        *  @param  __first  Iterator pointing to the start of the range to be
5591debfc3dSmrg        *                   inserted.
5601debfc3dSmrg        *  @param  __last  Iterator pointing to the end of the range.
5611debfc3dSmrg        *
5621debfc3dSmrg        *  Complexity similar to that of the range constructor.
5631debfc3dSmrg        */
5641debfc3dSmrg       template<typename _InputIterator>
5651debfc3dSmrg 	void
5661debfc3dSmrg 	insert(_InputIterator __first, _InputIterator __last)
567c0a68be4Smrg 	{ _M_t._M_insert_range_unique(__first, __last); }
5681debfc3dSmrg 
5691debfc3dSmrg #if __cplusplus >= 201103L
5701debfc3dSmrg       /**
5711debfc3dSmrg        *  @brief Attempts to insert a list of elements into the %set.
5721debfc3dSmrg        *  @param  __l  A std::initializer_list<value_type> of elements
5731debfc3dSmrg        *               to be inserted.
5741debfc3dSmrg        *
5751debfc3dSmrg        *  Complexity similar to that of the range constructor.
5761debfc3dSmrg        */
5771debfc3dSmrg       void
5781debfc3dSmrg       insert(initializer_list<value_type> __l)
5791debfc3dSmrg       { this->insert(__l.begin(), __l.end()); }
5801debfc3dSmrg #endif
5811debfc3dSmrg 
5821debfc3dSmrg #if __cplusplus > 201402L
5831debfc3dSmrg       /// Extract a node.
5841debfc3dSmrg       node_type
5851debfc3dSmrg       extract(const_iterator __pos)
5861debfc3dSmrg       {
5871debfc3dSmrg 	__glibcxx_assert(__pos != end());
5881debfc3dSmrg 	return _M_t.extract(__pos);
5891debfc3dSmrg       }
5901debfc3dSmrg 
5911debfc3dSmrg       /// Extract a node.
5921debfc3dSmrg       node_type
5931debfc3dSmrg       extract(const key_type& __x)
5941debfc3dSmrg       { return _M_t.extract(__x); }
5951debfc3dSmrg 
5961debfc3dSmrg       /// Re-insert an extracted node.
5971debfc3dSmrg       insert_return_type
5981debfc3dSmrg       insert(node_type&& __nh)
5991debfc3dSmrg       { return _M_t._M_reinsert_node_unique(std::move(__nh)); }
6001debfc3dSmrg 
6011debfc3dSmrg       /// Re-insert an extracted node.
6021debfc3dSmrg       iterator
6031debfc3dSmrg       insert(const_iterator __hint, node_type&& __nh)
6041debfc3dSmrg       { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
6051debfc3dSmrg 
6061debfc3dSmrg       template<typename, typename>
607a2dc1f3fSmrg 	friend class std::_Rb_tree_merge_helper;
6081debfc3dSmrg 
6091debfc3dSmrg       template<typename _Compare1>
6101debfc3dSmrg 	void
6111debfc3dSmrg 	merge(set<_Key, _Compare1, _Alloc>& __source)
6121debfc3dSmrg 	{
6131debfc3dSmrg 	  using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
6141debfc3dSmrg 	  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
6151debfc3dSmrg 	}
6161debfc3dSmrg 
6171debfc3dSmrg       template<typename _Compare1>
6181debfc3dSmrg 	void
6191debfc3dSmrg 	merge(set<_Key, _Compare1, _Alloc>&& __source)
6201debfc3dSmrg 	{ merge(__source); }
6211debfc3dSmrg 
6221debfc3dSmrg       template<typename _Compare1>
6231debfc3dSmrg 	void
6241debfc3dSmrg 	merge(multiset<_Key, _Compare1, _Alloc>& __source)
6251debfc3dSmrg 	{
6261debfc3dSmrg 	  using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
6271debfc3dSmrg 	  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
6281debfc3dSmrg 	}
6291debfc3dSmrg 
6301debfc3dSmrg       template<typename _Compare1>
6311debfc3dSmrg 	void
6321debfc3dSmrg 	merge(multiset<_Key, _Compare1, _Alloc>&& __source)
6331debfc3dSmrg 	{ merge(__source); }
6341debfc3dSmrg #endif // C++17
6351debfc3dSmrg 
6361debfc3dSmrg #if __cplusplus >= 201103L
6371debfc3dSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
6381debfc3dSmrg       // DR 130. Associative erase should return an iterator.
6391debfc3dSmrg       /**
6401debfc3dSmrg        *  @brief Erases an element from a %set.
6411debfc3dSmrg        *  @param  __position  An iterator pointing to the element to be erased.
6421debfc3dSmrg        *  @return An iterator pointing to the element immediately following
6431debfc3dSmrg        *          @a __position prior to the element being erased. If no such
6441debfc3dSmrg        *          element exists, end() is returned.
6451debfc3dSmrg        *
6461debfc3dSmrg        *  This function erases an element, pointed to by the given iterator,
6471debfc3dSmrg        *  from a %set.  Note that this function only erases the element, and
6481debfc3dSmrg        *  that if the element is itself a pointer, the pointed-to memory is not
6491debfc3dSmrg        *  touched in any way.  Managing the pointer is the user's
6501debfc3dSmrg        *  responsibility.
6511debfc3dSmrg        */
6521debfc3dSmrg       _GLIBCXX_ABI_TAG_CXX11
6531debfc3dSmrg       iterator
6541debfc3dSmrg       erase(const_iterator __position)
6551debfc3dSmrg       { return _M_t.erase(__position); }
6561debfc3dSmrg #else
6571debfc3dSmrg       /**
6581debfc3dSmrg        *  @brief Erases an element from a %set.
6591debfc3dSmrg        *  @param  position  An iterator pointing to the element to be erased.
6601debfc3dSmrg        *
6611debfc3dSmrg        *  This function erases an element, pointed to by the given iterator,
6621debfc3dSmrg        *  from a %set.  Note that this function only erases the element, and
6631debfc3dSmrg        *  that if the element is itself a pointer, the pointed-to memory is not
6641debfc3dSmrg        *  touched in any way.  Managing the pointer is the user's
6651debfc3dSmrg        *  responsibility.
6661debfc3dSmrg        */
6671debfc3dSmrg       void
6681debfc3dSmrg       erase(iterator __position)
6691debfc3dSmrg       { _M_t.erase(__position); }
6701debfc3dSmrg #endif
6711debfc3dSmrg 
6721debfc3dSmrg       /**
6731debfc3dSmrg        *  @brief Erases elements according to the provided key.
6741debfc3dSmrg        *  @param  __x  Key of element to be erased.
6751debfc3dSmrg        *  @return  The number of elements erased.
6761debfc3dSmrg        *
6771debfc3dSmrg        *  This function erases all the elements located by the given key from
6781debfc3dSmrg        *  a %set.
6791debfc3dSmrg        *  Note that this function only erases the element, and that if
6801debfc3dSmrg        *  the element is itself a pointer, the pointed-to memory is not touched
6811debfc3dSmrg        *  in any way.  Managing the pointer is the user's responsibility.
6821debfc3dSmrg        */
6831debfc3dSmrg       size_type
6841debfc3dSmrg       erase(const key_type& __x)
6851debfc3dSmrg       { return _M_t.erase(__x); }
6861debfc3dSmrg 
6871debfc3dSmrg #if __cplusplus >= 201103L
6881debfc3dSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
6891debfc3dSmrg       // DR 130. Associative erase should return an iterator.
6901debfc3dSmrg       /**
6911debfc3dSmrg        *  @brief Erases a [__first,__last) range of elements from a %set.
6921debfc3dSmrg        *  @param  __first  Iterator pointing to the start of the range to be
6931debfc3dSmrg        *                 erased.
6941debfc3dSmrg 
6951debfc3dSmrg        *  @param __last Iterator pointing to the end of the range to
6961debfc3dSmrg        *  be erased.
6971debfc3dSmrg        *  @return The iterator @a __last.
6981debfc3dSmrg        *
6991debfc3dSmrg        *  This function erases a sequence of elements from a %set.
7001debfc3dSmrg        *  Note that this function only erases the element, and that if
7011debfc3dSmrg        *  the element is itself a pointer, the pointed-to memory is not touched
7021debfc3dSmrg        *  in any way.  Managing the pointer is the user's responsibility.
7031debfc3dSmrg        */
7041debfc3dSmrg       _GLIBCXX_ABI_TAG_CXX11
7051debfc3dSmrg       iterator
7061debfc3dSmrg       erase(const_iterator __first, const_iterator __last)
7071debfc3dSmrg       { return _M_t.erase(__first, __last); }
7081debfc3dSmrg #else
7091debfc3dSmrg       /**
7101debfc3dSmrg        *  @brief Erases a [first,last) range of elements from a %set.
7111debfc3dSmrg        *  @param  __first  Iterator pointing to the start of the range to be
7121debfc3dSmrg        *                 erased.
7131debfc3dSmrg        *  @param __last Iterator pointing to the end of the range to
7141debfc3dSmrg        *  be erased.
7151debfc3dSmrg        *
7161debfc3dSmrg        *  This function erases a sequence of elements from a %set.
7171debfc3dSmrg        *  Note that this function only erases the element, and that if
7181debfc3dSmrg        *  the element is itself a pointer, the pointed-to memory is not touched
7191debfc3dSmrg        *  in any way.  Managing the pointer is the user's responsibility.
7201debfc3dSmrg        */
7211debfc3dSmrg       void
7221debfc3dSmrg       erase(iterator __first, iterator __last)
7231debfc3dSmrg       { _M_t.erase(__first, __last); }
7241debfc3dSmrg #endif
7251debfc3dSmrg 
7261debfc3dSmrg       /**
7271debfc3dSmrg        *  Erases all elements in a %set.  Note that this function only erases
7281debfc3dSmrg        *  the elements, and that if the elements themselves are pointers, the
7291debfc3dSmrg        *  pointed-to memory is not touched in any way.  Managing the pointer is
7301debfc3dSmrg        *  the user's responsibility.
7311debfc3dSmrg        */
7321debfc3dSmrg       void
7331debfc3dSmrg       clear() _GLIBCXX_NOEXCEPT
7341debfc3dSmrg       { _M_t.clear(); }
7351debfc3dSmrg 
7361debfc3dSmrg       // set operations:
7371debfc3dSmrg 
738*8feb0f0bSmrg       ///@{
7391debfc3dSmrg       /**
7401debfc3dSmrg        *  @brief  Finds the number of elements.
7411debfc3dSmrg        *  @param  __x  Element to located.
7421debfc3dSmrg        *  @return  Number of elements with specified key.
7431debfc3dSmrg        *
7441debfc3dSmrg        *  This function only makes sense for multisets; for set the result will
7451debfc3dSmrg        *  either be 0 (not present) or 1 (present).
7461debfc3dSmrg        */
7471debfc3dSmrg       size_type
7481debfc3dSmrg       count(const key_type& __x) const
7491debfc3dSmrg       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
7501debfc3dSmrg 
7511debfc3dSmrg #if __cplusplus > 201103L
7521debfc3dSmrg       template<typename _Kt>
7531debfc3dSmrg 	auto
7541debfc3dSmrg 	count(const _Kt& __x) const
7551debfc3dSmrg 	-> decltype(_M_t._M_count_tr(__x))
7561debfc3dSmrg 	{ return _M_t._M_count_tr(__x); }
7571debfc3dSmrg #endif
758*8feb0f0bSmrg       ///@}
7591debfc3dSmrg 
760c0a68be4Smrg #if __cplusplus > 201703L
761*8feb0f0bSmrg       ///@{
762c0a68be4Smrg       /**
763c0a68be4Smrg        *  @brief  Finds whether an element with the given key exists.
764c0a68be4Smrg        *  @param  __x  Key of elements to be located.
765c0a68be4Smrg        *  @return  True if there is an element with the specified key.
766c0a68be4Smrg        */
767c0a68be4Smrg       bool
768c0a68be4Smrg       contains(const key_type& __x) const
769c0a68be4Smrg       { return _M_t.find(__x) != _M_t.end(); }
770c0a68be4Smrg 
771c0a68be4Smrg       template<typename _Kt>
772c0a68be4Smrg 	auto
773c0a68be4Smrg 	contains(const _Kt& __x) const
774c0a68be4Smrg 	-> decltype(_M_t._M_find_tr(__x), void(), true)
775c0a68be4Smrg 	{ return _M_t._M_find_tr(__x) != _M_t.end(); }
776*8feb0f0bSmrg       ///@}
777c0a68be4Smrg #endif
778c0a68be4Smrg 
7791debfc3dSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
7801debfc3dSmrg       // 214.  set::find() missing const overload
781*8feb0f0bSmrg       ///@{
7821debfc3dSmrg       /**
7831debfc3dSmrg        *  @brief Tries to locate an element in a %set.
7841debfc3dSmrg        *  @param  __x  Element to be located.
7851debfc3dSmrg        *  @return  Iterator pointing to sought-after element, or end() if not
7861debfc3dSmrg        *           found.
7871debfc3dSmrg        *
7881debfc3dSmrg        *  This function takes a key and tries to locate the element with which
7891debfc3dSmrg        *  the key matches.  If successful the function returns an iterator
7901debfc3dSmrg        *  pointing to the sought after element.  If unsuccessful it returns the
7911debfc3dSmrg        *  past-the-end ( @c end() ) iterator.
7921debfc3dSmrg        */
7931debfc3dSmrg       iterator
7941debfc3dSmrg       find(const key_type& __x)
7951debfc3dSmrg       { return _M_t.find(__x); }
7961debfc3dSmrg 
7971debfc3dSmrg       const_iterator
7981debfc3dSmrg       find(const key_type& __x) const
7991debfc3dSmrg       { return _M_t.find(__x); }
8001debfc3dSmrg 
8011debfc3dSmrg #if __cplusplus > 201103L
8021debfc3dSmrg       template<typename _Kt>
8031debfc3dSmrg 	auto
8041debfc3dSmrg 	find(const _Kt& __x)
8051debfc3dSmrg 	-> decltype(iterator{_M_t._M_find_tr(__x)})
8061debfc3dSmrg 	{ return iterator{_M_t._M_find_tr(__x)}; }
8071debfc3dSmrg 
8081debfc3dSmrg       template<typename _Kt>
8091debfc3dSmrg 	auto
8101debfc3dSmrg 	find(const _Kt& __x) const
8111debfc3dSmrg 	-> decltype(const_iterator{_M_t._M_find_tr(__x)})
8121debfc3dSmrg 	{ return const_iterator{_M_t._M_find_tr(__x)}; }
8131debfc3dSmrg #endif
814*8feb0f0bSmrg       ///@}
8151debfc3dSmrg 
816*8feb0f0bSmrg       ///@{
8171debfc3dSmrg       /**
8181debfc3dSmrg        *  @brief Finds the beginning of a subsequence matching given key.
8191debfc3dSmrg        *  @param  __x  Key to be located.
8201debfc3dSmrg        *  @return  Iterator pointing to first element equal to or greater
8211debfc3dSmrg        *           than key, or end().
8221debfc3dSmrg        *
8231debfc3dSmrg        *  This function returns the first element of a subsequence of elements
8241debfc3dSmrg        *  that matches the given key.  If unsuccessful it returns an iterator
8251debfc3dSmrg        *  pointing to the first element that has a greater value than given key
8261debfc3dSmrg        *  or end() if no such element exists.
8271debfc3dSmrg        */
8281debfc3dSmrg       iterator
8291debfc3dSmrg       lower_bound(const key_type& __x)
8301debfc3dSmrg       { return _M_t.lower_bound(__x); }
8311debfc3dSmrg 
8321debfc3dSmrg       const_iterator
8331debfc3dSmrg       lower_bound(const key_type& __x) const
8341debfc3dSmrg       { return _M_t.lower_bound(__x); }
8351debfc3dSmrg 
8361debfc3dSmrg #if __cplusplus > 201103L
8371debfc3dSmrg       template<typename _Kt>
8381debfc3dSmrg 	auto
8391debfc3dSmrg 	lower_bound(const _Kt& __x)
8401debfc3dSmrg 	-> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
8411debfc3dSmrg 	{ return iterator(_M_t._M_lower_bound_tr(__x)); }
8421debfc3dSmrg 
8431debfc3dSmrg       template<typename _Kt>
8441debfc3dSmrg 	auto
8451debfc3dSmrg 	lower_bound(const _Kt& __x) const
8461debfc3dSmrg 	-> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
8471debfc3dSmrg 	{ return const_iterator(_M_t._M_lower_bound_tr(__x)); }
8481debfc3dSmrg #endif
849*8feb0f0bSmrg       ///@}
8501debfc3dSmrg 
851*8feb0f0bSmrg       ///@{
8521debfc3dSmrg       /**
8531debfc3dSmrg        *  @brief Finds the end of a subsequence matching given key.
8541debfc3dSmrg        *  @param  __x  Key to be located.
8551debfc3dSmrg        *  @return Iterator pointing to the first element
8561debfc3dSmrg        *          greater than key, or end().
8571debfc3dSmrg        */
8581debfc3dSmrg       iterator
8591debfc3dSmrg       upper_bound(const key_type& __x)
8601debfc3dSmrg       { return _M_t.upper_bound(__x); }
8611debfc3dSmrg 
8621debfc3dSmrg       const_iterator
8631debfc3dSmrg       upper_bound(const key_type& __x) const
8641debfc3dSmrg       { return _M_t.upper_bound(__x); }
8651debfc3dSmrg 
8661debfc3dSmrg #if __cplusplus > 201103L
8671debfc3dSmrg       template<typename _Kt>
8681debfc3dSmrg 	auto
8691debfc3dSmrg 	upper_bound(const _Kt& __x)
8701debfc3dSmrg 	-> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
8711debfc3dSmrg 	{ return iterator(_M_t._M_upper_bound_tr(__x)); }
8721debfc3dSmrg 
8731debfc3dSmrg       template<typename _Kt>
8741debfc3dSmrg 	auto
8751debfc3dSmrg 	upper_bound(const _Kt& __x) const
8761debfc3dSmrg 	-> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
8771debfc3dSmrg 	{ return const_iterator(_M_t._M_upper_bound_tr(__x)); }
8781debfc3dSmrg #endif
879*8feb0f0bSmrg       ///@}
8801debfc3dSmrg 
881*8feb0f0bSmrg       ///@{
8821debfc3dSmrg       /**
8831debfc3dSmrg        *  @brief Finds a subsequence matching given key.
8841debfc3dSmrg        *  @param  __x  Key to be located.
8851debfc3dSmrg        *  @return  Pair of iterators that possibly points to the subsequence
8861debfc3dSmrg        *           matching given key.
8871debfc3dSmrg        *
8881debfc3dSmrg        *  This function is equivalent to
8891debfc3dSmrg        *  @code
8901debfc3dSmrg        *    std::make_pair(c.lower_bound(val),
8911debfc3dSmrg        *                   c.upper_bound(val))
8921debfc3dSmrg        *  @endcode
8931debfc3dSmrg        *  (but is faster than making the calls separately).
8941debfc3dSmrg        *
8951debfc3dSmrg        *  This function probably only makes sense for multisets.
8961debfc3dSmrg        */
8971debfc3dSmrg       std::pair<iterator, iterator>
8981debfc3dSmrg       equal_range(const key_type& __x)
8991debfc3dSmrg       { return _M_t.equal_range(__x); }
9001debfc3dSmrg 
9011debfc3dSmrg       std::pair<const_iterator, const_iterator>
9021debfc3dSmrg       equal_range(const key_type& __x) const
9031debfc3dSmrg       { return _M_t.equal_range(__x); }
9041debfc3dSmrg 
9051debfc3dSmrg #if __cplusplus > 201103L
9061debfc3dSmrg       template<typename _Kt>
9071debfc3dSmrg 	auto
9081debfc3dSmrg 	equal_range(const _Kt& __x)
9091debfc3dSmrg 	-> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
9101debfc3dSmrg 	{ return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
9111debfc3dSmrg 
9121debfc3dSmrg       template<typename _Kt>
9131debfc3dSmrg 	auto
9141debfc3dSmrg 	equal_range(const _Kt& __x) const
9151debfc3dSmrg 	-> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
9161debfc3dSmrg 	{ return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
9171debfc3dSmrg #endif
918*8feb0f0bSmrg       ///@}
9191debfc3dSmrg 
9201debfc3dSmrg       template<typename _K1, typename _C1, typename _A1>
9211debfc3dSmrg 	friend bool
9221debfc3dSmrg 	operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
9231debfc3dSmrg 
924*8feb0f0bSmrg #if __cpp_lib_three_way_comparison
925*8feb0f0bSmrg       template<typename _K1, typename _C1, typename _A1>
926*8feb0f0bSmrg 	friend __detail::__synth3way_t<_K1>
927*8feb0f0bSmrg 	operator<=>(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
928*8feb0f0bSmrg #else
9291debfc3dSmrg       template<typename _K1, typename _C1, typename _A1>
9301debfc3dSmrg 	friend bool
9311debfc3dSmrg 	operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
932*8feb0f0bSmrg #endif
9331debfc3dSmrg     };
9341debfc3dSmrg 
935a2dc1f3fSmrg #if __cpp_deduction_guides >= 201606
936a2dc1f3fSmrg 
937a2dc1f3fSmrg   template<typename _InputIterator,
938a2dc1f3fSmrg 	   typename _Compare =
939a2dc1f3fSmrg 	     less<typename iterator_traits<_InputIterator>::value_type>,
940a2dc1f3fSmrg 	   typename _Allocator =
941a2dc1f3fSmrg 	     allocator<typename iterator_traits<_InputIterator>::value_type>,
942a2dc1f3fSmrg 	   typename = _RequireInputIter<_InputIterator>,
943c0a68be4Smrg 	   typename = _RequireNotAllocator<_Compare>,
944a2dc1f3fSmrg 	   typename = _RequireAllocator<_Allocator>>
945a2dc1f3fSmrg     set(_InputIterator, _InputIterator,
946a2dc1f3fSmrg 	_Compare = _Compare(), _Allocator = _Allocator())
947a2dc1f3fSmrg     -> set<typename iterator_traits<_InputIterator>::value_type,
948a2dc1f3fSmrg 	  _Compare, _Allocator>;
949a2dc1f3fSmrg 
950a2dc1f3fSmrg   template<typename _Key, typename _Compare = less<_Key>,
951a2dc1f3fSmrg 	   typename _Allocator = allocator<_Key>,
952c0a68be4Smrg 	   typename = _RequireNotAllocator<_Compare>,
953a2dc1f3fSmrg 	   typename = _RequireAllocator<_Allocator>>
954a2dc1f3fSmrg     set(initializer_list<_Key>,
955a2dc1f3fSmrg 	_Compare = _Compare(), _Allocator = _Allocator())
956a2dc1f3fSmrg     -> set<_Key, _Compare, _Allocator>;
957a2dc1f3fSmrg 
958a2dc1f3fSmrg   template<typename _InputIterator, typename _Allocator,
959a2dc1f3fSmrg 	   typename = _RequireInputIter<_InputIterator>,
960a2dc1f3fSmrg 	   typename = _RequireAllocator<_Allocator>>
961a2dc1f3fSmrg     set(_InputIterator, _InputIterator, _Allocator)
962a2dc1f3fSmrg     -> set<typename iterator_traits<_InputIterator>::value_type,
963a2dc1f3fSmrg 	   less<typename iterator_traits<_InputIterator>::value_type>,
964a2dc1f3fSmrg 	   _Allocator>;
965a2dc1f3fSmrg 
966a2dc1f3fSmrg   template<typename _Key, typename _Allocator,
967a2dc1f3fSmrg 	   typename = _RequireAllocator<_Allocator>>
968a2dc1f3fSmrg     set(initializer_list<_Key>, _Allocator)
969a2dc1f3fSmrg     -> set<_Key, less<_Key>, _Allocator>;
970a2dc1f3fSmrg 
971*8feb0f0bSmrg #endif // deduction guides
9721debfc3dSmrg 
9731debfc3dSmrg   /**
9741debfc3dSmrg    *  @brief  Set equality comparison.
9751debfc3dSmrg    *  @param  __x  A %set.
9761debfc3dSmrg    *  @param  __y  A %set of the same type as @a x.
9771debfc3dSmrg    *  @return  True iff the size and elements of the sets are equal.
9781debfc3dSmrg    *
9791debfc3dSmrg    *  This is an equivalence relation.  It is linear in the size of the sets.
9801debfc3dSmrg    *  Sets are considered equivalent if their sizes are equal, and if
9811debfc3dSmrg    *  corresponding elements compare equal.
9821debfc3dSmrg   */
9831debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
9841debfc3dSmrg     inline bool
9851debfc3dSmrg     operator==(const set<_Key, _Compare, _Alloc>& __x,
9861debfc3dSmrg 	       const set<_Key, _Compare, _Alloc>& __y)
9871debfc3dSmrg     { return __x._M_t == __y._M_t; }
9881debfc3dSmrg 
989*8feb0f0bSmrg #if __cpp_lib_three_way_comparison
990*8feb0f0bSmrg   /**
991*8feb0f0bSmrg    *  @brief  Set ordering relation.
992*8feb0f0bSmrg    *  @param  __x  A `set`.
993*8feb0f0bSmrg    *  @param  __y  A `set` of the same type as `x`.
994*8feb0f0bSmrg    *  @return  A value indicating whether `__x` is less than, equal to,
995*8feb0f0bSmrg    *           greater than, or incomparable with `__y`.
996*8feb0f0bSmrg    *
997*8feb0f0bSmrg    *  This is a total ordering relation.  It is linear in the size of the
998*8feb0f0bSmrg    *  maps.  The elements must be comparable with @c <.
999*8feb0f0bSmrg    *
1000*8feb0f0bSmrg    *  See `std::lexicographical_compare_three_way()` for how the determination
1001*8feb0f0bSmrg    *  is made. This operator is used to synthesize relational operators like
1002*8feb0f0bSmrg    *  `<` and `>=` etc.
1003*8feb0f0bSmrg   */
1004*8feb0f0bSmrg   template<typename _Key, typename _Compare, typename _Alloc>
1005*8feb0f0bSmrg     inline __detail::__synth3way_t<_Key>
1006*8feb0f0bSmrg     operator<=>(const set<_Key, _Compare, _Alloc>& __x,
1007*8feb0f0bSmrg 		const set<_Key, _Compare, _Alloc>& __y)
1008*8feb0f0bSmrg     { return __x._M_t <=> __y._M_t; }
1009*8feb0f0bSmrg #else
10101debfc3dSmrg   /**
10111debfc3dSmrg    *  @brief  Set ordering relation.
10121debfc3dSmrg    *  @param  __x  A %set.
10131debfc3dSmrg    *  @param  __y  A %set of the same type as @a x.
10141debfc3dSmrg    *  @return  True iff @a __x is lexicographically less than @a __y.
10151debfc3dSmrg    *
10161debfc3dSmrg    *  This is a total ordering relation.  It is linear in the size of the
10171debfc3dSmrg    *  sets.  The elements must be comparable with @c <.
10181debfc3dSmrg    *
10191debfc3dSmrg    *  See std::lexicographical_compare() for how the determination is made.
10201debfc3dSmrg   */
10211debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10221debfc3dSmrg     inline bool
10231debfc3dSmrg     operator<(const set<_Key, _Compare, _Alloc>& __x,
10241debfc3dSmrg 	      const set<_Key, _Compare, _Alloc>& __y)
10251debfc3dSmrg     { return __x._M_t < __y._M_t; }
10261debfc3dSmrg 
10271debfc3dSmrg   ///  Returns !(x == y).
10281debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10291debfc3dSmrg     inline bool
10301debfc3dSmrg     operator!=(const set<_Key, _Compare, _Alloc>& __x,
10311debfc3dSmrg 	       const set<_Key, _Compare, _Alloc>& __y)
10321debfc3dSmrg     { return !(__x == __y); }
10331debfc3dSmrg 
10341debfc3dSmrg   ///  Returns y < x.
10351debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10361debfc3dSmrg     inline bool
10371debfc3dSmrg     operator>(const set<_Key, _Compare, _Alloc>& __x,
10381debfc3dSmrg 	      const set<_Key, _Compare, _Alloc>& __y)
10391debfc3dSmrg     { return __y < __x; }
10401debfc3dSmrg 
10411debfc3dSmrg   ///  Returns !(y < x)
10421debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10431debfc3dSmrg     inline bool
10441debfc3dSmrg     operator<=(const set<_Key, _Compare, _Alloc>& __x,
10451debfc3dSmrg 	       const set<_Key, _Compare, _Alloc>& __y)
10461debfc3dSmrg     { return !(__y < __x); }
10471debfc3dSmrg 
10481debfc3dSmrg   ///  Returns !(x < y)
10491debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10501debfc3dSmrg     inline bool
10511debfc3dSmrg     operator>=(const set<_Key, _Compare, _Alloc>& __x,
10521debfc3dSmrg 	       const set<_Key, _Compare, _Alloc>& __y)
10531debfc3dSmrg     { return !(__x < __y); }
1054*8feb0f0bSmrg #endif // three-way comparison
10551debfc3dSmrg 
10561debfc3dSmrg   /// See std::set::swap().
10571debfc3dSmrg   template<typename _Key, typename _Compare, typename _Alloc>
10581debfc3dSmrg     inline void
10591debfc3dSmrg     swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
10601debfc3dSmrg     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
10611debfc3dSmrg     { __x.swap(__y); }
10621debfc3dSmrg 
10631debfc3dSmrg _GLIBCXX_END_NAMESPACE_CONTAINER
10641debfc3dSmrg 
10651debfc3dSmrg #if __cplusplus > 201402L
10661debfc3dSmrg   // Allow std::set access to internals of compatible sets.
10671debfc3dSmrg   template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
10681debfc3dSmrg     struct
10691debfc3dSmrg     _Rb_tree_merge_helper<_GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>, _Cmp2>
10701debfc3dSmrg     {
10711debfc3dSmrg     private:
10721debfc3dSmrg       friend class _GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>;
10731debfc3dSmrg 
10741debfc3dSmrg       static auto&
10751debfc3dSmrg       _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
10761debfc3dSmrg       { return __set._M_t; }
10771debfc3dSmrg 
10781debfc3dSmrg       static auto&
10791debfc3dSmrg       _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
10801debfc3dSmrg       { return __set._M_t; }
10811debfc3dSmrg     };
10821debfc3dSmrg #endif // C++17
10831debfc3dSmrg 
1084a2dc1f3fSmrg _GLIBCXX_END_NAMESPACE_VERSION
10851debfc3dSmrg } //namespace std
10861debfc3dSmrg #endif /* _STL_SET_H */
1087