libstdc++
stl_multimap.h
Go to the documentation of this file.
00001 // Multimap implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2016 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       _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
00708       { _M_t.swap(__x._M_t); }
00709 
00710       /**
00711        *  Erases all elements in a %multimap.  Note that this function only
00712        *  erases the elements, and that if the elements themselves are pointers,
00713        *  the pointed-to memory is not touched in any way.  Managing the pointer
00714        *  is the user's responsibility.
00715        */
00716       void
00717       clear() _GLIBCXX_NOEXCEPT
00718       { _M_t.clear(); }
00719 
00720       // observers
00721       /**
00722        *  Returns the key comparison object out of which the %multimap
00723        *  was constructed.
00724        */
00725       key_compare
00726       key_comp() const
00727       { return _M_t.key_comp(); }
00728 
00729       /**
00730        *  Returns a value comparison object, built from the key comparison
00731        *  object out of which the %multimap was constructed.
00732        */
00733       value_compare
00734       value_comp() const
00735       { return value_compare(_M_t.key_comp()); }
00736 
00737       // multimap operations
00738 
00739       //@{
00740       /**
00741        *  @brief Tries to locate an element in a %multimap.
00742        *  @param  __x  Key of (key, value) pair to be located.
00743        *  @return  Iterator pointing to sought-after element,
00744        *           or end() if not found.
00745        *
00746        *  This function takes a key and tries to locate the element with which
00747        *  the key matches.  If successful the function returns an iterator
00748        *  pointing to the sought after %pair.  If unsuccessful it returns the
00749        *  past-the-end ( @c end() ) iterator.
00750        */
00751       iterator
00752       find(const key_type& __x)
00753       { return _M_t.find(__x); }
00754 
00755 #if __cplusplus > 201103L
00756       template<typename _Kt>
00757         auto
00758         find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
00759         { return _M_t._M_find_tr(__x); }
00760 #endif
00761       //@}
00762 
00763       //@{
00764       /**
00765        *  @brief Tries to locate an element in a %multimap.
00766        *  @param  __x  Key of (key, value) pair to be located.
00767        *  @return  Read-only (constant) iterator pointing to sought-after
00768        *           element, or end() if not found.
00769        *
00770        *  This function takes a key and tries to locate the element with which
00771        *  the key matches.  If successful the function returns a constant
00772        *  iterator pointing to the sought after %pair.  If unsuccessful it
00773        *  returns the past-the-end ( @c end() ) iterator.
00774        */
00775       const_iterator
00776       find(const key_type& __x) const
00777       { return _M_t.find(__x); }
00778 
00779 #if __cplusplus > 201103L
00780       template<typename _Kt>
00781         auto
00782         find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
00783         { return _M_t._M_find_tr(__x); }
00784 #endif
00785       //@}
00786 
00787       //@{
00788       /**
00789        *  @brief Finds the number of elements with given key.
00790        *  @param  __x  Key of (key, value) pairs to be located.
00791        *  @return Number of elements with specified key.
00792        */
00793       size_type
00794       count(const key_type& __x) const
00795       { return _M_t.count(__x); }
00796 
00797 #if __cplusplus > 201103L
00798       template<typename _Kt>
00799         auto
00800         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
00801         { return _M_t._M_count_tr(__x); }
00802 #endif
00803       //@}
00804 
00805       //@{
00806       /**
00807        *  @brief Finds the beginning of a subsequence matching given key.
00808        *  @param  __x  Key of (key, value) pair to be located.
00809        *  @return  Iterator pointing to first element equal to or greater
00810        *           than key, or end().
00811        *
00812        *  This function returns the first element of a subsequence of elements
00813        *  that matches the given key.  If unsuccessful it returns an iterator
00814        *  pointing to the first element that has a greater value than given key
00815        *  or end() if no such element exists.
00816        */
00817       iterator
00818       lower_bound(const key_type& __x)
00819       { return _M_t.lower_bound(__x); }
00820 
00821 #if __cplusplus > 201103L
00822       template<typename _Kt>
00823         auto
00824         lower_bound(const _Kt& __x)
00825         -> decltype(_M_t._M_lower_bound_tr(__x))
00826         { return _M_t._M_lower_bound_tr(__x); }
00827 #endif
00828       //@}
00829 
00830       //@{
00831       /**
00832        *  @brief Finds the beginning of a subsequence matching given key.
00833        *  @param  __x  Key of (key, value) pair to be located.
00834        *  @return  Read-only (constant) iterator pointing to first element
00835        *           equal to or greater than key, or end().
00836        *
00837        *  This function returns the first element of a subsequence of
00838        *  elements that matches the given key.  If unsuccessful the
00839        *  iterator will point to the next greatest element or, if no
00840        *  such greater element exists, to end().
00841        */
00842       const_iterator
00843       lower_bound(const key_type& __x) const
00844       { return _M_t.lower_bound(__x); }
00845 
00846 #if __cplusplus > 201103L
00847       template<typename _Kt>
00848         auto
00849         lower_bound(const _Kt& __x) const
00850         -> decltype(_M_t._M_lower_bound_tr(__x))
00851         { return _M_t._M_lower_bound_tr(__x); }
00852 #endif
00853       //@}
00854 
00855       //@{
00856       /**
00857        *  @brief Finds the end of a subsequence matching given key.
00858        *  @param  __x  Key of (key, value) pair to be located.
00859        *  @return Iterator pointing to the first element
00860        *          greater than key, or end().
00861        */
00862       iterator
00863       upper_bound(const key_type& __x)
00864       { return _M_t.upper_bound(__x); }
00865 
00866 #if __cplusplus > 201103L
00867       template<typename _Kt>
00868         auto
00869         upper_bound(const _Kt& __x)
00870         -> decltype(_M_t._M_upper_bound_tr(__x))
00871         { return _M_t._M_upper_bound_tr(__x); }
00872 #endif
00873       //@}
00874 
00875       //@{
00876       /**
00877        *  @brief Finds the end of a subsequence matching given key.
00878        *  @param  __x  Key of (key, value) pair to be located.
00879        *  @return  Read-only (constant) iterator pointing to first iterator
00880        *           greater than key, or end().
00881        */
00882       const_iterator
00883       upper_bound(const key_type& __x) const
00884       { return _M_t.upper_bound(__x); }
00885 
00886 #if __cplusplus > 201103L
00887       template<typename _Kt>
00888         auto
00889         upper_bound(const _Kt& __x) const
00890         -> decltype(_M_t._M_upper_bound_tr(__x))
00891         { return _M_t._M_upper_bound_tr(__x); }
00892 #endif
00893       //@}
00894 
00895       //@{
00896       /**
00897        *  @brief Finds a subsequence matching given key.
00898        *  @param  __x  Key of (key, value) pairs to be located.
00899        *  @return  Pair of iterators that possibly points to the subsequence
00900        *           matching given key.
00901        *
00902        *  This function is equivalent to
00903        *  @code
00904        *    std::make_pair(c.lower_bound(val),
00905        *                   c.upper_bound(val))
00906        *  @endcode
00907        *  (but is faster than making the calls separately).
00908        */
00909       std::pair<iterator, iterator>
00910       equal_range(const key_type& __x)
00911       { return _M_t.equal_range(__x); }
00912 
00913 #if __cplusplus > 201103L
00914       template<typename _Kt>
00915         auto
00916         equal_range(const _Kt& __x)
00917         -> decltype(_M_t._M_equal_range_tr(__x))
00918         { return _M_t._M_equal_range_tr(__x); }
00919 #endif
00920       //@}
00921 
00922       //@{
00923       /**
00924        *  @brief Finds a subsequence matching given key.
00925        *  @param  __x  Key of (key, value) pairs to be located.
00926        *  @return  Pair of read-only (constant) iterators that possibly points
00927        *           to the subsequence matching given key.
00928        *
00929        *  This function is equivalent to
00930        *  @code
00931        *    std::make_pair(c.lower_bound(val),
00932        *                   c.upper_bound(val))
00933        *  @endcode
00934        *  (but is faster than making the calls separately).
00935        */
00936       std::pair<const_iterator, const_iterator>
00937       equal_range(const key_type& __x) const
00938       { return _M_t.equal_range(__x); }
00939 
00940 #if __cplusplus > 201103L
00941       template<typename _Kt>
00942         auto
00943         equal_range(const _Kt& __x) const
00944         -> decltype(_M_t._M_equal_range_tr(__x))
00945         { return _M_t._M_equal_range_tr(__x); }
00946 #endif
00947       //@}
00948 
00949       template<typename _K1, typename _T1, typename _C1, typename _A1>
00950         friend bool
00951         operator==(const multimap<_K1, _T1, _C1, _A1>&,
00952                    const multimap<_K1, _T1, _C1, _A1>&);
00953 
00954       template<typename _K1, typename _T1, typename _C1, typename _A1>
00955         friend bool
00956         operator<(const multimap<_K1, _T1, _C1, _A1>&,
00957                   const multimap<_K1, _T1, _C1, _A1>&);
00958   };
00959 
00960   /**
00961    *  @brief  Multimap equality comparison.
00962    *  @param  __x  A %multimap.
00963    *  @param  __y  A %multimap of the same type as @a __x.
00964    *  @return  True iff the size and elements of the maps are equal.
00965    *
00966    *  This is an equivalence relation.  It is linear in the size of the
00967    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
00968    *  and if corresponding elements compare equal.
00969   */
00970   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00971     inline bool
00972     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00973                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00974     { return __x._M_t == __y._M_t; }
00975 
00976   /**
00977    *  @brief  Multimap ordering relation.
00978    *  @param  __x  A %multimap.
00979    *  @param  __y  A %multimap of the same type as @a __x.
00980    *  @return  True iff @a x is lexicographically less than @a y.
00981    *
00982    *  This is a total ordering relation.  It is linear in the size of the
00983    *  multimaps.  The elements must be comparable with @c <.
00984    *
00985    *  See std::lexicographical_compare() for how the determination is made.
00986   */
00987   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00988     inline bool
00989     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
00990               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
00991     { return __x._M_t < __y._M_t; }
00992 
00993   /// Based on operator==
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 == __y); }
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 __y < __x; }
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 !(__x < __y); }
01020 
01021   /// See std::multimap::swap().
01022   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01023     inline void
01024     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
01025          multimap<_Key, _Tp, _Compare, _Alloc>& __y)
01026     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
01027     { __x.swap(__y); }
01028 
01029 _GLIBCXX_END_NAMESPACE_CONTAINER
01030 } // namespace std
01031 
01032 #endif /* _STL_MULTIMAP_H */