libstdc++
stl_multimap.h
Go to the documentation of this file.
00001 // Multimap 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,1997
00041  * Silicon Graphics Computer Systems, Inc.
00042  *
00043  * Permission to use, copy, modify, distribute and sell this software
00044  * and its documentation for any purpose is hereby granted without fee,
00045  * provided that the above copyright notice appear in all copies and
00046  * that both that copyright notice and this permission notice appear
00047  * in supporting documentation.  Silicon Graphics makes no
00048  * representations about the suitability of this software for any
00049  * purpose.  It is provided "as is" without express or implied warranty.
00050  */
00051 
00052 /** @file bits/stl_multimap.h
00053  *  This is an internal header file, included by other library headers.
00054  *  Do not attempt to use it directly. @headername{map}
00055  */
00056 
00057 #ifndef _STL_MULTIMAP_H
00058 #define _STL_MULTIMAP_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 (key,value) pairs, which can be
00071    *  retrieved based on a key, 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 multimap<Key,T> the key_type is Key, the mapped_type
00079    *  is T, and the value_type is std::pair<const Key,T>.
00080    *
00081    *  Multimaps support bidirectional iterators.
00082    *
00083    *  The private tree data is declared exactly the same way for map and
00084    *  multimap; the distinction is made entirely in how the tree functions are
00085    *  called (*_unique versus *_equal, same as the standard).
00086   */
00087   template <typename _Key, typename _Tp,
00088         typename _Compare = std::less<_Key>,
00089         typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00090     class multimap
00091     {
00092     public:
00093       typedef _Key                                          key_type;
00094       typedef _Tp                                           mapped_type;
00095       typedef std::pair<const _Key, _Tp>                    value_type;
00096       typedef _Compare                                      key_compare;
00097       typedef _Alloc                                        allocator_type;
00098 
00099     private:
00100       // concept requirements
00101       typedef typename _Alloc::value_type                   _Alloc_value_type;
00102       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00103       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
00104                 _BinaryFunctionConcept)
00105       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)    
00106 
00107     public:
00108       class value_compare
00109       : public std::binary_function<value_type, value_type, bool>
00110       {
00111     friend class multimap<_Key, _Tp, _Compare, _Alloc>;
00112       protected:
00113     _Compare comp;
00114 
00115     value_compare(_Compare __c)
00116     : comp(__c) { }
00117 
00118       public:
00119     bool operator()(const value_type& __x, const value_type& __y) const
00120     { return comp(__x.first, __y.first); }
00121       };
00122 
00123     private:
00124       /// This turns a red-black tree into a [multi]map.
00125       typedef typename _Alloc::template rebind<value_type>::other 
00126         _Pair_alloc_type;
00127 
00128       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
00129                key_compare, _Pair_alloc_type> _Rep_type;
00130       /// The actual tree structure.
00131       _Rep_type _M_t;
00132 
00133     public:
00134       // many of these are specified differently in ISO, but the following are
00135       // "functionally equivalent"
00136       typedef typename _Pair_alloc_type::pointer         pointer;
00137       typedef typename _Pair_alloc_type::const_pointer   const_pointer;
00138       typedef typename _Pair_alloc_type::reference       reference;
00139       typedef typename _Pair_alloc_type::const_reference const_reference;
00140       typedef typename _Rep_type::iterator               iterator;
00141       typedef typename _Rep_type::const_iterator         const_iterator;
00142       typedef typename _Rep_type::size_type              size_type;
00143       typedef typename _Rep_type::difference_type        difference_type;
00144       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
00145       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00146 
00147       // [23.3.2] construct/copy/destroy
00148       // (get_allocator() is also listed in this section)
00149       /**
00150        *  @brief  Default constructor creates no elements.
00151        */
00152       multimap()
00153       : _M_t() { }
00154 
00155       /**
00156        *  @brief  Creates a %multimap with no elements.
00157        *  @param  __comp  A comparison object.
00158        *  @param  __a  An allocator object.
00159        */
00160       explicit
00161       multimap(const _Compare& __comp,
00162            const allocator_type& __a = allocator_type())
00163       : _M_t(__comp, _Pair_alloc_type(__a)) { }
00164 
00165       /**
00166        *  @brief  %Multimap copy constructor.
00167        *  @param  __x  A %multimap of identical element and allocator types.
00168        *
00169        *  The newly-created %multimap uses a copy of the allocation object
00170        *  used by @a __x.
00171        */
00172       multimap(const multimap& __x)
00173       : _M_t(__x._M_t) { }
00174 
00175 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00176       /**
00177        *  @brief  %Multimap move constructor.
00178        *  @param   __x  A %multimap of identical element and allocator types.
00179        *
00180        *  The newly-created %multimap contains the exact contents of @a __x.
00181        *  The contents of @a __x are a valid, but unspecified %multimap.
00182        */
00183       multimap(multimap&& __x)
00184       noexcept(is_nothrow_copy_constructible<_Compare>::value)
00185       : _M_t(std::move(__x._M_t)) { }
00186 
00187       /**
00188        *  @brief  Builds a %multimap from an initializer_list.
00189        *  @param  __l  An initializer_list.
00190        *  @param  __comp  A comparison functor.
00191        *  @param  __a  An allocator object.
00192        *
00193        *  Create a %multimap consisting of copies of the elements from
00194        *  the initializer_list.  This is linear in N if the list is already
00195        *  sorted, and NlogN otherwise (where N is @a __l.size()).
00196        */
00197       multimap(initializer_list<value_type> __l,
00198            const _Compare& __comp = _Compare(),
00199            const allocator_type& __a = allocator_type())
00200       : _M_t(__comp, _Pair_alloc_type(__a))
00201       { _M_t._M_insert_equal(__l.begin(), __l.end()); }
00202 #endif
00203 
00204       /**
00205        *  @brief  Builds a %multimap from a range.
00206        *  @param  __first  An input iterator.
00207        *  @param  __last  An input iterator.
00208        *
00209        *  Create a %multimap consisting of copies of the elements from
00210        *  [__first,__last).  This is linear in N if the range is already sorted,
00211        *  and NlogN otherwise (where N is distance(__first,__last)).
00212        */
00213       template<typename _InputIterator>
00214         multimap(_InputIterator __first, _InputIterator __last)
00215     : _M_t()
00216         { _M_t._M_insert_equal(__first, __last); }
00217 
00218       /**
00219        *  @brief  Builds a %multimap from a range.
00220        *  @param  __first  An input iterator.
00221        *  @param  __last  An input iterator.
00222        *  @param  __comp  A comparison functor.
00223        *  @param  __a  An allocator object.
00224        *
00225        *  Create a %multimap consisting of copies of the elements from
00226        *  [__first,__last).  This is linear in N if the range is already sorted,
00227        *  and NlogN otherwise (where N is distance(__first,__last)).
00228        */
00229       template<typename _InputIterator>
00230         multimap(_InputIterator __first, _InputIterator __last,
00231          const _Compare& __comp,
00232          const allocator_type& __a = allocator_type())
00233     : _M_t(__comp, _Pair_alloc_type(__a))
00234         { _M_t._M_insert_equal(__first, __last); }
00235 
00236       // FIXME There is no dtor declared, but we should have something generated
00237       // by Doxygen.  I don't know what tags to add to this paragraph to make
00238       // that happen:
00239       /**
00240        *  The dtor only erases the elements, and note that if the elements
00241        *  themselves are pointers, the pointed-to memory is not touched in any
00242        *  way.  Managing the pointer is the user's responsibility.
00243        */
00244 
00245       /**
00246        *  @brief  %Multimap assignment operator.
00247        *  @param  __x  A %multimap of identical element and allocator types.
00248        *
00249        *  All the elements of @a __x are copied, but unlike the copy
00250        *  constructor, the allocator object is not copied.
00251        */
00252       multimap&
00253       operator=(const multimap& __x)
00254       {
00255     _M_t = __x._M_t;
00256     return *this;
00257       }
00258 
00259 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00260       /**
00261        *  @brief  %Multimap move assignment operator.
00262        *  @param  __x  A %multimap of identical element and allocator types.
00263        *
00264        *  The contents of @a __x are moved into this multimap (without copying).
00265        *  @a __x is a valid, but unspecified multimap.
00266        */
00267       multimap&
00268       operator=(multimap&& __x)
00269       {
00270     // NB: DR 1204.
00271     // NB: DR 675.
00272     this->clear();
00273     this->swap(__x);
00274     return *this;
00275       }
00276 
00277       /**
00278        *  @brief  %Multimap list assignment operator.
00279        *  @param  __l  An initializer_list.
00280        *
00281        *  This function fills a %multimap with copies of the elements
00282        *  in the initializer list @a __l.
00283        *
00284        *  Note that the assignment completely changes the %multimap and
00285        *  that the resulting %multimap's size is the same as the number
00286        *  of elements assigned.  Old data may be lost.
00287        */
00288       multimap&
00289       operator=(initializer_list<value_type> __l)
00290       {
00291     this->clear();
00292     this->insert(__l.begin(), __l.end());
00293     return *this;
00294       }
00295 #endif
00296 
00297       /// Get a copy of the memory allocation object.
00298       allocator_type
00299       get_allocator() const _GLIBCXX_NOEXCEPT 
00300       { return allocator_type(_M_t.get_allocator()); }
00301 
00302       // iterators
00303       /**
00304        *  Returns a read/write iterator that points to the first pair in the
00305        *  %multimap.  Iteration is done in ascending order according to the
00306        *  keys.
00307        */
00308       iterator
00309       begin() _GLIBCXX_NOEXCEPT
00310       { return _M_t.begin(); }
00311 
00312       /**
00313        *  Returns a read-only (constant) iterator that points to the first pair
00314        *  in the %multimap.  Iteration is done in ascending order according to
00315        *  the keys.
00316        */
00317       const_iterator
00318       begin() const _GLIBCXX_NOEXCEPT
00319       { return _M_t.begin(); }
00320 
00321       /**
00322        *  Returns a read/write iterator that points one past the last pair in
00323        *  the %multimap.  Iteration is done in ascending order according to the
00324        *  keys.
00325        */
00326       iterator
00327       end() _GLIBCXX_NOEXCEPT
00328       { return _M_t.end(); }
00329 
00330       /**
00331        *  Returns a read-only (constant) iterator that points one past the last
00332        *  pair in the %multimap.  Iteration is done in ascending order according
00333        *  to the keys.
00334        */
00335       const_iterator
00336       end() const _GLIBCXX_NOEXCEPT
00337       { return _M_t.end(); }
00338 
00339       /**
00340        *  Returns a read/write reverse iterator that points to the last pair in
00341        *  the %multimap.  Iteration is done in descending order according to the
00342        *  keys.
00343        */
00344       reverse_iterator
00345       rbegin() _GLIBCXX_NOEXCEPT
00346       { return _M_t.rbegin(); }
00347 
00348       /**
00349        *  Returns a read-only (constant) reverse iterator that points to the
00350        *  last pair in the %multimap.  Iteration is done in descending order
00351        *  according to the keys.
00352        */
00353       const_reverse_iterator
00354       rbegin() const _GLIBCXX_NOEXCEPT
00355       { return _M_t.rbegin(); }
00356 
00357       /**
00358        *  Returns a read/write reverse iterator that points to one before the
00359        *  first pair in the %multimap.  Iteration is done in descending order
00360        *  according to the keys.
00361        */
00362       reverse_iterator
00363       rend() _GLIBCXX_NOEXCEPT
00364       { return _M_t.rend(); }
00365 
00366       /**
00367        *  Returns a read-only (constant) reverse iterator that points to one
00368        *  before the first pair in the %multimap.  Iteration is done in
00369        *  descending order according to the keys.
00370        */
00371       const_reverse_iterator
00372       rend() const _GLIBCXX_NOEXCEPT
00373       { return _M_t.rend(); }
00374 
00375 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00376       /**
00377        *  Returns a read-only (constant) iterator that points to the first pair
00378        *  in the %multimap.  Iteration is done in ascending order according to
00379        *  the keys.
00380        */
00381       const_iterator
00382       cbegin() const noexcept
00383       { return _M_t.begin(); }
00384 
00385       /**
00386        *  Returns a read-only (constant) iterator that points one past the last
00387        *  pair in the %multimap.  Iteration is done in ascending order according
00388        *  to the keys.
00389        */
00390       const_iterator
00391       cend() const noexcept
00392       { return _M_t.end(); }
00393 
00394       /**
00395        *  Returns a read-only (constant) reverse iterator that points to the
00396        *  last pair in the %multimap.  Iteration is done in descending order
00397        *  according to the keys.
00398        */
00399       const_reverse_iterator
00400       crbegin() const noexcept
00401       { return _M_t.rbegin(); }
00402 
00403       /**
00404        *  Returns a read-only (constant) reverse iterator that points to one
00405        *  before the first pair in the %multimap.  Iteration is done in
00406        *  descending order according to the keys.
00407        */
00408       const_reverse_iterator
00409       crend() const noexcept
00410       { return _M_t.rend(); }
00411 #endif
00412 
00413       // capacity
00414       /** Returns true if the %multimap is empty.  */
00415       bool
00416       empty() const _GLIBCXX_NOEXCEPT
00417       { return _M_t.empty(); }
00418 
00419       /** Returns the size of the %multimap.  */
00420       size_type
00421       size() const _GLIBCXX_NOEXCEPT
00422       { return _M_t.size(); }
00423 
00424       /** Returns the maximum size of the %multimap.  */
00425       size_type
00426       max_size() const _GLIBCXX_NOEXCEPT
00427       { return _M_t.max_size(); }
00428 
00429       // modifiers
00430       /**
00431        *  @brief Inserts a std::pair into the %multimap.
00432        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00433        *             of pairs).
00434        *  @return An iterator that points to the inserted (key,value) pair.
00435        *
00436        *  This function inserts a (key, value) pair into the %multimap.
00437        *  Contrary to a std::map the %multimap does not rely on unique keys and
00438        *  thus multiple pairs with the same key can be inserted.
00439        *
00440        *  Insertion requires logarithmic time.
00441        */
00442       iterator
00443       insert(const value_type& __x)
00444       { return _M_t._M_insert_equal(__x); }
00445 
00446 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00447       template<typename _Pair, typename = typename
00448            std::enable_if<std::is_convertible<_Pair,
00449                           value_type>::value>::type>
00450         iterator
00451         insert(_Pair&& __x)
00452         { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
00453 #endif
00454 
00455       /**
00456        *  @brief Inserts a std::pair into the %multimap.
00457        *  @param  __position  An iterator that serves as a hint as to where the
00458        *                      pair should be inserted.
00459        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00460        *               of pairs).
00461        *  @return An iterator that points to the inserted (key,value) pair.
00462        *
00463        *  This function inserts a (key, value) pair into the %multimap.
00464        *  Contrary to a std::map the %multimap does not rely on unique keys and
00465        *  thus multiple pairs with the same key can be inserted.
00466        *  Note that the first parameter is only a hint and can potentially
00467        *  improve the performance of the insertion process.  A bad hint would
00468        *  cause no gains in efficiency.
00469        *
00470        *  For more on @a hinting, see:
00471        *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
00472        *
00473        *  Insertion requires logarithmic time (if the hint is not taken).
00474        */
00475       iterator
00476 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00477       insert(const_iterator __position, const value_type& __x)
00478 #else
00479       insert(iterator __position, const value_type& __x)
00480 #endif
00481       { return _M_t._M_insert_equal_(__position, __x); }
00482 
00483 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00484       template<typename _Pair, typename = typename
00485            std::enable_if<std::is_convertible<_Pair,
00486                           value_type>::value>::type>
00487         iterator
00488         insert(const_iterator __position, _Pair&& __x)
00489         { return _M_t._M_insert_equal_(__position,
00490                        std::forward<_Pair>(__x)); }
00491 #endif
00492 
00493       /**
00494        *  @brief A template function that attempts to insert a range
00495        *  of elements.
00496        *  @param  __first  Iterator pointing to the start of the range to be
00497        *                   inserted.
00498        *  @param  __last  Iterator pointing to the end of the range.
00499        *
00500        *  Complexity similar to that of the range constructor.
00501        */
00502       template<typename _InputIterator>
00503         void
00504         insert(_InputIterator __first, _InputIterator __last)
00505         { _M_t._M_insert_equal(__first, __last); }
00506 
00507 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00508       /**
00509        *  @brief Attempts to insert a list of std::pairs into the %multimap.
00510        *  @param  __l  A std::initializer_list<value_type> of pairs to be
00511        *               inserted.
00512        *
00513        *  Complexity similar to that of the range constructor.
00514        */
00515       void
00516       insert(initializer_list<value_type> __l)
00517       { this->insert(__l.begin(), __l.end()); }
00518 #endif
00519 
00520 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00521       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00522       // DR 130. Associative erase should return an iterator.
00523       /**
00524        *  @brief Erases an element from a %multimap.
00525        *  @param  __position  An iterator pointing to the element to be erased.
00526        *  @return An iterator pointing to the element immediately following
00527        *          @a position prior to the element being erased. If no such 
00528        *          element exists, end() is returned.
00529        *
00530        *  This function erases an element, pointed to by the given iterator,
00531        *  from a %multimap.  Note that this function only erases the element,
00532        *  and that if the element is itself a pointer, the pointed-to memory is
00533        *  not touched in any way.  Managing the pointer is the user's
00534        *  responsibility.
00535        */
00536       iterator
00537       erase(const_iterator __position)
00538       { return _M_t.erase(__position); }
00539 
00540       // LWG 2059.
00541       iterator
00542       erase(iterator __position)
00543       { return _M_t.erase(__position); }
00544 #else
00545       /**
00546        *  @brief Erases an element from a %multimap.
00547        *  @param  __position  An iterator pointing to the element to be erased.
00548        *
00549        *  This function erases an element, pointed to by the given iterator,
00550        *  from a %multimap.  Note that this function only erases the element,
00551        *  and that if the element is itself a pointer, the pointed-to memory is
00552        *  not touched in any way.  Managing the pointer is the user's
00553        *  responsibility.
00554        */
00555       void
00556       erase(iterator __position)
00557       { _M_t.erase(__position); }
00558 #endif
00559 
00560       /**
00561        *  @brief Erases elements according to the provided key.
00562        *  @param  __x  Key of element to be erased.
00563        *  @return  The number of elements erased.
00564        *
00565        *  This function erases all elements located by the given key from a
00566        *  %multimap.
00567        *  Note that this function only erases the element, and that if
00568        *  the element is itself a pointer, the pointed-to memory is not touched
00569        *  in any way.  Managing the pointer is the user's responsibility.
00570        */
00571       size_type
00572       erase(const key_type& __x)
00573       { return _M_t.erase(__x); }
00574 
00575 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00576       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00577       // DR 130. Associative erase should return an iterator.
00578       /**
00579        *  @brief Erases a [first,last) range of elements from a %multimap.
00580        *  @param  __first  Iterator pointing to the start of the range to be
00581        *                   erased.
00582        *  @param __last Iterator pointing to the end of the range to be
00583        *                erased .
00584        *  @return The iterator @a __last.
00585        *
00586        *  This function erases a sequence of elements from a %multimap.
00587        *  Note that this function only erases the elements, and that if
00588        *  the elements themselves are pointers, the pointed-to memory is not
00589        *  touched in any way.  Managing the pointer is the user's
00590        *  responsibility.
00591        */
00592       iterator
00593       erase(const_iterator __first, const_iterator __last)
00594       { return _M_t.erase(__first, __last); }
00595 #else
00596       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00597       // DR 130. Associative erase should return an iterator.
00598       /**
00599        *  @brief Erases a [first,last) range of elements from a %multimap.
00600        *  @param  __first  Iterator pointing to the start of the range to be
00601        *                 erased.
00602        *  @param __last Iterator pointing to the end of the range to
00603        *                be erased.
00604        *
00605        *  This function erases a sequence of elements from a %multimap.
00606        *  Note that this function only erases the elements, and that if
00607        *  the elements themselves are pointers, the pointed-to memory is not
00608        *  touched in any way.  Managing the pointer is the user's
00609        *  responsibility.
00610        */
00611       void
00612       erase(iterator __first, iterator __last)
00613       { _M_t.erase(__first, __last); }
00614 #endif
00615 
00616       /**
00617        *  @brief  Swaps data with another %multimap.
00618        *  @param  __x  A %multimap of the same element and allocator types.
00619        *
00620        *  This exchanges the elements between two multimaps in constant time.
00621        *  (It is only swapping a pointer, an integer, and an instance of
00622        *  the @c Compare type (which itself is often stateless and empty), so it
00623        *  should be quite fast.)
00624        *  Note that the global std::swap() function is specialized such that
00625        *  std::swap(m1,m2) will feed to this function.
00626        */
00627       void
00628       swap(multimap& __x)
00629       { _M_t.swap(__x._M_t); }
00630 
00631       /**
00632        *  Erases all elements in a %multimap.  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       // observers
00642       /**
00643        *  Returns the key comparison object out of which the %multimap
00644        *  was constructed.
00645        */
00646       key_compare
00647       key_comp() const
00648       { return _M_t.key_comp(); }
00649 
00650       /**
00651        *  Returns a value comparison object, built from the key comparison
00652        *  object out of which the %multimap was constructed.
00653        */
00654       value_compare
00655       value_comp() const
00656       { return value_compare(_M_t.key_comp()); }
00657 
00658       // multimap operations
00659       /**
00660        *  @brief Tries to locate an element in a %multimap.
00661        *  @param  __x  Key of (key, value) pair to be located.
00662        *  @return  Iterator pointing to sought-after element,
00663        *           or end() if not found.
00664        *
00665        *  This function takes a key and tries to locate the element with which
00666        *  the key matches.  If successful the function returns an iterator
00667        *  pointing to the sought after %pair.  If unsuccessful it returns the
00668        *  past-the-end ( @c end() ) iterator.
00669        */
00670       iterator
00671       find(const key_type& __x)
00672       { return _M_t.find(__x); }
00673 
00674       /**
00675        *  @brief Tries to locate an element in a %multimap.
00676        *  @param  __x  Key of (key, value) pair to be located.
00677        *  @return  Read-only (constant) iterator pointing to sought-after
00678        *           element, or end() if not found.
00679        *
00680        *  This function takes a key and tries to locate the element with which
00681        *  the key matches.  If successful the function returns a constant
00682        *  iterator pointing to the sought after %pair.  If unsuccessful it
00683        *  returns the past-the-end ( @c end() ) iterator.
00684        */
00685       const_iterator
00686       find(const key_type& __x) const
00687       { return _M_t.find(__x); }
00688 
00689       /**
00690        *  @brief Finds the number of elements with given key.
00691        *  @param  __x  Key of (key, value) pairs to be located.
00692        *  @return Number of elements with specified key.
00693        */
00694       size_type
00695       count(const key_type& __x) const
00696       { return _M_t.count(__x); }
00697 
00698       /**
00699        *  @brief Finds the beginning of a subsequence matching given key.
00700        *  @param  __x  Key of (key, value) pair to be located.
00701        *  @return  Iterator pointing to first element equal to or greater
00702        *           than key, or end().
00703        *
00704        *  This function returns the first element of a subsequence of elements
00705        *  that matches the given key.  If unsuccessful it returns an iterator
00706        *  pointing to the first element that has a greater value than given key
00707        *  or end() if no such element exists.
00708        */
00709       iterator
00710       lower_bound(const key_type& __x)
00711       { return _M_t.lower_bound(__x); }
00712 
00713       /**
00714        *  @brief Finds the beginning of a subsequence matching given key.
00715        *  @param  __x  Key of (key, value) pair to be located.
00716        *  @return  Read-only (constant) iterator pointing to first element
00717        *           equal to or greater than key, or end().
00718        *
00719        *  This function returns the first element of a subsequence of
00720        *  elements that matches the given key.  If unsuccessful the
00721        *  iterator will point to the next greatest element or, if no
00722        *  such greater element exists, to end().
00723        */
00724       const_iterator
00725       lower_bound(const key_type& __x) const
00726       { return _M_t.lower_bound(__x); }
00727 
00728       /**
00729        *  @brief Finds the end of a subsequence matching given key.
00730        *  @param  __x  Key of (key, value) pair to be located.
00731        *  @return Iterator pointing to the first element
00732        *          greater than key, or end().
00733        */
00734       iterator
00735       upper_bound(const key_type& __x)
00736       { return _M_t.upper_bound(__x); }
00737 
00738       /**
00739        *  @brief Finds the end of a subsequence matching given key.
00740        *  @param  __x  Key of (key, value) pair to be located.
00741        *  @return  Read-only (constant) iterator pointing to first iterator
00742        *           greater than key, or end().
00743        */
00744       const_iterator
00745       upper_bound(const key_type& __x) const
00746       { return _M_t.upper_bound(__x); }
00747 
00748       /**
00749        *  @brief Finds a subsequence matching given key.
00750        *  @param  __x  Key of (key, value) pairs to be located.
00751        *  @return  Pair of iterators that possibly points to the subsequence
00752        *           matching given key.
00753        *
00754        *  This function is equivalent to
00755        *  @code
00756        *    std::make_pair(c.lower_bound(val),
00757        *                   c.upper_bound(val))
00758        *  @endcode
00759        *  (but is faster than making the calls separately).
00760        */
00761       std::pair<iterator, iterator>
00762       equal_range(const key_type& __x)
00763       { return _M_t.equal_range(__x); }
00764 
00765       /**
00766        *  @brief Finds a subsequence matching given key.
00767        *  @param  __x  Key of (key, value) pairs to be located.
00768        *  @return  Pair of read-only (constant) iterators that possibly points
00769        *           to the subsequence matching given key.
00770        *
00771        *  This function is equivalent to
00772        *  @code
00773        *    std::make_pair(c.lower_bound(val),
00774        *                   c.upper_bound(val))
00775        *  @endcode
00776        *  (but is faster than making the calls separately).
00777        */
00778       std::pair<const_iterator, const_iterator>
00779       equal_range(const key_type& __x) const
00780       { return _M_t.equal_range(__x); }
00781 
00782       template<typename _K1, typename _T1, typename _C1, typename _A1>
00783         friend bool
00784         operator==(const multimap<_K1, _T1, _C1, _A1>&,
00785            const multimap<_K1, _T1, _C1, _A1>&);
00786 
00787       template<typename _K1, typename _T1, typename _C1, typename _A1>
00788         friend bool
00789         operator<(const multimap<_K1, _T1, _C1, _A1>&,
00790           const multimap<_K1, _T1, _C1, _A1>&);
00791   };
00792 
00793   /**
00794    *  @brief  Multimap equality comparison.
00795    *  @param  __x  A %multimap.
00796    *  @param  __y  A %multimap of the same type as @a __x.
00797    *  @return  True iff the size and elements of the maps are equal.
00798    *
00799    *  This is an equivalence relation.  It is linear in the size of the
00800    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
00801    *  and if corresponding elements compare equal.
00802   */
00803   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00804     inline bool
00805     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00806                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00807     { return __x._M_t == __y._M_t; }
00808 
00809   /**
00810    *  @brief  Multimap ordering relation.
00811    *  @param  __x  A %multimap.
00812    *  @param  __y  A %multimap of the same type as @a __x.
00813    *  @return  True iff @a x is lexicographically less than @a y.
00814    *
00815    *  This is a total ordering relation.  It is linear in the size of the
00816    *  multimaps.  The elements must be comparable with @c <.
00817    *
00818    *  See std::lexicographical_compare() for how the determination is made.
00819   */
00820   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00821     inline bool
00822     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00823               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00824     { return __x._M_t < __y._M_t; }
00825 
00826   /// Based on operator==
00827   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00828     inline bool
00829     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00830                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00831     { return !(__x == __y); }
00832 
00833   /// Based on operator<
00834   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00835     inline bool
00836     operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00837               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00838     { return __y < __x; }
00839 
00840   /// Based on operator<
00841   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00842     inline bool
00843     operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00844                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00845     { return !(__y < __x); }
00846 
00847   /// Based on operator<
00848   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00849     inline bool
00850     operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00851                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00852     { return !(__x < __y); }
00853 
00854   /// See std::multimap::swap().
00855   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00856     inline void
00857     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00858          multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00859     { __x.swap(__y); }
00860 
00861 _GLIBCXX_END_NAMESPACE_CONTAINER
00862 } // namespace std
00863 
00864 #endif /* _STL_MULTIMAP_H */