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