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