libstdc++
stl_multimap.h
Go to the documentation of this file.
00001 // Multimap implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2014 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 __gnu_cxx::__alloc_traits<_Alloc>::template
00131     rebind<value_type>::other _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       typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits;
00139 
00140     public:
00141       // many of these are specified differently in ISO, but the following are
00142       // "functionally equivalent"
00143       typedef typename _Alloc_traits::pointer            pointer;
00144       typedef typename _Alloc_traits::const_pointer      const_pointer;
00145       typedef typename _Alloc_traits::reference          reference;
00146       typedef typename _Alloc_traits::const_reference    const_reference;
00147       typedef typename _Rep_type::iterator               iterator;
00148       typedef typename _Rep_type::const_iterator         const_iterator;
00149       typedef typename _Rep_type::size_type              size_type;
00150       typedef typename _Rep_type::difference_type        difference_type;
00151       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
00152       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00153 
00154       // [23.3.2] construct/copy/destroy
00155       // (get_allocator() is also listed in this section)
00156 
00157       /**
00158        *  @brief  Default constructor creates no elements.
00159        */
00160       multimap()
00161       : _M_t() { }
00162 
00163       /**
00164        *  @brief  Creates a %multimap with no elements.
00165        *  @param  __comp  A comparison object.
00166        *  @param  __a  An allocator object.
00167        */
00168       explicit
00169       multimap(const _Compare& __comp,
00170            const allocator_type& __a = allocator_type())
00171       : _M_t(__comp, _Pair_alloc_type(__a)) { }
00172 
00173       /**
00174        *  @brief  %Multimap copy constructor.
00175        *  @param  __x  A %multimap of identical element and allocator types.
00176        *
00177        *  The newly-created %multimap uses a copy of the allocation object
00178        *  used by @a __x.
00179        */
00180       multimap(const multimap& __x)
00181       : _M_t(__x._M_t) { }
00182 
00183 #if __cplusplus >= 201103L
00184       /**
00185        *  @brief  %Multimap move constructor.
00186        *  @param   __x  A %multimap of identical element and allocator types.
00187        *
00188        *  The newly-created %multimap contains the exact contents of @a __x.
00189        *  The contents of @a __x are a valid, but unspecified %multimap.
00190        */
00191       multimap(multimap&& __x)
00192       noexcept(is_nothrow_copy_constructible<_Compare>::value)
00193       : _M_t(std::move(__x._M_t)) { }
00194 
00195       /**
00196        *  @brief  Builds a %multimap from an initializer_list.
00197        *  @param  __l  An initializer_list.
00198        *  @param  __comp  A comparison functor.
00199        *  @param  __a  An allocator object.
00200        *
00201        *  Create a %multimap consisting of copies of the elements from
00202        *  the initializer_list.  This is linear in N if the list is already
00203        *  sorted, and NlogN otherwise (where N is @a __l.size()).
00204        */
00205       multimap(initializer_list<value_type> __l,
00206            const _Compare& __comp = _Compare(),
00207            const allocator_type& __a = allocator_type())
00208       : _M_t(__comp, _Pair_alloc_type(__a))
00209       { _M_t._M_insert_equal(__l.begin(), __l.end()); }
00210 
00211       /// Allocator-extended default constructor.
00212       explicit
00213       multimap(const allocator_type& __a)
00214       : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
00215 
00216       /// Allocator-extended copy constructor.
00217       multimap(const multimap& __m, const allocator_type& __a)
00218       : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
00219 
00220       /// Allocator-extended move constructor.
00221       multimap(multimap&& __m, const allocator_type& __a)
00222       noexcept(is_nothrow_copy_constructible<_Compare>::value
00223            && _Alloc_traits::_S_always_equal())
00224       : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
00225 
00226       /// Allocator-extended initialier-list constructor.
00227       multimap(initializer_list<value_type> __l, const allocator_type& __a)
00228       : _M_t(_Compare(), _Pair_alloc_type(__a))
00229       { _M_t._M_insert_equal(__l.begin(), __l.end()); }
00230 
00231       /// Allocator-extended range constructor.
00232       template<typename _InputIterator>
00233         multimap(_InputIterator __first, _InputIterator __last,
00234          const allocator_type& __a)
00235     : _M_t(_Compare(), _Pair_alloc_type(__a))
00236         { _M_t._M_insert_equal(__first, __last); }
00237 #endif
00238 
00239       /**
00240        *  @brief  Builds a %multimap from a range.
00241        *  @param  __first  An input iterator.
00242        *  @param  __last  An input iterator.
00243        *
00244        *  Create a %multimap consisting of copies of the elements from
00245        *  [__first,__last).  This is linear in N if the range is already sorted,
00246        *  and NlogN otherwise (where N is distance(__first,__last)).
00247        */
00248       template<typename _InputIterator>
00249         multimap(_InputIterator __first, _InputIterator __last)
00250     : _M_t()
00251         { _M_t._M_insert_equal(__first, __last); }
00252 
00253       /**
00254        *  @brief  Builds a %multimap from a range.
00255        *  @param  __first  An input iterator.
00256        *  @param  __last  An input iterator.
00257        *  @param  __comp  A comparison functor.
00258        *  @param  __a  An allocator object.
00259        *
00260        *  Create a %multimap consisting of copies of the elements from
00261        *  [__first,__last).  This is linear in N if the range is already sorted,
00262        *  and NlogN otherwise (where N is distance(__first,__last)).
00263        */
00264       template<typename _InputIterator>
00265         multimap(_InputIterator __first, _InputIterator __last,
00266          const _Compare& __comp,
00267          const allocator_type& __a = allocator_type())
00268     : _M_t(__comp, _Pair_alloc_type(__a))
00269         { _M_t._M_insert_equal(__first, __last); }
00270 
00271       // FIXME There is no dtor declared, but we should have something generated
00272       // by Doxygen.  I don't know what tags to add to this paragraph to make
00273       // that happen:
00274       /**
00275        *  The dtor only erases the elements, and note that if the elements
00276        *  themselves are pointers, the pointed-to memory is not touched in any
00277        *  way.  Managing the pointer is the user's responsibility.
00278        */
00279 
00280       /**
00281        *  @brief  %Multimap assignment operator.
00282        *  @param  __x  A %multimap of identical element and allocator types.
00283        *
00284        *  All the elements of @a __x are copied, but unlike the copy
00285        *  constructor, the allocator object is not copied.
00286        */
00287       multimap&
00288       operator=(const multimap& __x)
00289       {
00290     _M_t = __x._M_t;
00291     return *this;
00292       }
00293 
00294 #if __cplusplus >= 201103L
00295       /**
00296        *  @brief  %Multimap move assignment operator.
00297        *  @param  __x  A %multimap of identical element and allocator types.
00298        *
00299        *  The contents of @a __x are moved into this multimap (without copying
00300        *  if the allocators compare equal or get moved on assignment).
00301        *  Afterwards @a __x is in a valid, but unspecified state.
00302        */
00303       multimap&
00304       operator=(multimap&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
00305       {
00306     if (!_M_t._M_move_assign(__x._M_t))
00307       {
00308         // The rvalue's allocator cannot be moved and is not equal,
00309         // so we need to individually move each element.
00310         clear();
00311         insert(std::__make_move_if_noexcept_iterator(__x.begin()),
00312            std::__make_move_if_noexcept_iterator(__x.end()));
00313         __x.clear();
00314       }
00315     return *this;
00316       }
00317 
00318       /**
00319        *  @brief  %Multimap list assignment operator.
00320        *  @param  __l  An initializer_list.
00321        *
00322        *  This function fills a %multimap with copies of the elements
00323        *  in the initializer list @a __l.
00324        *
00325        *  Note that the assignment completely changes the %multimap and
00326        *  that the resulting %multimap's size is the same as the number
00327        *  of elements assigned.  Old data may be lost.
00328        */
00329       multimap&
00330       operator=(initializer_list<value_type> __l)
00331       {
00332     this->clear();
00333     this->insert(__l.begin(), __l.end());
00334     return *this;
00335       }
00336 #endif
00337 
00338       /// Get a copy of the memory allocation object.
00339       allocator_type
00340       get_allocator() const _GLIBCXX_NOEXCEPT 
00341       { return allocator_type(_M_t.get_allocator()); }
00342 
00343       // iterators
00344       /**
00345        *  Returns a read/write iterator that points to the first pair in the
00346        *  %multimap.  Iteration is done in ascending order according to the
00347        *  keys.
00348        */
00349       iterator
00350       begin() _GLIBCXX_NOEXCEPT
00351       { return _M_t.begin(); }
00352 
00353       /**
00354        *  Returns a read-only (constant) iterator that points to the first pair
00355        *  in the %multimap.  Iteration is done in ascending order according to
00356        *  the keys.
00357        */
00358       const_iterator
00359       begin() const _GLIBCXX_NOEXCEPT
00360       { return _M_t.begin(); }
00361 
00362       /**
00363        *  Returns a read/write iterator that points one past the last pair in
00364        *  the %multimap.  Iteration is done in ascending order according to the
00365        *  keys.
00366        */
00367       iterator
00368       end() _GLIBCXX_NOEXCEPT
00369       { return _M_t.end(); }
00370 
00371       /**
00372        *  Returns a read-only (constant) iterator that points one past the last
00373        *  pair in the %multimap.  Iteration is done in ascending order according
00374        *  to the keys.
00375        */
00376       const_iterator
00377       end() const _GLIBCXX_NOEXCEPT
00378       { return _M_t.end(); }
00379 
00380       /**
00381        *  Returns a read/write reverse iterator that points to the last pair in
00382        *  the %multimap.  Iteration is done in descending order according to the
00383        *  keys.
00384        */
00385       reverse_iterator
00386       rbegin() _GLIBCXX_NOEXCEPT
00387       { return _M_t.rbegin(); }
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       rbegin() const _GLIBCXX_NOEXCEPT
00396       { return _M_t.rbegin(); }
00397 
00398       /**
00399        *  Returns a read/write reverse iterator that points to one before the
00400        *  first pair in the %multimap.  Iteration is done in descending order
00401        *  according to the keys.
00402        */
00403       reverse_iterator
00404       rend() _GLIBCXX_NOEXCEPT
00405       { return _M_t.rend(); }
00406 
00407       /**
00408        *  Returns a read-only (constant) reverse iterator that points to one
00409        *  before the first pair in the %multimap.  Iteration is done in
00410        *  descending order according to the keys.
00411        */
00412       const_reverse_iterator
00413       rend() const _GLIBCXX_NOEXCEPT
00414       { return _M_t.rend(); }
00415 
00416 #if __cplusplus >= 201103L
00417       /**
00418        *  Returns a read-only (constant) iterator that points to the first pair
00419        *  in the %multimap.  Iteration is done in ascending order according to
00420        *  the keys.
00421        */
00422       const_iterator
00423       cbegin() const noexcept
00424       { return _M_t.begin(); }
00425 
00426       /**
00427        *  Returns a read-only (constant) iterator that points one past the last
00428        *  pair in the %multimap.  Iteration is done in ascending order according
00429        *  to the keys.
00430        */
00431       const_iterator
00432       cend() const noexcept
00433       { return _M_t.end(); }
00434 
00435       /**
00436        *  Returns a read-only (constant) reverse iterator that points to the
00437        *  last pair in the %multimap.  Iteration is done in descending order
00438        *  according to the keys.
00439        */
00440       const_reverse_iterator
00441       crbegin() const noexcept
00442       { return _M_t.rbegin(); }
00443 
00444       /**
00445        *  Returns a read-only (constant) reverse iterator that points to one
00446        *  before the first pair in the %multimap.  Iteration is done in
00447        *  descending order according to the keys.
00448        */
00449       const_reverse_iterator
00450       crend() const noexcept
00451       { return _M_t.rend(); }
00452 #endif
00453 
00454       // capacity
00455       /** Returns true if the %multimap is empty.  */
00456       bool
00457       empty() const _GLIBCXX_NOEXCEPT
00458       { return _M_t.empty(); }
00459 
00460       /** Returns the size of the %multimap.  */
00461       size_type
00462       size() const _GLIBCXX_NOEXCEPT
00463       { return _M_t.size(); }
00464 
00465       /** Returns the maximum size of the %multimap.  */
00466       size_type
00467       max_size() const _GLIBCXX_NOEXCEPT
00468       { return _M_t.max_size(); }
00469 
00470       // modifiers
00471 #if __cplusplus >= 201103L
00472       /**
00473        *  @brief Build and insert a std::pair into the %multimap.
00474        *
00475        *  @param __args  Arguments used to generate a new pair instance (see
00476        *            std::piecewise_contruct for passing arguments to each
00477        *            part of the pair constructor).
00478        *
00479        *  @return An iterator that points to the inserted (key,value) pair.
00480        *
00481        *  This function builds and inserts a (key, value) %pair into the
00482        *  %multimap.
00483        *  Contrary to a std::map the %multimap does not rely on unique keys and
00484        *  thus multiple pairs with the same key can be inserted.
00485        *
00486        *  Insertion requires logarithmic time.
00487        */
00488       template<typename... _Args>
00489     iterator
00490     emplace(_Args&&... __args)
00491     { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
00492 
00493       /**
00494        *  @brief Builds and inserts a std::pair into the %multimap.
00495        *
00496        *  @param  __pos  An iterator that serves as a hint as to where the pair
00497        *                should be inserted.
00498        *  @param  __args  Arguments used to generate a new pair instance (see
00499        *             std::piecewise_contruct for passing arguments to each
00500        *             part of the pair constructor).
00501        *  @return An iterator that points to the inserted (key,value) pair.
00502        *
00503        *  This function inserts a (key, value) pair into the %multimap.
00504        *  Contrary to a std::map the %multimap does not rely on unique keys and
00505        *  thus multiple pairs with the same key can be inserted.
00506        *  Note that the first parameter is only a hint and can potentially
00507        *  improve the performance of the insertion process.  A bad hint would
00508        *  cause no gains in efficiency.
00509        *
00510        *  For more on @a hinting, see:
00511        *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
00512        *
00513        *  Insertion requires logarithmic time (if the hint is not taken).
00514        */
00515       template<typename... _Args>
00516     iterator
00517     emplace_hint(const_iterator __pos, _Args&&... __args)
00518     {
00519       return _M_t._M_emplace_hint_equal(__pos,
00520                         std::forward<_Args>(__args)...);
00521     }
00522 #endif
00523 
00524       /**
00525        *  @brief Inserts a std::pair into the %multimap.
00526        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00527        *             of pairs).
00528        *  @return An iterator that points to the inserted (key,value) pair.
00529        *
00530        *  This function inserts a (key, value) pair into the %multimap.
00531        *  Contrary to a std::map the %multimap does not rely on unique keys and
00532        *  thus multiple pairs with the same key can be inserted.
00533        *
00534        *  Insertion requires logarithmic time.
00535        */
00536       iterator
00537       insert(const value_type& __x)
00538       { return _M_t._M_insert_equal(__x); }
00539 
00540 #if __cplusplus >= 201103L
00541       template<typename _Pair, typename = typename
00542            std::enable_if<std::is_constructible<value_type,
00543                             _Pair&&>::value>::type>
00544         iterator
00545         insert(_Pair&& __x)
00546         { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
00547 #endif
00548 
00549       /**
00550        *  @brief Inserts a std::pair into the %multimap.
00551        *  @param  __position  An iterator that serves as a hint as to where the
00552        *                      pair should be inserted.
00553        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00554        *               of pairs).
00555        *  @return An iterator that points to the inserted (key,value) pair.
00556        *
00557        *  This function inserts a (key, value) pair into the %multimap.
00558        *  Contrary to a std::map the %multimap does not rely on unique keys and
00559        *  thus multiple pairs with the same key can be inserted.
00560        *  Note that the first parameter is only a hint and can potentially
00561        *  improve the performance of the insertion process.  A bad hint would
00562        *  cause no gains in efficiency.
00563        *
00564        *  For more on @a hinting, see:
00565        *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
00566        *
00567        *  Insertion requires logarithmic time (if the hint is not taken).
00568        */
00569       iterator
00570 #if __cplusplus >= 201103L
00571       insert(const_iterator __position, const value_type& __x)
00572 #else
00573       insert(iterator __position, const value_type& __x)
00574 #endif
00575       { return _M_t._M_insert_equal_(__position, __x); }
00576 
00577 #if __cplusplus >= 201103L
00578       template<typename _Pair, typename = typename
00579            std::enable_if<std::is_constructible<value_type,
00580                             _Pair&&>::value>::type>
00581         iterator
00582         insert(const_iterator __position, _Pair&& __x)
00583         { return _M_t._M_insert_equal_(__position,
00584                        std::forward<_Pair>(__x)); }
00585 #endif
00586 
00587       /**
00588        *  @brief A template function that attempts to insert a range
00589        *  of elements.
00590        *  @param  __first  Iterator pointing to the start of the range to be
00591        *                   inserted.
00592        *  @param  __last  Iterator pointing to the end of the range.
00593        *
00594        *  Complexity similar to that of the range constructor.
00595        */
00596       template<typename _InputIterator>
00597         void
00598         insert(_InputIterator __first, _InputIterator __last)
00599         { _M_t._M_insert_equal(__first, __last); }
00600 
00601 #if __cplusplus >= 201103L
00602       /**
00603        *  @brief Attempts to insert a list of std::pairs into the %multimap.
00604        *  @param  __l  A std::initializer_list<value_type> of pairs to be
00605        *               inserted.
00606        *
00607        *  Complexity similar to that of the range constructor.
00608        */
00609       void
00610       insert(initializer_list<value_type> __l)
00611       { this->insert(__l.begin(), __l.end()); }
00612 #endif
00613 
00614 #if __cplusplus >= 201103L
00615       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00616       // DR 130. Associative erase should return an iterator.
00617       /**
00618        *  @brief Erases an element from a %multimap.
00619        *  @param  __position  An iterator pointing to the element to be erased.
00620        *  @return An iterator pointing to the element immediately following
00621        *          @a position prior to the element being erased. If no such 
00622        *          element exists, end() is returned.
00623        *
00624        *  This function erases an element, pointed to by the given iterator,
00625        *  from a %multimap.  Note that this function only erases the element,
00626        *  and that if the element is itself a pointer, the pointed-to memory is
00627        *  not touched in any way.  Managing the pointer is the user's
00628        *  responsibility.
00629        */
00630       iterator
00631       erase(const_iterator __position)
00632       { return _M_t.erase(__position); }
00633 
00634       // LWG 2059.
00635       _GLIBCXX_ABI_TAG_CXX11
00636       iterator
00637       erase(iterator __position)
00638       { return _M_t.erase(__position); }
00639 #else
00640       /**
00641        *  @brief Erases an element from a %multimap.
00642        *  @param  __position  An iterator pointing to the element to be erased.
00643        *
00644        *  This function erases an element, pointed to by the given iterator,
00645        *  from a %multimap.  Note that this function only erases the element,
00646        *  and that if the element is itself a pointer, the pointed-to memory is
00647        *  not touched in any way.  Managing the pointer is the user's
00648        *  responsibility.
00649        */
00650       void
00651       erase(iterator __position)
00652       { _M_t.erase(__position); }
00653 #endif
00654 
00655       /**
00656        *  @brief Erases elements according to the provided key.
00657        *  @param  __x  Key of element to be erased.
00658        *  @return  The number of elements erased.
00659        *
00660        *  This function erases all elements located by the given key from a
00661        *  %multimap.
00662        *  Note that this function only erases the element, and that if
00663        *  the element is itself a pointer, the pointed-to memory is not touched
00664        *  in any way.  Managing the pointer is the user's responsibility.
00665        */
00666       size_type
00667       erase(const key_type& __x)
00668       { return _M_t.erase(__x); }
00669 
00670 #if __cplusplus >= 201103L
00671       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00672       // DR 130. Associative erase should return an iterator.
00673       /**
00674        *  @brief Erases a [first,last) range of elements from a %multimap.
00675        *  @param  __first  Iterator pointing to the start of the range to be
00676        *                   erased.
00677        *  @param __last Iterator pointing to the end of the range to be
00678        *                erased .
00679        *  @return The iterator @a __last.
00680        *
00681        *  This function erases a sequence of elements from a %multimap.
00682        *  Note that this function only erases the elements, and that if
00683        *  the elements themselves are pointers, the pointed-to memory is not
00684        *  touched in any way.  Managing the pointer is the user's
00685        *  responsibility.
00686        */
00687       iterator
00688       erase(const_iterator __first, const_iterator __last)
00689       { return _M_t.erase(__first, __last); }
00690 #else
00691       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00692       // DR 130. Associative erase should return an iterator.
00693       /**
00694        *  @brief Erases a [first,last) range of elements from a %multimap.
00695        *  @param  __first  Iterator pointing to the start of the range to be
00696        *                 erased.
00697        *  @param __last Iterator pointing to the end of the range to
00698        *                be erased.
00699        *
00700        *  This function erases a sequence of elements from a %multimap.
00701        *  Note that this function only erases the elements, and that if
00702        *  the elements themselves are pointers, the pointed-to memory is not
00703        *  touched in any way.  Managing the pointer is the user's
00704        *  responsibility.
00705        */
00706       void
00707       erase(iterator __first, iterator __last)
00708       { _M_t.erase(__first, __last); }
00709 #endif
00710 
00711       /**
00712        *  @brief  Swaps data with another %multimap.
00713        *  @param  __x  A %multimap of the same element and allocator types.
00714        *
00715        *  This exchanges the elements between two multimaps in constant time.
00716        *  (It is only swapping a pointer, an integer, and an instance of
00717        *  the @c Compare type (which itself is often stateless and empty), so it
00718        *  should be quite fast.)
00719        *  Note that the global std::swap() function is specialized such that
00720        *  std::swap(m1,m2) will feed to this function.
00721        */
00722       void
00723       swap(multimap& __x)
00724 #if __cplusplus >= 201103L
00725       noexcept(_Alloc_traits::_S_nothrow_swap())
00726 #endif
00727       { _M_t.swap(__x._M_t); }
00728 
00729       /**
00730        *  Erases all elements in a %multimap.  Note that this function only
00731        *  erases the elements, and that if the elements themselves are pointers,
00732        *  the pointed-to memory is not touched in any way.  Managing the pointer
00733        *  is the user's responsibility.
00734        */
00735       void
00736       clear() _GLIBCXX_NOEXCEPT
00737       { _M_t.clear(); }
00738 
00739       // observers
00740       /**
00741        *  Returns the key comparison object out of which the %multimap
00742        *  was constructed.
00743        */
00744       key_compare
00745       key_comp() const
00746       { return _M_t.key_comp(); }
00747 
00748       /**
00749        *  Returns a value comparison object, built from the key comparison
00750        *  object out of which the %multimap was constructed.
00751        */
00752       value_compare
00753       value_comp() const
00754       { return value_compare(_M_t.key_comp()); }
00755 
00756       // multimap operations
00757       /**
00758        *  @brief Tries to locate an element in a %multimap.
00759        *  @param  __x  Key of (key, value) pair to be located.
00760        *  @return  Iterator pointing to sought-after element,
00761        *           or end() if not found.
00762        *
00763        *  This function takes a key and tries to locate the element with which
00764        *  the key matches.  If successful the function returns an iterator
00765        *  pointing to the sought after %pair.  If unsuccessful it returns the
00766        *  past-the-end ( @c end() ) iterator.
00767        */
00768       iterator
00769       find(const key_type& __x)
00770       { return _M_t.find(__x); }
00771 
00772       /**
00773        *  @brief Tries to locate an element in a %multimap.
00774        *  @param  __x  Key of (key, value) pair to be located.
00775        *  @return  Read-only (constant) iterator pointing to sought-after
00776        *           element, or end() if not found.
00777        *
00778        *  This function takes a key and tries to locate the element with which
00779        *  the key matches.  If successful the function returns a constant
00780        *  iterator pointing to the sought after %pair.  If unsuccessful it
00781        *  returns the past-the-end ( @c end() ) iterator.
00782        */
00783       const_iterator
00784       find(const key_type& __x) const
00785       { return _M_t.find(__x); }
00786 
00787       /**
00788        *  @brief Finds the number of elements with given key.
00789        *  @param  __x  Key of (key, value) pairs to be located.
00790        *  @return Number of elements with specified key.
00791        */
00792       size_type
00793       count(const key_type& __x) const
00794       { return _M_t.count(__x); }
00795 
00796       /**
00797        *  @brief Finds the beginning of a subsequence matching given key.
00798        *  @param  __x  Key of (key, value) pair to be located.
00799        *  @return  Iterator pointing to first element equal to or greater
00800        *           than key, or end().
00801        *
00802        *  This function returns the first element of a subsequence of elements
00803        *  that matches the given key.  If unsuccessful it returns an iterator
00804        *  pointing to the first element that has a greater value than given key
00805        *  or end() if no such element exists.
00806        */
00807       iterator
00808       lower_bound(const key_type& __x)
00809       { return _M_t.lower_bound(__x); }
00810 
00811       /**
00812        *  @brief Finds the beginning of a subsequence matching given key.
00813        *  @param  __x  Key of (key, value) pair to be located.
00814        *  @return  Read-only (constant) iterator pointing to first element
00815        *           equal to or greater than key, or end().
00816        *
00817        *  This function returns the first element of a subsequence of
00818        *  elements that matches the given key.  If unsuccessful the
00819        *  iterator will point to the next greatest element or, if no
00820        *  such greater element exists, to end().
00821        */
00822       const_iterator
00823       lower_bound(const key_type& __x) const
00824       { return _M_t.lower_bound(__x); }
00825 
00826       /**
00827        *  @brief Finds the end of a subsequence matching given key.
00828        *  @param  __x  Key of (key, value) pair to be located.
00829        *  @return Iterator pointing to the first element
00830        *          greater than key, or end().
00831        */
00832       iterator
00833       upper_bound(const key_type& __x)
00834       { return _M_t.upper_bound(__x); }
00835 
00836       /**
00837        *  @brief Finds the end of a subsequence matching given key.
00838        *  @param  __x  Key of (key, value) pair to be located.
00839        *  @return  Read-only (constant) iterator pointing to first iterator
00840        *           greater than key, or end().
00841        */
00842       const_iterator
00843       upper_bound(const key_type& __x) const
00844       { return _M_t.upper_bound(__x); }
00845 
00846       /**
00847        *  @brief Finds a subsequence matching given key.
00848        *  @param  __x  Key of (key, value) pairs to be located.
00849        *  @return  Pair of iterators that possibly points to the subsequence
00850        *           matching given key.
00851        *
00852        *  This function is equivalent to
00853        *  @code
00854        *    std::make_pair(c.lower_bound(val),
00855        *                   c.upper_bound(val))
00856        *  @endcode
00857        *  (but is faster than making the calls separately).
00858        */
00859       std::pair<iterator, iterator>
00860       equal_range(const key_type& __x)
00861       { return _M_t.equal_range(__x); }
00862 
00863       /**
00864        *  @brief Finds a subsequence matching given key.
00865        *  @param  __x  Key of (key, value) pairs to be located.
00866        *  @return  Pair of read-only (constant) iterators that possibly points
00867        *           to the subsequence matching given key.
00868        *
00869        *  This function is equivalent to
00870        *  @code
00871        *    std::make_pair(c.lower_bound(val),
00872        *                   c.upper_bound(val))
00873        *  @endcode
00874        *  (but is faster than making the calls separately).
00875        */
00876       std::pair<const_iterator, const_iterator>
00877       equal_range(const key_type& __x) const
00878       { return _M_t.equal_range(__x); }
00879 
00880       template<typename _K1, typename _T1, typename _C1, typename _A1>
00881         friend bool
00882         operator==(const multimap<_K1, _T1, _C1, _A1>&,
00883            const multimap<_K1, _T1, _C1, _A1>&);
00884 
00885       template<typename _K1, typename _T1, typename _C1, typename _A1>
00886         friend bool
00887         operator<(const multimap<_K1, _T1, _C1, _A1>&,
00888           const multimap<_K1, _T1, _C1, _A1>&);
00889   };
00890 
00891   /**
00892    *  @brief  Multimap equality comparison.
00893    *  @param  __x  A %multimap.
00894    *  @param  __y  A %multimap of the same type as @a __x.
00895    *  @return  True iff the size and elements of the maps are equal.
00896    *
00897    *  This is an equivalence relation.  It is linear in the size of the
00898    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
00899    *  and if corresponding elements compare equal.
00900   */
00901   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00902     inline bool
00903     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00904                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00905     { return __x._M_t == __y._M_t; }
00906 
00907   /**
00908    *  @brief  Multimap ordering relation.
00909    *  @param  __x  A %multimap.
00910    *  @param  __y  A %multimap of the same type as @a __x.
00911    *  @return  True iff @a x is lexicographically less than @a y.
00912    *
00913    *  This is a total ordering relation.  It is linear in the size of the
00914    *  multimaps.  The elements must be comparable with @c <.
00915    *
00916    *  See std::lexicographical_compare() for how the determination is made.
00917   */
00918   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00919     inline bool
00920     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00921               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00922     { return __x._M_t < __y._M_t; }
00923 
00924   /// Based on operator==
00925   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00926     inline bool
00927     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00928                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00929     { return !(__x == __y); }
00930 
00931   /// Based on operator<
00932   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00933     inline bool
00934     operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00935               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00936     { return __y < __x; }
00937 
00938   /// Based on operator<
00939   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00940     inline bool
00941     operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00942                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00943     { return !(__y < __x); }
00944 
00945   /// Based on operator<
00946   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00947     inline bool
00948     operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00949                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00950     { return !(__x < __y); }
00951 
00952   /// See std::multimap::swap().
00953   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00954     inline void
00955     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00956          multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00957     { __x.swap(__y); }
00958 
00959 _GLIBCXX_END_NAMESPACE_CONTAINER
00960 } // namespace std
00961 
00962 #endif /* _STL_MULTIMAP_H */