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