libstdc++
unordered_map.h
Go to the documentation of this file.
1 // unordered_map implementation -*- C++ -*-
2 
3 // Copyright (C) 2010-2017 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file bits/unordered_map.h
26  * This is an internal header file, included by other library headers.
27  * Do not attempt to use it directly. @headername{unordered_map}
28  */
29 
30 #ifndef _UNORDERED_MAP_H
31 #define _UNORDERED_MAP_H
32 
33 namespace std _GLIBCXX_VISIBILITY(default)
34 {
35 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
36 
37  /// Base types for unordered_map.
38  template<bool _Cache>
40 
41  template<typename _Key,
42  typename _Tp,
43  typename _Hash = hash<_Key>,
44  typename _Pred = std::equal_to<_Key>,
48  _Alloc, __detail::_Select1st,
49  _Pred, _Hash,
53 
54  /// Base types for unordered_multimap.
55  template<bool _Cache>
57 
58  template<typename _Key,
59  typename _Tp,
60  typename _Hash = hash<_Key>,
61  typename _Pred = std::equal_to<_Key>,
65  _Alloc, __detail::_Select1st,
66  _Pred, _Hash,
67  __detail::_Mod_range_hashing,
68  __detail::_Default_ranged_hash,
69  __detail::_Prime_rehash_policy, _Tr>;
70 
71  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
73 
74  /**
75  * @brief A standard container composed of unique keys (containing
76  * at most one of each key value) that associates values of another type
77  * with the keys.
78  *
79  * @ingroup unordered_associative_containers
80  *
81  * @tparam _Key Type of key objects.
82  * @tparam _Tp Type of mapped objects.
83  * @tparam _Hash Hashing function object type, defaults to hash<_Value>.
84  * @tparam _Pred Predicate function object type, defaults
85  * to equal_to<_Value>.
86  * @tparam _Alloc Allocator type, defaults to
87  * std::allocator<std::pair<const _Key, _Tp>>.
88  *
89  * Meets the requirements of a <a href="tables.html#65">container</a>, and
90  * <a href="tables.html#xx">unordered associative container</a>
91  *
92  * The resulting value type of the container is std::pair<const _Key, _Tp>.
93  *
94  * Base is _Hashtable, dispatched at compile time via template
95  * alias __umap_hashtable.
96  */
97  template<class _Key, class _Tp,
98  class _Hash = hash<_Key>,
99  class _Pred = std::equal_to<_Key>,
102  {
104  _Hashtable _M_h;
105 
106  public:
107  // typedefs:
108  //@{
109  /// Public typedefs.
110  typedef typename _Hashtable::key_type key_type;
111  typedef typename _Hashtable::value_type value_type;
112  typedef typename _Hashtable::mapped_type mapped_type;
113  typedef typename _Hashtable::hasher hasher;
114  typedef typename _Hashtable::key_equal key_equal;
115  typedef typename _Hashtable::allocator_type allocator_type;
116  //@}
117 
118  //@{
119  /// Iterator-related typedefs.
120  typedef typename _Hashtable::pointer pointer;
121  typedef typename _Hashtable::const_pointer const_pointer;
122  typedef typename _Hashtable::reference reference;
123  typedef typename _Hashtable::const_reference const_reference;
124  typedef typename _Hashtable::iterator iterator;
125  typedef typename _Hashtable::const_iterator const_iterator;
126  typedef typename _Hashtable::local_iterator local_iterator;
127  typedef typename _Hashtable::const_local_iterator const_local_iterator;
128  typedef typename _Hashtable::size_type size_type;
129  typedef typename _Hashtable::difference_type difference_type;
130  //@}
131 
132 #if __cplusplus > 201402L
133  using node_type = typename _Hashtable::node_type;
134  using insert_return_type = typename _Hashtable::insert_return_type;
135 #endif
136 
137  //construct/destroy/copy
138 
139  /// Default constructor.
140  unordered_map() = default;
141 
142  /**
143  * @brief Default constructor creates no elements.
144  * @param __n Minimal initial number of buckets.
145  * @param __hf A hash functor.
146  * @param __eql A key equality functor.
147  * @param __a An allocator object.
148  */
149  explicit
150  unordered_map(size_type __n,
151  const hasher& __hf = hasher(),
152  const key_equal& __eql = key_equal(),
153  const allocator_type& __a = allocator_type())
154  : _M_h(__n, __hf, __eql, __a)
155  { }
156 
157  /**
158  * @brief Builds an %unordered_map from a range.
159  * @param __first An input iterator.
160  * @param __last An input iterator.
161  * @param __n Minimal initial number of buckets.
162  * @param __hf A hash functor.
163  * @param __eql A key equality functor.
164  * @param __a An allocator object.
165  *
166  * Create an %unordered_map consisting of copies of the elements from
167  * [__first,__last). This is linear in N (where N is
168  * distance(__first,__last)).
169  */
170  template<typename _InputIterator>
171  unordered_map(_InputIterator __first, _InputIterator __last,
172  size_type __n = 0,
173  const hasher& __hf = hasher(),
174  const key_equal& __eql = key_equal(),
175  const allocator_type& __a = allocator_type())
176  : _M_h(__first, __last, __n, __hf, __eql, __a)
177  { }
178 
179  /// Copy constructor.
180  unordered_map(const unordered_map&) = default;
181 
182  /// Move constructor.
183  unordered_map(unordered_map&&) = default;
184 
185  /**
186  * @brief Creates an %unordered_map with no elements.
187  * @param __a An allocator object.
188  */
189  explicit
190  unordered_map(const allocator_type& __a)
191  : _M_h(__a)
192  { }
193 
194  /*
195  * @brief Copy constructor with allocator argument.
196  * @param __uset Input %unordered_map to copy.
197  * @param __a An allocator object.
198  */
199  unordered_map(const unordered_map& __umap,
200  const allocator_type& __a)
201  : _M_h(__umap._M_h, __a)
202  { }
203 
204  /*
205  * @brief Move constructor with allocator argument.
206  * @param __uset Input %unordered_map to move.
207  * @param __a An allocator object.
208  */
209  unordered_map(unordered_map&& __umap,
210  const allocator_type& __a)
211  : _M_h(std::move(__umap._M_h), __a)
212  { }
213 
214  /**
215  * @brief Builds an %unordered_map from an initializer_list.
216  * @param __l An initializer_list.
217  * @param __n Minimal initial number of buckets.
218  * @param __hf A hash functor.
219  * @param __eql A key equality functor.
220  * @param __a An allocator object.
221  *
222  * Create an %unordered_map consisting of copies of the elements in the
223  * list. This is linear in N (where N is @a __l.size()).
224  */
226  size_type __n = 0,
227  const hasher& __hf = hasher(),
228  const key_equal& __eql = key_equal(),
229  const allocator_type& __a = allocator_type())
230  : _M_h(__l, __n, __hf, __eql, __a)
231  { }
232 
233  unordered_map(size_type __n, const allocator_type& __a)
234  : unordered_map(__n, hasher(), key_equal(), __a)
235  { }
236 
237  unordered_map(size_type __n, const hasher& __hf,
238  const allocator_type& __a)
239  : unordered_map(__n, __hf, key_equal(), __a)
240  { }
241 
242  template<typename _InputIterator>
243  unordered_map(_InputIterator __first, _InputIterator __last,
244  size_type __n,
245  const allocator_type& __a)
246  : unordered_map(__first, __last, __n, hasher(), key_equal(), __a)
247  { }
248 
249  template<typename _InputIterator>
250  unordered_map(_InputIterator __first, _InputIterator __last,
251  size_type __n, const hasher& __hf,
252  const allocator_type& __a)
253  : unordered_map(__first, __last, __n, __hf, key_equal(), __a)
254  { }
255 
257  size_type __n,
258  const allocator_type& __a)
259  : unordered_map(__l, __n, hasher(), key_equal(), __a)
260  { }
261 
263  size_type __n, const hasher& __hf,
264  const allocator_type& __a)
265  : unordered_map(__l, __n, __hf, key_equal(), __a)
266  { }
267 
268  /// Copy assignment operator.
270  operator=(const unordered_map&) = default;
271 
272  /// Move assignment operator.
274  operator=(unordered_map&&) = default;
275 
276  /**
277  * @brief %Unordered_map list assignment operator.
278  * @param __l An initializer_list.
279  *
280  * This function fills an %unordered_map with copies of the elements in
281  * the initializer list @a __l.
282  *
283  * Note that the assignment completely changes the %unordered_map and
284  * that the resulting %unordered_map's size is the same as the number
285  * of elements assigned.
286  */
289  {
290  _M_h = __l;
291  return *this;
292  }
293 
294  /// Returns the allocator object used by the %unordered_map.
295  allocator_type
296  get_allocator() const noexcept
297  { return _M_h.get_allocator(); }
298 
299  // size and capacity:
300 
301  /// Returns true if the %unordered_map is empty.
302  bool
303  empty() const noexcept
304  { return _M_h.empty(); }
305 
306  /// Returns the size of the %unordered_map.
307  size_type
308  size() const noexcept
309  { return _M_h.size(); }
310 
311  /// Returns the maximum size of the %unordered_map.
312  size_type
313  max_size() const noexcept
314  { return _M_h.max_size(); }
315 
316  // iterators.
317 
318  /**
319  * Returns a read/write iterator that points to the first element in the
320  * %unordered_map.
321  */
322  iterator
323  begin() noexcept
324  { return _M_h.begin(); }
325 
326  //@{
327  /**
328  * Returns a read-only (constant) iterator that points to the first
329  * element in the %unordered_map.
330  */
331  const_iterator
332  begin() const noexcept
333  { return _M_h.begin(); }
334 
335  const_iterator
336  cbegin() const noexcept
337  { return _M_h.begin(); }
338  //@}
339 
340  /**
341  * Returns a read/write iterator that points one past the last element in
342  * the %unordered_map.
343  */
344  iterator
345  end() noexcept
346  { return _M_h.end(); }
347 
348  //@{
349  /**
350  * Returns a read-only (constant) iterator that points one past the last
351  * element in the %unordered_map.
352  */
353  const_iterator
354  end() const noexcept
355  { return _M_h.end(); }
356 
357  const_iterator
358  cend() const noexcept
359  { return _M_h.end(); }
360  //@}
361 
362  // modifiers.
363 
364  /**
365  * @brief Attempts to build and insert a std::pair into the
366  * %unordered_map.
367  *
368  * @param __args Arguments used to generate a new pair instance (see
369  * std::piecewise_contruct for passing arguments to each
370  * part of the pair constructor).
371  *
372  * @return A pair, of which the first element is an iterator that points
373  * to the possibly inserted pair, and the second is a bool that
374  * is true if the pair was actually inserted.
375  *
376  * This function attempts to build and insert a (key, value) %pair into
377  * the %unordered_map.
378  * An %unordered_map relies on unique keys and thus a %pair is only
379  * inserted if its first element (the key) is not already present in the
380  * %unordered_map.
381  *
382  * Insertion requires amortized constant time.
383  */
384  template<typename... _Args>
386  emplace(_Args&&... __args)
387  { return _M_h.emplace(std::forward<_Args>(__args)...); }
388 
389  /**
390  * @brief Attempts to build and insert a std::pair into the
391  * %unordered_map.
392  *
393  * @param __pos An iterator that serves as a hint as to where the pair
394  * should be inserted.
395  * @param __args Arguments used to generate a new pair instance (see
396  * std::piecewise_contruct for passing arguments to each
397  * part of the pair constructor).
398  * @return An iterator that points to the element with key of the
399  * std::pair built from @a __args (may or may not be that
400  * std::pair).
401  *
402  * This function is not concerned about whether the insertion took place,
403  * and thus does not return a boolean like the single-argument emplace()
404  * does.
405  * Note that the first parameter is only a hint and can potentially
406  * improve the performance of the insertion process. A bad hint would
407  * cause no gains in efficiency.
408  *
409  * See
410  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
411  * for more on @a hinting.
412  *
413  * Insertion requires amortized constant time.
414  */
415  template<typename... _Args>
416  iterator
417  emplace_hint(const_iterator __pos, _Args&&... __args)
418  { return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
419 
420 #if __cplusplus > 201402L
421  /// Extract a node.
422  node_type
423  extract(const_iterator __pos)
424  {
425  __glibcxx_assert(__pos != end());
426  return _M_h.extract(__pos);
427  }
428 
429  /// Extract a node.
430  node_type
431  extract(const key_type& __key)
432  { return _M_h.extract(__key); }
433 
434  /// Re-insert an extracted node.
435  insert_return_type
436  insert(node_type&& __nh)
437  { return _M_h._M_reinsert_node(std::move(__nh)); }
438 
439  /// Re-insert an extracted node.
440  iterator
441  insert(const_iterator, node_type&& __nh)
442  { return _M_h._M_reinsert_node(std::move(__nh)).position; }
443 
444 #define __cpp_lib_unordered_map_try_emplace 201411
445  /**
446  * @brief Attempts to build and insert a std::pair into the
447  * %unordered_map.
448  *
449  * @param __k Key to use for finding a possibly existing pair in
450  * the unordered_map.
451  * @param __args Arguments used to generate the .second for a
452  * new pair instance.
453  *
454  * @return A pair, of which the first element is an iterator that points
455  * to the possibly inserted pair, and the second is a bool that
456  * is true if the pair was actually inserted.
457  *
458  * This function attempts to build and insert a (key, value) %pair into
459  * the %unordered_map.
460  * An %unordered_map relies on unique keys and thus a %pair is only
461  * inserted if its first element (the key) is not already present in the
462  * %unordered_map.
463  * If a %pair is not inserted, this function has no effect.
464  *
465  * Insertion requires amortized constant time.
466  */
467  template <typename... _Args>
469  try_emplace(const key_type& __k, _Args&&... __args)
470  {
471  iterator __i = find(__k);
472  if (__i == end())
473  {
475  std::forward_as_tuple(__k),
476  std::forward_as_tuple(
477  std::forward<_Args>(__args)...))
478  .first;
479  return {__i, true};
480  }
481  return {__i, false};
482  }
483 
484  // move-capable overload
485  template <typename... _Args>
487  try_emplace(key_type&& __k, _Args&&... __args)
488  {
489  iterator __i = find(__k);
490  if (__i == end())
491  {
493  std::forward_as_tuple(std::move(__k)),
494  std::forward_as_tuple(
495  std::forward<_Args>(__args)...))
496  .first;
497  return {__i, true};
498  }
499  return {__i, false};
500  }
501 
502  /**
503  * @brief Attempts to build and insert a std::pair into the
504  * %unordered_map.
505  *
506  * @param __hint An iterator that serves as a hint as to where the pair
507  * should be inserted.
508  * @param __k Key to use for finding a possibly existing pair in
509  * the unordered_map.
510  * @param __args Arguments used to generate the .second for a
511  * new pair instance.
512  * @return An iterator that points to the element with key of the
513  * std::pair built from @a __args (may or may not be that
514  * std::pair).
515  *
516  * This function is not concerned about whether the insertion took place,
517  * and thus does not return a boolean like the single-argument emplace()
518  * does. However, if insertion did not take place,
519  * this function has no effect.
520  * Note that the first parameter is only a hint and can potentially
521  * improve the performance of the insertion process. A bad hint would
522  * cause no gains in efficiency.
523  *
524  * See
525  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
526  * for more on @a hinting.
527  *
528  * Insertion requires amortized constant time.
529  */
530  template <typename... _Args>
531  iterator
532  try_emplace(const_iterator __hint, const key_type& __k,
533  _Args&&... __args)
534  {
535  iterator __i = find(__k);
536  if (__i == end())
538  std::forward_as_tuple(__k),
539  std::forward_as_tuple(
540  std::forward<_Args>(__args)...));
541  return __i;
542  }
543 
544  // move-capable overload
545  template <typename... _Args>
546  iterator
547  try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
548  {
549  iterator __i = find(__k);
550  if (__i == end())
552  std::forward_as_tuple(std::move(__k)),
553  std::forward_as_tuple(
554  std::forward<_Args>(__args)...));
555  return __i;
556  }
557 #endif // C++17
558 
559  //@{
560  /**
561  * @brief Attempts to insert a std::pair into the %unordered_map.
562 
563  * @param __x Pair to be inserted (see std::make_pair for easy
564  * creation of pairs).
565  *
566  * @return A pair, of which the first element is an iterator that
567  * points to the possibly inserted pair, and the second is
568  * a bool that is true if the pair was actually inserted.
569  *
570  * This function attempts to insert a (key, value) %pair into the
571  * %unordered_map. An %unordered_map relies on unique keys and thus a
572  * %pair is only inserted if its first element (the key) is not already
573  * present in the %unordered_map.
574  *
575  * Insertion requires amortized constant time.
576  */
578  insert(const value_type& __x)
579  { return _M_h.insert(__x); }
580 
581  template<typename _Pair, typename = typename
582  std::enable_if<std::is_constructible<value_type,
583  _Pair&&>::value>::type>
585  insert(_Pair&& __x)
586  { return _M_h.insert(std::forward<_Pair>(__x)); }
587  //@}
588 
589  //@{
590  /**
591  * @brief Attempts to insert a std::pair into the %unordered_map.
592  * @param __hint An iterator that serves as a hint as to where the
593  * pair should be inserted.
594  * @param __x Pair to be inserted (see std::make_pair for easy creation
595  * of pairs).
596  * @return An iterator that points to the element with key of
597  * @a __x (may or may not be the %pair passed in).
598  *
599  * This function is not concerned about whether the insertion took place,
600  * and thus does not return a boolean like the single-argument insert()
601  * does. Note that the first parameter is only a hint and can
602  * potentially improve the performance of the insertion process. A bad
603  * hint would cause no gains in efficiency.
604  *
605  * See
606  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
607  * for more on @a hinting.
608  *
609  * Insertion requires amortized constant time.
610  */
611  iterator
612  insert(const_iterator __hint, const value_type& __x)
613  { return _M_h.insert(__hint, __x); }
614 
615  template<typename _Pair, typename = typename
616  std::enable_if<std::is_constructible<value_type,
617  _Pair&&>::value>::type>
618  iterator
619  insert(const_iterator __hint, _Pair&& __x)
620  { return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
621  //@}
622 
623  /**
624  * @brief A template function that attempts to insert a range of
625  * elements.
626  * @param __first Iterator pointing to the start of the range to be
627  * inserted.
628  * @param __last Iterator pointing to the end of the range.
629  *
630  * Complexity similar to that of the range constructor.
631  */
632  template<typename _InputIterator>
633  void
634  insert(_InputIterator __first, _InputIterator __last)
635  { _M_h.insert(__first, __last); }
636 
637  /**
638  * @brief Attempts to insert a list of elements into the %unordered_map.
639  * @param __l A std::initializer_list<value_type> of elements
640  * to be inserted.
641  *
642  * Complexity similar to that of the range constructor.
643  */
644  void
646  { _M_h.insert(__l); }
647 
648 
649 #if __cplusplus > 201402L
650 #define __cpp_lib_unordered_map_insertion 201411
651  /**
652  * @brief Attempts to insert a std::pair into the %unordered_map.
653  * @param __k Key to use for finding a possibly existing pair in
654  * the map.
655  * @param __obj Argument used to generate the .second for a pair
656  * instance.
657  *
658  * @return A pair, of which the first element is an iterator that
659  * points to the possibly inserted pair, and the second is
660  * a bool that is true if the pair was actually inserted.
661  *
662  * This function attempts to insert a (key, value) %pair into the
663  * %unordered_map. An %unordered_map relies on unique keys and thus a
664  * %pair is only inserted if its first element (the key) is not already
665  * present in the %unordered_map.
666  * If the %pair was already in the %unordered_map, the .second of
667  * the %pair is assigned from __obj.
668  *
669  * Insertion requires amortized constant time.
670  */
671  template <typename _Obj>
673  insert_or_assign(const key_type& __k, _Obj&& __obj)
674  {
675  iterator __i = find(__k);
676  if (__i == end())
677  {
679  std::forward_as_tuple(__k),
680  std::forward_as_tuple(std::forward<_Obj>(__obj)))
681  .first;
682  return {__i, true};
683  }
684  (*__i).second = std::forward<_Obj>(__obj);
685  return {__i, false};
686  }
687 
688  // move-capable overload
689  template <typename _Obj>
691  insert_or_assign(key_type&& __k, _Obj&& __obj)
692  {
693  iterator __i = find(__k);
694  if (__i == end())
695  {
697  std::forward_as_tuple(std::move(__k)),
698  std::forward_as_tuple(std::forward<_Obj>(__obj)))
699  .first;
700  return {__i, true};
701  }
702  (*__i).second = std::forward<_Obj>(__obj);
703  return {__i, false};
704  }
705 
706  /**
707  * @brief Attempts to insert a std::pair into the %unordered_map.
708  * @param __hint An iterator that serves as a hint as to where the
709  * pair should be inserted.
710  * @param __k Key to use for finding a possibly existing pair in
711  * the unordered_map.
712  * @param __obj Argument used to generate the .second for a pair
713  * instance.
714  * @return An iterator that points to the element with key of
715  * @a __x (may or may not be the %pair passed in).
716  *
717  * This function is not concerned about whether the insertion took place,
718  * and thus does not return a boolean like the single-argument insert()
719  * does.
720  * If the %pair was already in the %unordered map, the .second of
721  * the %pair is assigned from __obj.
722  * Note that the first parameter is only a hint and can
723  * potentially improve the performance of the insertion process. A bad
724  * hint would cause no gains in efficiency.
725  *
726  * See
727  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
728  * for more on @a hinting.
729  *
730  * Insertion requires amortized constant time.
731  */
732  template <typename _Obj>
733  iterator
734  insert_or_assign(const_iterator __hint, const key_type& __k,
735  _Obj&& __obj)
736  {
737  iterator __i = find(__k);
738  if (__i == end())
739  {
740  return emplace_hint(__hint, std::piecewise_construct,
741  std::forward_as_tuple(__k),
742  std::forward_as_tuple(
743  std::forward<_Obj>(__obj)));
744  }
745  (*__i).second = std::forward<_Obj>(__obj);
746  return __i;
747  }
748 
749  // move-capable overload
750  template <typename _Obj>
751  iterator
752  insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
753  {
754  iterator __i = find(__k);
755  if (__i == end())
756  {
757  return emplace_hint(__hint, std::piecewise_construct,
758  std::forward_as_tuple(std::move(__k)),
759  std::forward_as_tuple(
760  std::forward<_Obj>(__obj)));
761  }
762  (*__i).second = std::forward<_Obj>(__obj);
763  return __i;
764  }
765 #endif
766 
767  //@{
768  /**
769  * @brief Erases an element from an %unordered_map.
770  * @param __position An iterator pointing to the element to be erased.
771  * @return An iterator pointing to the element immediately following
772  * @a __position prior to the element being erased. If no such
773  * element exists, end() is returned.
774  *
775  * This function erases an element, pointed to by the given iterator,
776  * from an %unordered_map.
777  * Note that this function only erases the element, and that if the
778  * element is itself a pointer, the pointed-to memory is not touched in
779  * any way. Managing the pointer is the user's responsibility.
780  */
781  iterator
782  erase(const_iterator __position)
783  { return _M_h.erase(__position); }
784 
785  // LWG 2059.
786  iterator
787  erase(iterator __position)
788  { return _M_h.erase(__position); }
789  //@}
790 
791  /**
792  * @brief Erases elements according to the provided key.
793  * @param __x Key of element to be erased.
794  * @return The number of elements erased.
795  *
796  * This function erases all the elements located by the given key from
797  * an %unordered_map. For an %unordered_map the result of this function
798  * can only be 0 (not present) or 1 (present).
799  * Note that this function only erases the element, and that if the
800  * element is itself a pointer, the pointed-to memory is not touched in
801  * any way. Managing the pointer is the user's responsibility.
802  */
803  size_type
804  erase(const key_type& __x)
805  { return _M_h.erase(__x); }
806 
807  /**
808  * @brief Erases a [__first,__last) range of elements from an
809  * %unordered_map.
810  * @param __first Iterator pointing to the start of the range to be
811  * erased.
812  * @param __last Iterator pointing to the end of the range to
813  * be erased.
814  * @return The iterator @a __last.
815  *
816  * This function erases a sequence of elements from an %unordered_map.
817  * Note that this function only erases the elements, and that if
818  * the element is itself a pointer, the pointed-to memory is not touched
819  * in any way. Managing the pointer is the user's responsibility.
820  */
821  iterator
822  erase(const_iterator __first, const_iterator __last)
823  { return _M_h.erase(__first, __last); }
824 
825  /**
826  * Erases all elements in an %unordered_map.
827  * Note that this function only erases the elements, and that if the
828  * elements themselves are pointers, the pointed-to memory is not touched
829  * in any way. Managing the pointer is the user's responsibility.
830  */
831  void
832  clear() noexcept
833  { _M_h.clear(); }
834 
835  /**
836  * @brief Swaps data with another %unordered_map.
837  * @param __x An %unordered_map of the same element and allocator
838  * types.
839  *
840  * This exchanges the elements between two %unordered_map in constant
841  * time.
842  * Note that the global std::swap() function is specialized such that
843  * std::swap(m1,m2) will feed to this function.
844  */
845  void
847  noexcept( noexcept(_M_h.swap(__x._M_h)) )
848  { _M_h.swap(__x._M_h); }
849 
850 #if __cplusplus > 201402L
851  template<typename, typename, typename>
852  friend class _Hash_merge_helper;
853 
854  template<typename _H2, typename _P2>
855  void
857  {
858  using _Merge_helper = _Hash_merge_helper<unordered_map, _H2, _P2>;
859  _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
860  }
861 
862  template<typename _H2, typename _P2>
863  void
865  { merge(__source); }
866 
867  template<typename _H2, typename _P2>
868  void
870  {
871  using _Merge_helper = _Hash_merge_helper<unordered_map, _H2, _P2>;
872  _M_h._M_merge_unique(_Merge_helper::_S_get_table(__source));
873  }
874 
875  template<typename _H2, typename _P2>
876  void
878  { merge(__source); }
879 #endif // C++17
880 
881  // observers.
882 
883  /// Returns the hash functor object with which the %unordered_map was
884  /// constructed.
885  hasher
887  { return _M_h.hash_function(); }
888 
889  /// Returns the key comparison object with which the %unordered_map was
890  /// constructed.
891  key_equal
892  key_eq() const
893  { return _M_h.key_eq(); }
894 
895  // lookup.
896 
897  //@{
898  /**
899  * @brief Tries to locate an element in an %unordered_map.
900  * @param __x Key to be located.
901  * @return Iterator pointing to sought-after element, or end() if not
902  * found.
903  *
904  * This function takes a key and tries to locate the element with which
905  * the key matches. If successful the function returns an iterator
906  * pointing to the sought after element. If unsuccessful it returns the
907  * past-the-end ( @c end() ) iterator.
908  */
909  iterator
910  find(const key_type& __x)
911  { return _M_h.find(__x); }
912 
913  const_iterator
914  find(const key_type& __x) const
915  { return _M_h.find(__x); }
916  //@}
917 
918  /**
919  * @brief Finds the number of elements.
920  * @param __x Key to count.
921  * @return Number of elements with specified key.
922  *
923  * This function only makes sense for %unordered_multimap; for
924  * %unordered_map the result will either be 0 (not present) or 1
925  * (present).
926  */
927  size_type
928  count(const key_type& __x) const
929  { return _M_h.count(__x); }
930 
931  //@{
932  /**
933  * @brief Finds a subsequence matching given key.
934  * @param __x Key to be located.
935  * @return Pair of iterators that possibly points to the subsequence
936  * matching given key.
937  *
938  * This function probably only makes sense for %unordered_multimap.
939  */
941  equal_range(const key_type& __x)
942  { return _M_h.equal_range(__x); }
943 
945  equal_range(const key_type& __x) const
946  { return _M_h.equal_range(__x); }
947  //@}
948 
949  //@{
950  /**
951  * @brief Subscript ( @c [] ) access to %unordered_map data.
952  * @param __k The key for which data should be retrieved.
953  * @return A reference to the data of the (key,data) %pair.
954  *
955  * Allows for easy lookup with the subscript ( @c [] )operator. Returns
956  * data associated with the key specified in subscript. If the key does
957  * not exist, a pair with that key is created using default values, which
958  * is then returned.
959  *
960  * Lookup requires constant time.
961  */
962  mapped_type&
963  operator[](const key_type& __k)
964  { return _M_h[__k]; }
965 
966  mapped_type&
967  operator[](key_type&& __k)
968  { return _M_h[std::move(__k)]; }
969  //@}
970 
971  //@{
972  /**
973  * @brief Access to %unordered_map data.
974  * @param __k The key for which data should be retrieved.
975  * @return A reference to the data whose key is equal to @a __k, if
976  * such a data is present in the %unordered_map.
977  * @throw std::out_of_range If no such data is present.
978  */
979  mapped_type&
980  at(const key_type& __k)
981  { return _M_h.at(__k); }
982 
983  const mapped_type&
984  at(const key_type& __k) const
985  { return _M_h.at(__k); }
986  //@}
987 
988  // bucket interface.
989 
990  /// Returns the number of buckets of the %unordered_map.
991  size_type
992  bucket_count() const noexcept
993  { return _M_h.bucket_count(); }
994 
995  /// Returns the maximum number of buckets of the %unordered_map.
996  size_type
997  max_bucket_count() const noexcept
998  { return _M_h.max_bucket_count(); }
999 
1000  /*
1001  * @brief Returns the number of elements in a given bucket.
1002  * @param __n A bucket index.
1003  * @return The number of elements in the bucket.
1004  */
1005  size_type
1006  bucket_size(size_type __n) const
1007  { return _M_h.bucket_size(__n); }
1008 
1009  /*
1010  * @brief Returns the bucket index of a given element.
1011  * @param __key A key instance.
1012  * @return The key bucket index.
1013  */
1014  size_type
1015  bucket(const key_type& __key) const
1016  { return _M_h.bucket(__key); }
1017 
1018  /**
1019  * @brief Returns a read/write iterator pointing to the first bucket
1020  * element.
1021  * @param __n The bucket index.
1022  * @return A read/write local iterator.
1023  */
1024  local_iterator
1025  begin(size_type __n)
1026  { return _M_h.begin(__n); }
1027 
1028  //@{
1029  /**
1030  * @brief Returns a read-only (constant) iterator pointing to the first
1031  * bucket element.
1032  * @param __n The bucket index.
1033  * @return A read-only local iterator.
1034  */
1035  const_local_iterator
1036  begin(size_type __n) const
1037  { return _M_h.begin(__n); }
1038 
1039  const_local_iterator
1040  cbegin(size_type __n) const
1041  { return _M_h.cbegin(__n); }
1042  //@}
1043 
1044  /**
1045  * @brief Returns a read/write iterator pointing to one past the last
1046  * bucket elements.
1047  * @param __n The bucket index.
1048  * @return A read/write local iterator.
1049  */
1050  local_iterator
1051  end(size_type __n)
1052  { return _M_h.end(__n); }
1053 
1054  //@{
1055  /**
1056  * @brief Returns a read-only (constant) iterator pointing to one past
1057  * the last bucket elements.
1058  * @param __n The bucket index.
1059  * @return A read-only local iterator.
1060  */
1061  const_local_iterator
1062  end(size_type __n) const
1063  { return _M_h.end(__n); }
1064 
1065  const_local_iterator
1066  cend(size_type __n) const
1067  { return _M_h.cend(__n); }
1068  //@}
1069 
1070  // hash policy.
1071 
1072  /// Returns the average number of elements per bucket.
1073  float
1074  load_factor() const noexcept
1075  { return _M_h.load_factor(); }
1076 
1077  /// Returns a positive number that the %unordered_map tries to keep the
1078  /// load factor less than or equal to.
1079  float
1080  max_load_factor() const noexcept
1081  { return _M_h.max_load_factor(); }
1082 
1083  /**
1084  * @brief Change the %unordered_map maximum load factor.
1085  * @param __z The new maximum load factor.
1086  */
1087  void
1088  max_load_factor(float __z)
1089  { _M_h.max_load_factor(__z); }
1090 
1091  /**
1092  * @brief May rehash the %unordered_map.
1093  * @param __n The new number of buckets.
1094  *
1095  * Rehash will occur only if the new number of buckets respect the
1096  * %unordered_map maximum load factor.
1097  */
1098  void
1099  rehash(size_type __n)
1100  { _M_h.rehash(__n); }
1101 
1102  /**
1103  * @brief Prepare the %unordered_map for a specified number of
1104  * elements.
1105  * @param __n Number of elements required.
1106  *
1107  * Same as rehash(ceil(n / max_load_factor())).
1108  */
1109  void
1110  reserve(size_type __n)
1111  { _M_h.reserve(__n); }
1112 
1113  template<typename _Key1, typename _Tp1, typename _Hash1, typename _Pred1,
1114  typename _Alloc1>
1115  friend bool
1118  };
1119 
1120  /**
1121  * @brief A standard container composed of equivalent keys
1122  * (possibly containing multiple of each key value) that associates
1123  * values of another type with the keys.
1124  *
1125  * @ingroup unordered_associative_containers
1126  *
1127  * @tparam _Key Type of key objects.
1128  * @tparam _Tp Type of mapped objects.
1129  * @tparam _Hash Hashing function object type, defaults to hash<_Value>.
1130  * @tparam _Pred Predicate function object type, defaults
1131  * to equal_to<_Value>.
1132  * @tparam _Alloc Allocator type, defaults to
1133  * std::allocator<std::pair<const _Key, _Tp>>.
1134  *
1135  * Meets the requirements of a <a href="tables.html#65">container</a>, and
1136  * <a href="tables.html#xx">unordered associative container</a>
1137  *
1138  * The resulting value type of the container is std::pair<const _Key, _Tp>.
1139  *
1140  * Base is _Hashtable, dispatched at compile time via template
1141  * alias __ummap_hashtable.
1142  */
1143  template<class _Key, class _Tp,
1144  class _Hash = hash<_Key>,
1145  class _Pred = std::equal_to<_Key>,
1147  class unordered_multimap
1148  {
1150  _Hashtable _M_h;
1151 
1152  public:
1153  // typedefs:
1154  //@{
1155  /// Public typedefs.
1156  typedef typename _Hashtable::key_type key_type;
1157  typedef typename _Hashtable::value_type value_type;
1158  typedef typename _Hashtable::mapped_type mapped_type;
1159  typedef typename _Hashtable::hasher hasher;
1160  typedef typename _Hashtable::key_equal key_equal;
1161  typedef typename _Hashtable::allocator_type allocator_type;
1162  //@}
1163 
1164  //@{
1165  /// Iterator-related typedefs.
1166  typedef typename _Hashtable::pointer pointer;
1167  typedef typename _Hashtable::const_pointer const_pointer;
1168  typedef typename _Hashtable::reference reference;
1169  typedef typename _Hashtable::const_reference const_reference;
1170  typedef typename _Hashtable::iterator iterator;
1171  typedef typename _Hashtable::const_iterator const_iterator;
1172  typedef typename _Hashtable::local_iterator local_iterator;
1173  typedef typename _Hashtable::const_local_iterator const_local_iterator;
1174  typedef typename _Hashtable::size_type size_type;
1175  typedef typename _Hashtable::difference_type difference_type;
1176  //@}
1177 
1178 #if __cplusplus > 201402L
1179  using node_type = typename _Hashtable::node_type;
1180 #endif
1181 
1182  //construct/destroy/copy
1183 
1184  /// Default constructor.
1185  unordered_multimap() = default;
1186 
1187  /**
1188  * @brief Default constructor creates no elements.
1189  * @param __n Mnimal initial number of buckets.
1190  * @param __hf A hash functor.
1191  * @param __eql A key equality functor.
1192  * @param __a An allocator object.
1193  */
1194  explicit
1195  unordered_multimap(size_type __n,
1196  const hasher& __hf = hasher(),
1197  const key_equal& __eql = key_equal(),
1198  const allocator_type& __a = allocator_type())
1199  : _M_h(__n, __hf, __eql, __a)
1200  { }
1201 
1202  /**
1203  * @brief Builds an %unordered_multimap from a range.
1204  * @param __first An input iterator.
1205  * @param __last An input iterator.
1206  * @param __n Minimal initial number of buckets.
1207  * @param __hf A hash functor.
1208  * @param __eql A key equality functor.
1209  * @param __a An allocator object.
1210  *
1211  * Create an %unordered_multimap consisting of copies of the elements
1212  * from [__first,__last). This is linear in N (where N is
1213  * distance(__first,__last)).
1214  */
1215  template<typename _InputIterator>
1216  unordered_multimap(_InputIterator __first, _InputIterator __last,
1217  size_type __n = 0,
1218  const hasher& __hf = hasher(),
1219  const key_equal& __eql = key_equal(),
1220  const allocator_type& __a = allocator_type())
1221  : _M_h(__first, __last, __n, __hf, __eql, __a)
1222  { }
1223 
1224  /// Copy constructor.
1225  unordered_multimap(const unordered_multimap&) = default;
1226 
1227  /// Move constructor.
1229 
1230  /**
1231  * @brief Creates an %unordered_multimap with no elements.
1232  * @param __a An allocator object.
1233  */
1234  explicit
1235  unordered_multimap(const allocator_type& __a)
1236  : _M_h(__a)
1237  { }
1238 
1239  /*
1240  * @brief Copy constructor with allocator argument.
1241  * @param __uset Input %unordered_multimap to copy.
1242  * @param __a An allocator object.
1243  */
1244  unordered_multimap(const unordered_multimap& __ummap,
1245  const allocator_type& __a)
1246  : _M_h(__ummap._M_h, __a)
1247  { }
1248 
1249  /*
1250  * @brief Move constructor with allocator argument.
1251  * @param __uset Input %unordered_multimap to move.
1252  * @param __a An allocator object.
1253  */
1255  const allocator_type& __a)
1256  : _M_h(std::move(__ummap._M_h), __a)
1257  { }
1258 
1259  /**
1260  * @brief Builds an %unordered_multimap from an initializer_list.
1261  * @param __l An initializer_list.
1262  * @param __n Minimal initial number of buckets.
1263  * @param __hf A hash functor.
1264  * @param __eql A key equality functor.
1265  * @param __a An allocator object.
1266  *
1267  * Create an %unordered_multimap consisting of copies of the elements in
1268  * the list. This is linear in N (where N is @a __l.size()).
1269  */
1271  size_type __n = 0,
1272  const hasher& __hf = hasher(),
1273  const key_equal& __eql = key_equal(),
1274  const allocator_type& __a = allocator_type())
1275  : _M_h(__l, __n, __hf, __eql, __a)
1276  { }
1277 
1278  unordered_multimap(size_type __n, const allocator_type& __a)
1279  : unordered_multimap(__n, hasher(), key_equal(), __a)
1280  { }
1281 
1282  unordered_multimap(size_type __n, const hasher& __hf,
1283  const allocator_type& __a)
1284  : unordered_multimap(__n, __hf, key_equal(), __a)
1285  { }
1286 
1287  template<typename _InputIterator>
1288  unordered_multimap(_InputIterator __first, _InputIterator __last,
1289  size_type __n,
1290  const allocator_type& __a)
1291  : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a)
1292  { }
1293 
1294  template<typename _InputIterator>
1295  unordered_multimap(_InputIterator __first, _InputIterator __last,
1296  size_type __n, const hasher& __hf,
1297  const allocator_type& __a)
1298  : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a)
1299  { }
1300 
1302  size_type __n,
1303  const allocator_type& __a)
1304  : unordered_multimap(__l, __n, hasher(), key_equal(), __a)
1305  { }
1306 
1308  size_type __n, const hasher& __hf,
1309  const allocator_type& __a)
1310  : unordered_multimap(__l, __n, __hf, key_equal(), __a)
1311  { }
1312 
1313  /// Copy assignment operator.
1315  operator=(const unordered_multimap&) = default;
1316 
1317  /// Move assignment operator.
1319  operator=(unordered_multimap&&) = default;
1320 
1321  /**
1322  * @brief %Unordered_multimap list assignment operator.
1323  * @param __l An initializer_list.
1324  *
1325  * This function fills an %unordered_multimap with copies of the
1326  * elements in the initializer list @a __l.
1327  *
1328  * Note that the assignment completely changes the %unordered_multimap
1329  * and that the resulting %unordered_multimap's size is the same as the
1330  * number of elements assigned.
1331  */
1334  {
1335  _M_h = __l;
1336  return *this;
1337  }
1338 
1339  /// Returns the allocator object used by the %unordered_multimap.
1340  allocator_type
1341  get_allocator() const noexcept
1342  { return _M_h.get_allocator(); }
1343 
1344  // size and capacity:
1345 
1346  /// Returns true if the %unordered_multimap is empty.
1347  bool
1348  empty() const noexcept
1349  { return _M_h.empty(); }
1350 
1351  /// Returns the size of the %unordered_multimap.
1352  size_type
1353  size() const noexcept
1354  { return _M_h.size(); }
1355 
1356  /// Returns the maximum size of the %unordered_multimap.
1357  size_type
1358  max_size() const noexcept
1359  { return _M_h.max_size(); }
1360 
1361  // iterators.
1362 
1363  /**
1364  * Returns a read/write iterator that points to the first element in the
1365  * %unordered_multimap.
1366  */
1367  iterator
1368  begin() noexcept
1369  { return _M_h.begin(); }
1370 
1371  //@{
1372  /**
1373  * Returns a read-only (constant) iterator that points to the first
1374  * element in the %unordered_multimap.
1375  */
1376  const_iterator
1377  begin() const noexcept
1378  { return _M_h.begin(); }
1379 
1380  const_iterator
1381  cbegin() const noexcept
1382  { return _M_h.begin(); }
1383  //@}
1384 
1385  /**
1386  * Returns a read/write iterator that points one past the last element in
1387  * the %unordered_multimap.
1388  */
1389  iterator
1390  end() noexcept
1391  { return _M_h.end(); }
1392 
1393  //@{
1394  /**
1395  * Returns a read-only (constant) iterator that points one past the last
1396  * element in the %unordered_multimap.
1397  */
1398  const_iterator
1399  end() const noexcept
1400  { return _M_h.end(); }
1401 
1402  const_iterator
1403  cend() const noexcept
1404  { return _M_h.end(); }
1405  //@}
1406 
1407  // modifiers.
1408 
1409  /**
1410  * @brief Attempts to build and insert a std::pair into the
1411  * %unordered_multimap.
1412  *
1413  * @param __args Arguments used to generate a new pair instance (see
1414  * std::piecewise_contruct for passing arguments to each
1415  * part of the pair constructor).
1416  *
1417  * @return An iterator that points to the inserted pair.
1418  *
1419  * This function attempts to build and insert a (key, value) %pair into
1420  * the %unordered_multimap.
1421  *
1422  * Insertion requires amortized constant time.
1423  */
1424  template<typename... _Args>
1425  iterator
1426  emplace(_Args&&... __args)
1427  { return _M_h.emplace(std::forward<_Args>(__args)...); }
1428 
1429  /**
1430  * @brief Attempts to build and insert a std::pair into the
1431  * %unordered_multimap.
1432  *
1433  * @param __pos An iterator that serves as a hint as to where the pair
1434  * should be inserted.
1435  * @param __args Arguments used to generate a new pair instance (see
1436  * std::piecewise_contruct for passing arguments to each
1437  * part of the pair constructor).
1438  * @return An iterator that points to the element with key of the
1439  * std::pair built from @a __args.
1440  *
1441  * Note that the first parameter is only a hint and can potentially
1442  * improve the performance of the insertion process. A bad hint would
1443  * cause no gains in efficiency.
1444  *
1445  * See
1446  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
1447  * for more on @a hinting.
1448  *
1449  * Insertion requires amortized constant time.
1450  */
1451  template<typename... _Args>
1452  iterator
1453  emplace_hint(const_iterator __pos, _Args&&... __args)
1454  { return _M_h.emplace_hint(__pos, std::forward<_Args>(__args)...); }
1455 
1456  //@{
1457  /**
1458  * @brief Inserts a std::pair into the %unordered_multimap.
1459  * @param __x Pair to be inserted (see std::make_pair for easy
1460  * creation of pairs).
1461  *
1462  * @return An iterator that points to the inserted pair.
1463  *
1464  * Insertion requires amortized constant time.
1465  */
1466  iterator
1467  insert(const value_type& __x)
1468  { return _M_h.insert(__x); }
1469 
1470  template<typename _Pair, typename = typename
1471  std::enable_if<std::is_constructible<value_type,
1472  _Pair&&>::value>::type>
1473  iterator
1474  insert(_Pair&& __x)
1475  { return _M_h.insert(std::forward<_Pair>(__x)); }
1476  //@}
1477 
1478  //@{
1479  /**
1480  * @brief Inserts a std::pair into the %unordered_multimap.
1481  * @param __hint An iterator that serves as a hint as to where the
1482  * pair should be inserted.
1483  * @param __x Pair to be inserted (see std::make_pair for easy creation
1484  * of pairs).
1485  * @return An iterator that points to the element with key of
1486  * @a __x (may or may not be the %pair passed in).
1487  *
1488  * Note that the first parameter is only a hint and can potentially
1489  * improve the performance of the insertion process. A bad hint would
1490  * cause no gains in efficiency.
1491  *
1492  * See
1493  * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
1494  * for more on @a hinting.
1495  *
1496  * Insertion requires amortized constant time.
1497  */
1498  iterator
1499  insert(const_iterator __hint, const value_type& __x)
1500  { return _M_h.insert(__hint, __x); }
1501 
1502  template<typename _Pair, typename = typename
1503  std::enable_if<std::is_constructible<value_type,
1504  _Pair&&>::value>::type>
1505  iterator
1506  insert(const_iterator __hint, _Pair&& __x)
1507  { return _M_h.insert(__hint, std::forward<_Pair>(__x)); }
1508  //@}
1509 
1510  /**
1511  * @brief A template function that attempts to insert a range of
1512  * elements.
1513  * @param __first Iterator pointing to the start of the range to be
1514  * inserted.
1515  * @param __last Iterator pointing to the end of the range.
1516  *
1517  * Complexity similar to that of the range constructor.
1518  */
1519  template<typename _InputIterator>
1520  void
1521  insert(_InputIterator __first, _InputIterator __last)
1522  { _M_h.insert(__first, __last); }
1523 
1524  /**
1525  * @brief Attempts to insert a list of elements into the
1526  * %unordered_multimap.
1527  * @param __l A std::initializer_list<value_type> of elements
1528  * to be inserted.
1529  *
1530  * Complexity similar to that of the range constructor.
1531  */
1532  void
1534  { _M_h.insert(__l); }
1535 
1536 #if __cplusplus > 201402L
1537  /// Extract a node.
1538  node_type
1539  extract(const_iterator __pos)
1540  {
1541  __glibcxx_assert(__pos != end());
1542  return _M_h.extract(__pos);
1543  }
1544 
1545  /// Extract a node.
1546  node_type
1547  extract(const key_type& __key)
1548  { return _M_h.extract(__key); }
1549 
1550  /// Re-insert an extracted node.
1551  iterator
1552  insert(node_type&& __nh)
1553  { return _M_h._M_reinsert_node_multi(cend(), std::move(__nh)); }
1554 
1555  /// Re-insert an extracted node.
1556  iterator
1557  insert(const_iterator __hint, node_type&& __nh)
1558  { return _M_h._M_reinsert_node_multi(__hint, std::move(__nh)); }
1559 #endif // C++17
1560 
1561  //@{
1562  /**
1563  * @brief Erases an element from an %unordered_multimap.
1564  * @param __position An iterator pointing to the element to be erased.
1565  * @return An iterator pointing to the element immediately following
1566  * @a __position prior to the element being erased. If no such
1567  * element exists, end() is returned.
1568  *
1569  * This function erases an element, pointed to by the given iterator,
1570  * from an %unordered_multimap.
1571  * Note that this function only erases the element, and that if the
1572  * element is itself a pointer, the pointed-to memory is not touched in
1573  * any way. Managing the pointer is the user's responsibility.
1574  */
1575  iterator
1576  erase(const_iterator __position)
1577  { return _M_h.erase(__position); }
1578 
1579  // LWG 2059.
1580  iterator
1581  erase(iterator __position)
1582  { return _M_h.erase(__position); }
1583  //@}
1584 
1585  /**
1586  * @brief Erases elements according to the provided key.
1587  * @param __x Key of elements to be erased.
1588  * @return The number of elements erased.
1589  *
1590  * This function erases all the elements located by the given key from
1591  * an %unordered_multimap.
1592  * Note that this function only erases the element, and that if the
1593  * element is itself a pointer, the pointed-to memory is not touched in
1594  * any way. Managing the pointer is the user's responsibility.
1595  */
1596  size_type
1597  erase(const key_type& __x)
1598  { return _M_h.erase(__x); }
1599 
1600  /**
1601  * @brief Erases a [__first,__last) range of elements from an
1602  * %unordered_multimap.
1603  * @param __first Iterator pointing to the start of the range to be
1604  * erased.
1605  * @param __last Iterator pointing to the end of the range to
1606  * be erased.
1607  * @return The iterator @a __last.
1608  *
1609  * This function erases a sequence of elements from an
1610  * %unordered_multimap.
1611  * Note that this function only erases the elements, and that if
1612  * the element is itself a pointer, the pointed-to memory is not touched
1613  * in any way. Managing the pointer is the user's responsibility.
1614  */
1615  iterator
1616  erase(const_iterator __first, const_iterator __last)
1617  { return _M_h.erase(__first, __last); }
1618 
1619  /**
1620  * Erases all elements in an %unordered_multimap.
1621  * Note that this function only erases the elements, and that if the
1622  * elements themselves are pointers, the pointed-to memory is not touched
1623  * in any way. Managing the pointer is the user's responsibility.
1624  */
1625  void
1626  clear() noexcept
1627  { _M_h.clear(); }
1628 
1629  /**
1630  * @brief Swaps data with another %unordered_multimap.
1631  * @param __x An %unordered_multimap of the same element and allocator
1632  * types.
1633  *
1634  * This exchanges the elements between two %unordered_multimap in
1635  * constant time.
1636  * Note that the global std::swap() function is specialized such that
1637  * std::swap(m1,m2) will feed to this function.
1638  */
1639  void
1641  noexcept( noexcept(_M_h.swap(__x._M_h)) )
1642  { _M_h.swap(__x._M_h); }
1643 
1644 #if __cplusplus > 201402L
1645  template<typename, typename, typename>
1646  friend class _Hash_merge_helper;
1647 
1648  template<typename _H2, typename _P2>
1649  void
1651  {
1652  using _Merge_helper
1653  = _Hash_merge_helper<unordered_multimap, _H2, _P2>;
1654  _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1655  }
1656 
1657  template<typename _H2, typename _P2>
1658  void
1660  { merge(__source); }
1661 
1662  template<typename _H2, typename _P2>
1663  void
1665  {
1666  using _Merge_helper
1667  = _Hash_merge_helper<unordered_multimap, _H2, _P2>;
1668  _M_h._M_merge_multi(_Merge_helper::_S_get_table(__source));
1669  }
1670 
1671  template<typename _H2, typename _P2>
1672  void
1674  { merge(__source); }
1675 #endif // C++17
1676 
1677  // observers.
1678 
1679  /// Returns the hash functor object with which the %unordered_multimap
1680  /// was constructed.
1681  hasher
1683  { return _M_h.hash_function(); }
1684 
1685  /// Returns the key comparison object with which the %unordered_multimap
1686  /// was constructed.
1687  key_equal
1688  key_eq() const
1689  { return _M_h.key_eq(); }
1690 
1691  // lookup.
1692 
1693  //@{
1694  /**
1695  * @brief Tries to locate an element in an %unordered_multimap.
1696  * @param __x Key to be located.
1697  * @return Iterator pointing to sought-after element, or end() if not
1698  * found.
1699  *
1700  * This function takes a key and tries to locate the element with which
1701  * the key matches. If successful the function returns an iterator
1702  * pointing to the sought after element. If unsuccessful it returns the
1703  * past-the-end ( @c end() ) iterator.
1704  */
1705  iterator
1706  find(const key_type& __x)
1707  { return _M_h.find(__x); }
1708 
1709  const_iterator
1710  find(const key_type& __x) const
1711  { return _M_h.find(__x); }
1712  //@}
1713 
1714  /**
1715  * @brief Finds the number of elements.
1716  * @param __x Key to count.
1717  * @return Number of elements with specified key.
1718  */
1719  size_type
1720  count(const key_type& __x) const
1721  { return _M_h.count(__x); }
1722 
1723  //@{
1724  /**
1725  * @brief Finds a subsequence matching given key.
1726  * @param __x Key to be located.
1727  * @return Pair of iterators that possibly points to the subsequence
1728  * matching given key.
1729  */
1731  equal_range(const key_type& __x)
1732  { return _M_h.equal_range(__x); }
1733 
1735  equal_range(const key_type& __x) const
1736  { return _M_h.equal_range(__x); }
1737  //@}
1738 
1739  // bucket interface.
1740 
1741  /// Returns the number of buckets of the %unordered_multimap.
1742  size_type
1743  bucket_count() const noexcept
1744  { return _M_h.bucket_count(); }
1745 
1746  /// Returns the maximum number of buckets of the %unordered_multimap.
1747  size_type
1748  max_bucket_count() const noexcept
1749  { return _M_h.max_bucket_count(); }
1750 
1751  /*
1752  * @brief Returns the number of elements in a given bucket.
1753  * @param __n A bucket index.
1754  * @return The number of elements in the bucket.
1755  */
1756  size_type
1757  bucket_size(size_type __n) const
1758  { return _M_h.bucket_size(__n); }
1759 
1760  /*
1761  * @brief Returns the bucket index of a given element.
1762  * @param __key A key instance.
1763  * @return The key bucket index.
1764  */
1765  size_type
1766  bucket(const key_type& __key) const
1767  { return _M_h.bucket(__key); }
1768 
1769  /**
1770  * @brief Returns a read/write iterator pointing to the first bucket
1771  * element.
1772  * @param __n The bucket index.
1773  * @return A read/write local iterator.
1774  */
1775  local_iterator
1776  begin(size_type __n)
1777  { return _M_h.begin(__n); }
1778 
1779  //@{
1780  /**
1781  * @brief Returns a read-only (constant) iterator pointing to the first
1782  * bucket element.
1783  * @param __n The bucket index.
1784  * @return A read-only local iterator.
1785  */
1786  const_local_iterator
1787  begin(size_type __n) const
1788  { return _M_h.begin(__n); }
1789 
1790  const_local_iterator
1791  cbegin(size_type __n) const
1792  { return _M_h.cbegin(__n); }
1793  //@}
1794 
1795  /**
1796  * @brief Returns a read/write iterator pointing to one past the last
1797  * bucket elements.
1798  * @param __n The bucket index.
1799  * @return A read/write local iterator.
1800  */
1801  local_iterator
1802  end(size_type __n)
1803  { return _M_h.end(__n); }
1804 
1805  //@{
1806  /**
1807  * @brief Returns a read-only (constant) iterator pointing to one past
1808  * the last bucket elements.
1809  * @param __n The bucket index.
1810  * @return A read-only local iterator.
1811  */
1812  const_local_iterator
1813  end(size_type __n) const
1814  { return _M_h.end(__n); }
1815 
1816  const_local_iterator
1817  cend(size_type __n) const
1818  { return _M_h.cend(__n); }
1819  //@}
1820 
1821  // hash policy.
1822 
1823  /// Returns the average number of elements per bucket.
1824  float
1825  load_factor() const noexcept
1826  { return _M_h.load_factor(); }
1827 
1828  /// Returns a positive number that the %unordered_multimap tries to keep
1829  /// the load factor less than or equal to.
1830  float
1831  max_load_factor() const noexcept
1832  { return _M_h.max_load_factor(); }
1833 
1834  /**
1835  * @brief Change the %unordered_multimap maximum load factor.
1836  * @param __z The new maximum load factor.
1837  */
1838  void
1839  max_load_factor(float __z)
1840  { _M_h.max_load_factor(__z); }
1841 
1842  /**
1843  * @brief May rehash the %unordered_multimap.
1844  * @param __n The new number of buckets.
1845  *
1846  * Rehash will occur only if the new number of buckets respect the
1847  * %unordered_multimap maximum load factor.
1848  */
1849  void
1850  rehash(size_type __n)
1851  { _M_h.rehash(__n); }
1852 
1853  /**
1854  * @brief Prepare the %unordered_multimap for a specified number of
1855  * elements.
1856  * @param __n Number of elements required.
1857  *
1858  * Same as rehash(ceil(n / max_load_factor())).
1859  */
1860  void
1861  reserve(size_type __n)
1862  { _M_h.reserve(__n); }
1863 
1864  template<typename _Key1, typename _Tp1, typename _Hash1, typename _Pred1,
1865  typename _Alloc1>
1866  friend bool
1867  operator==(const unordered_multimap<_Key1, _Tp1,
1868  _Hash1, _Pred1, _Alloc1>&,
1869  const unordered_multimap<_Key1, _Tp1,
1870  _Hash1, _Pred1, _Alloc1>&);
1871  };
1872 
1873  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1874  inline void
1877  noexcept(noexcept(__x.swap(__y)))
1878  { __x.swap(__y); }
1879 
1880  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1881  inline void
1884  noexcept(noexcept(__x.swap(__y)))
1885  { __x.swap(__y); }
1886 
1887  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1888  inline bool
1889  operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1891  { return __x._M_h._M_equal(__y._M_h); }
1892 
1893  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1894  inline bool
1895  operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1897  { return !(__x == __y); }
1898 
1899  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1900  inline bool
1903  { return __x._M_h._M_equal(__y._M_h); }
1904 
1905  template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1906  inline bool
1909  { return !(__x == __y); }
1910 
1911 _GLIBCXX_END_NAMESPACE_CONTAINER
1912 
1913 #if __cplusplus > 201402L
1914 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1915  // Allow std::unordered_map access to internals of compatible maps.
1916  template<typename _Key, typename _Val, typename _Hash1, typename _Eq1,
1917  typename _Alloc, typename _Hash2, typename _Eq2>
1918  struct _Hash_merge_helper<
1919  _GLIBCXX_STD_C::unordered_map<_Key, _Val, _Hash1, _Eq1, _Alloc>,
1920  _Hash2, _Eq2>
1921  {
1922  private:
1923  template<typename... _Tp>
1924  using unordered_map = _GLIBCXX_STD_C::unordered_map<_Tp...>;
1925  template<typename... _Tp>
1926  using unordered_multimap = _GLIBCXX_STD_C::unordered_multimap<_Tp...>;
1927 
1929 
1930  static auto&
1932  { return __map._M_h; }
1933 
1934  static auto&
1936  { return __map._M_h; }
1937  };
1938 
1939  // Allow std::unordered_multimap access to internals of compatible maps.
1940  template<typename _Key, typename _Val, typename _Hash1, typename _Eq1,
1941  typename _Alloc, typename _Hash2, typename _Eq2>
1942  struct _Hash_merge_helper<
1943  _GLIBCXX_STD_C::unordered_multimap<_Key, _Val, _Hash1, _Eq1, _Alloc>,
1944  _Hash2, _Eq2>
1945  {
1946  private:
1947  template<typename... _Tp>
1948  using unordered_map = _GLIBCXX_STD_C::unordered_map<_Tp...>;
1949  template<typename... _Tp>
1950  using unordered_multimap = _GLIBCXX_STD_C::unordered_multimap<_Tp...>;
1951 
1953 
1954  static auto&
1956  { return __map._M_h; }
1957 
1958  static auto&
1960  { return __map._M_h; }
1961  };
1962 _GLIBCXX_END_NAMESPACE_VERSION
1963 #endif // C++17
1964 
1965 } // namespace std
1966 
1967 #endif /* _UNORDERED_MAP_H */
_Hashtable::key_equal key_equal
Public typedefs.
_GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct
piecewise_construct
Definition: stl_pair.h:79
const_iterator cbegin() const noexcept
const mapped_type & at(const key_type &__k) const
Access to unordered_map data.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
A standard container composed of unique keys (containing at most one of each key value) that associat...
void clear() noexcept
iterator begin() noexcept
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
const_local_iterator cbegin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
_Hashtable::iterator iterator
Iterator-related typedefs.
iterator insert(_Pair &&__x)
Inserts a std::pair into the unordered_multimap.
iterator insert(const_iterator __hint, _Pair &&__x)
Attempts to insert a std::pair into the unordered_map.
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
const_local_iterator cend(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the unordered_map.
_Hashtable::pointer pointer
Iterator-related typedefs.
The standard allocator, as per [20.4].
Definition: allocator.h:108
const_iterator begin() const noexcept
_Hashtable::size_type size_type
Iterator-related typedefs.
float max_load_factor() const noexcept
Returns a positive number that the unordered_multimap tries to keep the load factor less than or equa...
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
size_type max_size() const noexcept
Returns the maximum size of the unordered_map.
iterator insert(const_iterator __hint, _Pair &&__x)
Inserts a std::pair into the unordered_multimap.
_Hashtable::pointer pointer
Iterator-related typedefs.
const_local_iterator cbegin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
size_type count(const key_type &__x) const
Finds the number of elements.
iterator find(const key_type &__x)
Tries to locate an element in an unordered_multimap.
bool empty() const noexcept
Returns true if the unordered_multimap is empty.
unordered_map & operator=(initializer_list< value_type > __l)
Unordered_map list assignment operator.
unordered_map & operator=(const unordered_map &)=default
Copy assignment operator.
std::pair< iterator, bool > insert(_Pair &&__x)
Attempts to insert a std::pair into the unordered_map.
_Hashtable::reference reference
Iterator-related typedefs.
iterator begin() noexcept
unordered_map()=default
Default constructor.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
_Hashtable::hasher hasher
Public typedefs.
A standard container composed of equivalent keys (possibly containing multiple of each key value) tha...
Definition: unordered_map.h:72
const_iterator cend() const noexcept
iterator find(const key_type &__x)
Tries to locate an element in an unordered_map.
void reserve(size_type __n)
Prepare the unordered_multimap for a specified number of elements.
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert a std::pair into the unordered_map.
bool empty() const noexcept
Returns true if the unordered_map is empty.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the unordered_map.
mapped_type & operator[](key_type &&__k)
Subscript ( [] ) access to unordered_map data.
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_multimap.
unordered_map(initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_map from an initializer_list.
initializer_list
_Hashtable::iterator iterator
Iterator-related typedefs.
iterator insert(const value_type &__x)
Inserts a std::pair into the unordered_multimap.
size_type count(const key_type &__x) const
Finds the number of elements.
ISO C++ entities toplevel namespace is std.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
local_iterator begin(size_type __n)
Returns a read/write iterator pointing to the first bucket element.
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
Default ranged hash function H. In principle it should be a function object composed from objects of ...
const_iterator cbegin() const noexcept
_Hashtable::value_type value_type
Public typedefs.
iterator end() noexcept
const_iterator end() const noexcept
unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_multimap from a range.
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
unordered_multimap & operator=(initializer_list< value_type > __l)
Unordered_multimap list assignment operator.
void rehash(size_type __n)
May rehash the unordered_map.
mapped_type & operator[](const key_type &__k)
Subscript ( [] ) access to unordered_map data.
_Hashtable::const_pointer const_pointer
Iterator-related typedefs.
_Hashtable::mapped_type mapped_type
Public typedefs.
_Hashtable::difference_type difference_type
Iterator-related typedefs.
_Hashtable::size_type size_type
Iterator-related typedefs.
Default range hashing function: use division to fold a large number into the range [0...
allocator_type get_allocator() const noexcept
Returns the allocator object used by the unordered_map.
size_type size() const noexcept
Returns the size of the unordered_map.
unordered_multimap(size_type __n, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Default constructor creates no elements.
size_type size() const noexcept
Returns the size of the unordered_multimap.
_Hashtable::reference reference
Iterator-related typedefs.
local_iterator end(size_type __n)
Returns a read/write iterator pointing to one past the last bucket elements.
_Hashtable::key_equal key_equal
Public typedefs.
size_type bucket_count() const noexcept
Returns the number of buckets of the unordered_multimap.
size_type erase(const key_type &__x)
Erases elements according to the provided key.
float max_load_factor() const noexcept
Returns a positive number that the unordered_map tries to keep the load factor less than or equal to...
hasher hash_function() const
Returns the hash functor object with which the unordered_multimap was constructed.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
void swap(unordered_multimap &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_multimap.
key_equal key_eq() const
Returns the key comparison object with which the unordered_map was constructed.
iterator insert(const_iterator __hint, const value_type &__x)
Inserts a std::pair into the unordered_multimap.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the unordered_multimap.
_Hashtable::const_iterator const_iterator
Iterator-related typedefs.
_Hashtable::allocator_type allocator_type
Public typedefs.
iterator end() noexcept
float load_factor() const noexcept
Returns the average number of elements per bucket.
void max_load_factor(float __z)
Change the unordered_multimap maximum load factor.
unordered_multimap(initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_multimap from an initializer_list.
_Hashtable::key_type key_type
Public typedefs.
void max_load_factor(float __z)
Change the unordered_map maximum load factor.
hasher hash_function() const
Returns the hash functor object with which the unordered_map was constructed.
iterator erase(const_iterator __position)
Erases an element from an unordered_map.
_Hashtable::value_type value_type
Public typedefs.
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_multimap.
iterator erase(iterator __position)
Erases an element from an unordered_map.
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_multimap.
void reserve(size_type __n)
Prepare the unordered_map for a specified number of elements.
unordered_map(size_type __n, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Default constructor creates no elements.
iterator insert(const_iterator __hint, const value_type &__x)
Attempts to insert a std::pair into the unordered_map.
size_type bucket_count() const noexcept
Returns the number of buckets of the unordered_map.
const_iterator end() const noexcept
key_equal key_eq() const
Returns the key comparison object with which the unordered_multimap was constructed.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
const_local_iterator begin(size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element.
_Hashtable::allocator_type allocator_type
Public typedefs.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_multimap.
_Hashtable::const_pointer const_pointer
Iterator-related typedefs.
local_iterator begin(size_type __n)
Returns a read/write iterator pointing to the first bucket element.
float load_factor() const noexcept
Returns the average number of elements per bucket.
iterator erase(iterator __position)
Erases an element from an unordered_multimap.
void insert(_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements.
_Hashtable::hasher hasher
Public typedefs.
unordered_multimap(const allocator_type &__a)
Creates an unordered_multimap with no elements.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the unordered_map.
size_type max_size() const noexcept
Returns the maximum size of the unordered_multimap.
const_local_iterator end(size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
local_iterator end(size_type __n)
Returns a read/write iterator pointing to one past the last bucket elements.
const_iterator begin() const noexcept
size_type erase(const key_type &__x)
Erases elements according to the provided key.
One of the comparison functors.
Definition: stl_function.h:331
iterator erase(const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_map.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
Primary class template hash.
Definition: system_error:142
size_type max_bucket_count() const noexcept
Returns the maximum number of buckets of the unordered_map.
void rehash(size_type __n)
May rehash the unordered_multimap.
_Hashtable::const_reference const_reference
Iterator-related typedefs.
_Hashtable::const_local_iterator const_local_iterator
Iterator-related typedefs.
iterator emplace(_Args &&... __args)
Attempts to build and insert a std::pair into the unordered_multimap.
const_iterator cend() const noexcept
mapped_type & at(const key_type &__k)
Access to unordered_map data.
_Hashtable::local_iterator local_iterator
Iterator-related typedefs.
const_iterator find(const key_type &__x) const
Tries to locate an element in an unordered_map.
unordered_map(const allocator_type &__a)
Creates an unordered_map with no elements.
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:198
void insert(initializer_list< value_type > __l)
Attempts to insert a list of elements into the unordered_multimap.
_Hashtable::mapped_type mapped_type
Public typedefs.
_Hashtable::key_type key_type
Public typedefs.
iterator erase(const_iterator __position)
Erases an element from an unordered_multimap.
Default value for rehash policy. Bucket size is (usually) the smallest prime that keeps the load fact...
void swap(unordered_map &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_map.
unordered_map(_InputIterator __first, _InputIterator __last, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_map from a range.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.