xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/stl_set.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj // Set implementation -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /*
26*38fd1498Szrj  *
27*38fd1498Szrj  * Copyright (c) 1994
28*38fd1498Szrj  * Hewlett-Packard Company
29*38fd1498Szrj  *
30*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
31*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
32*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
33*38fd1498Szrj  * that both that copyright notice and this permission notice appear
34*38fd1498Szrj  * in supporting documentation.  Hewlett-Packard Company makes no
35*38fd1498Szrj  * representations about the suitability of this software for any
36*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
37*38fd1498Szrj  *
38*38fd1498Szrj  *
39*38fd1498Szrj  * Copyright (c) 1996,1997
40*38fd1498Szrj  * Silicon Graphics Computer Systems, Inc.
41*38fd1498Szrj  *
42*38fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
43*38fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
44*38fd1498Szrj  * provided that the above copyright notice appear in all copies and
45*38fd1498Szrj  * that both that copyright notice and this permission notice appear
46*38fd1498Szrj  * in supporting documentation.  Silicon Graphics makes no
47*38fd1498Szrj  * representations about the suitability of this software for any
48*38fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
49*38fd1498Szrj  */
50*38fd1498Szrj 
51*38fd1498Szrj /** @file bits/stl_set.h
52*38fd1498Szrj  *  This is an internal header file, included by other library headers.
53*38fd1498Szrj  *  Do not attempt to use it directly. @headername{set}
54*38fd1498Szrj  */
55*38fd1498Szrj 
56*38fd1498Szrj #ifndef _STL_SET_H
57*38fd1498Szrj #define _STL_SET_H 1
58*38fd1498Szrj 
59*38fd1498Szrj #include <bits/concept_check.h>
60*38fd1498Szrj #if __cplusplus >= 201103L
61*38fd1498Szrj #include <initializer_list>
62*38fd1498Szrj #endif
63*38fd1498Szrj 
_GLIBCXX_VISIBILITY(default)64*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
65*38fd1498Szrj {
66*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
67*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68*38fd1498Szrj 
69*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
70*38fd1498Szrj     class multiset;
71*38fd1498Szrj 
72*38fd1498Szrj   /**
73*38fd1498Szrj    *  @brief A standard container made up of unique keys, which can be
74*38fd1498Szrj    *  retrieved in logarithmic time.
75*38fd1498Szrj    *
76*38fd1498Szrj    *  @ingroup associative_containers
77*38fd1498Szrj    *
78*38fd1498Szrj    *  @tparam _Key  Type of key objects.
79*38fd1498Szrj    *  @tparam _Compare  Comparison function object type, defaults to less<_Key>.
80*38fd1498Szrj    *  @tparam _Alloc  Allocator type, defaults to allocator<_Key>.
81*38fd1498Szrj    *
82*38fd1498Szrj    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
83*38fd1498Szrj    *  <a href="tables.html#66">reversible container</a>, and an
84*38fd1498Szrj    *  <a href="tables.html#69">associative container</a> (using unique keys).
85*38fd1498Szrj    *
86*38fd1498Szrj    *  Sets support bidirectional iterators.
87*38fd1498Szrj    *
88*38fd1498Szrj    *  The private tree data is declared exactly the same way for set and
89*38fd1498Szrj    *  multiset; the distinction is made entirely in how the tree functions are
90*38fd1498Szrj    *  called (*_unique versus *_equal, same as the standard).
91*38fd1498Szrj   */
92*38fd1498Szrj   template<typename _Key, typename _Compare = std::less<_Key>,
93*38fd1498Szrj 	   typename _Alloc = std::allocator<_Key> >
94*38fd1498Szrj     class set
95*38fd1498Szrj     {
96*38fd1498Szrj #ifdef _GLIBCXX_CONCEPT_CHECKS
97*38fd1498Szrj       // concept requirements
98*38fd1498Szrj       typedef typename _Alloc::value_type		_Alloc_value_type;
99*38fd1498Szrj # if __cplusplus < 201103L
100*38fd1498Szrj       __glibcxx_class_requires(_Key, _SGIAssignableConcept)
101*38fd1498Szrj # endif
102*38fd1498Szrj       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
103*38fd1498Szrj 				_BinaryFunctionConcept)
104*38fd1498Szrj       __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
105*38fd1498Szrj #endif
106*38fd1498Szrj 
107*38fd1498Szrj #if __cplusplus >= 201103L
108*38fd1498Szrj       static_assert(is_same<typename remove_cv<_Key>::type, _Key>::value,
109*38fd1498Szrj 	  "std::set must have a non-const, non-volatile value_type");
110*38fd1498Szrj # ifdef __STRICT_ANSI__
111*38fd1498Szrj       static_assert(is_same<typename _Alloc::value_type, _Key>::value,
112*38fd1498Szrj 	  "std::set must have the same value_type as its allocator");
113*38fd1498Szrj # endif
114*38fd1498Szrj #endif
115*38fd1498Szrj 
116*38fd1498Szrj     public:
117*38fd1498Szrj       // typedefs:
118*38fd1498Szrj       //@{
119*38fd1498Szrj       /// Public typedefs.
120*38fd1498Szrj       typedef _Key     key_type;
121*38fd1498Szrj       typedef _Key     value_type;
122*38fd1498Szrj       typedef _Compare key_compare;
123*38fd1498Szrj       typedef _Compare value_compare;
124*38fd1498Szrj       typedef _Alloc   allocator_type;
125*38fd1498Szrj       //@}
126*38fd1498Szrj 
127*38fd1498Szrj     private:
128*38fd1498Szrj       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
129*38fd1498Szrj 	rebind<_Key>::other _Key_alloc_type;
130*38fd1498Szrj 
131*38fd1498Szrj       typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
132*38fd1498Szrj 		       key_compare, _Key_alloc_type> _Rep_type;
133*38fd1498Szrj       _Rep_type _M_t;  // Red-black tree representing set.
134*38fd1498Szrj 
135*38fd1498Szrj       typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
136*38fd1498Szrj 
137*38fd1498Szrj     public:
138*38fd1498Szrj       //@{
139*38fd1498Szrj       ///  Iterator-related typedefs.
140*38fd1498Szrj       typedef typename _Alloc_traits::pointer		 pointer;
141*38fd1498Szrj       typedef typename _Alloc_traits::const_pointer	 const_pointer;
142*38fd1498Szrj       typedef typename _Alloc_traits::reference		 reference;
143*38fd1498Szrj       typedef typename _Alloc_traits::const_reference	 const_reference;
144*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
145*38fd1498Szrj       // DR 103. set::iterator is required to be modifiable,
146*38fd1498Szrj       // but this allows modification of keys.
147*38fd1498Szrj       typedef typename _Rep_type::const_iterator	 iterator;
148*38fd1498Szrj       typedef typename _Rep_type::const_iterator	 const_iterator;
149*38fd1498Szrj       typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
150*38fd1498Szrj       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
151*38fd1498Szrj       typedef typename _Rep_type::size_type		 size_type;
152*38fd1498Szrj       typedef typename _Rep_type::difference_type	 difference_type;
153*38fd1498Szrj       //@}
154*38fd1498Szrj 
155*38fd1498Szrj #if __cplusplus > 201402L
156*38fd1498Szrj       using node_type = typename _Rep_type::node_type;
157*38fd1498Szrj       using insert_return_type = typename _Rep_type::insert_return_type;
158*38fd1498Szrj #endif
159*38fd1498Szrj 
160*38fd1498Szrj       // allocation/deallocation
161*38fd1498Szrj       /**
162*38fd1498Szrj        *  @brief  Default constructor creates no elements.
163*38fd1498Szrj        */
164*38fd1498Szrj #if __cplusplus < 201103L
165*38fd1498Szrj       set() : _M_t() { }
166*38fd1498Szrj #else
167*38fd1498Szrj       set() = default;
168*38fd1498Szrj #endif
169*38fd1498Szrj 
170*38fd1498Szrj       /**
171*38fd1498Szrj        *  @brief  Creates a %set with no elements.
172*38fd1498Szrj        *  @param  __comp  Comparator to use.
173*38fd1498Szrj        *  @param  __a  An allocator object.
174*38fd1498Szrj        */
175*38fd1498Szrj       explicit
176*38fd1498Szrj       set(const _Compare& __comp,
177*38fd1498Szrj 	  const allocator_type& __a = allocator_type())
178*38fd1498Szrj       : _M_t(__comp, _Key_alloc_type(__a)) { }
179*38fd1498Szrj 
180*38fd1498Szrj       /**
181*38fd1498Szrj        *  @brief  Builds a %set from a range.
182*38fd1498Szrj        *  @param  __first  An input iterator.
183*38fd1498Szrj        *  @param  __last  An input iterator.
184*38fd1498Szrj        *
185*38fd1498Szrj        *  Create a %set consisting of copies of the elements from
186*38fd1498Szrj        *  [__first,__last).  This is linear in N if the range is
187*38fd1498Szrj        *  already sorted, and NlogN otherwise (where N is
188*38fd1498Szrj        *  distance(__first,__last)).
189*38fd1498Szrj        */
190*38fd1498Szrj       template<typename _InputIterator>
191*38fd1498Szrj 	set(_InputIterator __first, _InputIterator __last)
192*38fd1498Szrj 	: _M_t()
193*38fd1498Szrj 	{ _M_t._M_insert_unique(__first, __last); }
194*38fd1498Szrj 
195*38fd1498Szrj       /**
196*38fd1498Szrj        *  @brief  Builds a %set from a range.
197*38fd1498Szrj        *  @param  __first  An input iterator.
198*38fd1498Szrj        *  @param  __last  An input iterator.
199*38fd1498Szrj        *  @param  __comp  A comparison functor.
200*38fd1498Szrj        *  @param  __a  An allocator object.
201*38fd1498Szrj        *
202*38fd1498Szrj        *  Create a %set consisting of copies of the elements from
203*38fd1498Szrj        *  [__first,__last).  This is linear in N if the range is
204*38fd1498Szrj        *  already sorted, and NlogN otherwise (where N is
205*38fd1498Szrj        *  distance(__first,__last)).
206*38fd1498Szrj        */
207*38fd1498Szrj       template<typename _InputIterator>
208*38fd1498Szrj 	set(_InputIterator __first, _InputIterator __last,
209*38fd1498Szrj 	    const _Compare& __comp,
210*38fd1498Szrj 	    const allocator_type& __a = allocator_type())
211*38fd1498Szrj 	: _M_t(__comp, _Key_alloc_type(__a))
212*38fd1498Szrj 	{ _M_t._M_insert_unique(__first, __last); }
213*38fd1498Szrj 
214*38fd1498Szrj       /**
215*38fd1498Szrj        *  @brief  %Set copy constructor.
216*38fd1498Szrj        *
217*38fd1498Szrj        *  Whether the allocator is copied depends on the allocator traits.
218*38fd1498Szrj        */
219*38fd1498Szrj #if __cplusplus < 201103L
220*38fd1498Szrj       set(const set& __x)
221*38fd1498Szrj       : _M_t(__x._M_t) { }
222*38fd1498Szrj #else
223*38fd1498Szrj       set(const set&) = default;
224*38fd1498Szrj 
225*38fd1498Szrj      /**
226*38fd1498Szrj        *  @brief %Set move constructor
227*38fd1498Szrj        *
228*38fd1498Szrj        *  The newly-created %set contains the exact contents of the moved
229*38fd1498Szrj        *  instance. The moved instance is a valid, but unspecified, %set.
230*38fd1498Szrj        */
231*38fd1498Szrj       set(set&&) = default;
232*38fd1498Szrj 
233*38fd1498Szrj       /**
234*38fd1498Szrj        *  @brief  Builds a %set from an initializer_list.
235*38fd1498Szrj        *  @param  __l  An initializer_list.
236*38fd1498Szrj        *  @param  __comp  A comparison functor.
237*38fd1498Szrj        *  @param  __a  An allocator object.
238*38fd1498Szrj        *
239*38fd1498Szrj        *  Create a %set consisting of copies of the elements in the list.
240*38fd1498Szrj        *  This is linear in N if the list is already sorted, and NlogN
241*38fd1498Szrj        *  otherwise (where N is @a __l.size()).
242*38fd1498Szrj        */
243*38fd1498Szrj       set(initializer_list<value_type> __l,
244*38fd1498Szrj 	  const _Compare& __comp = _Compare(),
245*38fd1498Szrj 	  const allocator_type& __a = allocator_type())
246*38fd1498Szrj       : _M_t(__comp, _Key_alloc_type(__a))
247*38fd1498Szrj       { _M_t._M_insert_unique(__l.begin(), __l.end()); }
248*38fd1498Szrj 
249*38fd1498Szrj       /// Allocator-extended default constructor.
250*38fd1498Szrj       explicit
251*38fd1498Szrj       set(const allocator_type& __a)
252*38fd1498Szrj       : _M_t(_Compare(), _Key_alloc_type(__a)) { }
253*38fd1498Szrj 
254*38fd1498Szrj       /// Allocator-extended copy constructor.
255*38fd1498Szrj       set(const set& __x, const allocator_type& __a)
256*38fd1498Szrj       : _M_t(__x._M_t, _Key_alloc_type(__a)) { }
257*38fd1498Szrj 
258*38fd1498Szrj       /// Allocator-extended move constructor.
259*38fd1498Szrj       set(set&& __x, const allocator_type& __a)
260*38fd1498Szrj       noexcept(is_nothrow_copy_constructible<_Compare>::value
261*38fd1498Szrj 	       && _Alloc_traits::_S_always_equal())
262*38fd1498Szrj       : _M_t(std::move(__x._M_t), _Key_alloc_type(__a)) { }
263*38fd1498Szrj 
264*38fd1498Szrj       /// Allocator-extended initialier-list constructor.
265*38fd1498Szrj       set(initializer_list<value_type> __l, const allocator_type& __a)
266*38fd1498Szrj       : _M_t(_Compare(), _Key_alloc_type(__a))
267*38fd1498Szrj       { _M_t._M_insert_unique(__l.begin(), __l.end()); }
268*38fd1498Szrj 
269*38fd1498Szrj       /// Allocator-extended range constructor.
270*38fd1498Szrj       template<typename _InputIterator>
271*38fd1498Szrj 	set(_InputIterator __first, _InputIterator __last,
272*38fd1498Szrj 	    const allocator_type& __a)
273*38fd1498Szrj 	: _M_t(_Compare(), _Key_alloc_type(__a))
274*38fd1498Szrj 	{ _M_t._M_insert_unique(__first, __last); }
275*38fd1498Szrj 
276*38fd1498Szrj       /**
277*38fd1498Szrj        *  The dtor only erases the elements, and note that if the elements
278*38fd1498Szrj        *  themselves are pointers, the pointed-to memory is not touched in any
279*38fd1498Szrj        *  way. Managing the pointer is the user's responsibility.
280*38fd1498Szrj        */
281*38fd1498Szrj       ~set() = default;
282*38fd1498Szrj #endif
283*38fd1498Szrj 
284*38fd1498Szrj       /**
285*38fd1498Szrj        *  @brief  %Set assignment operator.
286*38fd1498Szrj        *
287*38fd1498Szrj        *  Whether the allocator is copied depends on the allocator traits.
288*38fd1498Szrj        */
289*38fd1498Szrj #if __cplusplus < 201103L
290*38fd1498Szrj       set&
291*38fd1498Szrj       operator=(const set& __x)
292*38fd1498Szrj       {
293*38fd1498Szrj 	_M_t = __x._M_t;
294*38fd1498Szrj 	return *this;
295*38fd1498Szrj       }
296*38fd1498Szrj #else
297*38fd1498Szrj       set&
298*38fd1498Szrj       operator=(const set&) = default;
299*38fd1498Szrj 
300*38fd1498Szrj       /// Move assignment operator.
301*38fd1498Szrj       set&
302*38fd1498Szrj       operator=(set&&) = default;
303*38fd1498Szrj 
304*38fd1498Szrj       /**
305*38fd1498Szrj        *  @brief  %Set list assignment operator.
306*38fd1498Szrj        *  @param  __l  An initializer_list.
307*38fd1498Szrj        *
308*38fd1498Szrj        *  This function fills a %set with copies of the elements in the
309*38fd1498Szrj        *  initializer list @a __l.
310*38fd1498Szrj        *
311*38fd1498Szrj        *  Note that the assignment completely changes the %set and
312*38fd1498Szrj        *  that the resulting %set's size is the same as the number
313*38fd1498Szrj        *  of elements assigned.
314*38fd1498Szrj        */
315*38fd1498Szrj       set&
316*38fd1498Szrj       operator=(initializer_list<value_type> __l)
317*38fd1498Szrj       {
318*38fd1498Szrj 	_M_t._M_assign_unique(__l.begin(), __l.end());
319*38fd1498Szrj 	return *this;
320*38fd1498Szrj       }
321*38fd1498Szrj #endif
322*38fd1498Szrj 
323*38fd1498Szrj       // accessors:
324*38fd1498Szrj 
325*38fd1498Szrj       ///  Returns the comparison object with which the %set was constructed.
326*38fd1498Szrj       key_compare
327*38fd1498Szrj       key_comp() const
328*38fd1498Szrj       { return _M_t.key_comp(); }
329*38fd1498Szrj       ///  Returns the comparison object with which the %set was constructed.
330*38fd1498Szrj       value_compare
331*38fd1498Szrj       value_comp() const
332*38fd1498Szrj       { return _M_t.key_comp(); }
333*38fd1498Szrj       ///  Returns the allocator object with which the %set was constructed.
334*38fd1498Szrj       allocator_type
335*38fd1498Szrj       get_allocator() const _GLIBCXX_NOEXCEPT
336*38fd1498Szrj       { return allocator_type(_M_t.get_allocator()); }
337*38fd1498Szrj 
338*38fd1498Szrj       /**
339*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
340*38fd1498Szrj        *  element in the %set.  Iteration is done in ascending order according
341*38fd1498Szrj        *  to the keys.
342*38fd1498Szrj        */
343*38fd1498Szrj       iterator
344*38fd1498Szrj       begin() const _GLIBCXX_NOEXCEPT
345*38fd1498Szrj       { return _M_t.begin(); }
346*38fd1498Szrj 
347*38fd1498Szrj       /**
348*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the last
349*38fd1498Szrj        *  element in the %set.  Iteration is done in ascending order according
350*38fd1498Szrj        *  to the keys.
351*38fd1498Szrj        */
352*38fd1498Szrj       iterator
353*38fd1498Szrj       end() const _GLIBCXX_NOEXCEPT
354*38fd1498Szrj       { return _M_t.end(); }
355*38fd1498Szrj 
356*38fd1498Szrj       /**
357*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the last
358*38fd1498Szrj        *  element in the %set.  Iteration is done in descending order according
359*38fd1498Szrj        *  to the keys.
360*38fd1498Szrj        */
361*38fd1498Szrj       reverse_iterator
362*38fd1498Szrj       rbegin() const _GLIBCXX_NOEXCEPT
363*38fd1498Szrj       { return _M_t.rbegin(); }
364*38fd1498Szrj 
365*38fd1498Szrj       /**
366*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to the
367*38fd1498Szrj        *  last pair in the %set.  Iteration is done in descending order
368*38fd1498Szrj        *  according to the keys.
369*38fd1498Szrj        */
370*38fd1498Szrj       reverse_iterator
371*38fd1498Szrj       rend() const _GLIBCXX_NOEXCEPT
372*38fd1498Szrj       { return _M_t.rend(); }
373*38fd1498Szrj 
374*38fd1498Szrj #if __cplusplus >= 201103L
375*38fd1498Szrj       /**
376*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the first
377*38fd1498Szrj        *  element in the %set.  Iteration is done in ascending order according
378*38fd1498Szrj        *  to the keys.
379*38fd1498Szrj        */
380*38fd1498Szrj       iterator
381*38fd1498Szrj       cbegin() const noexcept
382*38fd1498Szrj       { return _M_t.begin(); }
383*38fd1498Szrj 
384*38fd1498Szrj       /**
385*38fd1498Szrj        *  Returns a read-only (constant) iterator that points one past the last
386*38fd1498Szrj        *  element in the %set.  Iteration is done in ascending order according
387*38fd1498Szrj        *  to the keys.
388*38fd1498Szrj        */
389*38fd1498Szrj       iterator
390*38fd1498Szrj       cend() const noexcept
391*38fd1498Szrj       { return _M_t.end(); }
392*38fd1498Szrj 
393*38fd1498Szrj       /**
394*38fd1498Szrj        *  Returns a read-only (constant) iterator that points to the last
395*38fd1498Szrj        *  element in the %set.  Iteration is done in descending order according
396*38fd1498Szrj        *  to the keys.
397*38fd1498Szrj        */
398*38fd1498Szrj       reverse_iterator
399*38fd1498Szrj       crbegin() const noexcept
400*38fd1498Szrj       { return _M_t.rbegin(); }
401*38fd1498Szrj 
402*38fd1498Szrj       /**
403*38fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to the
404*38fd1498Szrj        *  last pair in the %set.  Iteration is done in descending order
405*38fd1498Szrj        *  according to the keys.
406*38fd1498Szrj        */
407*38fd1498Szrj       reverse_iterator
408*38fd1498Szrj       crend() const noexcept
409*38fd1498Szrj       { return _M_t.rend(); }
410*38fd1498Szrj #endif
411*38fd1498Szrj 
412*38fd1498Szrj       ///  Returns true if the %set is empty.
413*38fd1498Szrj       bool
414*38fd1498Szrj       empty() const _GLIBCXX_NOEXCEPT
415*38fd1498Szrj       { return _M_t.empty(); }
416*38fd1498Szrj 
417*38fd1498Szrj       ///  Returns the size of the %set.
418*38fd1498Szrj       size_type
419*38fd1498Szrj       size() const _GLIBCXX_NOEXCEPT
420*38fd1498Szrj       { return _M_t.size(); }
421*38fd1498Szrj 
422*38fd1498Szrj       ///  Returns the maximum size of the %set.
423*38fd1498Szrj       size_type
424*38fd1498Szrj       max_size() const _GLIBCXX_NOEXCEPT
425*38fd1498Szrj       { return _M_t.max_size(); }
426*38fd1498Szrj 
427*38fd1498Szrj       /**
428*38fd1498Szrj        *  @brief  Swaps data with another %set.
429*38fd1498Szrj        *  @param  __x  A %set of the same element and allocator types.
430*38fd1498Szrj        *
431*38fd1498Szrj        *  This exchanges the elements between two sets in constant
432*38fd1498Szrj        *  time.  (It is only swapping a pointer, an integer, and an
433*38fd1498Szrj        *  instance of the @c Compare type (which itself is often
434*38fd1498Szrj        *  stateless and empty), so it should be quite fast.)  Note
435*38fd1498Szrj        *  that the global std::swap() function is specialized such
436*38fd1498Szrj        *  that std::swap(s1,s2) will feed to this function.
437*38fd1498Szrj        *
438*38fd1498Szrj        *  Whether the allocators are swapped depends on the allocator traits.
439*38fd1498Szrj        */
440*38fd1498Szrj       void
441*38fd1498Szrj       swap(set& __x)
442*38fd1498Szrj       _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
443*38fd1498Szrj       { _M_t.swap(__x._M_t); }
444*38fd1498Szrj 
445*38fd1498Szrj       // insert/erase
446*38fd1498Szrj #if __cplusplus >= 201103L
447*38fd1498Szrj       /**
448*38fd1498Szrj        *  @brief Attempts to build and insert an element into the %set.
449*38fd1498Szrj        *  @param __args  Arguments used to generate an element.
450*38fd1498Szrj        *  @return  A pair, of which the first element is an iterator that points
451*38fd1498Szrj        *           to the possibly inserted element, and the second is a bool
452*38fd1498Szrj        *           that is true if the element was actually inserted.
453*38fd1498Szrj        *
454*38fd1498Szrj        *  This function attempts to build and insert an element into the %set.
455*38fd1498Szrj        *  A %set relies on unique keys and thus an element is only inserted if
456*38fd1498Szrj        *  it is not already present in the %set.
457*38fd1498Szrj        *
458*38fd1498Szrj        *  Insertion requires logarithmic time.
459*38fd1498Szrj        */
460*38fd1498Szrj       template<typename... _Args>
461*38fd1498Szrj 	std::pair<iterator, bool>
462*38fd1498Szrj 	emplace(_Args&&... __args)
463*38fd1498Szrj 	{ return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
464*38fd1498Szrj 
465*38fd1498Szrj       /**
466*38fd1498Szrj        *  @brief Attempts to insert an element into the %set.
467*38fd1498Szrj        *  @param  __pos  An iterator that serves as a hint as to where the
468*38fd1498Szrj        *                element should be inserted.
469*38fd1498Szrj        *  @param  __args  Arguments used to generate the element to be
470*38fd1498Szrj        *                 inserted.
471*38fd1498Szrj        *  @return An iterator that points to the element with key equivalent to
472*38fd1498Szrj        *          the one generated from @a __args (may or may not be the
473*38fd1498Szrj        *          element itself).
474*38fd1498Szrj        *
475*38fd1498Szrj        *  This function is not concerned about whether the insertion took place,
476*38fd1498Szrj        *  and thus does not return a boolean like the single-argument emplace()
477*38fd1498Szrj        *  does.  Note that the first parameter is only a hint and can
478*38fd1498Szrj        *  potentially improve the performance of the insertion process.  A bad
479*38fd1498Szrj        *  hint would cause no gains in efficiency.
480*38fd1498Szrj        *
481*38fd1498Szrj        *  For more on @a hinting, see:
482*38fd1498Szrj        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
483*38fd1498Szrj        *
484*38fd1498Szrj        *  Insertion requires logarithmic time (if the hint is not taken).
485*38fd1498Szrj        */
486*38fd1498Szrj       template<typename... _Args>
487*38fd1498Szrj 	iterator
488*38fd1498Szrj 	emplace_hint(const_iterator __pos, _Args&&... __args)
489*38fd1498Szrj 	{
490*38fd1498Szrj 	  return _M_t._M_emplace_hint_unique(__pos,
491*38fd1498Szrj 					     std::forward<_Args>(__args)...);
492*38fd1498Szrj 	}
493*38fd1498Szrj #endif
494*38fd1498Szrj 
495*38fd1498Szrj       /**
496*38fd1498Szrj        *  @brief Attempts to insert an element into the %set.
497*38fd1498Szrj        *  @param  __x  Element to be inserted.
498*38fd1498Szrj        *  @return  A pair, of which the first element is an iterator that points
499*38fd1498Szrj        *           to the possibly inserted element, and the second is a bool
500*38fd1498Szrj        *           that is true if the element was actually inserted.
501*38fd1498Szrj        *
502*38fd1498Szrj        *  This function attempts to insert an element into the %set.  A %set
503*38fd1498Szrj        *  relies on unique keys and thus an element is only inserted if it is
504*38fd1498Szrj        *  not already present in the %set.
505*38fd1498Szrj        *
506*38fd1498Szrj        *  Insertion requires logarithmic time.
507*38fd1498Szrj        */
508*38fd1498Szrj       std::pair<iterator, bool>
509*38fd1498Szrj       insert(const value_type& __x)
510*38fd1498Szrj       {
511*38fd1498Szrj 	std::pair<typename _Rep_type::iterator, bool> __p =
512*38fd1498Szrj 	  _M_t._M_insert_unique(__x);
513*38fd1498Szrj 	return std::pair<iterator, bool>(__p.first, __p.second);
514*38fd1498Szrj       }
515*38fd1498Szrj 
516*38fd1498Szrj #if __cplusplus >= 201103L
517*38fd1498Szrj       std::pair<iterator, bool>
518*38fd1498Szrj       insert(value_type&& __x)
519*38fd1498Szrj       {
520*38fd1498Szrj 	std::pair<typename _Rep_type::iterator, bool> __p =
521*38fd1498Szrj 	  _M_t._M_insert_unique(std::move(__x));
522*38fd1498Szrj 	return std::pair<iterator, bool>(__p.first, __p.second);
523*38fd1498Szrj       }
524*38fd1498Szrj #endif
525*38fd1498Szrj 
526*38fd1498Szrj       /**
527*38fd1498Szrj        *  @brief Attempts to insert an element into the %set.
528*38fd1498Szrj        *  @param  __position  An iterator that serves as a hint as to where the
529*38fd1498Szrj        *                    element should be inserted.
530*38fd1498Szrj        *  @param  __x  Element to be inserted.
531*38fd1498Szrj        *  @return An iterator that points to the element with key of
532*38fd1498Szrj        *           @a __x (may or may not be the element passed in).
533*38fd1498Szrj        *
534*38fd1498Szrj        *  This function is not concerned about whether the insertion took place,
535*38fd1498Szrj        *  and thus does not return a boolean like the single-argument insert()
536*38fd1498Szrj        *  does.  Note that the first parameter is only a hint and can
537*38fd1498Szrj        *  potentially improve the performance of the insertion process.  A bad
538*38fd1498Szrj        *  hint would cause no gains in efficiency.
539*38fd1498Szrj        *
540*38fd1498Szrj        *  For more on @a hinting, see:
541*38fd1498Szrj        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
542*38fd1498Szrj        *
543*38fd1498Szrj        *  Insertion requires logarithmic time (if the hint is not taken).
544*38fd1498Szrj        */
545*38fd1498Szrj       iterator
546*38fd1498Szrj       insert(const_iterator __position, const value_type& __x)
547*38fd1498Szrj       { return _M_t._M_insert_unique_(__position, __x); }
548*38fd1498Szrj 
549*38fd1498Szrj #if __cplusplus >= 201103L
550*38fd1498Szrj       iterator
551*38fd1498Szrj       insert(const_iterator __position, value_type&& __x)
552*38fd1498Szrj       { return _M_t._M_insert_unique_(__position, std::move(__x)); }
553*38fd1498Szrj #endif
554*38fd1498Szrj 
555*38fd1498Szrj       /**
556*38fd1498Szrj        *  @brief A template function that attempts to insert a range
557*38fd1498Szrj        *  of elements.
558*38fd1498Szrj        *  @param  __first  Iterator pointing to the start of the range to be
559*38fd1498Szrj        *                   inserted.
560*38fd1498Szrj        *  @param  __last  Iterator pointing to the end of the range.
561*38fd1498Szrj        *
562*38fd1498Szrj        *  Complexity similar to that of the range constructor.
563*38fd1498Szrj        */
564*38fd1498Szrj       template<typename _InputIterator>
565*38fd1498Szrj 	void
566*38fd1498Szrj 	insert(_InputIterator __first, _InputIterator __last)
567*38fd1498Szrj 	{ _M_t._M_insert_unique(__first, __last); }
568*38fd1498Szrj 
569*38fd1498Szrj #if __cplusplus >= 201103L
570*38fd1498Szrj       /**
571*38fd1498Szrj        *  @brief Attempts to insert a list of elements into the %set.
572*38fd1498Szrj        *  @param  __l  A std::initializer_list<value_type> of elements
573*38fd1498Szrj        *               to be inserted.
574*38fd1498Szrj        *
575*38fd1498Szrj        *  Complexity similar to that of the range constructor.
576*38fd1498Szrj        */
577*38fd1498Szrj       void
578*38fd1498Szrj       insert(initializer_list<value_type> __l)
579*38fd1498Szrj       { this->insert(__l.begin(), __l.end()); }
580*38fd1498Szrj #endif
581*38fd1498Szrj 
582*38fd1498Szrj #if __cplusplus > 201402L
583*38fd1498Szrj       /// Extract a node.
584*38fd1498Szrj       node_type
585*38fd1498Szrj       extract(const_iterator __pos)
586*38fd1498Szrj       {
587*38fd1498Szrj 	__glibcxx_assert(__pos != end());
588*38fd1498Szrj 	return _M_t.extract(__pos);
589*38fd1498Szrj       }
590*38fd1498Szrj 
591*38fd1498Szrj       /// Extract a node.
592*38fd1498Szrj       node_type
593*38fd1498Szrj       extract(const key_type& __x)
594*38fd1498Szrj       { return _M_t.extract(__x); }
595*38fd1498Szrj 
596*38fd1498Szrj       /// Re-insert an extracted node.
597*38fd1498Szrj       insert_return_type
598*38fd1498Szrj       insert(node_type&& __nh)
599*38fd1498Szrj       { return _M_t._M_reinsert_node_unique(std::move(__nh)); }
600*38fd1498Szrj 
601*38fd1498Szrj       /// Re-insert an extracted node.
602*38fd1498Szrj       iterator
603*38fd1498Szrj       insert(const_iterator __hint, node_type&& __nh)
604*38fd1498Szrj       { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
605*38fd1498Szrj 
606*38fd1498Szrj       template<typename, typename>
607*38fd1498Szrj 	friend class std::_Rb_tree_merge_helper;
608*38fd1498Szrj 
609*38fd1498Szrj       template<typename _Compare1>
610*38fd1498Szrj 	void
611*38fd1498Szrj 	merge(set<_Key, _Compare1, _Alloc>& __source)
612*38fd1498Szrj 	{
613*38fd1498Szrj 	  using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
614*38fd1498Szrj 	  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
615*38fd1498Szrj 	}
616*38fd1498Szrj 
617*38fd1498Szrj       template<typename _Compare1>
618*38fd1498Szrj 	void
619*38fd1498Szrj 	merge(set<_Key, _Compare1, _Alloc>&& __source)
620*38fd1498Szrj 	{ merge(__source); }
621*38fd1498Szrj 
622*38fd1498Szrj       template<typename _Compare1>
623*38fd1498Szrj 	void
624*38fd1498Szrj 	merge(multiset<_Key, _Compare1, _Alloc>& __source)
625*38fd1498Szrj 	{
626*38fd1498Szrj 	  using _Merge_helper = _Rb_tree_merge_helper<set, _Compare1>;
627*38fd1498Szrj 	  _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
628*38fd1498Szrj 	}
629*38fd1498Szrj 
630*38fd1498Szrj       template<typename _Compare1>
631*38fd1498Szrj 	void
632*38fd1498Szrj 	merge(multiset<_Key, _Compare1, _Alloc>&& __source)
633*38fd1498Szrj 	{ merge(__source); }
634*38fd1498Szrj #endif // C++17
635*38fd1498Szrj 
636*38fd1498Szrj #if __cplusplus >= 201103L
637*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
638*38fd1498Szrj       // DR 130. Associative erase should return an iterator.
639*38fd1498Szrj       /**
640*38fd1498Szrj        *  @brief Erases an element from a %set.
641*38fd1498Szrj        *  @param  __position  An iterator pointing to the element to be erased.
642*38fd1498Szrj        *  @return An iterator pointing to the element immediately following
643*38fd1498Szrj        *          @a __position prior to the element being erased. If no such
644*38fd1498Szrj        *          element exists, end() is returned.
645*38fd1498Szrj        *
646*38fd1498Szrj        *  This function erases an element, pointed to by the given iterator,
647*38fd1498Szrj        *  from a %set.  Note that this function only erases the element, and
648*38fd1498Szrj        *  that if the element is itself a pointer, the pointed-to memory is not
649*38fd1498Szrj        *  touched in any way.  Managing the pointer is the user's
650*38fd1498Szrj        *  responsibility.
651*38fd1498Szrj        */
652*38fd1498Szrj       _GLIBCXX_ABI_TAG_CXX11
653*38fd1498Szrj       iterator
654*38fd1498Szrj       erase(const_iterator __position)
655*38fd1498Szrj       { return _M_t.erase(__position); }
656*38fd1498Szrj #else
657*38fd1498Szrj       /**
658*38fd1498Szrj        *  @brief Erases an element from a %set.
659*38fd1498Szrj        *  @param  position  An iterator pointing to the element to be erased.
660*38fd1498Szrj        *
661*38fd1498Szrj        *  This function erases an element, pointed to by the given iterator,
662*38fd1498Szrj        *  from a %set.  Note that this function only erases the element, and
663*38fd1498Szrj        *  that if the element is itself a pointer, the pointed-to memory is not
664*38fd1498Szrj        *  touched in any way.  Managing the pointer is the user's
665*38fd1498Szrj        *  responsibility.
666*38fd1498Szrj        */
667*38fd1498Szrj       void
668*38fd1498Szrj       erase(iterator __position)
669*38fd1498Szrj       { _M_t.erase(__position); }
670*38fd1498Szrj #endif
671*38fd1498Szrj 
672*38fd1498Szrj       /**
673*38fd1498Szrj        *  @brief Erases elements according to the provided key.
674*38fd1498Szrj        *  @param  __x  Key of element to be erased.
675*38fd1498Szrj        *  @return  The number of elements erased.
676*38fd1498Szrj        *
677*38fd1498Szrj        *  This function erases all the elements located by the given key from
678*38fd1498Szrj        *  a %set.
679*38fd1498Szrj        *  Note that this function only erases the element, and that if
680*38fd1498Szrj        *  the element is itself a pointer, the pointed-to memory is not touched
681*38fd1498Szrj        *  in any way.  Managing the pointer is the user's responsibility.
682*38fd1498Szrj        */
683*38fd1498Szrj       size_type
684*38fd1498Szrj       erase(const key_type& __x)
685*38fd1498Szrj       { return _M_t.erase(__x); }
686*38fd1498Szrj 
687*38fd1498Szrj #if __cplusplus >= 201103L
688*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
689*38fd1498Szrj       // DR 130. Associative erase should return an iterator.
690*38fd1498Szrj       /**
691*38fd1498Szrj        *  @brief Erases a [__first,__last) range of elements from a %set.
692*38fd1498Szrj        *  @param  __first  Iterator pointing to the start of the range to be
693*38fd1498Szrj        *                 erased.
694*38fd1498Szrj 
695*38fd1498Szrj        *  @param __last Iterator pointing to the end of the range to
696*38fd1498Szrj        *  be erased.
697*38fd1498Szrj        *  @return The iterator @a __last.
698*38fd1498Szrj        *
699*38fd1498Szrj        *  This function erases a sequence of elements from a %set.
700*38fd1498Szrj        *  Note that this function only erases the element, and that if
701*38fd1498Szrj        *  the element is itself a pointer, the pointed-to memory is not touched
702*38fd1498Szrj        *  in any way.  Managing the pointer is the user's responsibility.
703*38fd1498Szrj        */
704*38fd1498Szrj       _GLIBCXX_ABI_TAG_CXX11
705*38fd1498Szrj       iterator
706*38fd1498Szrj       erase(const_iterator __first, const_iterator __last)
707*38fd1498Szrj       { return _M_t.erase(__first, __last); }
708*38fd1498Szrj #else
709*38fd1498Szrj       /**
710*38fd1498Szrj        *  @brief Erases a [first,last) range of elements from a %set.
711*38fd1498Szrj        *  @param  __first  Iterator pointing to the start of the range to be
712*38fd1498Szrj        *                 erased.
713*38fd1498Szrj        *  @param __last Iterator pointing to the end of the range to
714*38fd1498Szrj        *  be erased.
715*38fd1498Szrj        *
716*38fd1498Szrj        *  This function erases a sequence of elements from a %set.
717*38fd1498Szrj        *  Note that this function only erases the element, and that if
718*38fd1498Szrj        *  the element is itself a pointer, the pointed-to memory is not touched
719*38fd1498Szrj        *  in any way.  Managing the pointer is the user's responsibility.
720*38fd1498Szrj        */
721*38fd1498Szrj       void
722*38fd1498Szrj       erase(iterator __first, iterator __last)
723*38fd1498Szrj       { _M_t.erase(__first, __last); }
724*38fd1498Szrj #endif
725*38fd1498Szrj 
726*38fd1498Szrj       /**
727*38fd1498Szrj        *  Erases all elements in a %set.  Note that this function only erases
728*38fd1498Szrj        *  the elements, and that if the elements themselves are pointers, the
729*38fd1498Szrj        *  pointed-to memory is not touched in any way.  Managing the pointer is
730*38fd1498Szrj        *  the user's responsibility.
731*38fd1498Szrj        */
732*38fd1498Szrj       void
733*38fd1498Szrj       clear() _GLIBCXX_NOEXCEPT
734*38fd1498Szrj       { _M_t.clear(); }
735*38fd1498Szrj 
736*38fd1498Szrj       // set operations:
737*38fd1498Szrj 
738*38fd1498Szrj       //@{
739*38fd1498Szrj       /**
740*38fd1498Szrj        *  @brief  Finds the number of elements.
741*38fd1498Szrj        *  @param  __x  Element to located.
742*38fd1498Szrj        *  @return  Number of elements with specified key.
743*38fd1498Szrj        *
744*38fd1498Szrj        *  This function only makes sense for multisets; for set the result will
745*38fd1498Szrj        *  either be 0 (not present) or 1 (present).
746*38fd1498Szrj        */
747*38fd1498Szrj       size_type
748*38fd1498Szrj       count(const key_type& __x) const
749*38fd1498Szrj       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
750*38fd1498Szrj 
751*38fd1498Szrj #if __cplusplus > 201103L
752*38fd1498Szrj       template<typename _Kt>
753*38fd1498Szrj 	auto
754*38fd1498Szrj 	count(const _Kt& __x) const
755*38fd1498Szrj 	-> decltype(_M_t._M_count_tr(__x))
756*38fd1498Szrj 	{ return _M_t._M_count_tr(__x); }
757*38fd1498Szrj #endif
758*38fd1498Szrj       //@}
759*38fd1498Szrj 
760*38fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
761*38fd1498Szrj       // 214.  set::find() missing const overload
762*38fd1498Szrj       //@{
763*38fd1498Szrj       /**
764*38fd1498Szrj        *  @brief Tries to locate an element in a %set.
765*38fd1498Szrj        *  @param  __x  Element to be located.
766*38fd1498Szrj        *  @return  Iterator pointing to sought-after element, or end() if not
767*38fd1498Szrj        *           found.
768*38fd1498Szrj        *
769*38fd1498Szrj        *  This function takes a key and tries to locate the element with which
770*38fd1498Szrj        *  the key matches.  If successful the function returns an iterator
771*38fd1498Szrj        *  pointing to the sought after element.  If unsuccessful it returns the
772*38fd1498Szrj        *  past-the-end ( @c end() ) iterator.
773*38fd1498Szrj        */
774*38fd1498Szrj       iterator
775*38fd1498Szrj       find(const key_type& __x)
776*38fd1498Szrj       { return _M_t.find(__x); }
777*38fd1498Szrj 
778*38fd1498Szrj       const_iterator
779*38fd1498Szrj       find(const key_type& __x) const
780*38fd1498Szrj       { return _M_t.find(__x); }
781*38fd1498Szrj 
782*38fd1498Szrj #if __cplusplus > 201103L
783*38fd1498Szrj       template<typename _Kt>
784*38fd1498Szrj 	auto
785*38fd1498Szrj 	find(const _Kt& __x)
786*38fd1498Szrj 	-> decltype(iterator{_M_t._M_find_tr(__x)})
787*38fd1498Szrj 	{ return iterator{_M_t._M_find_tr(__x)}; }
788*38fd1498Szrj 
789*38fd1498Szrj       template<typename _Kt>
790*38fd1498Szrj 	auto
791*38fd1498Szrj 	find(const _Kt& __x) const
792*38fd1498Szrj 	-> decltype(const_iterator{_M_t._M_find_tr(__x)})
793*38fd1498Szrj 	{ return const_iterator{_M_t._M_find_tr(__x)}; }
794*38fd1498Szrj #endif
795*38fd1498Szrj       //@}
796*38fd1498Szrj 
797*38fd1498Szrj       //@{
798*38fd1498Szrj       /**
799*38fd1498Szrj        *  @brief Finds the beginning of a subsequence matching given key.
800*38fd1498Szrj        *  @param  __x  Key to be located.
801*38fd1498Szrj        *  @return  Iterator pointing to first element equal to or greater
802*38fd1498Szrj        *           than key, or end().
803*38fd1498Szrj        *
804*38fd1498Szrj        *  This function returns the first element of a subsequence of elements
805*38fd1498Szrj        *  that matches the given key.  If unsuccessful it returns an iterator
806*38fd1498Szrj        *  pointing to the first element that has a greater value than given key
807*38fd1498Szrj        *  or end() if no such element exists.
808*38fd1498Szrj        */
809*38fd1498Szrj       iterator
810*38fd1498Szrj       lower_bound(const key_type& __x)
811*38fd1498Szrj       { return _M_t.lower_bound(__x); }
812*38fd1498Szrj 
813*38fd1498Szrj       const_iterator
814*38fd1498Szrj       lower_bound(const key_type& __x) const
815*38fd1498Szrj       { return _M_t.lower_bound(__x); }
816*38fd1498Szrj 
817*38fd1498Szrj #if __cplusplus > 201103L
818*38fd1498Szrj       template<typename _Kt>
819*38fd1498Szrj 	auto
820*38fd1498Szrj 	lower_bound(const _Kt& __x)
821*38fd1498Szrj 	-> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
822*38fd1498Szrj 	{ return iterator(_M_t._M_lower_bound_tr(__x)); }
823*38fd1498Szrj 
824*38fd1498Szrj       template<typename _Kt>
825*38fd1498Szrj 	auto
826*38fd1498Szrj 	lower_bound(const _Kt& __x) const
827*38fd1498Szrj 	-> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
828*38fd1498Szrj 	{ return const_iterator(_M_t._M_lower_bound_tr(__x)); }
829*38fd1498Szrj #endif
830*38fd1498Szrj       //@}
831*38fd1498Szrj 
832*38fd1498Szrj       //@{
833*38fd1498Szrj       /**
834*38fd1498Szrj        *  @brief Finds the end of a subsequence matching given key.
835*38fd1498Szrj        *  @param  __x  Key to be located.
836*38fd1498Szrj        *  @return Iterator pointing to the first element
837*38fd1498Szrj        *          greater than key, or end().
838*38fd1498Szrj        */
839*38fd1498Szrj       iterator
840*38fd1498Szrj       upper_bound(const key_type& __x)
841*38fd1498Szrj       { return _M_t.upper_bound(__x); }
842*38fd1498Szrj 
843*38fd1498Szrj       const_iterator
844*38fd1498Szrj       upper_bound(const key_type& __x) const
845*38fd1498Szrj       { return _M_t.upper_bound(__x); }
846*38fd1498Szrj 
847*38fd1498Szrj #if __cplusplus > 201103L
848*38fd1498Szrj       template<typename _Kt>
849*38fd1498Szrj 	auto
850*38fd1498Szrj 	upper_bound(const _Kt& __x)
851*38fd1498Szrj 	-> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
852*38fd1498Szrj 	{ return iterator(_M_t._M_upper_bound_tr(__x)); }
853*38fd1498Szrj 
854*38fd1498Szrj       template<typename _Kt>
855*38fd1498Szrj 	auto
856*38fd1498Szrj 	upper_bound(const _Kt& __x) const
857*38fd1498Szrj 	-> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
858*38fd1498Szrj 	{ return const_iterator(_M_t._M_upper_bound_tr(__x)); }
859*38fd1498Szrj #endif
860*38fd1498Szrj       //@}
861*38fd1498Szrj 
862*38fd1498Szrj       //@{
863*38fd1498Szrj       /**
864*38fd1498Szrj        *  @brief Finds a subsequence matching given key.
865*38fd1498Szrj        *  @param  __x  Key to be located.
866*38fd1498Szrj        *  @return  Pair of iterators that possibly points to the subsequence
867*38fd1498Szrj        *           matching given key.
868*38fd1498Szrj        *
869*38fd1498Szrj        *  This function is equivalent to
870*38fd1498Szrj        *  @code
871*38fd1498Szrj        *    std::make_pair(c.lower_bound(val),
872*38fd1498Szrj        *                   c.upper_bound(val))
873*38fd1498Szrj        *  @endcode
874*38fd1498Szrj        *  (but is faster than making the calls separately).
875*38fd1498Szrj        *
876*38fd1498Szrj        *  This function probably only makes sense for multisets.
877*38fd1498Szrj        */
878*38fd1498Szrj       std::pair<iterator, iterator>
879*38fd1498Szrj       equal_range(const key_type& __x)
880*38fd1498Szrj       { return _M_t.equal_range(__x); }
881*38fd1498Szrj 
882*38fd1498Szrj       std::pair<const_iterator, const_iterator>
883*38fd1498Szrj       equal_range(const key_type& __x) const
884*38fd1498Szrj       { return _M_t.equal_range(__x); }
885*38fd1498Szrj 
886*38fd1498Szrj #if __cplusplus > 201103L
887*38fd1498Szrj       template<typename _Kt>
888*38fd1498Szrj 	auto
889*38fd1498Szrj 	equal_range(const _Kt& __x)
890*38fd1498Szrj 	-> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
891*38fd1498Szrj 	{ return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
892*38fd1498Szrj 
893*38fd1498Szrj       template<typename _Kt>
894*38fd1498Szrj 	auto
895*38fd1498Szrj 	equal_range(const _Kt& __x) const
896*38fd1498Szrj 	-> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
897*38fd1498Szrj 	{ return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
898*38fd1498Szrj #endif
899*38fd1498Szrj       //@}
900*38fd1498Szrj 
901*38fd1498Szrj       template<typename _K1, typename _C1, typename _A1>
902*38fd1498Szrj 	friend bool
903*38fd1498Szrj 	operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
904*38fd1498Szrj 
905*38fd1498Szrj       template<typename _K1, typename _C1, typename _A1>
906*38fd1498Szrj 	friend bool
907*38fd1498Szrj 	operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
908*38fd1498Szrj     };
909*38fd1498Szrj 
910*38fd1498Szrj #if __cpp_deduction_guides >= 201606
911*38fd1498Szrj 
912*38fd1498Szrj   template<typename _InputIterator,
913*38fd1498Szrj 	   typename _Compare =
914*38fd1498Szrj 	     less<typename iterator_traits<_InputIterator>::value_type>,
915*38fd1498Szrj 	   typename _Allocator =
916*38fd1498Szrj 	     allocator<typename iterator_traits<_InputIterator>::value_type>,
917*38fd1498Szrj 	   typename = _RequireInputIter<_InputIterator>,
918*38fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
919*38fd1498Szrj     set(_InputIterator, _InputIterator,
920*38fd1498Szrj 	_Compare = _Compare(), _Allocator = _Allocator())
921*38fd1498Szrj     -> set<typename iterator_traits<_InputIterator>::value_type,
922*38fd1498Szrj 	  _Compare, _Allocator>;
923*38fd1498Szrj 
924*38fd1498Szrj   template<typename _Key, typename _Compare = less<_Key>,
925*38fd1498Szrj 	   typename _Allocator = allocator<_Key>,
926*38fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
927*38fd1498Szrj     set(initializer_list<_Key>,
928*38fd1498Szrj 	_Compare = _Compare(), _Allocator = _Allocator())
929*38fd1498Szrj     -> set<_Key, _Compare, _Allocator>;
930*38fd1498Szrj 
931*38fd1498Szrj   template<typename _InputIterator, typename _Allocator,
932*38fd1498Szrj 	   typename = _RequireInputIter<_InputIterator>,
933*38fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
934*38fd1498Szrj     set(_InputIterator, _InputIterator, _Allocator)
935*38fd1498Szrj     -> set<typename iterator_traits<_InputIterator>::value_type,
936*38fd1498Szrj 	   less<typename iterator_traits<_InputIterator>::value_type>,
937*38fd1498Szrj 	   _Allocator>;
938*38fd1498Szrj 
939*38fd1498Szrj   template<typename _Key, typename _Allocator,
940*38fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
941*38fd1498Szrj     set(initializer_list<_Key>, _Allocator)
942*38fd1498Szrj     -> set<_Key, less<_Key>, _Allocator>;
943*38fd1498Szrj 
944*38fd1498Szrj #endif
945*38fd1498Szrj 
946*38fd1498Szrj   /**
947*38fd1498Szrj    *  @brief  Set equality comparison.
948*38fd1498Szrj    *  @param  __x  A %set.
949*38fd1498Szrj    *  @param  __y  A %set of the same type as @a x.
950*38fd1498Szrj    *  @return  True iff the size and elements of the sets are equal.
951*38fd1498Szrj    *
952*38fd1498Szrj    *  This is an equivalence relation.  It is linear in the size of the sets.
953*38fd1498Szrj    *  Sets are considered equivalent if their sizes are equal, and if
954*38fd1498Szrj    *  corresponding elements compare equal.
955*38fd1498Szrj   */
956*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
957*38fd1498Szrj     inline bool
958*38fd1498Szrj     operator==(const set<_Key, _Compare, _Alloc>& __x,
959*38fd1498Szrj 	       const set<_Key, _Compare, _Alloc>& __y)
960*38fd1498Szrj     { return __x._M_t == __y._M_t; }
961*38fd1498Szrj 
962*38fd1498Szrj   /**
963*38fd1498Szrj    *  @brief  Set ordering relation.
964*38fd1498Szrj    *  @param  __x  A %set.
965*38fd1498Szrj    *  @param  __y  A %set of the same type as @a x.
966*38fd1498Szrj    *  @return  True iff @a __x is lexicographically less than @a __y.
967*38fd1498Szrj    *
968*38fd1498Szrj    *  This is a total ordering relation.  It is linear in the size of the
969*38fd1498Szrj    *  sets.  The elements must be comparable with @c <.
970*38fd1498Szrj    *
971*38fd1498Szrj    *  See std::lexicographical_compare() for how the determination is made.
972*38fd1498Szrj   */
973*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
974*38fd1498Szrj     inline bool
975*38fd1498Szrj     operator<(const set<_Key, _Compare, _Alloc>& __x,
976*38fd1498Szrj 	      const set<_Key, _Compare, _Alloc>& __y)
977*38fd1498Szrj     { return __x._M_t < __y._M_t; }
978*38fd1498Szrj 
979*38fd1498Szrj   ///  Returns !(x == y).
980*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
981*38fd1498Szrj     inline bool
982*38fd1498Szrj     operator!=(const set<_Key, _Compare, _Alloc>& __x,
983*38fd1498Szrj 	       const set<_Key, _Compare, _Alloc>& __y)
984*38fd1498Szrj     { return !(__x == __y); }
985*38fd1498Szrj 
986*38fd1498Szrj   ///  Returns y < x.
987*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
988*38fd1498Szrj     inline bool
989*38fd1498Szrj     operator>(const set<_Key, _Compare, _Alloc>& __x,
990*38fd1498Szrj 	      const set<_Key, _Compare, _Alloc>& __y)
991*38fd1498Szrj     { return __y < __x; }
992*38fd1498Szrj 
993*38fd1498Szrj   ///  Returns !(y < x)
994*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
995*38fd1498Szrj     inline bool
996*38fd1498Szrj     operator<=(const set<_Key, _Compare, _Alloc>& __x,
997*38fd1498Szrj 	       const set<_Key, _Compare, _Alloc>& __y)
998*38fd1498Szrj     { return !(__y < __x); }
999*38fd1498Szrj 
1000*38fd1498Szrj   ///  Returns !(x < y)
1001*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
1002*38fd1498Szrj     inline bool
1003*38fd1498Szrj     operator>=(const set<_Key, _Compare, _Alloc>& __x,
1004*38fd1498Szrj 	       const set<_Key, _Compare, _Alloc>& __y)
1005*38fd1498Szrj     { return !(__x < __y); }
1006*38fd1498Szrj 
1007*38fd1498Szrj   /// See std::set::swap().
1008*38fd1498Szrj   template<typename _Key, typename _Compare, typename _Alloc>
1009*38fd1498Szrj     inline void
1010*38fd1498Szrj     swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
1011*38fd1498Szrj     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1012*38fd1498Szrj     { __x.swap(__y); }
1013*38fd1498Szrj 
1014*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER
1015*38fd1498Szrj 
1016*38fd1498Szrj #if __cplusplus > 201402L
1017*38fd1498Szrj   // Allow std::set access to internals of compatible sets.
1018*38fd1498Szrj   template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
1019*38fd1498Szrj     struct
1020*38fd1498Szrj     _Rb_tree_merge_helper<_GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>, _Cmp2>
1021*38fd1498Szrj     {
1022*38fd1498Szrj     private:
1023*38fd1498Szrj       friend class _GLIBCXX_STD_C::set<_Val, _Cmp1, _Alloc>;
1024*38fd1498Szrj 
1025*38fd1498Szrj       static auto&
1026*38fd1498Szrj       _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1027*38fd1498Szrj       { return __set._M_t; }
1028*38fd1498Szrj 
1029*38fd1498Szrj       static auto&
1030*38fd1498Szrj       _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1031*38fd1498Szrj       { return __set._M_t; }
1032*38fd1498Szrj     };
1033*38fd1498Szrj #endif // C++17
1034*38fd1498Szrj 
1035*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
1036*38fd1498Szrj } //namespace std
1037*38fd1498Szrj #endif /* _STL_SET_H */
1038