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

Generated on 21 Dec 2009 for libstdc++ by  doxygen 1.6.1