libstdc++
stl_set.h
Go to the documentation of this file.
00001 // Set implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
00004 // 2011 Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /*
00027  *
00028  * Copyright (c) 1994
00029  * Hewlett-Packard Company
00030  *
00031  * Permission to use, copy, modify, distribute and sell this software
00032  * and its documentation for any purpose is hereby granted without fee,
00033  * provided that the above copyright notice appear in all copies and
00034  * that both that copyright notice and this permission notice appear
00035  * in supporting documentation.  Hewlett-Packard Company makes no
00036  * representations about the suitability of this software for any
00037  * purpose.  It is provided "as is" without express or implied warranty.
00038  *
00039  *
00040  * Copyright (c) 1996,1997
00041  * Silicon Graphics Computer Systems, Inc.
00042  *
00043  * Permission to use, copy, modify, distribute and sell this software
00044  * and its documentation for any purpose is hereby granted without fee,
00045  * provided that the above copyright notice appear in all copies and
00046  * that both that copyright notice and this permission notice appear
00047  * in supporting documentation.  Silicon Graphics makes no
00048  * representations about the suitability of this software for any
00049  * purpose.  It is provided "as is" without express or implied warranty.
00050  */
00051 
00052 /** @file bits/stl_set.h
00053  *  This is an internal header file, included by other library headers.
00054  *  Do not attempt to use it directly. @headername{set}
00055  */
00056 
00057 #ifndef _STL_SET_H
00058 #define _STL_SET_H 1
00059 
00060 #include <bits/concept_check.h>
00061 #include <initializer_list>
00062 
00063 namespace std _GLIBCXX_VISIBILITY(default)
00064 {
00065 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
00066 
00067   /**
00068    *  @brief A standard container made up of unique keys, which can be
00069    *  retrieved in logarithmic time.
00070    *
00071    *  @ingroup associative_containers
00072    *
00073    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00074    *  <a href="tables.html#66">reversible container</a>, and an
00075    *  <a href="tables.html#69">associative container</a> (using unique keys).
00076    *
00077    *  Sets support bidirectional iterators.
00078    *
00079    *  @param  Key  Type of key objects.
00080    *  @param  Compare  Comparison function object type, defaults to less<Key>.
00081    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00082    *
00083    *  The private tree data is declared exactly the same way for set and
00084    *  multiset; the distinction is made entirely in how the tree functions are
00085    *  called (*_unique versus *_equal, same as the standard).
00086   */
00087   template<typename _Key, typename _Compare = std::less<_Key>,
00088        typename _Alloc = std::allocator<_Key> >
00089     class set
00090     {
00091       // concept requirements
00092       typedef typename _Alloc::value_type                   _Alloc_value_type;
00093       __glibcxx_class_requires(_Key, _SGIAssignableConcept)
00094       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
00095                 _BinaryFunctionConcept)
00096       __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
00097 
00098     public:
00099       // typedefs:
00100       //@{
00101       /// Public typedefs.
00102       typedef _Key     key_type;
00103       typedef _Key     value_type;
00104       typedef _Compare key_compare;
00105       typedef _Compare value_compare;
00106       typedef _Alloc   allocator_type;
00107       //@}
00108 
00109     private:
00110       typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
00111 
00112       typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
00113                key_compare, _Key_alloc_type> _Rep_type;
00114       _Rep_type _M_t;  // Red-black tree representing set.
00115 
00116     public:
00117       //@{
00118       ///  Iterator-related typedefs.
00119       typedef typename _Key_alloc_type::pointer             pointer;
00120       typedef typename _Key_alloc_type::const_pointer       const_pointer;
00121       typedef typename _Key_alloc_type::reference           reference;
00122       typedef typename _Key_alloc_type::const_reference     const_reference;
00123       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00124       // DR 103. set::iterator is required to be modifiable,
00125       // but this allows modification of keys.
00126       typedef typename _Rep_type::const_iterator            iterator;
00127       typedef typename _Rep_type::const_iterator            const_iterator;
00128       typedef typename _Rep_type::const_reverse_iterator    reverse_iterator;
00129       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00130       typedef typename _Rep_type::size_type                 size_type;
00131       typedef typename _Rep_type::difference_type           difference_type;
00132       //@}
00133 
00134       // allocation/deallocation
00135       /**
00136        *  @brief  Default constructor creates no elements.
00137        */
00138       set()
00139       : _M_t() { }
00140 
00141       /**
00142        *  @brief  Creates a %set with no elements.
00143        *  @param  comp  Comparator to use.
00144        *  @param  a  An allocator object.
00145        */
00146       explicit
00147       set(const _Compare& __comp,
00148       const allocator_type& __a = allocator_type())
00149       : _M_t(__comp, __a) { }
00150 
00151       /**
00152        *  @brief  Builds a %set from a range.
00153        *  @param  first  An input iterator.
00154        *  @param  last  An input iterator.
00155        *
00156        *  Create a %set consisting of copies of the elements from [first,last).
00157        *  This is linear in N if the range is already sorted, and NlogN
00158        *  otherwise (where N is distance(first,last)).
00159        */
00160       template<typename _InputIterator>
00161     set(_InputIterator __first, _InputIterator __last)
00162     : _M_t()
00163     { _M_t._M_insert_unique(__first, __last); }
00164 
00165       /**
00166        *  @brief  Builds a %set from a range.
00167        *  @param  first  An input iterator.
00168        *  @param  last  An input iterator.
00169        *  @param  comp  A comparison functor.
00170        *  @param  a  An allocator object.
00171        *
00172        *  Create a %set consisting of copies of the elements from [first,last).
00173        *  This is linear in N if the range is already sorted, and NlogN
00174        *  otherwise (where N is distance(first,last)).
00175        */
00176       template<typename _InputIterator>
00177     set(_InputIterator __first, _InputIterator __last,
00178         const _Compare& __comp,
00179         const allocator_type& __a = allocator_type())
00180     : _M_t(__comp, __a)
00181     { _M_t._M_insert_unique(__first, __last); }
00182 
00183       /**
00184        *  @brief  %Set copy constructor.
00185        *  @param  x  A %set of identical element and allocator types.
00186        *
00187        *  The newly-created %set uses a copy of the allocation object used
00188        *  by @a x.
00189        */
00190       set(const set& __x)
00191       : _M_t(__x._M_t) { }
00192 
00193 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00194      /**
00195        *  @brief %Set move constructor
00196        *  @param x  A %set of identical element and allocator types.
00197        *
00198        *  The newly-created %set contains the exact contents of @a x.
00199        *  The contents of @a x are a valid, but unspecified %set.
00200        */
00201       set(set&& __x)
00202       : _M_t(std::move(__x._M_t)) { }
00203 
00204       /**
00205        *  @brief  Builds a %set from an initializer_list.
00206        *  @param  l  An initializer_list.
00207        *  @param  comp  A comparison functor.
00208        *  @param  a  An allocator object.
00209        *
00210        *  Create a %set consisting of copies of the elements in the list.
00211        *  This is linear in N if the list is already sorted, and NlogN
00212        *  otherwise (where N is @a l.size()).
00213        */
00214       set(initializer_list<value_type> __l,
00215       const _Compare& __comp = _Compare(),
00216       const allocator_type& __a = allocator_type())
00217       : _M_t(__comp, __a)
00218       { _M_t._M_insert_unique(__l.begin(), __l.end()); }
00219 #endif
00220 
00221       /**
00222        *  @brief  %Set assignment operator.
00223        *  @param  x  A %set of identical element and allocator types.
00224        *
00225        *  All the elements of @a x are copied, but unlike the copy constructor,
00226        *  the allocator object is not copied.
00227        */
00228       set&
00229       operator=(const set& __x)
00230       {
00231     _M_t = __x._M_t;
00232     return *this;
00233       }
00234 
00235 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00236       /**
00237        *  @brief %Set move assignment operator.
00238        *  @param x  A %set of identical element and allocator types.
00239        *
00240        *  The contents of @a x are moved into this %set (without copying).
00241        *  @a x is a valid, but unspecified %set.
00242        */
00243       set&
00244       operator=(set&& __x)
00245       {
00246     // NB: DR 1204.
00247     // NB: DR 675.
00248     this->clear();
00249     this->swap(__x);
00250         return *this;
00251       }
00252 
00253       /**
00254        *  @brief  %Set list assignment operator.
00255        *  @param  l  An initializer_list.
00256        *
00257        *  This function fills a %set with copies of the elements in the
00258        *  initializer list @a l.
00259        *
00260        *  Note that the assignment completely changes the %set and
00261        *  that the resulting %set's size is the same as the number
00262        *  of elements assigned.  Old data may be lost.
00263        */
00264       set&
00265       operator=(initializer_list<value_type> __l)
00266       {
00267     this->clear();
00268     this->insert(__l.begin(), __l.end());
00269     return *this;
00270       }
00271 #endif
00272 
00273       // accessors:
00274 
00275       ///  Returns the comparison object with which the %set was constructed.
00276       key_compare
00277       key_comp() const
00278       { return _M_t.key_comp(); }
00279       ///  Returns the comparison object with which the %set was constructed.
00280       value_compare
00281       value_comp() const
00282       { return _M_t.key_comp(); }
00283       ///  Returns the allocator object with which the %set was constructed.
00284       allocator_type
00285       get_allocator() const
00286       { return _M_t.get_allocator(); }
00287 
00288       /**
00289        *  Returns a read-only (constant) iterator that points to the first
00290        *  element in the %set.  Iteration is done in ascending order according
00291        *  to the keys.
00292        */
00293       iterator
00294       begin() const
00295       { return _M_t.begin(); }
00296 
00297       /**
00298        *  Returns a read-only (constant) iterator that points one past the last
00299        *  element in the %set.  Iteration is done in ascending order according
00300        *  to the keys.
00301        */
00302       iterator
00303       end() const
00304       { return _M_t.end(); }
00305 
00306       /**
00307        *  Returns a read-only (constant) iterator that points to the last
00308        *  element in the %set.  Iteration is done in descending order according
00309        *  to the keys.
00310        */
00311       reverse_iterator
00312       rbegin() const
00313       { return _M_t.rbegin(); }
00314 
00315       /**
00316        *  Returns a read-only (constant) reverse iterator that points to the
00317        *  last pair in the %set.  Iteration is done in descending order
00318        *  according to the keys.
00319        */
00320       reverse_iterator
00321       rend() const
00322       { return _M_t.rend(); }
00323 
00324 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00325       /**
00326        *  Returns a read-only (constant) iterator that points to the first
00327        *  element in the %set.  Iteration is done in ascending order according
00328        *  to the keys.
00329        */
00330       iterator
00331       cbegin() const
00332       { return _M_t.begin(); }
00333 
00334       /**
00335        *  Returns a read-only (constant) iterator that points one past the last
00336        *  element in the %set.  Iteration is done in ascending order according
00337        *  to the keys.
00338        */
00339       iterator
00340       cend() const
00341       { return _M_t.end(); }
00342 
00343       /**
00344        *  Returns a read-only (constant) iterator that points to the last
00345        *  element in the %set.  Iteration is done in descending order according
00346        *  to the keys.
00347        */
00348       reverse_iterator
00349       crbegin() const
00350       { return _M_t.rbegin(); }
00351 
00352       /**
00353        *  Returns a read-only (constant) reverse iterator that points to the
00354        *  last pair in the %set.  Iteration is done in descending order
00355        *  according to the keys.
00356        */
00357       reverse_iterator
00358       crend() const
00359       { return _M_t.rend(); }
00360 #endif
00361 
00362       ///  Returns true if the %set is empty.
00363       bool
00364       empty() const
00365       { return _M_t.empty(); }
00366 
00367       ///  Returns the size of the %set.
00368       size_type
00369       size() const
00370       { return _M_t.size(); }
00371 
00372       ///  Returns the maximum size of the %set.
00373       size_type
00374       max_size() const
00375       { return _M_t.max_size(); }
00376 
00377       /**
00378        *  @brief  Swaps data with another %set.
00379        *  @param  x  A %set of the same element and allocator types.
00380        *
00381        *  This exchanges the elements between two sets in constant time.
00382        *  (It is only swapping a pointer, an integer, and an instance of
00383        *  the @c Compare type (which itself is often stateless and empty), so it
00384        *  should be quite fast.)
00385        *  Note that the global std::swap() function is specialized such that
00386        *  std::swap(s1,s2) will feed to this function.
00387        */
00388       void
00389       swap(set& __x)
00390       { _M_t.swap(__x._M_t); }
00391 
00392       // insert/erase
00393       /**
00394        *  @brief Attempts to insert an element into the %set.
00395        *  @param  x  Element to be inserted.
00396        *  @return  A pair, of which the first element is an iterator that points
00397        *           to the possibly inserted element, and the second is a bool
00398        *           that is true if the element was actually inserted.
00399        *
00400        *  This function attempts to insert an element into the %set.  A %set
00401        *  relies on unique keys and thus an element is only inserted if it is
00402        *  not already present in the %set.
00403        *
00404        *  Insertion requires logarithmic time.
00405        */
00406       std::pair<iterator, bool>
00407       insert(const value_type& __x)
00408       {
00409     std::pair<typename _Rep_type::iterator, bool> __p =
00410       _M_t._M_insert_unique(__x);
00411     return std::pair<iterator, bool>(__p.first, __p.second);
00412       }
00413 
00414 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00415       std::pair<iterator, bool>
00416       insert(value_type&& __x)
00417       {
00418     std::pair<typename _Rep_type::iterator, bool> __p =
00419       _M_t._M_insert_unique(std::move(__x));
00420     return std::pair<iterator, bool>(__p.first, __p.second);
00421       }
00422 #endif
00423 
00424       /**
00425        *  @brief Attempts to insert an element into the %set.
00426        *  @param  position  An iterator that serves as a hint as to where the
00427        *                    element should be inserted.
00428        *  @param  x  Element to be inserted.
00429        *  @return  An iterator that points to the element with key of @a x (may
00430        *           or may not be the element passed in).
00431        *
00432        *  This function is not concerned about whether the insertion took place,
00433        *  and thus does not return a boolean like the single-argument insert()
00434        *  does.  Note that the first parameter is only a hint and can
00435        *  potentially improve the performance of the insertion process.  A bad
00436        *  hint would cause no gains in efficiency.
00437        *
00438        *  For more on @a hinting, see:
00439        *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
00440        *
00441        *  Insertion requires logarithmic time (if the hint is not taken).
00442        */
00443       iterator
00444       insert(const_iterator __position, const value_type& __x)
00445       { return _M_t._M_insert_unique_(__position, __x); }
00446 
00447 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00448       iterator
00449       insert(const_iterator __position, value_type&& __x)
00450       { return _M_t._M_insert_unique_(__position, std::move(__x)); }
00451 #endif
00452 
00453       /**
00454        *  @brief A template function that attempts to insert a range
00455        *  of elements.
00456        *  @param  first  Iterator pointing to the start of the range to be
00457        *                 inserted.
00458        *  @param  last  Iterator pointing to the end of the range.
00459        *
00460        *  Complexity similar to that of the range constructor.
00461        */
00462       template<typename _InputIterator>
00463     void
00464     insert(_InputIterator __first, _InputIterator __last)
00465     { _M_t._M_insert_unique(__first, __last); }
00466 
00467 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00468       /**
00469        *  @brief Attempts to insert a list of elements into the %set.
00470        *  @param  list  A std::initializer_list<value_type> of elements
00471        *                to be inserted.
00472        *
00473        *  Complexity similar to that of the range constructor.
00474        */
00475       void
00476       insert(initializer_list<value_type> __l)
00477       { this->insert(__l.begin(), __l.end()); }
00478 #endif
00479 
00480 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00481       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00482       // DR 130. Associative erase should return an iterator.
00483       /**
00484        *  @brief Erases an element from a %set.
00485        *  @param  position  An iterator pointing to the element to be erased.
00486        *  @return An iterator pointing to the element immediately following
00487        *          @a position prior to the element being erased. If no such
00488        *          element exists, end() is returned.
00489        *
00490        *  This function erases an element, pointed to by the given iterator,
00491        *  from a %set.  Note that this function only erases the element, and
00492        *  that if the element is itself a pointer, the pointed-to memory is not
00493        *  touched in any way.  Managing the pointer is the user's
00494        *  responsibility.
00495        */
00496       iterator
00497       erase(const_iterator __position)
00498       { return _M_t.erase(__position); }
00499 #else
00500       /**
00501        *  @brief Erases an element from a %set.
00502        *  @param  position  An iterator pointing to the element to be erased.
00503        *
00504        *  This function erases an element, pointed to by the given iterator,
00505        *  from a %set.  Note that this function only erases the element, and
00506        *  that if the element is itself a pointer, the pointed-to memory is not
00507        *  touched in any way.  Managing the pointer is the user's
00508        *  responsibility.
00509        */
00510       void
00511       erase(iterator __position)
00512       { _M_t.erase(__position); }
00513 #endif
00514 
00515       /**
00516        *  @brief Erases elements according to the provided key.
00517        *  @param  x  Key of element to be erased.
00518        *  @return  The number of elements erased.
00519        *
00520        *  This function erases all the elements located by the given key from
00521        *  a %set.
00522        *  Note that this function only erases the element, and that if
00523        *  the element is itself a pointer, the pointed-to memory is not touched
00524        *  in any way.  Managing the pointer is the user's responsibility.
00525        */
00526       size_type
00527       erase(const key_type& __x)
00528       { return _M_t.erase(__x); }
00529 
00530 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00531       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00532       // DR 130. Associative erase should return an iterator.
00533       /**
00534        *  @brief Erases a [first,last) range of elements from a %set.
00535        *  @param  first  Iterator pointing to the start of the range to be
00536        *                 erased.
00537        *  @param  last  Iterator pointing to the end of the range to be erased.
00538        *  @return The iterator @a last.
00539        *
00540        *  This function erases a sequence of elements from a %set.
00541        *  Note that this function only erases the element, and that if
00542        *  the element is itself a pointer, the pointed-to memory is not touched
00543        *  in any way.  Managing the pointer is the user's responsibility.
00544        */
00545       iterator
00546       erase(const_iterator __first, const_iterator __last)
00547       { return _M_t.erase(__first, __last); }
00548 #else
00549       /**
00550        *  @brief Erases a [first,last) range of elements from a %set.
00551        *  @param  first  Iterator pointing to the start of the range to be
00552        *                 erased.
00553        *  @param  last  Iterator pointing to the end of the range to be erased.
00554        *
00555        *  This function erases a sequence of elements from a %set.
00556        *  Note that this function only erases the element, and that if
00557        *  the element is itself a pointer, the pointed-to memory is not touched
00558        *  in any way.  Managing the pointer is the user's responsibility.
00559        */
00560       void
00561       erase(iterator __first, iterator __last)
00562       { _M_t.erase(__first, __last); }
00563 #endif
00564 
00565       /**
00566        *  Erases all elements in a %set.  Note that this function only erases
00567        *  the elements, and that if the elements themselves are pointers, the
00568        *  pointed-to memory is not touched in any way.  Managing the pointer is
00569        *  the user's responsibility.
00570        */
00571       void
00572       clear()
00573       { _M_t.clear(); }
00574 
00575       // set operations:
00576 
00577       /**
00578        *  @brief  Finds the number of elements.
00579        *  @param  x  Element to located.
00580        *  @return  Number of elements with specified key.
00581        *
00582        *  This function only makes sense for multisets; for set the result will
00583        *  either be 0 (not present) or 1 (present).
00584        */
00585       size_type
00586       count(const key_type& __x) const
00587       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
00588 
00589       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00590       // 214.  set::find() missing const overload
00591       //@{
00592       /**
00593        *  @brief Tries to locate an element in a %set.
00594        *  @param  x  Element to be located.
00595        *  @return  Iterator pointing to sought-after element, or end() if not
00596        *           found.
00597        *
00598        *  This function takes a key and tries to locate the element with which
00599        *  the key matches.  If successful the function returns an iterator
00600        *  pointing to the sought after element.  If unsuccessful it returns the
00601        *  past-the-end ( @c end() ) iterator.
00602        */
00603       iterator
00604       find(const key_type& __x)
00605       { return _M_t.find(__x); }
00606 
00607       const_iterator
00608       find(const key_type& __x) const
00609       { return _M_t.find(__x); }
00610       //@}
00611 
00612       //@{
00613       /**
00614        *  @brief Finds the beginning of a subsequence matching given key.
00615        *  @param  x  Key to be located.
00616        *  @return  Iterator pointing to first element equal to or greater
00617        *           than key, or end().
00618        *
00619        *  This function returns the first element of a subsequence of elements
00620        *  that matches the given key.  If unsuccessful it returns an iterator
00621        *  pointing to the first element that has a greater value than given key
00622        *  or end() if no such element exists.
00623        */
00624       iterator
00625       lower_bound(const key_type& __x)
00626       { return _M_t.lower_bound(__x); }
00627 
00628       const_iterator
00629       lower_bound(const key_type& __x) const
00630       { return _M_t.lower_bound(__x); }
00631       //@}
00632 
00633       //@{
00634       /**
00635        *  @brief Finds the end of a subsequence matching given key.
00636        *  @param  x  Key to be located.
00637        *  @return Iterator pointing to the first element
00638        *          greater than key, or end().
00639        */
00640       iterator
00641       upper_bound(const key_type& __x)
00642       { return _M_t.upper_bound(__x); }
00643 
00644       const_iterator
00645       upper_bound(const key_type& __x) const
00646       { return _M_t.upper_bound(__x); }
00647       //@}
00648 
00649       //@{
00650       /**
00651        *  @brief Finds a subsequence matching given key.
00652        *  @param  x  Key to be located.
00653        *  @return  Pair of iterators that possibly points to the subsequence
00654        *           matching given key.
00655        *
00656        *  This function is equivalent to
00657        *  @code
00658        *    std::make_pair(c.lower_bound(val),
00659        *                   c.upper_bound(val))
00660        *  @endcode
00661        *  (but is faster than making the calls separately).
00662        *
00663        *  This function probably only makes sense for multisets.
00664        */
00665       std::pair<iterator, iterator>
00666       equal_range(const key_type& __x)
00667       { return _M_t.equal_range(__x); }
00668 
00669       std::pair<const_iterator, const_iterator>
00670       equal_range(const key_type& __x) const
00671       { return _M_t.equal_range(__x); }
00672       //@}
00673 
00674       template<typename _K1, typename _C1, typename _A1>
00675     friend bool
00676     operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
00677 
00678       template<typename _K1, typename _C1, typename _A1>
00679     friend bool
00680     operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
00681     };
00682 
00683 
00684   /**
00685    *  @brief  Set equality comparison.
00686    *  @param  x  A %set.
00687    *  @param  y  A %set of the same type as @a x.
00688    *  @return  True iff the size and elements of the sets are equal.
00689    *
00690    *  This is an equivalence relation.  It is linear in the size of the sets.
00691    *  Sets are considered equivalent if their sizes are equal, and if
00692    *  corresponding elements compare equal.
00693   */
00694   template<typename _Key, typename _Compare, typename _Alloc>
00695     inline bool
00696     operator==(const set<_Key, _Compare, _Alloc>& __x,
00697            const set<_Key, _Compare, _Alloc>& __y)
00698     { return __x._M_t == __y._M_t; }
00699 
00700   /**
00701    *  @brief  Set ordering relation.
00702    *  @param  x  A %set.
00703    *  @param  y  A %set of the same type as @a x.
00704    *  @return  True iff @a x is lexicographically less than @a y.
00705    *
00706    *  This is a total ordering relation.  It is linear in the size of the
00707    *  maps.  The elements must be comparable with @c <.
00708    *
00709    *  See std::lexicographical_compare() for how the determination is made.
00710   */
00711   template<typename _Key, typename _Compare, typename _Alloc>
00712     inline bool
00713     operator<(const set<_Key, _Compare, _Alloc>& __x,
00714           const set<_Key, _Compare, _Alloc>& __y)
00715     { return __x._M_t < __y._M_t; }
00716 
00717   ///  Returns !(x == y).
00718   template<typename _Key, typename _Compare, typename _Alloc>
00719     inline bool
00720     operator!=(const set<_Key, _Compare, _Alloc>& __x,
00721            const set<_Key, _Compare, _Alloc>& __y)
00722     { return !(__x == __y); }
00723 
00724   ///  Returns y < x.
00725   template<typename _Key, typename _Compare, typename _Alloc>
00726     inline bool
00727     operator>(const set<_Key, _Compare, _Alloc>& __x,
00728           const set<_Key, _Compare, _Alloc>& __y)
00729     { return __y < __x; }
00730 
00731   ///  Returns !(y < x)
00732   template<typename _Key, typename _Compare, typename _Alloc>
00733     inline bool
00734     operator<=(const set<_Key, _Compare, _Alloc>& __x,
00735            const set<_Key, _Compare, _Alloc>& __y)
00736     { return !(__y < __x); }
00737 
00738   ///  Returns !(x < y)
00739   template<typename _Key, typename _Compare, typename _Alloc>
00740     inline bool
00741     operator>=(const set<_Key, _Compare, _Alloc>& __x,
00742            const set<_Key, _Compare, _Alloc>& __y)
00743     { return !(__x < __y); }
00744 
00745   /// See std::set::swap().
00746   template<typename _Key, typename _Compare, typename _Alloc>
00747     inline void
00748     swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y)
00749     { __x.swap(__y); }
00750 
00751 _GLIBCXX_END_NAMESPACE_CONTAINER
00752 } //namespace std
00753 #endif /* _STL_SET_H */