libstdc++

stl_multimap.h

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