libstdc++

unordered_map.h

Go to the documentation of this file.
00001 // unordered_map implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2010-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 /** @file bits/unordered_map.h
00026  *  This is an internal header file, included by other library headers.
00027  *  Do not attempt to use it directly. @headername{unordered_map}
00028  */
00029 
00030 #ifndef _UNORDERED_MAP_H
00031 #define _UNORDERED_MAP_H
00032 
00033 namespace std _GLIBCXX_VISIBILITY(default)
00034 {
00035 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
00036 
00037   /// Base types for unordered_map.
00038   template<bool _Cache>
00039     using __umap_traits = __detail::_Hashtable_traits<_Cache, false, true>;
00040 
00041   template<typename _Key,
00042            typename _Tp,
00043            typename _Hash = hash<_Key>,
00044            typename _Pred = std::equal_to<_Key>,
00045            typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00046            typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>>
00047     using __umap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
00048                                         _Alloc, __detail::_Select1st,
00049                                         _Pred, _Hash,
00050                                         __detail::_Mod_range_hashing,
00051                                         __detail::_Default_ranged_hash,
00052                                         __detail::_Prime_rehash_policy, _Tr>;
00053 
00054   /// Base types for unordered_multimap.
00055   template<bool _Cache>
00056     using __ummap_traits = __detail::_Hashtable_traits<_Cache, false, false>;
00057 
00058   template<typename _Key,
00059            typename _Tp,
00060            typename _Hash = hash<_Key>,
00061            typename _Pred = std::equal_to<_Key>,
00062            typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
00063            typename _Tr = __ummap_traits<__cache_default<_Key, _Hash>::value>>
00064     using __ummap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
00065                                          _Alloc, __detail::_Select1st,
00066                                          _Pred, _Hash,
00067                                          __detail::_Mod_range_hashing,
00068                                          __detail::_Default_ranged_hash,
00069                                          __detail::_Prime_rehash_policy, _Tr>;
00070 
00071   /**
00072    *  @brief A standard container composed of unique keys (containing
00073    *  at most one of each key value) that associates values of another type
00074    *  with the keys.
00075    *
00076    *  @ingroup unordered_associative_containers
00077    *
00078    *  @tparam  _Key    Type of key objects.
00079    *  @tparam  _Tp     Type of mapped objects.
00080    *  @tparam  _Hash   Hashing function object type, defaults to hash<_Value>.
00081    *  @tparam  _Pred   Predicate function object type, defaults
00082    *                   to equal_to<_Value>.
00083    *  @tparam  _Alloc  Allocator type, defaults to 
00084    *                   std::allocator<std::pair<const _Key, _Tp>>.
00085    *
00086    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00087    *  <a href="tables.html#xx">unordered associative container</a>
00088    *
00089    * The resulting value type of the container is std::pair<const _Key, _Tp>.
00090    *
00091    *  Base is _Hashtable, dispatched at compile time via template
00092    *  alias __umap_hashtable.
00093    */
00094   template<class _Key, class _Tp,
00095            class _Hash = hash<_Key>,
00096            class _Pred = std::equal_to<_Key>,
00097            class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00098     class unordered_map
00099     {
00100       typedef __umap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc>  _Hashtable;
00101       _Hashtable _M_h;
00102 
00103     public:
00104       // typedefs:
00105       //@{
00106       /// Public typedefs.
00107       typedef typename _Hashtable::key_type     key_type;
00108       typedef typename _Hashtable::value_type   value_type;
00109       typedef typename _Hashtable::mapped_type  mapped_type;
00110       typedef typename _Hashtable::hasher       hasher;
00111       typedef typename _Hashtable::key_equal    key_equal;
00112       typedef typename _Hashtable::allocator_type allocator_type;
00113       //@}
00114 
00115       //@{
00116       ///  Iterator-related typedefs.
00117       typedef typename _Hashtable::pointer              pointer;
00118       typedef typename _Hashtable::const_pointer        const_pointer;
00119       typedef typename _Hashtable::reference            reference;
00120       typedef typename _Hashtable::const_reference      const_reference;
00121       typedef typename _Hashtable::iterator             iterator;
00122       typedef typename _Hashtable::const_iterator       const_iterator;
00123       typedef typename _Hashtable::local_iterator       local_iterator;
00124       typedef typename _Hashtable::const_local_iterator const_local_iterator;
00125       typedef typename _Hashtable::size_type            size_type;
00126       typedef typename _Hashtable::difference_type      difference_type;
00127       //@}
00128 
00129       //construct/destroy/copy
00130 
00131       /// Default constructor.
00132       unordered_map() = default;
00133 
00134       /**
00135        *  @brief  Default constructor creates no elements.
00136        *  @param __n  Minimal initial number of buckets.
00137        *  @param __hf  A hash functor.
00138        *  @param __eql  A key equality functor.
00139        *  @param __a  An allocator object.
00140        */
00141       explicit
00142       unordered_map(size_type __n,
00143                     const hasher& __hf = hasher(),
00144                     const key_equal& __eql = key_equal(),
00145                     const allocator_type& __a = allocator_type())
00146       : _M_h(__n, __hf, __eql, __a)
00147       { }
00148 
00149       /**
00150        *  @brief  Builds an %unordered_map from a range.
00151        *  @param  __first  An input iterator.
00152        *  @param  __last  An input iterator.
00153        *  @param __n  Minimal initial number of buckets.
00154        *  @param __hf  A hash functor.
00155        *  @param __eql  A key equality functor.
00156        *  @param __a  An allocator object.
00157        *
00158        *  Create an %unordered_map consisting of copies of the elements from
00159        *  [__first,__last).  This is linear in N (where N is
00160        *  distance(__first,__last)).
00161        */
00162       template<typename _InputIterator>
00163         unordered_map(_InputIterator __first, _InputIterator __last,
00164                       size_type __n = 0,
00165                       const hasher& __hf = hasher(),
00166                       const key_equal& __eql = key_equal(),
00167                       const allocator_type& __a = allocator_type())
00168         : _M_h(__first, __last, __n, __hf, __eql, __a)
00169         { }
00170 
00171       /// Copy constructor.
00172       unordered_map(const unordered_map&) = default;
00173 
00174       /// Move constructor.
00175       unordered_map(unordered_map&&) = default;
00176 
00177       /**
00178        *  @brief Creates an %unordered_map with no elements.
00179        *  @param __a An allocator object.
00180        */
00181       explicit
00182       unordered_map(const allocator_type& __a)
00183         : _M_h(__a)
00184       { }
00185 
00186       /*
00187        *  @brief Copy constructor with allocator argument.
00188        * @param  __uset  Input %unordered_map to copy.
00189        * @param  __a  An allocator object.
00190        */
00191       unordered_map(const unordered_map& __umap,
00192                     const allocator_type& __a)
00193         : _M_h(__umap._M_h, __a)
00194       { }
00195 
00196       /*
00197        *  @brief  Move constructor with allocator argument.
00198        *  @param  __uset Input %unordered_map to move.
00199        *  @param  __a    An allocator object.
00200        */
00201       unordered_map(unordered_map&& __umap,
00202                     const allocator_type& __a)
00203         : _M_h(std::move(__umap._M_h), __a)
00204       { }
00205 
00206       /**
00207        *  @brief  Builds an %unordered_map from an initializer_list.
00208        *  @param  __l  An initializer_list.
00209        *  @param __n  Minimal initial number of buckets.
00210        *  @param __hf  A hash functor.
00211        *  @param __eql  A key equality functor.
00212        *  @param  __a  An allocator object.
00213        *
00214        *  Create an %unordered_map consisting of copies of the elements in the
00215        *  list. This is linear in N (where N is @a __l.size()).
00216        */
00217       unordered_map(initializer_list<value_type> __l,
00218                     size_type __n = 0,
00219                     const hasher& __hf = hasher(),
00220                     const key_equal& __eql = key_equal(),
00221                     const allocator_type& __a = allocator_type())
00222         : _M_h(__l, __n, __hf, __eql, __a)
00223       { }
00224 
00225       /// Copy assignment operator.
00226       unordered_map&
00227       operator=(const unordered_map&) = default;
00228 
00229       /// Move assignment operator.
00230       unordered_map&
00231       operator=(unordered_map&&) = default;
00232 
00233       /**
00234        *  @brief  %Unordered_map list assignment operator.
00235        *  @param  __l  An initializer_list.
00236        *
00237        *  This function fills an %unordered_map with copies of the elements in
00238        *  the initializer list @a __l.
00239        *
00240        *  Note that the assignment completely changes the %unordered_map and
00241        *  that the resulting %unordered_map's size is the same as the number
00242        *  of elements assigned.  Old data may be lost.
00243        */
00244       unordered_map&
00245       operator=(initializer_list<value_type> __l)
00246       {
00247         _M_h = __l;
00248         return *this;
00249       }
00250 
00251       ///  Returns the allocator object with which the %unordered_map was
00252       ///  constructed.
00253       allocator_type
00254       get_allocator() const noexcept
00255       { return _M_h.get_allocator(); }
00256 
00257       // size and capacity:
00258 
00259       ///  Returns true if the %unordered_map is empty.
00260       bool
00261       empty() const noexcept
00262       { return _M_h.empty(); }
00263 
00264       ///  Returns the size of the %unordered_map.
00265       size_type
00266       size() const noexcept
00267       { return _M_h.size(); }
00268 
00269       ///  Returns the maximum size of the %unordered_map.
00270       size_type
00271       max_size() const noexcept
00272       { return _M_h.max_size(); }
00273 
00274       // iterators.
00275 
00276       /**
00277        *  Returns a read/write iterator that points to the first element in the
00278        *  %unordered_map.
00279        */
00280       iterator
00281       begin() noexcept
00282       { return _M_h.begin(); }
00283 
00284       //@{
00285       /**
00286        *  Returns a read-only (constant) iterator that points to the first
00287        *  element in the %unordered_map.
00288        */
00289       const_iterator
00290       begin() const noexcept
00291       { return _M_h.begin(); }
00292 
00293       const_iterator
00294       cbegin() const noexcept
00295       { return _M_h.begin(); }
00296       //@}
00297 
00298       /**
00299        *  Returns a read/write iterator that points one past the last element in
00300        *  the %unordered_map.
00301        */
00302       iterator
00303       end() noexcept
00304       { return _M_h.end(); }
00305 
00306       //@{
00307       /**
00308        *  Returns a read-only (constant) iterator that points one past the last
00309        *  element in the %unordered_map.
00310        */
00311       const_iterator
00312       end() const noexcept
00313       { return _M_h.end(); }
00314 
00315       const_iterator
00316       cend() const noexcept
00317       { return _M_h.end(); }
00318       //@}
00319 
00320       // modifiers.
00321 
00322       /**
00323        *  @brief Attempts to build and insert a std::pair into the %unordered_map.
00324        *
00325        *  @param __args  Arguments used to generate a new pair instance (see
00326        *                std::piecewise_contruct for passing arguments to each
00327        *                part of the pair constructor).
00328        *
00329        *  @return  A pair, of which the first element is an iterator that points
00330        *           to the possibly inserted pair, and the second is a bool that
00331        *           is true if the pair was actually inserted.
00332        *
00333        *  This function attempts to build and insert a (key, value) %pair into
00334        *  the %unordered_map.
00335        *  An %unordered_map relies on unique keys and thus a %pair is only
00336        *  inserted if its first element (the key) is not already present in the
00337        *  %unordered_map.
00338        *
00339        *  Insertion requires amortized constant time.
00340        */
00341       template<typename... _Args>
00342         std::pair<iterator, bool>
00343         emplace(_Args&&... __args)
00344         { return _M_h.emplace(std::forward<_Args>(__args)...); }
00345 
00346       /**
00347        *  @brief Attempts to build and insert a std::pair into the %unordered_map.
00348        *
00349        *  @param  __pos  An iterator that serves as a hint as to where the pair
00350        *                should be inserted.
00351        *  @param  __args  Arguments used to generate a new pair instance (see
00352        *                 std::piecewise_contruct for passing arguments to each
00353        *                 part of the pair constructor).
00354        *  @return An iterator that points to the element with key of the
00355        *          std::pair built from @a __args (may or may not be that
00356        *          std::pair).
00357        *
00358        *  This function is not concerned about whether the insertion took place,
00359        *  and thus does not return a boolean like the single-argument emplace()
00360        *  does.
00361        *  Note that the first parameter is only a hint and can potentially
00362        *  improve the performance of the insertion process. A bad hint would
00363        *  cause no gains in efficiency.
00364        *
00365        *  See
00366        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00367        *  for more on @a hinting.
00368        *
00369        *  Insertion requires amortized constant time.
00370        */
00371       template<typename... _Args>
00372         iterator
00373         emplace_hint(const_iterator __pos, _Args&&... __args)
00374         { return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
00375 
00376       //@{
00377       /**
00378        *  @brief Attempts to insert a std::pair into the %unordered_map.
00379 
00380        *  @param __x Pair to be inserted (see std::make_pair for easy
00381        *             creation of pairs).
00382        *
00383        *  @return  A pair, of which the first element is an iterator that 
00384        *           points to the possibly inserted pair, and the second is 
00385        *           a bool that is true if the pair was actually inserted.
00386        *
00387        *  This function attempts to insert a (key, value) %pair into the
00388        *  %unordered_map. An %unordered_map relies on unique keys and thus a
00389        *  %pair is only inserted if its first element (the key) is not already
00390        *  present in the %unordered_map.
00391        *
00392        *  Insertion requires amortized constant time.
00393        */
00394       std::pair<iterator, bool>
00395       insert(const value_type& __x)
00396       { return _M_h.insert(__x); }
00397 
00398       template<typename _Pair, typename = typename
00399                std::enable_if<std::is_constructible<value_type,
00400                                                     _Pair&&>::value>::type>
00401         std::pair<iterator, bool>
00402         insert(_Pair&& __x)
00403         { return _M_h.insert(std::forward<_Pair>(__x)); }
00404       //@}
00405 
00406       //@{
00407       /**
00408        *  @brief Attempts to insert a std::pair into the %unordered_map.
00409        *  @param  __hint  An iterator that serves as a hint as to where the
00410        *                 pair should be inserted.
00411        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00412        *               of pairs).
00413        *  @return An iterator that points to the element with key of
00414        *           @a __x (may or may not be the %pair passed in).
00415        *
00416        *  This function is not concerned about whether the insertion took place,
00417        *  and thus does not return a boolean like the single-argument insert()
00418        *  does.  Note that the first parameter is only a hint and can
00419        *  potentially improve the performance of the insertion process.  A bad
00420        *  hint would cause no gains in efficiency.
00421        *
00422        *  See
00423        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00424        *  for more on @a hinting.
00425        *
00426        *  Insertion requires amortized constant time.
00427        */
00428       iterator
00429       insert(const_iterator __hint, const value_type& __x)
00430       { return _M_h.insert(__hint, __x); }
00431 
00432       template<typename _Pair, typename = typename
00433                std::enable_if<std::is_constructible<value_type,
00434                                                     _Pair&&>::value>::type>
00435         iterator
00436         insert(const_iterator __hint, _Pair&& __x)
00437         { return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
00438       //@}
00439 
00440       /**
00441        *  @brief A template function that attempts to insert a range of
00442        *  elements.
00443        *  @param  __first  Iterator pointing to the start of the range to be
00444        *                   inserted.
00445        *  @param  __last  Iterator pointing to the end of the range.
00446        *
00447        *  Complexity similar to that of the range constructor.
00448        */
00449       template<typename _InputIterator>
00450         void
00451         insert(_InputIterator __first, _InputIterator __last)
00452         { _M_h.insert(__first, __last); }
00453 
00454       /**
00455        *  @brief Attempts to insert a list of elements into the %unordered_map.
00456        *  @param  __l  A std::initializer_list<value_type> of elements
00457        *               to be inserted.
00458        *
00459        *  Complexity similar to that of the range constructor.
00460        */
00461       void
00462       insert(initializer_list<value_type> __l)
00463       { _M_h.insert(__l); }
00464 
00465       //@{
00466       /**
00467        *  @brief Erases an element from an %unordered_map.
00468        *  @param  __position  An iterator pointing to the element to be erased.
00469        *  @return An iterator pointing to the element immediately following
00470        *          @a __position prior to the element being erased. If no such
00471        *          element exists, end() is returned.
00472        *
00473        *  This function erases an element, pointed to by the given iterator,
00474        *  from an %unordered_map.
00475        *  Note that this function only erases the element, and that if the
00476        *  element is itself a pointer, the pointed-to memory is not touched in
00477        *  any way.  Managing the pointer is the user's responsibility.
00478        */
00479       iterator
00480       erase(const_iterator __position)
00481       { return _M_h.erase(__position); }
00482 
00483       // LWG 2059.
00484       iterator
00485       erase(iterator __position)
00486       { return _M_h.erase(__position); }
00487       //@}
00488 
00489       /**
00490        *  @brief Erases elements according to the provided key.
00491        *  @param  __x  Key of element to be erased.
00492        *  @return  The number of elements erased.
00493        *
00494        *  This function erases all the elements located by the given key from
00495        *  an %unordered_map. For an %unordered_map the result of this function
00496        *  can only be 0 (not present) or 1 (present).
00497        *  Note that this function only erases the element, and that if the
00498        *  element is itself a pointer, the pointed-to memory is not touched in
00499        *  any way.  Managing the pointer is the user's responsibility.
00500        */
00501       size_type
00502       erase(const key_type& __x)
00503       { return _M_h.erase(__x); }
00504 
00505       /**
00506        *  @brief Erases a [__first,__last) range of elements from an
00507        *  %unordered_map.
00508        *  @param  __first  Iterator pointing to the start of the range to be
00509        *                  erased.
00510        *  @param __last  Iterator pointing to the end of the range to
00511        *                be erased.
00512        *  @return The iterator @a __last.
00513        *
00514        *  This function erases a sequence of elements from an %unordered_map.
00515        *  Note that this function only erases the elements, and that if
00516        *  the element is itself a pointer, the pointed-to memory is not touched
00517        *  in any way.  Managing the pointer is the user's responsibility.
00518        */
00519       iterator
00520       erase(const_iterator __first, const_iterator __last)
00521       { return _M_h.erase(__first, __last); }
00522 
00523       /**
00524        *  Erases all elements in an %unordered_map.
00525        *  Note that this function only erases the elements, and that if the
00526        *  elements themselves are pointers, the pointed-to memory is not touched
00527        *  in any way.  Managing the pointer is the user's responsibility.
00528        */
00529       void
00530       clear() noexcept
00531       { _M_h.clear(); }
00532 
00533       /**
00534        *  @brief  Swaps data with another %unordered_map.
00535        *  @param  __x  An %unordered_map of the same element and allocator
00536        *  types.
00537        *
00538        *  This exchanges the elements between two %unordered_map in constant time.
00539        *  Note that the global std::swap() function is specialized such that
00540        *  std::swap(m1,m2) will feed to this function.
00541        */
00542       void
00543       swap(unordered_map& __x)
00544       noexcept( noexcept(_M_h.swap(__x._M_h)) )
00545       { _M_h.swap(__x._M_h); }
00546 
00547       // observers.
00548 
00549       ///  Returns the hash functor object with which the %unordered_map was
00550       ///  constructed.
00551       hasher
00552       hash_function() const
00553       { return _M_h.hash_function(); }
00554 
00555       ///  Returns the key comparison object with which the %unordered_map was
00556       ///  constructed.
00557       key_equal
00558       key_eq() const
00559       { return _M_h.key_eq(); }
00560 
00561       // lookup.
00562 
00563       //@{
00564       /**
00565        *  @brief Tries to locate an element in an %unordered_map.
00566        *  @param  __x  Key to be located.
00567        *  @return  Iterator pointing to sought-after element, or end() if not
00568        *           found.
00569        *
00570        *  This function takes a key and tries to locate the element with which
00571        *  the key matches.  If successful the function returns an iterator
00572        *  pointing to the sought after element.  If unsuccessful it returns the
00573        *  past-the-end ( @c end() ) iterator.
00574        */
00575       iterator
00576       find(const key_type& __x)
00577       { return _M_h.find(__x); }
00578 
00579       const_iterator
00580       find(const key_type& __x) const
00581       { return _M_h.find(__x); }
00582       //@}
00583 
00584       /**
00585        *  @brief  Finds the number of elements.
00586        *  @param  __x  Key to count.
00587        *  @return  Number of elements with specified key.
00588        *
00589        *  This function only makes sense for %unordered_multimap; for
00590        *  %unordered_map the result will either be 0 (not present) or 1
00591        *  (present).
00592        */
00593       size_type
00594       count(const key_type& __x) const
00595       { return _M_h.count(__x); }
00596 
00597       //@{
00598       /**
00599        *  @brief Finds a subsequence matching given key.
00600        *  @param  __x  Key to be located.
00601        *  @return  Pair of iterators that possibly points to the subsequence
00602        *           matching given key.
00603        *
00604        *  This function probably only makes sense for %unordered_multimap.
00605        */
00606       std::pair<iterator, iterator>
00607       equal_range(const key_type& __x)
00608       { return _M_h.equal_range(__x); }
00609 
00610       std::pair<const_iterator, const_iterator>
00611       equal_range(const key_type& __x) const
00612       { return _M_h.equal_range(__x); }
00613       //@}
00614 
00615       //@{
00616       /**
00617        *  @brief  Subscript ( @c [] ) access to %unordered_map data.
00618        *  @param  __k  The key for which data should be retrieved.
00619        *  @return  A reference to the data of the (key,data) %pair.
00620        *
00621        *  Allows for easy lookup with the subscript ( @c [] )operator.  Returns
00622        *  data associated with the key specified in subscript.  If the key does
00623        *  not exist, a pair with that key is created using default values, which
00624        *  is then returned.
00625        *
00626        *  Lookup requires constant time.
00627        */
00628       mapped_type&
00629       operator[](const key_type& __k)
00630       { return _M_h[__k]; }
00631 
00632       mapped_type&
00633       operator[](key_type&& __k)
00634       { return _M_h[std::move(__k)]; }
00635       //@}
00636 
00637       //@{
00638       /**
00639        *  @brief  Access to %unordered_map data.
00640        *  @param  __k  The key for which data should be retrieved.
00641        *  @return  A reference to the data whose key is equal to @a __k, if
00642        *           such a data is present in the %unordered_map.
00643        *  @throw  std::out_of_range  If no such data is present.
00644        */
00645       mapped_type&
00646       at(const key_type& __k)
00647       { return _M_h.at(__k); }
00648 
00649       const mapped_type&
00650       at(const key_type& __k) const
00651       { return _M_h.at(__k); }
00652       //@}
00653 
00654       // bucket interface.
00655 
00656       /// Returns the number of buckets of the %unordered_map.
00657       size_type
00658       bucket_count() const noexcept
00659       { return _M_h.bucket_count(); }
00660 
00661       /// Returns the maximum number of buckets of the %unordered_map.
00662       size_type
00663       max_bucket_count() const noexcept
00664       { return _M_h.max_bucket_count(); }
00665 
00666       /*
00667        * @brief  Returns the number of elements in a given bucket.
00668        * @param  __n  A bucket index.
00669        * @return  The number of elements in the bucket.
00670        */
00671       size_type
00672       bucket_size(size_type __n) const
00673       { return _M_h.bucket_size(__n); }
00674 
00675       /*
00676        * @brief  Returns the bucket index of a given element.
00677        * @param  __key  A key instance.
00678        * @return  The key bucket index.
00679        */
00680       size_type
00681       bucket(const key_type& __key) const
00682       { return _M_h.bucket(__key); }
00683       
00684       /**
00685        *  @brief  Returns a read/write iterator pointing to the first bucket
00686        *         element.
00687        *  @param  __n The bucket index.
00688        *  @return  A read/write local iterator.
00689        */
00690       local_iterator
00691       begin(size_type __n)
00692       { return _M_h.begin(__n); }
00693 
00694       //@{
00695       /**
00696        *  @brief  Returns a read-only (constant) iterator pointing to the first
00697        *         bucket element.
00698        *  @param  __n The bucket index.
00699        *  @return  A read-only local iterator.
00700        */
00701       const_local_iterator
00702       begin(size_type __n) const
00703       { return _M_h.begin(__n); }
00704 
00705       const_local_iterator
00706       cbegin(size_type __n) const
00707       { return _M_h.cbegin(__n); }
00708       //@}
00709 
00710       /**
00711        *  @brief  Returns a read/write iterator pointing to one past the last
00712        *         bucket elements.
00713        *  @param  __n The bucket index.
00714        *  @return  A read/write local iterator.
00715        */
00716       local_iterator
00717       end(size_type __n)
00718       { return _M_h.end(__n); }
00719 
00720       //@{
00721       /**
00722        *  @brief  Returns a read-only (constant) iterator pointing to one past
00723        *         the last bucket elements.
00724        *  @param  __n The bucket index.
00725        *  @return  A read-only local iterator.
00726        */
00727       const_local_iterator
00728       end(size_type __n) const
00729       { return _M_h.end(__n); }
00730 
00731       const_local_iterator
00732       cend(size_type __n) const
00733       { return _M_h.cend(__n); }
00734       //@}
00735 
00736       // hash policy.
00737 
00738       /// Returns the average number of elements per bucket.
00739       float
00740       load_factor() const noexcept
00741       { return _M_h.load_factor(); }
00742 
00743       /// Returns a positive number that the %unordered_map tries to keep the
00744       /// load factor less than or equal to.
00745       float
00746       max_load_factor() const noexcept
00747       { return _M_h.max_load_factor(); }
00748 
00749       /**
00750        *  @brief  Change the %unordered_map maximum load factor.
00751        *  @param  __z The new maximum load factor.
00752        */
00753       void
00754       max_load_factor(float __z)
00755       { _M_h.max_load_factor(__z); }
00756 
00757       /**
00758        *  @brief  May rehash the %unordered_map.
00759        *  @param  __n The new number of buckets.
00760        *
00761        *  Rehash will occur only if the new number of buckets respect the
00762        *  %unordered_map maximum load factor.
00763        */
00764       void
00765       rehash(size_type __n)
00766       { _M_h.rehash(__n); }
00767 
00768       /**
00769        *  @brief  Prepare the %unordered_map for a specified number of
00770        *          elements.
00771        *  @param  __n Number of elements required.
00772        *
00773        *  Same as rehash(ceil(n / max_load_factor())).
00774        */
00775       void
00776       reserve(size_type __n)
00777       { _M_h.reserve(__n); }
00778 
00779       template<typename _Key1, typename _Tp1, typename _Hash1, typename _Pred1,
00780                typename _Alloc1>
00781         friend bool
00782       operator==(const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&,
00783                  const unordered_map<_Key1, _Tp1, _Hash1, _Pred1, _Alloc1>&);
00784     };
00785 
00786   /**
00787    *  @brief A standard container composed of equivalent keys
00788    *  (possibly containing multiple of each key value) that associates
00789    *  values of another type with the keys.
00790    *
00791    *  @ingroup unordered_associative_containers
00792    *
00793    *  @tparam  _Key    Type of key objects.
00794    *  @tparam  _Tp     Type of mapped objects.
00795    *  @tparam  _Hash   Hashing function object type, defaults to hash<_Value>.
00796    *  @tparam  _Pred   Predicate function object type, defaults
00797    *                   to equal_to<_Value>.
00798    *  @tparam  _Alloc  Allocator type, defaults to
00799    *                   std::allocator<std::pair<const _Key, _Tp>>.
00800    *
00801    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00802    *  <a href="tables.html#xx">unordered associative container</a>
00803    *
00804    * The resulting value type of the container is std::pair<const _Key, _Tp>.
00805    *
00806    *  Base is _Hashtable, dispatched at compile time via template
00807    *  alias __ummap_hashtable.
00808    */
00809   template<class _Key, class _Tp,
00810            class _Hash = hash<_Key>,
00811            class _Pred = std::equal_to<_Key>,
00812            class _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00813     class unordered_multimap
00814     {
00815       typedef __ummap_hashtable<_Key, _Tp, _Hash, _Pred, _Alloc>  _Hashtable;
00816       _Hashtable _M_h;
00817 
00818     public:
00819       // typedefs:
00820       //@{
00821       /// Public typedefs.
00822       typedef typename _Hashtable::key_type     key_type;
00823       typedef typename _Hashtable::value_type   value_type;
00824       typedef typename _Hashtable::mapped_type  mapped_type;
00825       typedef typename _Hashtable::hasher       hasher;
00826       typedef typename _Hashtable::key_equal    key_equal;
00827       typedef typename _Hashtable::allocator_type allocator_type;
00828       //@}
00829 
00830       //@{
00831       ///  Iterator-related typedefs.
00832       typedef typename _Hashtable::pointer              pointer;
00833       typedef typename _Hashtable::const_pointer        const_pointer;
00834       typedef typename _Hashtable::reference            reference;
00835       typedef typename _Hashtable::const_reference      const_reference;
00836       typedef typename _Hashtable::iterator             iterator;
00837       typedef typename _Hashtable::const_iterator       const_iterator;
00838       typedef typename _Hashtable::local_iterator       local_iterator;
00839       typedef typename _Hashtable::const_local_iterator const_local_iterator;
00840       typedef typename _Hashtable::size_type            size_type;
00841       typedef typename _Hashtable::difference_type      difference_type;
00842       //@}
00843 
00844       //construct/destroy/copy
00845 
00846       /// Default constructor.
00847       unordered_multimap() = default;
00848 
00849       /**
00850        *  @brief  Default constructor creates no elements.
00851        *  @param __n  Mnimal initial number of buckets.
00852        *  @param __hf  A hash functor.
00853        *  @param __eql  A key equality functor.
00854        *  @param __a  An allocator object.
00855        */
00856       explicit
00857       unordered_multimap(size_type __n,
00858                          const hasher& __hf = hasher(),
00859                          const key_equal& __eql = key_equal(),
00860                          const allocator_type& __a = allocator_type())
00861       : _M_h(__n, __hf, __eql, __a)
00862       { }
00863 
00864       /**
00865        *  @brief  Builds an %unordered_multimap from a range.
00866        *  @param  __first An input iterator.
00867        *  @param  __last  An input iterator.
00868        *  @param __n      Minimal initial number of buckets.
00869        *  @param __hf     A hash functor.
00870        *  @param __eql    A key equality functor.
00871        *  @param __a      An allocator object.
00872        *
00873        *  Create an %unordered_multimap consisting of copies of the elements
00874        *  from [__first,__last).  This is linear in N (where N is
00875        *  distance(__first,__last)).
00876        */
00877       template<typename _InputIterator>
00878         unordered_multimap(_InputIterator __first, _InputIterator __last,
00879                            size_type __n = 0,
00880                            const hasher& __hf = hasher(),
00881                            const key_equal& __eql = key_equal(),
00882                            const allocator_type& __a = allocator_type())
00883         : _M_h(__first, __last, __n, __hf, __eql, __a)
00884         { }
00885 
00886       /// Copy constructor.
00887       unordered_multimap(const unordered_multimap&) = default;
00888 
00889       /// Move constructor.
00890       unordered_multimap(unordered_multimap&&) = default;
00891 
00892       /**
00893        *  @brief Creates an %unordered_multimap with no elements.
00894        *  @param __a An allocator object.
00895        */
00896       explicit
00897       unordered_multimap(const allocator_type& __a)
00898         : _M_h(__a)
00899       { }
00900 
00901       /*
00902        *  @brief Copy constructor with allocator argument.
00903        * @param  __uset  Input %unordered_multimap to copy.
00904        * @param  __a  An allocator object.
00905        */
00906       unordered_multimap(const unordered_multimap& __ummap,
00907                          const allocator_type& __a)
00908         : _M_h(__ummap._M_h, __a)
00909       { }
00910 
00911       /*
00912        *  @brief  Move constructor with allocator argument.
00913        *  @param  __uset Input %unordered_multimap to move.
00914        *  @param  __a    An allocator object.
00915        */
00916       unordered_multimap(unordered_multimap&& __ummap,
00917                          const allocator_type& __a)
00918         : _M_h(std::move(__ummap._M_h), __a)
00919       { }
00920 
00921       /**
00922        *  @brief  Builds an %unordered_multimap from an initializer_list.
00923        *  @param  __l  An initializer_list.
00924        *  @param __n  Minimal initial number of buckets.
00925        *  @param __hf  A hash functor.
00926        *  @param __eql  A key equality functor.
00927        *  @param  __a  An allocator object.
00928        *
00929        *  Create an %unordered_multimap consisting of copies of the elements in
00930        *  the list. This is linear in N (where N is @a __l.size()).
00931        */
00932       unordered_multimap(initializer_list<value_type> __l,
00933                          size_type __n = 0,
00934                          const hasher& __hf = hasher(),
00935                          const key_equal& __eql = key_equal(),
00936                          const allocator_type& __a = allocator_type())
00937         : _M_h(__l, __n, __hf, __eql, __a)
00938       { }
00939 
00940       /// Copy assignment operator.
00941       unordered_multimap&
00942       operator=(const unordered_multimap&) = default;
00943 
00944       /// Move assignment operator.
00945       unordered_multimap&
00946       operator=(unordered_multimap&&) = default;
00947 
00948       /**
00949        *  @brief  %Unordered_multimap list assignment operator.
00950        *  @param  __l  An initializer_list.
00951        *
00952        *  This function fills an %unordered_multimap with copies of the elements
00953        *  in the initializer list @a __l.
00954        *
00955        *  Note that the assignment completely changes the %unordered_multimap
00956        *  and that the resulting %unordered_multimap's size is the same as the
00957        *  number of elements assigned.  Old data may be lost.
00958        */
00959       unordered_multimap&
00960       operator=(initializer_list<value_type> __l)
00961       {
00962         _M_h = __l;
00963         return *this;
00964       }
00965 
00966       ///  Returns the allocator object with which the %unordered_multimap was
00967       ///  constructed.
00968       allocator_type
00969       get_allocator() const noexcept
00970       { return _M_h.get_allocator(); }
00971 
00972       // size and capacity:
00973 
00974       ///  Returns true if the %unordered_multimap is empty.
00975       bool
00976       empty() const noexcept
00977       { return _M_h.empty(); }
00978 
00979       ///  Returns the size of the %unordered_multimap.
00980       size_type
00981       size() const noexcept
00982       { return _M_h.size(); }
00983 
00984       ///  Returns the maximum size of the %unordered_multimap.
00985       size_type
00986       max_size() const noexcept
00987       { return _M_h.max_size(); }
00988 
00989       // iterators.
00990 
00991       /**
00992        *  Returns a read/write iterator that points to the first element in the
00993        *  %unordered_multimap.
00994        */
00995       iterator
00996       begin() noexcept
00997       { return _M_h.begin(); }
00998 
00999       //@{
01000       /**
01001        *  Returns a read-only (constant) iterator that points to the first
01002        *  element in the %unordered_multimap.
01003        */
01004       const_iterator
01005       begin() const noexcept
01006       { return _M_h.begin(); }
01007 
01008       const_iterator
01009       cbegin() const noexcept
01010       { return _M_h.begin(); }
01011       //@}
01012 
01013       /**
01014        *  Returns a read/write iterator that points one past the last element in
01015        *  the %unordered_multimap.
01016        */
01017       iterator
01018       end() noexcept
01019       { return _M_h.end(); }
01020 
01021       //@{
01022       /**
01023        *  Returns a read-only (constant) iterator that points one past the last
01024        *  element in the %unordered_multimap.
01025        */
01026       const_iterator
01027       end() const noexcept
01028       { return _M_h.end(); }
01029 
01030       const_iterator
01031       cend() const noexcept
01032       { return _M_h.end(); }
01033       //@}
01034 
01035       // modifiers.
01036 
01037       /**
01038        *  @brief Attempts to build and insert a std::pair into the
01039        *  %unordered_multimap.
01040        *
01041        *  @param __args  Arguments used to generate a new pair instance (see
01042        *                std::piecewise_contruct for passing arguments to each
01043        *                part of the pair constructor).
01044        *
01045        *  @return  An iterator that points to the inserted pair.
01046        *
01047        *  This function attempts to build and insert a (key, value) %pair into
01048        *  the %unordered_multimap.
01049        *
01050        *  Insertion requires amortized constant time.
01051        */
01052       template<typename... _Args>
01053         iterator
01054         emplace(_Args&&... __args)
01055         { return _M_h.emplace(std::forward<_Args>(__args)...); }
01056 
01057       /**
01058        *  @brief Attempts to build and insert a std::pair into the %unordered_multimap.
01059        *
01060        *  @param  __pos  An iterator that serves as a hint as to where the pair
01061        *                should be inserted.
01062        *  @param  __args  Arguments used to generate a new pair instance (see
01063        *                 std::piecewise_contruct for passing arguments to each
01064        *                 part of the pair constructor).
01065        *  @return An iterator that points to the element with key of the
01066        *          std::pair built from @a __args.
01067        *
01068        *  Note that the first parameter is only a hint and can potentially
01069        *  improve the performance of the insertion process. A bad hint would
01070        *  cause no gains in efficiency.
01071        *
01072        *  See
01073        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
01074        *  for more on @a hinting.
01075        *
01076        *  Insertion requires amortized constant time.
01077        */
01078       template<typename... _Args>
01079         iterator
01080         emplace_hint(const_iterator __pos, _Args&&... __args)
01081         { return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
01082 
01083       //@{
01084       /**
01085        *  @brief Inserts a std::pair into the %unordered_multimap.
01086        *  @param __x Pair to be inserted (see std::make_pair for easy
01087        *             creation of pairs).
01088        *
01089        *  @return  An iterator that points to the inserted pair.
01090        *
01091        *  Insertion requires amortized constant time.
01092        */
01093       iterator
01094       insert(const value_type& __x)
01095       { return _M_h.insert(__x); }
01096 
01097       template<typename _Pair, typename = typename
01098                std::enable_if<std::is_constructible<value_type,
01099                                                     _Pair&&>::value>::type>
01100         iterator
01101         insert(_Pair&& __x)
01102         { return _M_h.insert(std::forward<_Pair>(__x)); }
01103       //@}
01104 
01105       //@{
01106       /**
01107        *  @brief Inserts a std::pair into the %unordered_multimap.
01108        *  @param  __hint  An iterator that serves as a hint as to where the
01109        *                 pair should be inserted.
01110        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
01111        *               of pairs).
01112        *  @return An iterator that points to the element with key of
01113        *           @a __x (may or may not be the %pair passed in).
01114        *
01115        *  Note that the first parameter is only a hint and can potentially
01116        *  improve the performance of the insertion process.  A bad hint would
01117        *  cause no gains in efficiency.
01118        *
01119        *  See
01120        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
01121        *  for more on @a hinting.
01122        *
01123        *  Insertion requires amortized constant time.
01124        */
01125       iterator
01126       insert(const_iterator __hint, const value_type& __x)
01127       { return _M_h.insert(__hint, __x); }
01128 
01129       template<typename _Pair, typename = typename
01130                std::enable_if<std::is_constructible<value_type,
01131                                                     _Pair&&>::value>::type>
01132         iterator
01133         insert(const_iterator __hint, _Pair&& __x)
01134         { return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
01135       //@}
01136 
01137       /**
01138        *  @brief A template function that attempts to insert a range of
01139        *  elements.
01140        *  @param  __first  Iterator pointing to the start of the range to be
01141        *                   inserted.
01142        *  @param  __last  Iterator pointing to the end of the range.
01143        *
01144        *  Complexity similar to that of the range constructor.
01145        */
01146       template<typename _InputIterator>
01147         void
01148         insert(_InputIterator __first, _InputIterator __last)
01149         { _M_h.insert(__first, __last); }
01150 
01151       /**
01152        *  @brief Attempts to insert a list of elements into the
01153        *  %unordered_multimap.
01154        *  @param  __l  A std::initializer_list<value_type> of elements
01155        *               to be inserted.
01156        *
01157        *  Complexity similar to that of the range constructor.
01158        */
01159       void
01160       insert(initializer_list<value_type> __l)
01161       { _M_h.insert(__l); }
01162 
01163       //@{
01164       /**
01165        *  @brief Erases an element from an %unordered_multimap.
01166        *  @param  __position  An iterator pointing to the element to be erased.
01167        *  @return An iterator pointing to the element immediately following
01168        *          @a __position prior to the element being erased. If no such
01169        *          element exists, end() is returned.
01170        *
01171        *  This function erases an element, pointed to by the given iterator,
01172        *  from an %unordered_multimap.
01173        *  Note that this function only erases the element, and that if the
01174        *  element is itself a pointer, the pointed-to memory is not touched in
01175        *  any way.  Managing the pointer is the user's responsibility.
01176        */
01177       iterator
01178       erase(const_iterator __position)
01179       { return _M_h.erase(__position); }
01180 
01181       // LWG 2059.
01182       iterator
01183       erase(iterator __position)
01184       { return _M_h.erase(__position); }
01185       //@}
01186 
01187       /**
01188        *  @brief Erases elements according to the provided key.
01189        *  @param  __x  Key of elements to be erased.
01190        *  @return  The number of elements erased.
01191        *
01192        *  This function erases all the elements located by the given key from
01193        *  an %unordered_multimap.
01194        *  Note that this function only erases the element, and that if the
01195        *  element is itself a pointer, the pointed-to memory is not touched in
01196        *  any way.  Managing the pointer is the user's responsibility.
01197        */
01198       size_type
01199       erase(const key_type& __x)
01200       { return _M_h.erase(__x); }
01201 
01202       /**
01203        *  @brief Erases a [__first,__last) range of elements from an
01204        *  %unordered_multimap.
01205        *  @param  __first  Iterator pointing to the start of the range to be
01206        *                  erased.
01207        *  @param __last  Iterator pointing to the end of the range to
01208        *                be erased.
01209        *  @return The iterator @a __last.
01210        *
01211        *  This function erases a sequence of elements from an
01212        *  %unordered_multimap.
01213        *  Note that this function only erases the elements, and that if
01214        *  the element is itself a pointer, the pointed-to memory is not touched
01215        *  in any way.  Managing the pointer is the user's responsibility.
01216        */
01217       iterator
01218       erase(const_iterator __first, const_iterator __last)
01219       { return _M_h.erase(__first, __last); }
01220 
01221       /**
01222        *  Erases all elements in an %unordered_multimap.
01223        *  Note that this function only erases the elements, and that if the
01224        *  elements themselves are pointers, the pointed-to memory is not touched
01225        *  in any way.  Managing the pointer is the user's responsibility.
01226        */
01227       void
01228       clear() noexcept
01229       { _M_h.clear(); }
01230 
01231       /**
01232        *  @brief  Swaps data with another %unordered_multimap.
01233        *  @param  __x  An %unordered_multimap of the same element and allocator
01234        *  types.
01235        *
01236        *  This exchanges the elements between two %unordered_multimap in
01237        *  constant time.
01238        *  Note that the global std::swap() function is specialized such that
01239        *  std::swap(m1,m2) will feed to this function.
01240        */
01241       void
01242       swap(unordered_multimap& __x)
01243       noexcept( noexcept(_M_h.swap(__x._M_h)) )
01244       { _M_h.swap(__x._M_h); }
01245 
01246       // observers.
01247 
01248       ///  Returns the hash functor object with which the %unordered_multimap
01249       ///  was constructed.
01250       hasher
01251       hash_function() const
01252       { return _M_h.hash_function(); }
01253 
01254       ///  Returns the key comparison object with which the %unordered_multimap
01255       ///  was constructed.
01256       key_equal
01257       key_eq() const
01258       { return _M_h.key_eq(); }
01259 
01260       // lookup.
01261 
01262       //@{
01263       /**
01264        *  @brief Tries to locate an element in an %unordered_multimap.
01265        *  @param  __x  Key to be located.
01266        *  @return  Iterator pointing to sought-after element, or end() if not
01267        *           found.
01268        *
01269        *  This function takes a key and tries to locate the element with which
01270        *  the key matches.  If successful the function returns an iterator
01271        *  pointing to the sought after element.  If unsuccessful it returns the
01272        *  past-the-end ( @c end() ) iterator.
01273        */
01274       iterator
01275       find(const key_type& __x)
01276       { return _M_h.find(__x); }
01277 
01278       const_iterator
01279       find(const key_type& __x) const
01280       { return _M_h.find(__x); }
01281       //@}
01282 
01283       /**
01284        *  @brief  Finds the number of elements.
01285        *  @param  __x  Key to count.
01286        *  @return  Number of elements with specified key.
01287        */
01288       size_type
01289       count(const key_type& __x) const
01290       { return _M_h.count(__x); }
01291 
01292       //@{
01293       /**
01294        *  @brief Finds a subsequence matching given key.
01295        *  @param  __x  Key to be located.
01296        *  @return  Pair of iterators that possibly points to the subsequence
01297        *           matching given key.
01298        */
01299       std::pair<iterator, iterator>
01300       equal_range(const key_type& __x)
01301       { return _M_h.equal_range(__x); }
01302 
01303       std::pair<const_iterator, const_iterator>
01304       equal_range(const key_type& __x) const
01305       { return _M_h.equal_range(__x); }
01306       //@}
01307 
01308       // bucket interface.
01309 
01310       /// Returns the number of buckets of the %unordered_multimap.
01311       size_type
01312       bucket_count() const noexcept
01313       { return _M_h.bucket_count(); }
01314 
01315       /// Returns the maximum number of buckets of the %unordered_multimap.
01316       size_type
01317       max_bucket_count() const noexcept
01318       { return _M_h.max_bucket_count(); }
01319 
01320       /*
01321        * @brief  Returns the number of elements in a given bucket.
01322        * @param  __n  A bucket index.
01323        * @return  The number of elements in the bucket.
01324        */
01325       size_type
01326       bucket_size(size_type __n) const
01327       { return _M_h.bucket_size(__n); }
01328 
01329       /*
01330        * @brief  Returns the bucket index of a given element.
01331        * @param  __key  A key instance.
01332        * @return  The key bucket index.
01333        */
01334       size_type
01335       bucket(const key_type& __key) const
01336       { return _M_h.bucket(__key); }
01337       
01338       /**
01339        *  @brief  Returns a read/write iterator pointing to the first bucket
01340        *         element.
01341        *  @param  __n The bucket index.
01342        *  @return  A read/write local iterator.
01343        */
01344       local_iterator
01345       begin(size_type __n)
01346       { return _M_h.begin(__n); }
01347 
01348       //@{
01349       /**
01350        *  @brief  Returns a read-only (constant) iterator pointing to the first
01351        *         bucket element.
01352        *  @param  __n The bucket index.
01353        *  @return  A read-only local iterator.
01354        */
01355       const_local_iterator
01356       begin(size_type __n) const
01357       { return _M_h.begin(__n); }
01358 
01359       const_local_iterator
01360       cbegin(size_type __n) const
01361       { return _M_h.cbegin(__n); }
01362       //@}
01363 
01364       /**
01365        *  @brief  Returns a read/write iterator pointing to one past the last
01366        *         bucket elements.
01367        *  @param  __n The bucket index.
01368        *  @return  A read/write local iterator.
01369        */
01370       local_iterator
01371       end(size_type __n)
01372       { return _M_h.end(__n); }
01373 
01374       //@{
01375       /**
01376        *  @brief  Returns a read-only (constant) iterator pointing to one past
01377        *         the last bucket elements.
01378        *  @param  __n The bucket index.
01379        *  @return  A read-only local iterator.
01380        */
01381       const_local_iterator
01382       end(size_type __n) const
01383       { return _M_h.end(__n); }
01384 
01385       const_local_iterator
01386       cend(size_type __n) const
01387       { return _M_h.cend(__n); }
01388       //@}
01389 
01390       // hash policy.
01391 
01392       /// Returns the average number of elements per bucket.
01393       float
01394       load_factor() const noexcept
01395       { return _M_h.load_factor(); }
01396 
01397       /// Returns a positive number that the %unordered_multimap tries to keep
01398       /// the load factor less than or equal to.
01399       float
01400       max_load_factor() const noexcept
01401       { return _M_h.max_load_factor(); }
01402 
01403       /**
01404        *  @brief  Change the %unordered_multimap maximum load factor.
01405        *  @param  __z The new maximum load factor.
01406        */
01407       void
01408       max_load_factor(float __z)
01409       { _M_h.max_load_factor(__z); }
01410 
01411       /**
01412        *  @brief  May rehash the %unordered_multimap.
01413        *  @param  __n The new number of buckets.
01414        *
01415        *  Rehash will occur only if the new number of buckets respect the
01416        *  %unordered_multimap maximum load factor.
01417        */
01418       void
01419       rehash(size_type __n)
01420       { _M_h.rehash(__n); }
01421 
01422       /**
01423        *  @brief  Prepare the %unordered_multimap for a specified number of
01424        *          elements.
01425        *  @param  __n Number of elements required.
01426        *
01427        *  Same as rehash(ceil(n / max_load_factor())).
01428        */
01429       void
01430       reserve(size_type __n)
01431       { _M_h.reserve(__n); }
01432 
01433       template<typename _Key1, typename _Tp1, typename _Hash1, typename _Pred1,
01434                typename _Alloc1>
01435         friend bool
01436         operator==(const unordered_multimap<_Key1, _Tp1,
01437                                             _Hash1, _Pred1, _Alloc1>&,
01438                    const unordered_multimap<_Key1, _Tp1,
01439                                             _Hash1, _Pred1, _Alloc1>&);
01440     };
01441 
01442   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01443     inline void
01444     swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01445          unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01446     { __x.swap(__y); }
01447 
01448   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01449     inline void
01450     swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01451          unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01452     { __x.swap(__y); }
01453 
01454   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01455     inline bool
01456     operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01457                const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01458     { return __x._M_h._M_equal(__y._M_h); }
01459 
01460   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01461     inline bool
01462     operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01463                const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01464     { return !(__x == __y); }
01465 
01466   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01467     inline bool
01468     operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01469                const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01470     { return __x._M_h._M_equal(__y._M_h); }
01471 
01472   template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
01473     inline bool
01474     operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
01475                const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
01476     { return !(__x == __y); }
01477 
01478 _GLIBCXX_END_NAMESPACE_CONTAINER
01479 } // namespace std
01480 
01481 #endif /* _UNORDERED_MAP_H */