libstdc++

stl_set.h

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