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