libstdc++

stl_multiset.h

Go to the documentation of this file.
00001 // Multiset 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
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 __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       /// The actual tree structure.
00117       _Rep_type _M_t;
00118 
00119       typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
00120 
00121     public:
00122       typedef typename _Alloc_traits::pointer               pointer;
00123       typedef typename _Alloc_traits::const_pointer         const_pointer;
00124       typedef typename _Alloc_traits::reference             reference;
00125       typedef typename _Alloc_traits::const_reference       const_reference;
00126       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00127       // DR 103. set::iterator is required to be modifiable,
00128       // but this allows modification of keys.
00129       typedef typename _Rep_type::const_iterator            iterator;
00130       typedef typename _Rep_type::const_iterator            const_iterator;
00131       typedef typename _Rep_type::const_reverse_iterator    reverse_iterator;
00132       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00133       typedef typename _Rep_type::size_type                 size_type;
00134       typedef typename _Rep_type::difference_type           difference_type;
00135 
00136       // allocation/deallocation
00137       /**
00138        *  @brief  Default constructor creates no elements.
00139        */
00140       multiset()
00141 #if __cplusplus >= 201103L
00142       noexcept(is_nothrow_default_constructible<allocator_type>::value
00143                && is_nothrow_default_constructible<key_compare>::value)
00144 #endif
00145       : _M_t() { }
00146 
00147       /**
00148        *  @brief  Creates a %multiset with no elements.
00149        *  @param  __comp  Comparator to use.
00150        *  @param  __a  An allocator object.
00151        */
00152       explicit
00153       multiset(const _Compare& __comp,
00154                const allocator_type& __a = allocator_type())
00155       : _M_t(__comp, _Key_alloc_type(__a)) { }
00156 
00157       /**
00158        *  @brief  Builds a %multiset from a range.
00159        *  @param  __first  An input iterator.
00160        *  @param  __last  An input iterator.
00161        *
00162        *  Create a %multiset consisting of copies of the elements from
00163        *  [first,last).  This is linear in N if the range is already sorted,
00164        *  and NlogN otherwise (where N is distance(__first,__last)).
00165        */
00166       template<typename _InputIterator>
00167         multiset(_InputIterator __first, _InputIterator __last)
00168         : _M_t()
00169         { _M_t._M_insert_equal(__first, __last); }
00170 
00171       /**
00172        *  @brief  Builds a %multiset from a range.
00173        *  @param  __first  An input iterator.
00174        *  @param  __last  An input iterator.
00175        *  @param  __comp  A comparison functor.
00176        *  @param  __a  An allocator object.
00177        *
00178        *  Create a %multiset consisting of copies of the elements from
00179        *  [__first,__last).  This is linear in N if the range is already sorted,
00180        *  and NlogN otherwise (where N is distance(__first,__last)).
00181        */
00182       template<typename _InputIterator>
00183         multiset(_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_equal(__first, __last); }
00188 
00189       /**
00190        *  @brief  %Multiset copy constructor.
00191        *  @param  __x  A %multiset of identical element and allocator types.
00192        *
00193        *  The newly-created %multiset uses a copy of the allocation object used
00194        *  by @a __x.
00195        */
00196       multiset(const multiset& __x)
00197       : _M_t(__x._M_t) { }
00198 
00199 #if __cplusplus >= 201103L
00200      /**
00201        *  @brief  %Multiset move constructor.
00202        *  @param  __x  A %multiset of identical element and allocator types.
00203        *
00204        *  The newly-created %multiset contains the exact contents of @a __x.
00205        *  The contents of @a __x are a valid, but unspecified %multiset.
00206        */
00207       multiset(multiset&& __x)
00208       noexcept(is_nothrow_copy_constructible<_Compare>::value)
00209       : _M_t(std::move(__x._M_t)) { }
00210 
00211       /**
00212        *  @brief  Builds a %multiset 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 %multiset consisting of copies of the elements from
00218        *  the list.  This is linear in N if the list is already sorted,
00219        *  and NlogN otherwise (where N is @a __l.size()).
00220        */
00221       multiset(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_equal(__l.begin(), __l.end()); }
00226 
00227       /// Allocator-extended default constructor.
00228       explicit
00229       multiset(const allocator_type& __a)
00230       : _M_t(_Compare(), _Key_alloc_type(__a)) { }
00231 
00232       /// Allocator-extended copy constructor.
00233       multiset(const multiset& __m, const allocator_type& __a)
00234       : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
00235 
00236       /// Allocator-extended move constructor.
00237       multiset(multiset&& __m, const allocator_type& __a)
00238       noexcept(is_nothrow_copy_constructible<_Compare>::value
00239                && _Alloc_traits::_S_always_equal())
00240       : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { }
00241 
00242       /// Allocator-extended initialier-list constructor.
00243       multiset(initializer_list<value_type> __l, const allocator_type& __a)
00244       : _M_t(_Compare(), _Key_alloc_type(__a))
00245       { _M_t._M_insert_equal(__l.begin(), __l.end()); }
00246 
00247       /// Allocator-extended range constructor.
00248       template<typename _InputIterator>
00249         multiset(_InputIterator __first, _InputIterator __last,
00250                  const allocator_type& __a)
00251         : _M_t(_Compare(), _Key_alloc_type(__a))
00252         { _M_t._M_insert_equal(__first, __last); }
00253 #endif
00254 
00255       /**
00256        *  @brief  %Multiset assignment operator.
00257        *  @param  __x  A %multiset 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       multiset&
00263       operator=(const multiset& __x)
00264       {
00265         _M_t = __x._M_t;
00266         return *this;
00267       }
00268 
00269 #if __cplusplus >= 201103L
00270       /// Move assignment operator.
00271       multiset&
00272       operator=(multiset&&) = default;
00273 
00274       /**
00275        *  @brief  %Multiset list assignment operator.
00276        *  @param  __l  An initializer_list.
00277        *
00278        *  This function fills a %multiset with copies of the elements in the
00279        *  initializer list @a __l.
00280        *
00281        *  Note that the assignment completely changes the %multiset and
00282        *  that the resulting %multiset's size is the same as the number
00283        *  of elements assigned.  Old data may be lost.
00284        */
00285       multiset&
00286       operator=(initializer_list<value_type> __l)
00287       {
00288         _M_t._M_assign_equal(__l.begin(), __l.end());
00289         return *this;
00290       }
00291 #endif
00292 
00293       // accessors:
00294 
00295       ///  Returns the comparison object.
00296       key_compare
00297       key_comp() const
00298       { return _M_t.key_comp(); }
00299       ///  Returns the comparison object.
00300       value_compare
00301       value_comp() const
00302       { return _M_t.key_comp(); }
00303       ///  Returns the memory allocation object.
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 %multiset.  Iteration is done in ascending order
00311        *  according 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 %multiset.  Iteration is done in ascending order
00320        *  according to the keys.
00321        */
00322       iterator
00323       end() const _GLIBCXX_NOEXCEPT
00324       { return _M_t.end(); }
00325 
00326       /**
00327        *  Returns a read-only (constant) reverse iterator that points to the
00328        *  last element in the %multiset.  Iteration is done in descending order
00329        *  according 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 element in the %multiset.  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 %multiset.  Iteration is done in ascending order
00348        *  according 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 %multiset.  Iteration is done in ascending order
00357        *  according to the keys.
00358        */
00359       iterator
00360       cend() const noexcept
00361       { return _M_t.end(); }
00362 
00363       /**
00364        *  Returns a read-only (constant) reverse iterator that points to the
00365        *  last element in the %multiset.  Iteration is done in descending order
00366        *  according 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 element in the %multiset.  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 %multiset.
00399        *  @param  __x  A %multiset of the same element and allocator types.
00400        *
00401        *  This exchanges the elements between two multisets in constant time.
00402        *  (It is only swapping a pointer, an integer, and an instance of the @c
00403        *  Compare type (which itself is often stateless and empty), so it should
00404        *  be quite fast.)
00405        *  Note that the global std::swap() function is specialized such that
00406        *  std::swap(s1,s2) will feed to this function.
00407        */
00408       void
00409       swap(multiset& __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 Builds and inserts an element into the %multiset.
00419        *  @param  __args  Arguments used to generate the element instance to be
00420        *                 inserted.
00421        *  @return An iterator that points to the inserted element.
00422        *
00423        *  This function inserts an element into the %multiset.  Contrary
00424        *  to a std::set the %multiset does not rely on unique keys and thus
00425        *  multiple copies of the same element can be inserted.
00426        *
00427        *  Insertion requires logarithmic time.
00428        */
00429       template<typename... _Args>
00430         iterator
00431         emplace(_Args&&... __args)
00432         { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
00433 
00434       /**
00435        *  @brief Builds and inserts an element into the %multiset.
00436        *  @param  __pos  An iterator that serves as a hint as to where the
00437        *                element should be inserted.
00438        *  @param  __args  Arguments used to generate the element instance to be
00439        *                 inserted.
00440        *  @return An iterator that points to the inserted element.
00441        *
00442        *  This function inserts an element into the %multiset.  Contrary
00443        *  to a std::set the %multiset does not rely on unique keys and thus
00444        *  multiple copies of the same element can be inserted.
00445        *
00446        *  Note that the first parameter is only a hint and can potentially
00447        *  improve the performance of the insertion process.  A bad hint would
00448        *  cause no gains in efficiency.
00449        *
00450        *  See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00451        *  for more on @a hinting.
00452        *
00453        *  Insertion requires logarithmic time (if the hint is not taken).
00454        */
00455       template<typename... _Args>
00456         iterator
00457         emplace_hint(const_iterator __pos, _Args&&... __args)
00458         {
00459           return _M_t._M_emplace_hint_equal(__pos,
00460                                             std::forward<_Args>(__args)...);
00461         }
00462 #endif
00463 
00464       /**
00465        *  @brief Inserts an element into the %multiset.
00466        *  @param  __x  Element to be inserted.
00467        *  @return An iterator that points to the inserted element.
00468        *
00469        *  This function inserts an element into the %multiset.  Contrary
00470        *  to a std::set the %multiset does not rely on unique keys and thus
00471        *  multiple copies of the same element can be inserted.
00472        *
00473        *  Insertion requires logarithmic time.
00474        */
00475       iterator
00476       insert(const value_type& __x)
00477       { return _M_t._M_insert_equal(__x); }
00478 
00479 #if __cplusplus >= 201103L
00480       iterator
00481       insert(value_type&& __x)
00482       { return _M_t._M_insert_equal(std::move(__x)); }
00483 #endif
00484 
00485       /**
00486        *  @brief Inserts an element into the %multiset.
00487        *  @param  __position  An iterator that serves as a hint as to where the
00488        *                    element should be inserted.
00489        *  @param  __x  Element to be inserted.
00490        *  @return An iterator that points to the inserted element.
00491        *
00492        *  This function inserts an element into the %multiset.  Contrary
00493        *  to a std::set the %multiset does not rely on unique keys and thus
00494        *  multiple copies of the same element can be inserted.
00495        *
00496        *  Note that the first parameter is only a hint and can potentially
00497        *  improve the performance of the insertion process.  A bad hint would
00498        *  cause no gains in efficiency.
00499        *
00500        *  See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00501        *  for more on @a hinting.
00502        *
00503        *  Insertion requires logarithmic time (if the hint is not taken).
00504        */
00505       iterator
00506       insert(const_iterator __position, const value_type& __x)
00507       { return _M_t._M_insert_equal_(__position, __x); }
00508 
00509 #if __cplusplus >= 201103L
00510       iterator
00511       insert(const_iterator __position, value_type&& __x)
00512       { return _M_t._M_insert_equal_(__position, std::move(__x)); }
00513 #endif
00514 
00515       /**
00516        *  @brief A template function that tries to insert a range of elements.
00517        *  @param  __first  Iterator pointing to the start of the range to be
00518        *                   inserted.
00519        *  @param  __last  Iterator pointing to the end of the range.
00520        *
00521        *  Complexity similar to that of the range constructor.
00522        */
00523       template<typename _InputIterator>
00524         void
00525         insert(_InputIterator __first, _InputIterator __last)
00526         { _M_t._M_insert_equal(__first, __last); }
00527 
00528 #if __cplusplus >= 201103L
00529       /**
00530        *  @brief Attempts to insert a list of elements into the %multiset.
00531        *  @param  __l  A std::initializer_list<value_type> of elements
00532        *               to be inserted.
00533        *
00534        *  Complexity similar to that of the range constructor.
00535        */
00536       void
00537       insert(initializer_list<value_type> __l)
00538       { this->insert(__l.begin(), __l.end()); }
00539 #endif
00540 
00541 #if __cplusplus >= 201103L
00542       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00543       // DR 130. Associative erase should return an iterator.
00544       /**
00545        *  @brief Erases an element from a %multiset.
00546        *  @param  __position  An iterator pointing to the element to be erased.
00547        *  @return An iterator pointing to the element immediately following
00548        *          @a position prior to the element being erased. If no such 
00549        *          element exists, end() is returned.
00550        *
00551        *  This function erases an element, pointed to by the given iterator,
00552        *  from a %multiset.  Note that this function only erases the element,
00553        *  and that if the element is itself a pointer, the pointed-to memory is
00554        *  not touched in any way.  Managing the pointer is the user's
00555        *  responsibility.
00556        */
00557       _GLIBCXX_ABI_TAG_CXX11
00558       iterator
00559       erase(const_iterator __position)
00560       { return _M_t.erase(__position); }
00561 #else
00562       /**
00563        *  @brief Erases an element from a %multiset.
00564        *  @param  __position  An iterator pointing to the element to be erased.
00565        *
00566        *  This function erases an element, pointed to by the given iterator,
00567        *  from a %multiset.  Note that this function only erases the element,
00568        *  and that if the element is itself a pointer, the pointed-to memory is
00569        *  not touched in any way.  Managing the pointer is the user's
00570        *  responsibility.
00571        */
00572       void
00573       erase(iterator __position)
00574       { _M_t.erase(__position); }
00575 #endif
00576 
00577       /**
00578        *  @brief Erases elements according to the provided key.
00579        *  @param  __x  Key of element to be erased.
00580        *  @return  The number of elements erased.
00581        *
00582        *  This function erases all elements located by the given key from a
00583        *  %multiset.
00584        *  Note that this function only erases the element, and that if
00585        *  the element is itself a pointer, the pointed-to memory is not touched
00586        *  in any way.  Managing the pointer is the user's responsibility.
00587        */
00588       size_type
00589       erase(const key_type& __x)
00590       { return _M_t.erase(__x); }
00591 
00592 #if __cplusplus >= 201103L
00593       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00594       // DR 130. Associative erase should return an iterator.
00595       /**
00596        *  @brief Erases a [first,last) range of elements from a %multiset.
00597        *  @param  __first  Iterator pointing to the start of the range to be
00598        *                   erased.
00599        *  @param __last Iterator pointing to the end of the range to
00600        *                be erased.
00601        *  @return The iterator @a last.
00602        *
00603        *  This function erases a sequence of elements from a %multiset.
00604        *  Note that this function only erases the elements, and that if
00605        *  the elements themselves are pointers, the pointed-to memory is not
00606        *  touched in any way.  Managing the pointer is the user's
00607        *  responsibility.
00608        */
00609       _GLIBCXX_ABI_TAG_CXX11
00610       iterator
00611       erase(const_iterator __first, const_iterator __last)
00612       { return _M_t.erase(__first, __last); }
00613 #else
00614       /**
00615        *  @brief Erases a [first,last) range of elements from a %multiset.
00616        *  @param  first  Iterator pointing to the start of the range to be
00617        *                 erased.
00618        *  @param  last  Iterator pointing to the end of the range to be erased.
00619        *
00620        *  This function erases a sequence of elements from a %multiset.
00621        *  Note that this function only erases the elements, and that if
00622        *  the elements themselves are pointers, the pointed-to memory is not
00623        *  touched in any way.  Managing the pointer is the user's
00624        *  responsibility.
00625        */
00626       void
00627       erase(iterator __first, iterator __last)
00628       { _M_t.erase(__first, __last); }
00629 #endif
00630 
00631       /**
00632        *  Erases all elements in a %multiset.  Note that this function only
00633        *  erases the elements, and that if the elements themselves are pointers,
00634        *  the pointed-to memory is not touched in any way.  Managing the pointer
00635        *  is the user's responsibility.
00636        */
00637       void
00638       clear() _GLIBCXX_NOEXCEPT
00639       { _M_t.clear(); }
00640 
00641       // multiset operations:
00642 
00643       //@{
00644       /**
00645        *  @brief Finds the number of elements with given key.
00646        *  @param  __x  Key of elements to be located.
00647        *  @return Number of elements with specified key.
00648        */
00649       size_type
00650       count(const key_type& __x) const
00651       { return _M_t.count(__x); }
00652 
00653 #if __cplusplus > 201103L
00654       template<typename _Kt>
00655         auto
00656         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
00657         { return _M_t._M_count_tr(__x); }
00658 #endif
00659       //@}
00660 
00661       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00662       // 214.  set::find() missing const overload
00663       //@{
00664       /**
00665        *  @brief Tries to locate an element in a %set.
00666        *  @param  __x  Element to be located.
00667        *  @return  Iterator pointing to sought-after element, or end() if not
00668        *           found.
00669        *
00670        *  This function takes a key and tries to locate the element with which
00671        *  the key matches.  If successful the function returns an iterator
00672        *  pointing to the sought after element.  If unsuccessful it returns the
00673        *  past-the-end ( @c end() ) iterator.
00674        */
00675       iterator
00676       find(const key_type& __x)
00677       { return _M_t.find(__x); }
00678 
00679       const_iterator
00680       find(const key_type& __x) const
00681       { return _M_t.find(__x); }
00682 
00683 #if __cplusplus > 201103L
00684       template<typename _Kt>
00685         auto
00686         find(const _Kt& __x)
00687         -> decltype(iterator{_M_t._M_find_tr(__x)})
00688         { return iterator{_M_t._M_find_tr(__x)}; }
00689 
00690       template<typename _Kt>
00691         auto
00692         find(const _Kt& __x) const
00693         -> decltype(const_iterator{_M_t._M_find_tr(__x)})
00694         { return const_iterator{_M_t._M_find_tr(__x)}; }
00695 #endif
00696       //@}
00697 
00698       //@{
00699       /**
00700        *  @brief Finds the beginning of a subsequence matching given key.
00701        *  @param  __x  Key to be located.
00702        *  @return  Iterator pointing to first element equal to or greater
00703        *           than key, or end().
00704        *
00705        *  This function returns the first element of a subsequence of elements
00706        *  that matches the given key.  If unsuccessful it returns an iterator
00707        *  pointing to the first element that has a greater value than given key
00708        *  or end() if no such element exists.
00709        */
00710       iterator
00711       lower_bound(const key_type& __x)
00712       { return _M_t.lower_bound(__x); }
00713 
00714       const_iterator
00715       lower_bound(const key_type& __x) const
00716       { return _M_t.lower_bound(__x); }
00717 
00718 #if __cplusplus > 201103L
00719       template<typename _Kt>
00720         auto
00721         lower_bound(const _Kt& __x)
00722         -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
00723         { return iterator(_M_t._M_lower_bound_tr(__x)); }
00724 
00725       template<typename _Kt>
00726         auto
00727         lower_bound(const _Kt& __x) const
00728         -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
00729         { return iterator(_M_t._M_lower_bound_tr(__x)); }
00730 #endif
00731       //@}
00732 
00733       //@{
00734       /**
00735        *  @brief Finds the end of a subsequence matching given key.
00736        *  @param  __x  Key to be located.
00737        *  @return Iterator pointing to the first element
00738        *          greater than key, or end().
00739        */
00740       iterator
00741       upper_bound(const key_type& __x)
00742       { return _M_t.upper_bound(__x); }
00743 
00744       const_iterator
00745       upper_bound(const key_type& __x) const
00746       { return _M_t.upper_bound(__x); }
00747 
00748 #if __cplusplus > 201103L
00749       template<typename _Kt>
00750         auto
00751         upper_bound(const _Kt& __x)
00752         -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
00753         { return iterator(_M_t._M_upper_bound_tr(__x)); }
00754 
00755       template<typename _Kt>
00756         auto
00757         upper_bound(const _Kt& __x) const
00758         -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
00759         { return iterator(_M_t._M_upper_bound_tr(__x)); }
00760 #endif
00761       //@}
00762 
00763       //@{
00764       /**
00765        *  @brief Finds a subsequence matching given key.
00766        *  @param  __x  Key to be located.
00767        *  @return  Pair of iterators that possibly points to the subsequence
00768        *           matching given key.
00769        *
00770        *  This function is equivalent to
00771        *  @code
00772        *    std::make_pair(c.lower_bound(val),
00773        *                   c.upper_bound(val))
00774        *  @endcode
00775        *  (but is faster than making the calls separately).
00776        *
00777        *  This function probably only makes sense for multisets.
00778        */
00779       std::pair<iterator, iterator>
00780       equal_range(const key_type& __x)
00781       { return _M_t.equal_range(__x); }
00782 
00783       std::pair<const_iterator, const_iterator>
00784       equal_range(const key_type& __x) const
00785       { return _M_t.equal_range(__x); }
00786 
00787 #if __cplusplus > 201103L
00788       template<typename _Kt>
00789         auto
00790         equal_range(const _Kt& __x)
00791         -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
00792         { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
00793 
00794       template<typename _Kt>
00795         auto
00796         equal_range(const _Kt& __x) const
00797         -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
00798         { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
00799 #endif
00800       //@}
00801 
00802       template<typename _K1, typename _C1, typename _A1>
00803         friend bool
00804         operator==(const multiset<_K1, _C1, _A1>&,
00805                    const multiset<_K1, _C1, _A1>&);
00806 
00807       template<typename _K1, typename _C1, typename _A1>
00808         friend bool
00809         operator< (const multiset<_K1, _C1, _A1>&,
00810                    const multiset<_K1, _C1, _A1>&);
00811     };
00812 
00813   /**
00814    *  @brief  Multiset equality comparison.
00815    *  @param  __x  A %multiset.
00816    *  @param  __y  A %multiset of the same type as @a __x.
00817    *  @return  True iff the size and elements of the multisets are equal.
00818    *
00819    *  This is an equivalence relation.  It is linear in the size of the
00820    *  multisets.
00821    *  Multisets are considered equivalent if their sizes are equal, and if
00822    *  corresponding elements compare equal.
00823   */
00824   template<typename _Key, typename _Compare, typename _Alloc>
00825     inline bool
00826     operator==(const multiset<_Key, _Compare, _Alloc>& __x,
00827                const multiset<_Key, _Compare, _Alloc>& __y)
00828     { return __x._M_t == __y._M_t; }
00829 
00830   /**
00831    *  @brief  Multiset ordering relation.
00832    *  @param  __x  A %multiset.
00833    *  @param  __y  A %multiset of the same type as @a __x.
00834    *  @return  True iff @a __x is lexicographically less than @a __y.
00835    *
00836    *  This is a total ordering relation.  It is linear in the size of the
00837    *  sets.  The elements must be comparable with @c <.
00838    *
00839    *  See std::lexicographical_compare() for how the determination is made.
00840   */
00841   template<typename _Key, typename _Compare, typename _Alloc>
00842     inline bool
00843     operator<(const multiset<_Key, _Compare, _Alloc>& __x,
00844               const multiset<_Key, _Compare, _Alloc>& __y)
00845     { return __x._M_t < __y._M_t; }
00846 
00847   ///  Returns !(x == y).
00848   template<typename _Key, typename _Compare, typename _Alloc>
00849     inline bool
00850     operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
00851                const multiset<_Key, _Compare, _Alloc>& __y)
00852     { return !(__x == __y); }
00853 
00854   ///  Returns y < x.
00855   template<typename _Key, typename _Compare, typename _Alloc>
00856     inline bool
00857     operator>(const multiset<_Key,_Compare,_Alloc>& __x,
00858               const multiset<_Key,_Compare,_Alloc>& __y)
00859     { return __y < __x; }
00860 
00861   ///  Returns !(y < x)
00862   template<typename _Key, typename _Compare, typename _Alloc>
00863     inline bool
00864     operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
00865                const multiset<_Key, _Compare, _Alloc>& __y)
00866     { return !(__y < __x); }
00867 
00868   ///  Returns !(x < y)
00869   template<typename _Key, typename _Compare, typename _Alloc>
00870     inline bool
00871     operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
00872                const multiset<_Key, _Compare, _Alloc>& __y)
00873     { return !(__x < __y); }
00874 
00875   /// See std::multiset::swap().
00876   template<typename _Key, typename _Compare, typename _Alloc>
00877     inline void
00878     swap(multiset<_Key, _Compare, _Alloc>& __x,
00879          multiset<_Key, _Compare, _Alloc>& __y)
00880     { __x.swap(__y); }
00881 
00882 _GLIBCXX_END_NAMESPACE_CONTAINER
00883 } // namespace std
00884 
00885 #endif /* _STL_MULTISET_H */