1*404b540aSrobert // Set implementation -*- C++ -*-
2*404b540aSrobert
3*404b540aSrobert // Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the
7*404b540aSrobert // terms of the GNU General Public License as published by the
8*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert // any later version.
10*404b540aSrobert
11*404b540aSrobert // This library is distributed in the hope that it will be useful,
12*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*404b540aSrobert // GNU General Public License for more details.
15*404b540aSrobert
16*404b540aSrobert // You should have received a copy of the GNU General Public License along
17*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free
18*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert // USA.
20*404b540aSrobert
21*404b540aSrobert // As a special exception, you may use this file as part of a free software
22*404b540aSrobert // library without restriction. Specifically, if other files instantiate
23*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert // this file and link it with other files to produce an executable, this
25*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert // the GNU General Public License. This exception does not however
27*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert // the GNU General Public License.
29*404b540aSrobert
30*404b540aSrobert /*
31*404b540aSrobert *
32*404b540aSrobert * Copyright (c) 1994
33*404b540aSrobert * Hewlett-Packard Company
34*404b540aSrobert *
35*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software
36*404b540aSrobert * and its documentation for any purpose is hereby granted without fee,
37*404b540aSrobert * provided that the above copyright notice appear in all copies and
38*404b540aSrobert * that both that copyright notice and this permission notice appear
39*404b540aSrobert * in supporting documentation. Hewlett-Packard Company makes no
40*404b540aSrobert * representations about the suitability of this software for any
41*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty.
42*404b540aSrobert *
43*404b540aSrobert *
44*404b540aSrobert * Copyright (c) 1996,1997
45*404b540aSrobert * Silicon Graphics Computer Systems, Inc.
46*404b540aSrobert *
47*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software
48*404b540aSrobert * and its documentation for any purpose is hereby granted without fee,
49*404b540aSrobert * provided that the above copyright notice appear in all copies and
50*404b540aSrobert * that both that copyright notice and this permission notice appear
51*404b540aSrobert * in supporting documentation. Silicon Graphics makes no
52*404b540aSrobert * representations about the suitability of this software for any
53*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty.
54*404b540aSrobert */
55*404b540aSrobert
56*404b540aSrobert /** @file stl_set.h
57*404b540aSrobert * This is an internal header file, included by other library headers.
58*404b540aSrobert * You should not attempt to use it directly.
59*404b540aSrobert */
60*404b540aSrobert
61*404b540aSrobert #ifndef _SET_H
62*404b540aSrobert #define _SET_H 1
63*404b540aSrobert
64*404b540aSrobert #include <bits/concept_check.h>
65*404b540aSrobert
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std,_GLIBCXX_STD)66*404b540aSrobert _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
67*404b540aSrobert
68*404b540aSrobert /**
69*404b540aSrobert * @brief A standard container made up of unique keys, which can be
70*404b540aSrobert * retrieved in logarithmic time.
71*404b540aSrobert *
72*404b540aSrobert * @ingroup Containers
73*404b540aSrobert * @ingroup Assoc_containers
74*404b540aSrobert *
75*404b540aSrobert * Meets the requirements of a <a href="tables.html#65">container</a>, a
76*404b540aSrobert * <a href="tables.html#66">reversible container</a>, and an
77*404b540aSrobert * <a href="tables.html#69">associative container</a> (using unique keys).
78*404b540aSrobert *
79*404b540aSrobert * Sets support bidirectional iterators.
80*404b540aSrobert *
81*404b540aSrobert * @param Key Type of key objects.
82*404b540aSrobert * @param Compare Comparison function object type, defaults to less<Key>.
83*404b540aSrobert * @param Alloc Allocator type, defaults to allocator<Key>.
84*404b540aSrobert *
85*404b540aSrobert * @if maint
86*404b540aSrobert * The private tree data is declared exactly the same way for set and
87*404b540aSrobert * multiset; the distinction is made entirely in how the tree functions are
88*404b540aSrobert * called (*_unique versus *_equal, same as the standard).
89*404b540aSrobert * @endif
90*404b540aSrobert */
91*404b540aSrobert template<class _Key, class _Compare = std::less<_Key>,
92*404b540aSrobert class _Alloc = std::allocator<_Key> >
93*404b540aSrobert class set
94*404b540aSrobert {
95*404b540aSrobert // concept requirements
96*404b540aSrobert typedef typename _Alloc::value_type _Alloc_value_type;
97*404b540aSrobert __glibcxx_class_requires(_Key, _SGIAssignableConcept)
98*404b540aSrobert __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
99*404b540aSrobert _BinaryFunctionConcept)
100*404b540aSrobert __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
101*404b540aSrobert
102*404b540aSrobert public:
103*404b540aSrobert // typedefs:
104*404b540aSrobert //@{
105*404b540aSrobert /// Public typedefs.
106*404b540aSrobert typedef _Key key_type;
107*404b540aSrobert typedef _Key value_type;
108*404b540aSrobert typedef _Compare key_compare;
109*404b540aSrobert typedef _Compare value_compare;
110*404b540aSrobert typedef _Alloc allocator_type;
111*404b540aSrobert //@}
112*404b540aSrobert
113*404b540aSrobert private:
114*404b540aSrobert typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
115*404b540aSrobert
116*404b540aSrobert typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
117*404b540aSrobert key_compare, _Key_alloc_type> _Rep_type;
118*404b540aSrobert _Rep_type _M_t; // red-black tree representing set
119*404b540aSrobert
120*404b540aSrobert public:
121*404b540aSrobert //@{
122*404b540aSrobert /// Iterator-related typedefs.
123*404b540aSrobert typedef typename _Key_alloc_type::pointer pointer;
124*404b540aSrobert typedef typename _Key_alloc_type::const_pointer const_pointer;
125*404b540aSrobert typedef typename _Key_alloc_type::reference reference;
126*404b540aSrobert typedef typename _Key_alloc_type::const_reference const_reference;
127*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS
128*404b540aSrobert // DR 103. set::iterator is required to be modifiable,
129*404b540aSrobert // but this allows modification of keys.
130*404b540aSrobert typedef typename _Rep_type::const_iterator iterator;
131*404b540aSrobert typedef typename _Rep_type::const_iterator const_iterator;
132*404b540aSrobert typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
133*404b540aSrobert typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
134*404b540aSrobert typedef typename _Rep_type::size_type size_type;
135*404b540aSrobert typedef typename _Rep_type::difference_type difference_type;
136*404b540aSrobert //@}
137*404b540aSrobert
138*404b540aSrobert // allocation/deallocation
139*404b540aSrobert /// Default constructor creates no elements.
140*404b540aSrobert set()
141*404b540aSrobert : _M_t(_Compare(), allocator_type()) {}
142*404b540aSrobert
143*404b540aSrobert /**
144*404b540aSrobert * @brief Default constructor creates no elements.
145*404b540aSrobert *
146*404b540aSrobert * @param comp Comparator to use.
147*404b540aSrobert * @param a Allocator to use.
148*404b540aSrobert */
149*404b540aSrobert explicit
150*404b540aSrobert set(const _Compare& __comp,
151*404b540aSrobert const allocator_type& __a = allocator_type())
152*404b540aSrobert : _M_t(__comp, __a) {}
153*404b540aSrobert
154*404b540aSrobert /**
155*404b540aSrobert * @brief Builds a %set from a range.
156*404b540aSrobert * @param first An input iterator.
157*404b540aSrobert * @param last An input iterator.
158*404b540aSrobert *
159*404b540aSrobert * Create a %set consisting of copies of the elements from [first,last).
160*404b540aSrobert * This is linear in N if the range is already sorted, and NlogN
161*404b540aSrobert * otherwise (where N is distance(first,last)).
162*404b540aSrobert */
163*404b540aSrobert template<class _InputIterator>
164*404b540aSrobert set(_InputIterator __first, _InputIterator __last)
165*404b540aSrobert : _M_t(_Compare(), allocator_type())
166*404b540aSrobert { _M_t._M_insert_unique(__first, __last); }
167*404b540aSrobert
168*404b540aSrobert /**
169*404b540aSrobert * @brief Builds a %set from a range.
170*404b540aSrobert * @param first An input iterator.
171*404b540aSrobert * @param last An input iterator.
172*404b540aSrobert * @param comp A comparison functor.
173*404b540aSrobert * @param a An allocator object.
174*404b540aSrobert *
175*404b540aSrobert * Create a %set consisting of copies of the elements from [first,last).
176*404b540aSrobert * This is linear in N if the range is already sorted, and NlogN
177*404b540aSrobert * otherwise (where N is distance(first,last)).
178*404b540aSrobert */
179*404b540aSrobert template<class _InputIterator>
180*404b540aSrobert set(_InputIterator __first, _InputIterator __last,
181*404b540aSrobert const _Compare& __comp,
182*404b540aSrobert const allocator_type& __a = allocator_type())
183*404b540aSrobert : _M_t(__comp, __a)
184*404b540aSrobert { _M_t._M_insert_unique(__first, __last); }
185*404b540aSrobert
186*404b540aSrobert /**
187*404b540aSrobert * @brief Set copy constructor.
188*404b540aSrobert * @param x A %set of identical element and allocator types.
189*404b540aSrobert *
190*404b540aSrobert * The newly-created %set uses a copy of the allocation object used
191*404b540aSrobert * by @a x.
192*404b540aSrobert */
193*404b540aSrobert set(const set<_Key,_Compare,_Alloc>& __x)
194*404b540aSrobert : _M_t(__x._M_t) { }
195*404b540aSrobert
196*404b540aSrobert /**
197*404b540aSrobert * @brief Set assignment operator.
198*404b540aSrobert * @param x A %set of identical element and allocator types.
199*404b540aSrobert *
200*404b540aSrobert * All the elements of @a x are copied, but unlike the copy constructor,
201*404b540aSrobert * the allocator object is not copied.
202*404b540aSrobert */
203*404b540aSrobert set<_Key,_Compare,_Alloc>&
204*404b540aSrobert operator=(const set<_Key, _Compare, _Alloc>& __x)
205*404b540aSrobert {
206*404b540aSrobert _M_t = __x._M_t;
207*404b540aSrobert return *this;
208*404b540aSrobert }
209*404b540aSrobert
210*404b540aSrobert // accessors:
211*404b540aSrobert
212*404b540aSrobert /// Returns the comparison object with which the %set was constructed.
213*404b540aSrobert key_compare
214*404b540aSrobert key_comp() const
215*404b540aSrobert { return _M_t.key_comp(); }
216*404b540aSrobert /// Returns the comparison object with which the %set was constructed.
217*404b540aSrobert value_compare
218*404b540aSrobert value_comp() const
219*404b540aSrobert { return _M_t.key_comp(); }
220*404b540aSrobert /// Returns the allocator object with which the %set was constructed.
221*404b540aSrobert allocator_type
222*404b540aSrobert get_allocator() const
223*404b540aSrobert { return _M_t.get_allocator(); }
224*404b540aSrobert
225*404b540aSrobert /**
226*404b540aSrobert * Returns a read/write iterator that points to the first element in the
227*404b540aSrobert * %set. Iteration is done in ascending order according to the keys.
228*404b540aSrobert */
229*404b540aSrobert iterator
230*404b540aSrobert begin() const
231*404b540aSrobert { return _M_t.begin(); }
232*404b540aSrobert
233*404b540aSrobert /**
234*404b540aSrobert * Returns a read/write iterator that points one past the last element in
235*404b540aSrobert * the %set. Iteration is done in ascending order according to the keys.
236*404b540aSrobert */
237*404b540aSrobert iterator
238*404b540aSrobert end() const
239*404b540aSrobert { return _M_t.end(); }
240*404b540aSrobert
241*404b540aSrobert /**
242*404b540aSrobert * Returns a read/write reverse iterator that points to the last element
243*404b540aSrobert * in the %set. Iteration is done in descending order according to the
244*404b540aSrobert * keys.
245*404b540aSrobert */
246*404b540aSrobert reverse_iterator
247*404b540aSrobert rbegin() const
248*404b540aSrobert { return _M_t.rbegin(); }
249*404b540aSrobert
250*404b540aSrobert /**
251*404b540aSrobert * Returns a read-only (constant) reverse iterator that points to the
252*404b540aSrobert * last pair in the %map. Iteration is done in descending order
253*404b540aSrobert * according to the keys.
254*404b540aSrobert */
255*404b540aSrobert reverse_iterator
256*404b540aSrobert rend() const
257*404b540aSrobert { return _M_t.rend(); }
258*404b540aSrobert
259*404b540aSrobert /// Returns true if the %set is empty.
260*404b540aSrobert bool
261*404b540aSrobert empty() const
262*404b540aSrobert { return _M_t.empty(); }
263*404b540aSrobert
264*404b540aSrobert /// Returns the size of the %set.
265*404b540aSrobert size_type
266*404b540aSrobert size() const
267*404b540aSrobert { return _M_t.size(); }
268*404b540aSrobert
269*404b540aSrobert /// Returns the maximum size of the %set.
270*404b540aSrobert size_type
271*404b540aSrobert max_size() const
272*404b540aSrobert { return _M_t.max_size(); }
273*404b540aSrobert
274*404b540aSrobert /**
275*404b540aSrobert * @brief Swaps data with another %set.
276*404b540aSrobert * @param x A %set of the same element and allocator types.
277*404b540aSrobert *
278*404b540aSrobert * This exchanges the elements between two sets in constant time.
279*404b540aSrobert * (It is only swapping a pointer, an integer, and an instance of
280*404b540aSrobert * the @c Compare type (which itself is often stateless and empty), so it
281*404b540aSrobert * should be quite fast.)
282*404b540aSrobert * Note that the global std::swap() function is specialized such that
283*404b540aSrobert * std::swap(s1,s2) will feed to this function.
284*404b540aSrobert */
285*404b540aSrobert void
286*404b540aSrobert swap(set<_Key,_Compare,_Alloc>& __x)
287*404b540aSrobert { _M_t.swap(__x._M_t); }
288*404b540aSrobert
289*404b540aSrobert // insert/erase
290*404b540aSrobert /**
291*404b540aSrobert * @brief Attempts to insert an element into the %set.
292*404b540aSrobert * @param x Element to be inserted.
293*404b540aSrobert * @return A pair, of which the first element is an iterator that points
294*404b540aSrobert * to the possibly inserted element, and the second is a bool
295*404b540aSrobert * that is true if the element was actually inserted.
296*404b540aSrobert *
297*404b540aSrobert * This function attempts to insert an element into the %set. A %set
298*404b540aSrobert * relies on unique keys and thus an element is only inserted if it is
299*404b540aSrobert * not already present in the %set.
300*404b540aSrobert *
301*404b540aSrobert * Insertion requires logarithmic time.
302*404b540aSrobert */
303*404b540aSrobert std::pair<iterator,bool>
304*404b540aSrobert insert(const value_type& __x)
305*404b540aSrobert {
306*404b540aSrobert std::pair<typename _Rep_type::iterator, bool> __p =
307*404b540aSrobert _M_t._M_insert_unique(__x);
308*404b540aSrobert return std::pair<iterator, bool>(__p.first, __p.second);
309*404b540aSrobert }
310*404b540aSrobert
311*404b540aSrobert /**
312*404b540aSrobert * @brief Attempts to insert an element into the %set.
313*404b540aSrobert * @param position An iterator that serves as a hint as to where the
314*404b540aSrobert * element should be inserted.
315*404b540aSrobert * @param x Element to be inserted.
316*404b540aSrobert * @return An iterator that points to the element with key of @a x (may
317*404b540aSrobert * or may not be the element passed in).
318*404b540aSrobert *
319*404b540aSrobert * This function is not concerned about whether the insertion took place,
320*404b540aSrobert * and thus does not return a boolean like the single-argument insert()
321*404b540aSrobert * does. Note that the first parameter is only a hint and can
322*404b540aSrobert * potentially improve the performance of the insertion process. A bad
323*404b540aSrobert * hint would cause no gains in efficiency.
324*404b540aSrobert *
325*404b540aSrobert * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
326*404b540aSrobert * for more on "hinting".
327*404b540aSrobert *
328*404b540aSrobert * Insertion requires logarithmic time (if the hint is not taken).
329*404b540aSrobert */
330*404b540aSrobert iterator
331*404b540aSrobert insert(iterator __position, const value_type& __x)
332*404b540aSrobert { return _M_t._M_insert_unique(__position, __x); }
333*404b540aSrobert
334*404b540aSrobert /**
335*404b540aSrobert * @brief A template function that attemps to insert a range of elements.
336*404b540aSrobert * @param first Iterator pointing to the start of the range to be
337*404b540aSrobert * inserted.
338*404b540aSrobert * @param last Iterator pointing to the end of the range.
339*404b540aSrobert *
340*404b540aSrobert * Complexity similar to that of the range constructor.
341*404b540aSrobert */
342*404b540aSrobert template<class _InputIterator>
343*404b540aSrobert void
344*404b540aSrobert insert(_InputIterator __first, _InputIterator __last)
345*404b540aSrobert { _M_t._M_insert_unique(__first, __last); }
346*404b540aSrobert
347*404b540aSrobert /**
348*404b540aSrobert * @brief Erases an element from a %set.
349*404b540aSrobert * @param position An iterator pointing to the element to be erased.
350*404b540aSrobert *
351*404b540aSrobert * This function erases an element, pointed to by the given iterator,
352*404b540aSrobert * from a %set. Note that this function only erases the element, and
353*404b540aSrobert * that if the element is itself a pointer, the pointed-to memory is not
354*404b540aSrobert * touched in any way. Managing the pointer is the user's responsibilty.
355*404b540aSrobert */
356*404b540aSrobert void
357*404b540aSrobert erase(iterator __position)
358*404b540aSrobert { _M_t.erase(__position); }
359*404b540aSrobert
360*404b540aSrobert /**
361*404b540aSrobert * @brief Erases elements according to the provided key.
362*404b540aSrobert * @param x Key of element to be erased.
363*404b540aSrobert * @return The number of elements erased.
364*404b540aSrobert *
365*404b540aSrobert * This function erases all the elements located by the given key from
366*404b540aSrobert * a %set.
367*404b540aSrobert * Note that this function only erases the element, and that if
368*404b540aSrobert * the element is itself a pointer, the pointed-to memory is not touched
369*404b540aSrobert * in any way. Managing the pointer is the user's responsibilty.
370*404b540aSrobert */
371*404b540aSrobert size_type
372*404b540aSrobert erase(const key_type& __x)
373*404b540aSrobert { return _M_t.erase(__x); }
374*404b540aSrobert
375*404b540aSrobert /**
376*404b540aSrobert * @brief Erases a [first,last) range of elements from a %set.
377*404b540aSrobert * @param first Iterator pointing to the start of the range to be
378*404b540aSrobert * erased.
379*404b540aSrobert * @param last Iterator pointing to the end of the range to be erased.
380*404b540aSrobert *
381*404b540aSrobert * This function erases a sequence of elements from a %set.
382*404b540aSrobert * Note that this function only erases the element, and that if
383*404b540aSrobert * the element is itself a pointer, the pointed-to memory is not touched
384*404b540aSrobert * in any way. Managing the pointer is the user's responsibilty.
385*404b540aSrobert */
386*404b540aSrobert void
387*404b540aSrobert erase(iterator __first, iterator __last)
388*404b540aSrobert { _M_t.erase(__first, __last); }
389*404b540aSrobert
390*404b540aSrobert /**
391*404b540aSrobert * Erases all elements in a %set. Note that this function only erases
392*404b540aSrobert * the elements, and that if the elements themselves are pointers, the
393*404b540aSrobert * pointed-to memory is not touched in any way. Managing the pointer is
394*404b540aSrobert * the user's responsibilty.
395*404b540aSrobert */
396*404b540aSrobert void
397*404b540aSrobert clear()
398*404b540aSrobert { _M_t.clear(); }
399*404b540aSrobert
400*404b540aSrobert // set operations:
401*404b540aSrobert
402*404b540aSrobert /**
403*404b540aSrobert * @brief Finds the number of elements.
404*404b540aSrobert * @param x Element to located.
405*404b540aSrobert * @return Number of elements with specified key.
406*404b540aSrobert *
407*404b540aSrobert * This function only makes sense for multisets; for set the result will
408*404b540aSrobert * either be 0 (not present) or 1 (present).
409*404b540aSrobert */
410*404b540aSrobert size_type
411*404b540aSrobert count(const key_type& __x) const
412*404b540aSrobert { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
413*404b540aSrobert
414*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS
415*404b540aSrobert // 214. set::find() missing const overload
416*404b540aSrobert //@{
417*404b540aSrobert /**
418*404b540aSrobert * @brief Tries to locate an element in a %set.
419*404b540aSrobert * @param x Element to be located.
420*404b540aSrobert * @return Iterator pointing to sought-after element, or end() if not
421*404b540aSrobert * found.
422*404b540aSrobert *
423*404b540aSrobert * This function takes a key and tries to locate the element with which
424*404b540aSrobert * the key matches. If successful the function returns an iterator
425*404b540aSrobert * pointing to the sought after element. If unsuccessful it returns the
426*404b540aSrobert * past-the-end ( @c end() ) iterator.
427*404b540aSrobert */
428*404b540aSrobert iterator
429*404b540aSrobert find(const key_type& __x)
430*404b540aSrobert { return _M_t.find(__x); }
431*404b540aSrobert
432*404b540aSrobert const_iterator
433*404b540aSrobert find(const key_type& __x) const
434*404b540aSrobert { return _M_t.find(__x); }
435*404b540aSrobert //@}
436*404b540aSrobert
437*404b540aSrobert //@{
438*404b540aSrobert /**
439*404b540aSrobert * @brief Finds the beginning of a subsequence matching given key.
440*404b540aSrobert * @param x Key to be located.
441*404b540aSrobert * @return Iterator pointing to first element equal to or greater
442*404b540aSrobert * than key, or end().
443*404b540aSrobert *
444*404b540aSrobert * This function returns the first element of a subsequence of elements
445*404b540aSrobert * that matches the given key. If unsuccessful it returns an iterator
446*404b540aSrobert * pointing to the first element that has a greater value than given key
447*404b540aSrobert * or end() if no such element exists.
448*404b540aSrobert */
449*404b540aSrobert iterator
450*404b540aSrobert lower_bound(const key_type& __x)
451*404b540aSrobert { return _M_t.lower_bound(__x); }
452*404b540aSrobert
453*404b540aSrobert const_iterator
454*404b540aSrobert lower_bound(const key_type& __x) const
455*404b540aSrobert { return _M_t.lower_bound(__x); }
456*404b540aSrobert //@}
457*404b540aSrobert
458*404b540aSrobert //@{
459*404b540aSrobert /**
460*404b540aSrobert * @brief Finds the end of a subsequence matching given key.
461*404b540aSrobert * @param x Key to be located.
462*404b540aSrobert * @return Iterator pointing to the first element
463*404b540aSrobert * greater than key, or end().
464*404b540aSrobert */
465*404b540aSrobert iterator
466*404b540aSrobert upper_bound(const key_type& __x)
467*404b540aSrobert { return _M_t.upper_bound(__x); }
468*404b540aSrobert
469*404b540aSrobert const_iterator
470*404b540aSrobert upper_bound(const key_type& __x) const
471*404b540aSrobert { return _M_t.upper_bound(__x); }
472*404b540aSrobert //@}
473*404b540aSrobert
474*404b540aSrobert //@{
475*404b540aSrobert /**
476*404b540aSrobert * @brief Finds a subsequence matching given key.
477*404b540aSrobert * @param x Key to be located.
478*404b540aSrobert * @return Pair of iterators that possibly points to the subsequence
479*404b540aSrobert * matching given key.
480*404b540aSrobert *
481*404b540aSrobert * This function is equivalent to
482*404b540aSrobert * @code
483*404b540aSrobert * std::make_pair(c.lower_bound(val),
484*404b540aSrobert * c.upper_bound(val))
485*404b540aSrobert * @endcode
486*404b540aSrobert * (but is faster than making the calls separately).
487*404b540aSrobert *
488*404b540aSrobert * This function probably only makes sense for multisets.
489*404b540aSrobert */
490*404b540aSrobert std::pair<iterator, iterator>
491*404b540aSrobert equal_range(const key_type& __x)
492*404b540aSrobert { return _M_t.equal_range(__x); }
493*404b540aSrobert
494*404b540aSrobert std::pair<const_iterator, const_iterator>
495*404b540aSrobert equal_range(const key_type& __x) const
496*404b540aSrobert { return _M_t.equal_range(__x); }
497*404b540aSrobert //@}
498*404b540aSrobert
499*404b540aSrobert template<class _K1, class _C1, class _A1>
500*404b540aSrobert friend bool
501*404b540aSrobert operator== (const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
502*404b540aSrobert
503*404b540aSrobert template<class _K1, class _C1, class _A1>
504*404b540aSrobert friend bool
505*404b540aSrobert operator< (const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
506*404b540aSrobert };
507*404b540aSrobert
508*404b540aSrobert
509*404b540aSrobert /**
510*404b540aSrobert * @brief Set equality comparison.
511*404b540aSrobert * @param x A %set.
512*404b540aSrobert * @param y A %set of the same type as @a x.
513*404b540aSrobert * @return True iff the size and elements of the sets are equal.
514*404b540aSrobert *
515*404b540aSrobert * This is an equivalence relation. It is linear in the size of the sets.
516*404b540aSrobert * Sets are considered equivalent if their sizes are equal, and if
517*404b540aSrobert * corresponding elements compare equal.
518*404b540aSrobert */
519*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
520*404b540aSrobert inline bool
521*404b540aSrobert operator==(const set<_Key, _Compare, _Alloc>& __x,
522*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
523*404b540aSrobert { return __x._M_t == __y._M_t; }
524*404b540aSrobert
525*404b540aSrobert /**
526*404b540aSrobert * @brief Set ordering relation.
527*404b540aSrobert * @param x A %set.
528*404b540aSrobert * @param y A %set of the same type as @a x.
529*404b540aSrobert * @return True iff @a x is lexicographically less than @a y.
530*404b540aSrobert *
531*404b540aSrobert * This is a total ordering relation. It is linear in the size of the
532*404b540aSrobert * maps. The elements must be comparable with @c <.
533*404b540aSrobert *
534*404b540aSrobert * See std::lexicographical_compare() for how the determination is made.
535*404b540aSrobert */
536*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
537*404b540aSrobert inline bool
538*404b540aSrobert operator<(const set<_Key, _Compare, _Alloc>& __x,
539*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
540*404b540aSrobert { return __x._M_t < __y._M_t; }
541*404b540aSrobert
542*404b540aSrobert /// Returns !(x == y).
543*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
544*404b540aSrobert inline bool
545*404b540aSrobert operator!=(const set<_Key, _Compare, _Alloc>& __x,
546*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
547*404b540aSrobert { return !(__x == __y); }
548*404b540aSrobert
549*404b540aSrobert /// Returns y < x.
550*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
551*404b540aSrobert inline bool
552*404b540aSrobert operator>(const set<_Key, _Compare, _Alloc>& __x,
553*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
554*404b540aSrobert { return __y < __x; }
555*404b540aSrobert
556*404b540aSrobert /// Returns !(y < x)
557*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
558*404b540aSrobert inline bool
559*404b540aSrobert operator<=(const set<_Key, _Compare, _Alloc>& __x,
560*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
561*404b540aSrobert { return !(__y < __x); }
562*404b540aSrobert
563*404b540aSrobert /// Returns !(x < y)
564*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
565*404b540aSrobert inline bool
566*404b540aSrobert operator>=(const set<_Key, _Compare, _Alloc>& __x,
567*404b540aSrobert const set<_Key, _Compare, _Alloc>& __y)
568*404b540aSrobert { return !(__x < __y); }
569*404b540aSrobert
570*404b540aSrobert /// See std::set::swap().
571*404b540aSrobert template<class _Key, class _Compare, class _Alloc>
572*404b540aSrobert inline void
swap(set<_Key,_Compare,_Alloc> & __x,set<_Key,_Compare,_Alloc> & __y)573*404b540aSrobert swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
574*404b540aSrobert { __x.swap(__y); }
575*404b540aSrobert
576*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE
577*404b540aSrobert
578*404b540aSrobert #endif /* _SET_H */
579