]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_set.h
* many: Replace uses of __GXX_EXPERIMENTAL_CXX0X__ with __cplusplus.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_set.h
1 // Set implementation -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011, 2012 Free Software Foundation, Inc.
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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25
26 /*
27 *
28 * Copyright (c) 1994
29 * Hewlett-Packard Company
30 *
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
38 *
39 *
40 * Copyright (c) 1996,1997
41 * Silicon Graphics Computer Systems, Inc.
42 *
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
50 */
51
52 /** @file bits/stl_set.h
53 * This is an internal header file, included by other library headers.
54 * Do not attempt to use it directly. @headername{set}
55 */
56
57 #ifndef _STL_SET_H
58 #define _STL_SET_H 1
59
60 #include <bits/concept_check.h>
61 #if __cplusplus >= 201103L
62 #include <initializer_list>
63 #endif
64
65 namespace std _GLIBCXX_VISIBILITY(default)
66 {
67 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68
69 /**
70 * @brief A standard container made up of unique keys, which can be
71 * retrieved in logarithmic time.
72 *
73 * @ingroup associative_containers
74 *
75 * @tparam _Key Type of key objects.
76 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
77 * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
78 *
79 * Meets the requirements of a <a href="tables.html#65">container</a>, a
80 * <a href="tables.html#66">reversible container</a>, and an
81 * <a href="tables.html#69">associative container</a> (using unique keys).
82 *
83 * Sets support bidirectional iterators.
84 *
85 * The private tree data is declared exactly the same way for set and
86 * multiset; the distinction is made entirely in how the tree functions are
87 * called (*_unique versus *_equal, same as the standard).
88 */
89 template<typename _Key, typename _Compare = std::less<_Key>,
90 typename _Alloc = std::allocator<_Key> >
91 class set
92 {
93 // concept requirements
94 typedef typename _Alloc::value_type _Alloc_value_type;
95 __glibcxx_class_requires(_Key, _SGIAssignableConcept)
96 __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
97 _BinaryFunctionConcept)
98 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
99
100 public:
101 // typedefs:
102 //@{
103 /// Public typedefs.
104 typedef _Key key_type;
105 typedef _Key value_type;
106 typedef _Compare key_compare;
107 typedef _Compare value_compare;
108 typedef _Alloc allocator_type;
109 //@}
110
111 private:
112 typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
113
114 typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
115 key_compare, _Key_alloc_type> _Rep_type;
116 _Rep_type _M_t; // Red-black tree representing set.
117
118 public:
119 //@{
120 /// Iterator-related typedefs.
121 typedef typename _Key_alloc_type::pointer pointer;
122 typedef typename _Key_alloc_type::const_pointer const_pointer;
123 typedef typename _Key_alloc_type::reference reference;
124 typedef typename _Key_alloc_type::const_reference const_reference;
125 // _GLIBCXX_RESOLVE_LIB_DEFECTS
126 // DR 103. set::iterator is required to be modifiable,
127 // but this allows modification of keys.
128 typedef typename _Rep_type::const_iterator iterator;
129 typedef typename _Rep_type::const_iterator const_iterator;
130 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
131 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
132 typedef typename _Rep_type::size_type size_type;
133 typedef typename _Rep_type::difference_type difference_type;
134 //@}
135
136 // allocation/deallocation
137 /**
138 * @brief Default constructor creates no elements.
139 */
140 set()
141 : _M_t() { }
142
143 /**
144 * @brief Creates a %set with no elements.
145 * @param __comp Comparator to use.
146 * @param __a An allocator object.
147 */
148 explicit
149 set(const _Compare& __comp,
150 const allocator_type& __a = allocator_type())
151 : _M_t(__comp, _Key_alloc_type(__a)) { }
152
153 /**
154 * @brief Builds a %set from a range.
155 * @param __first An input iterator.
156 * @param __last An input iterator.
157 *
158 * Create a %set consisting of copies of the elements from
159 * [__first,__last). This is linear in N if the range is
160 * already sorted, and NlogN otherwise (where N is
161 * distance(__first,__last)).
162 */
163 template<typename _InputIterator>
164 set(_InputIterator __first, _InputIterator __last)
165 : _M_t()
166 { _M_t._M_insert_unique(__first, __last); }
167
168 /**
169 * @brief Builds a %set from a range.
170 * @param __first An input iterator.
171 * @param __last An input iterator.
172 * @param __comp A comparison functor.
173 * @param __a An allocator object.
174 *
175 * Create a %set consisting of copies of the elements from
176 * [__first,__last). This is linear in N if the range is
177 * already sorted, and NlogN otherwise (where N is
178 * distance(__first,__last)).
179 */
180 template<typename _InputIterator>
181 set(_InputIterator __first, _InputIterator __last,
182 const _Compare& __comp,
183 const allocator_type& __a = allocator_type())
184 : _M_t(__comp, _Key_alloc_type(__a))
185 { _M_t._M_insert_unique(__first, __last); }
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 */
194 set(const set& __x)
195 : _M_t(__x._M_t) { }
196
197 #if __cplusplus >= 201103L
198 /**
199 * @brief %Set move constructor
200 * @param __x A %set of identical element and allocator types.
201 *
202 * The newly-created %set contains the exact contents of @a x.
203 * The contents of @a x are a valid, but unspecified %set.
204 */
205 set(set&& __x)
206 noexcept(is_nothrow_copy_constructible<_Compare>::value)
207 : _M_t(std::move(__x._M_t)) { }
208
209 /**
210 * @brief Builds a %set from an initializer_list.
211 * @param __l An initializer_list.
212 * @param __comp A comparison functor.
213 * @param __a An allocator object.
214 *
215 * Create a %set consisting of copies of the elements in the list.
216 * This is linear in N if the list is already sorted, and NlogN
217 * otherwise (where N is @a __l.size()).
218 */
219 set(initializer_list<value_type> __l,
220 const _Compare& __comp = _Compare(),
221 const allocator_type& __a = allocator_type())
222 : _M_t(__comp, _Key_alloc_type(__a))
223 { _M_t._M_insert_unique(__l.begin(), __l.end()); }
224 #endif
225
226 /**
227 * @brief %Set assignment operator.
228 * @param __x A %set of identical element and allocator types.
229 *
230 * All the elements of @a __x are copied, but unlike the copy
231 * constructor, the allocator object is not copied.
232 */
233 set&
234 operator=(const set& __x)
235 {
236 _M_t = __x._M_t;
237 return *this;
238 }
239
240 #if __cplusplus >= 201103L
241 /**
242 * @brief %Set move assignment operator.
243 * @param __x A %set of identical element and allocator types.
244 *
245 * The contents of @a __x are moved into this %set (without copying).
246 * @a __x is a valid, but unspecified %set.
247 */
248 set&
249 operator=(set&& __x)
250 {
251 // NB: DR 1204.
252 // NB: DR 675.
253 this->clear();
254 this->swap(__x);
255 return *this;
256 }
257
258 /**
259 * @brief %Set list assignment operator.
260 * @param __l An initializer_list.
261 *
262 * This function fills a %set with copies of the elements in the
263 * initializer list @a __l.
264 *
265 * Note that the assignment completely changes the %set and
266 * that the resulting %set's size is the same as the number
267 * of elements assigned. Old data may be lost.
268 */
269 set&
270 operator=(initializer_list<value_type> __l)
271 {
272 this->clear();
273 this->insert(__l.begin(), __l.end());
274 return *this;
275 }
276 #endif
277
278 // accessors:
279
280 /// Returns the comparison object with which the %set was constructed.
281 key_compare
282 key_comp() const
283 { return _M_t.key_comp(); }
284 /// Returns the comparison object with which the %set was constructed.
285 value_compare
286 value_comp() const
287 { return _M_t.key_comp(); }
288 /// Returns the allocator object with which the %set was constructed.
289 allocator_type
290 get_allocator() const _GLIBCXX_NOEXCEPT
291 { return allocator_type(_M_t.get_allocator()); }
292
293 /**
294 * Returns a read-only (constant) iterator that points to the first
295 * element in the %set. Iteration is done in ascending order according
296 * to the keys.
297 */
298 iterator
299 begin() const _GLIBCXX_NOEXCEPT
300 { return _M_t.begin(); }
301
302 /**
303 * Returns a read-only (constant) iterator that points one past the last
304 * element in the %set. Iteration is done in ascending order according
305 * to the keys.
306 */
307 iterator
308 end() const _GLIBCXX_NOEXCEPT
309 { return _M_t.end(); }
310
311 /**
312 * Returns a read-only (constant) iterator that points to the last
313 * element in the %set. Iteration is done in descending order according
314 * to the keys.
315 */
316 reverse_iterator
317 rbegin() const _GLIBCXX_NOEXCEPT
318 { return _M_t.rbegin(); }
319
320 /**
321 * Returns a read-only (constant) reverse iterator that points to the
322 * last pair in the %set. Iteration is done in descending order
323 * according to the keys.
324 */
325 reverse_iterator
326 rend() const _GLIBCXX_NOEXCEPT
327 { return _M_t.rend(); }
328
329 #if __cplusplus >= 201103L
330 /**
331 * Returns a read-only (constant) iterator that points to the first
332 * element in the %set. Iteration is done in ascending order according
333 * to the keys.
334 */
335 iterator
336 cbegin() const noexcept
337 { return _M_t.begin(); }
338
339 /**
340 * Returns a read-only (constant) iterator that points one past the last
341 * element in the %set. Iteration is done in ascending order according
342 * to the keys.
343 */
344 iterator
345 cend() const noexcept
346 { return _M_t.end(); }
347
348 /**
349 * Returns a read-only (constant) iterator that points to the last
350 * element in the %set. Iteration is done in descending order according
351 * to the keys.
352 */
353 reverse_iterator
354 crbegin() const noexcept
355 { return _M_t.rbegin(); }
356
357 /**
358 * Returns a read-only (constant) reverse iterator that points to the
359 * last pair in the %set. Iteration is done in descending order
360 * according to the keys.
361 */
362 reverse_iterator
363 crend() const noexcept
364 { return _M_t.rend(); }
365 #endif
366
367 /// Returns true if the %set is empty.
368 bool
369 empty() const _GLIBCXX_NOEXCEPT
370 { return _M_t.empty(); }
371
372 /// Returns the size of the %set.
373 size_type
374 size() const _GLIBCXX_NOEXCEPT
375 { return _M_t.size(); }
376
377 /// Returns the maximum size of the %set.
378 size_type
379 max_size() const _GLIBCXX_NOEXCEPT
380 { return _M_t.max_size(); }
381
382 /**
383 * @brief Swaps data with another %set.
384 * @param __x A %set of the same element and allocator types.
385 *
386 * This exchanges the elements between two sets in constant
387 * time. (It is only swapping a pointer, an integer, and an
388 * instance of the @c Compare type (which itself is often
389 * stateless and empty), so it should be quite fast.) Note
390 * that the global std::swap() function is specialized such
391 * that std::swap(s1,s2) will feed to this function.
392 */
393 void
394 swap(set& __x)
395 { _M_t.swap(__x._M_t); }
396
397 // insert/erase
398 #if __cplusplus >= 201103L
399 /**
400 * @brief Attempts to build and insert an element into the %set.
401 * @param __args Arguments used to generate an element.
402 * @return A pair, of which the first element is an iterator that points
403 * to the possibly inserted element, and the second is a bool
404 * that is true if the element was actually inserted.
405 *
406 * This function attempts to build and insert an element into the %set.
407 * A %set relies on unique keys and thus an element is only inserted if
408 * it is not already present in the %set.
409 *
410 * Insertion requires logarithmic time.
411 */
412 template<typename... _Args>
413 std::pair<iterator, bool>
414 emplace(_Args&&... __args)
415 { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
416
417 /**
418 * @brief Attempts to insert an element into the %set.
419 * @param __pos An iterator that serves as a hint as to where the
420 * element should be inserted.
421 * @param __args Arguments used to generate the element to be
422 * inserted.
423 * @return An iterator that points to the element with key equivalent to
424 * the one generated from @a __args (may or may not be the
425 * element itself).
426 *
427 * This function is not concerned about whether the insertion took place,
428 * and thus does not return a boolean like the single-argument emplace()
429 * does. Note that the first parameter is only a hint and can
430 * potentially improve the performance of the insertion process. A bad
431 * hint would cause no gains in efficiency.
432 *
433 * For more on @a hinting, see:
434 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
435 *
436 * Insertion requires logarithmic time (if the hint is not taken).
437 */
438 template<typename... _Args>
439 iterator
440 emplace_hint(const_iterator __pos, _Args&&... __args)
441 {
442 return _M_t._M_emplace_hint_unique(__pos,
443 std::forward<_Args>(__args)...);
444 }
445 #endif
446
447 /**
448 * @brief Attempts to insert an element into the %set.
449 * @param __x Element to be inserted.
450 * @return A pair, of which the first element is an iterator that points
451 * to the possibly inserted element, and the second is a bool
452 * that is true if the element was actually inserted.
453 *
454 * This function attempts to insert an element into the %set. A %set
455 * relies on unique keys and thus an element is only inserted if it is
456 * not already present in the %set.
457 *
458 * Insertion requires logarithmic time.
459 */
460 std::pair<iterator, bool>
461 insert(const value_type& __x)
462 {
463 std::pair<typename _Rep_type::iterator, bool> __p =
464 _M_t._M_insert_unique(__x);
465 return std::pair<iterator, bool>(__p.first, __p.second);
466 }
467
468 #if __cplusplus >= 201103L
469 std::pair<iterator, bool>
470 insert(value_type&& __x)
471 {
472 std::pair<typename _Rep_type::iterator, bool> __p =
473 _M_t._M_insert_unique(std::move(__x));
474 return std::pair<iterator, bool>(__p.first, __p.second);
475 }
476 #endif
477
478 /**
479 * @brief Attempts to insert an element into the %set.
480 * @param __position An iterator that serves as a hint as to where the
481 * element should be inserted.
482 * @param __x Element to be inserted.
483 * @return An iterator that points to the element with key of
484 * @a __x (may or may not be the element passed in).
485 *
486 * This function is not concerned about whether the insertion took place,
487 * and thus does not return a boolean like the single-argument insert()
488 * does. Note that the first parameter is only a hint and can
489 * potentially improve the performance of the insertion process. A bad
490 * hint would cause no gains in efficiency.
491 *
492 * For more on @a hinting, see:
493 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
494 *
495 * Insertion requires logarithmic time (if the hint is not taken).
496 */
497 iterator
498 insert(const_iterator __position, const value_type& __x)
499 { return _M_t._M_insert_unique_(__position, __x); }
500
501 #if __cplusplus >= 201103L
502 iterator
503 insert(const_iterator __position, value_type&& __x)
504 { return _M_t._M_insert_unique_(__position, std::move(__x)); }
505 #endif
506
507 /**
508 * @brief A template function that attempts to insert a range
509 * of elements.
510 * @param __first Iterator pointing to the start of the range to be
511 * inserted.
512 * @param __last Iterator pointing to the end of the range.
513 *
514 * Complexity similar to that of the range constructor.
515 */
516 template<typename _InputIterator>
517 void
518 insert(_InputIterator __first, _InputIterator __last)
519 { _M_t._M_insert_unique(__first, __last); }
520
521 #if __cplusplus >= 201103L
522 /**
523 * @brief Attempts to insert a list of elements into the %set.
524 * @param __l A std::initializer_list<value_type> of elements
525 * to be inserted.
526 *
527 * Complexity similar to that of the range constructor.
528 */
529 void
530 insert(initializer_list<value_type> __l)
531 { this->insert(__l.begin(), __l.end()); }
532 #endif
533
534 #if __cplusplus >= 201103L
535 // _GLIBCXX_RESOLVE_LIB_DEFECTS
536 // DR 130. Associative erase should return an iterator.
537 /**
538 * @brief Erases an element from a %set.
539 * @param __position An iterator pointing to the element to be erased.
540 * @return An iterator pointing to the element immediately following
541 * @a __position prior to the element being erased. If no such
542 * element exists, end() is returned.
543 *
544 * This function erases an element, pointed to by the given iterator,
545 * from a %set. Note that this function only erases the element, and
546 * that if the element is itself a pointer, the pointed-to memory is not
547 * touched in any way. Managing the pointer is the user's
548 * responsibility.
549 */
550 iterator
551 erase(const_iterator __position)
552 { return _M_t.erase(__position); }
553 #else
554 /**
555 * @brief Erases an element from a %set.
556 * @param position An iterator pointing to the element to be erased.
557 *
558 * This function erases an element, pointed to by the given iterator,
559 * from a %set. Note that this function only erases the element, and
560 * that if the element is itself a pointer, the pointed-to memory is not
561 * touched in any way. Managing the pointer is the user's
562 * responsibility.
563 */
564 void
565 erase(iterator __position)
566 { _M_t.erase(__position); }
567 #endif
568
569 /**
570 * @brief Erases elements according to the provided key.
571 * @param __x Key of element to be erased.
572 * @return The number of elements erased.
573 *
574 * This function erases all the elements located by the given key from
575 * a %set.
576 * Note that this function only erases the element, and that if
577 * the element is itself a pointer, the pointed-to memory is not touched
578 * in any way. Managing the pointer is the user's responsibility.
579 */
580 size_type
581 erase(const key_type& __x)
582 { return _M_t.erase(__x); }
583
584 #if __cplusplus >= 201103L
585 // _GLIBCXX_RESOLVE_LIB_DEFECTS
586 // DR 130. Associative erase should return an iterator.
587 /**
588 * @brief Erases a [__first,__last) range of elements from a %set.
589 * @param __first Iterator pointing to the start of the range to be
590 * erased.
591
592 * @param __last Iterator pointing to the end of the range to
593 * be erased.
594 * @return The iterator @a __last.
595 *
596 * This function erases a sequence of elements from a %set.
597 * Note that this function only erases the element, and that if
598 * the element is itself a pointer, the pointed-to memory is not touched
599 * in any way. Managing the pointer is the user's responsibility.
600 */
601 iterator
602 erase(const_iterator __first, const_iterator __last)
603 { return _M_t.erase(__first, __last); }
604 #else
605 /**
606 * @brief Erases a [first,last) range of elements from a %set.
607 * @param __first Iterator pointing to the start of the range to be
608 * erased.
609 * @param __last Iterator pointing to the end of the range to
610 * be erased.
611 *
612 * This function erases a sequence of elements from a %set.
613 * Note that this function only erases the element, and that if
614 * the element is itself a pointer, the pointed-to memory is not touched
615 * in any way. Managing the pointer is the user's responsibility.
616 */
617 void
618 erase(iterator __first, iterator __last)
619 { _M_t.erase(__first, __last); }
620 #endif
621
622 /**
623 * Erases all elements in a %set. Note that this function only erases
624 * the elements, and that if the elements themselves are pointers, the
625 * pointed-to memory is not touched in any way. Managing the pointer is
626 * the user's responsibility.
627 */
628 void
629 clear() _GLIBCXX_NOEXCEPT
630 { _M_t.clear(); }
631
632 // set operations:
633
634 /**
635 * @brief Finds the number of elements.
636 * @param __x Element to located.
637 * @return Number of elements with specified key.
638 *
639 * This function only makes sense for multisets; for set the result will
640 * either be 0 (not present) or 1 (present).
641 */
642 size_type
643 count(const key_type& __x) const
644 { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
645
646 // _GLIBCXX_RESOLVE_LIB_DEFECTS
647 // 214. set::find() missing const overload
648 //@{
649 /**
650 * @brief Tries to locate an element in a %set.
651 * @param __x Element to be located.
652 * @return Iterator pointing to sought-after element, or end() if not
653 * found.
654 *
655 * This function takes a key and tries to locate the element with which
656 * the key matches. If successful the function returns an iterator
657 * pointing to the sought after element. If unsuccessful it returns the
658 * past-the-end ( @c end() ) iterator.
659 */
660 iterator
661 find(const key_type& __x)
662 { return _M_t.find(__x); }
663
664 const_iterator
665 find(const key_type& __x) const
666 { return _M_t.find(__x); }
667 //@}
668
669 //@{
670 /**
671 * @brief Finds the beginning of a subsequence matching given key.
672 * @param __x Key to be located.
673 * @return Iterator pointing to first element equal to or greater
674 * than key, or end().
675 *
676 * This function returns the first element of a subsequence of elements
677 * that matches the given key. If unsuccessful it returns an iterator
678 * pointing to the first element that has a greater value than given key
679 * or end() if no such element exists.
680 */
681 iterator
682 lower_bound(const key_type& __x)
683 { return _M_t.lower_bound(__x); }
684
685 const_iterator
686 lower_bound(const key_type& __x) const
687 { return _M_t.lower_bound(__x); }
688 //@}
689
690 //@{
691 /**
692 * @brief Finds the end of a subsequence matching given key.
693 * @param __x Key to be located.
694 * @return Iterator pointing to the first element
695 * greater than key, or end().
696 */
697 iterator
698 upper_bound(const key_type& __x)
699 { return _M_t.upper_bound(__x); }
700
701 const_iterator
702 upper_bound(const key_type& __x) const
703 { return _M_t.upper_bound(__x); }
704 //@}
705
706 //@{
707 /**
708 * @brief Finds a subsequence matching given key.
709 * @param __x Key to be located.
710 * @return Pair of iterators that possibly points to the subsequence
711 * matching given key.
712 *
713 * This function is equivalent to
714 * @code
715 * std::make_pair(c.lower_bound(val),
716 * c.upper_bound(val))
717 * @endcode
718 * (but is faster than making the calls separately).
719 *
720 * This function probably only makes sense for multisets.
721 */
722 std::pair<iterator, iterator>
723 equal_range(const key_type& __x)
724 { return _M_t.equal_range(__x); }
725
726 std::pair<const_iterator, const_iterator>
727 equal_range(const key_type& __x) const
728 { return _M_t.equal_range(__x); }
729 //@}
730
731 template<typename _K1, typename _C1, typename _A1>
732 friend bool
733 operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
734
735 template<typename _K1, typename _C1, typename _A1>
736 friend bool
737 operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
738 };
739
740
741 /**
742 * @brief Set equality comparison.
743 * @param __x A %set.
744 * @param __y A %set of the same type as @a x.
745 * @return True iff the size and elements of the sets are equal.
746 *
747 * This is an equivalence relation. It is linear in the size of the sets.
748 * Sets are considered equivalent if their sizes are equal, and if
749 * corresponding elements compare equal.
750 */
751 template<typename _Key, typename _Compare, typename _Alloc>
752 inline bool
753 operator==(const set<_Key, _Compare, _Alloc>& __x,
754 const set<_Key, _Compare, _Alloc>& __y)
755 { return __x._M_t == __y._M_t; }
756
757 /**
758 * @brief Set ordering relation.
759 * @param __x A %set.
760 * @param __y A %set of the same type as @a x.
761 * @return True iff @a __x is lexicographically less than @a __y.
762 *
763 * This is a total ordering relation. It is linear in the size of the
764 * maps. The elements must be comparable with @c <.
765 *
766 * See std::lexicographical_compare() for how the determination is made.
767 */
768 template<typename _Key, typename _Compare, typename _Alloc>
769 inline bool
770 operator<(const set<_Key, _Compare, _Alloc>& __x,
771 const set<_Key, _Compare, _Alloc>& __y)
772 { return __x._M_t < __y._M_t; }
773
774 /// Returns !(x == y).
775 template<typename _Key, typename _Compare, typename _Alloc>
776 inline bool
777 operator!=(const set<_Key, _Compare, _Alloc>& __x,
778 const set<_Key, _Compare, _Alloc>& __y)
779 { return !(__x == __y); }
780
781 /// Returns y < x.
782 template<typename _Key, typename _Compare, typename _Alloc>
783 inline bool
784 operator>(const set<_Key, _Compare, _Alloc>& __x,
785 const set<_Key, _Compare, _Alloc>& __y)
786 { return __y < __x; }
787
788 /// Returns !(y < x)
789 template<typename _Key, typename _Compare, typename _Alloc>
790 inline bool
791 operator<=(const set<_Key, _Compare, _Alloc>& __x,
792 const set<_Key, _Compare, _Alloc>& __y)
793 { return !(__y < __x); }
794
795 /// Returns !(x < y)
796 template<typename _Key, typename _Compare, typename _Alloc>
797 inline bool
798 operator>=(const set<_Key, _Compare, _Alloc>& __x,
799 const set<_Key, _Compare, _Alloc>& __y)
800 { return !(__x < __y); }
801
802 /// See std::set::swap().
803 template<typename _Key, typename _Compare, typename _Alloc>
804 inline void
805 swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
806 { __x.swap(__y); }
807
808 _GLIBCXX_END_NAMESPACE_CONTAINER
809 } //namespace std
810 #endif /* _STL_SET_H */