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