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