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