29#ifndef _GLIBCXX_DEBUG_UNORDERED_MAP
30#define _GLIBCXX_DEBUG_UNORDERED_MAP 1
33#pragma GCC system_header
36#if __cplusplus < 201103L
40namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
41 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred,
44 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred,
56namespace std _GLIBCXX_VISIBILITY(default)
61 template<
typename _Key,
typename _Tp,
62 typename _Hash = std::hash<_Key>,
63 typename _Pred = std::equal_to<_Key>,
64 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
67 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>, _Alloc,
68 __gnu_debug::_Safe_unordered_container>,
69 public _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
71 typedef _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash,
75 typedef typename _Base::const_iterator _Base_const_iterator;
76 typedef typename _Base::iterator _Base_iterator;
77 typedef typename _Base::const_local_iterator
78 _Base_const_local_iterator;
79 typedef typename _Base::local_iterator _Base_local_iterator;
81 template<
typename _ItT,
typename _SeqT,
typename _CatT>
82 friend class ::__gnu_debug::_Safe_iterator;
83 template<
typename _ItT,
typename _SeqT>
84 friend class ::__gnu_debug::_Safe_local_iterator;
89 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
95 typedef typename _Base::size_type size_type;
96 typedef typename _Base::hasher hasher;
97 typedef typename _Base::key_equal key_equal;
98 typedef typename _Base::allocator_type allocator_type;
100 typedef typename _Base::key_type key_type;
101 typedef typename _Base::value_type value_type;
102 typedef typename _Base::mapped_type mapped_type;
104 typedef typename _Base::pointer pointer;
105 typedef typename _Base::const_pointer const_pointer;
106 typedef typename _Base::reference reference;
107 typedef typename _Base::const_reference const_reference;
109 _Base_iterator, unordered_map> iterator;
111 _Base_const_iterator, unordered_map> const_iterator;
113 _Base_local_iterator, unordered_map> local_iterator;
115 _Base_const_local_iterator, unordered_map> const_local_iterator;
116 typedef typename _Base::difference_type difference_type;
118 unordered_map() =
default;
121 unordered_map(size_type __n,
122 const hasher& __hf = hasher(),
123 const key_equal& __eql = key_equal(),
124 const allocator_type& __a = allocator_type())
125 : _Base(__n, __hf, __eql, __a) { }
127 template<
typename _InputIterator>
128 unordered_map(_InputIterator __first, _InputIterator __last,
130 const hasher& __hf = hasher(),
131 const key_equal& __eql = key_equal(),
132 const allocator_type& __a = allocator_type())
134 __glibcxx_check_valid_constructor_range(__first, __last)),
136 __hf, __eql, __a) { }
138 unordered_map(
const unordered_map&) =
default;
140 unordered_map(_Base_ref __x)
141 : _Base(__x._M_ref) { }
143 unordered_map(unordered_map&&) =
default;
146 unordered_map(
const allocator_type& __a)
149 unordered_map(
const unordered_map& __umap,
150 const allocator_type& __a)
151 : _Base(__umap, __a) { }
153 unordered_map(unordered_map&& __umap,
154 const allocator_type& __a)
155 noexcept(
noexcept(_Base(
std::move(__umap), __a)) )
161 const hasher& __hf = hasher(),
162 const key_equal& __eql = key_equal(),
163 const allocator_type& __a = allocator_type())
164 : _Base(__l, __n, __hf, __eql, __a) { }
166 unordered_map(size_type __n,
const allocator_type& __a)
167 : unordered_map(__n, hasher(), key_equal(), __a)
170 unordered_map(size_type __n,
172 const allocator_type& __a)
173 : unordered_map(__n, __hf, key_equal(), __a)
176 template<
typename _InputIterator>
177 unordered_map(_InputIterator __first, _InputIterator __last,
178 const allocator_type& __a)
179 : unordered_map(__first, __last, 0, hasher(), key_equal(), __a)
182 template<
typename _InputIterator>
183 unordered_map(_InputIterator __first, _InputIterator __last,
185 const allocator_type& __a)
186 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a)
189 template<
typename _InputIterator>
190 unordered_map(_InputIterator __first, _InputIterator __last,
193 const allocator_type& __a)
194 : unordered_map(__first, __last, __n, __hf, key_equal(), __a)
198 const allocator_type& __a)
199 : unordered_map(__l, 0, hasher(), key_equal(), __a)
204 const allocator_type& __a)
205 : unordered_map(__l, __n, hasher(), key_equal(), __a)
211 const allocator_type& __a)
212 : unordered_map(__l, __n, __hf, key_equal(), __a)
215#if __glibcxx_containers_ranges
216 template<__detail::__container_compatible_range<value_type> _Rg>
217 unordered_map(from_range_t, _Rg&& __rg,
219 const hasher& __hf = hasher(),
220 const key_equal& __eql = key_equal(),
221 const allocator_type& __a = allocator_type())
225 template<__detail::__container_compatible_range<value_type> _Rg>
226 unordered_map(from_range_t, _Rg&& __rg,
const allocator_type& __a)
230 template<__detail::__container_compatible_range<value_type> _Rg>
231 unordered_map(from_range_t, _Rg&& __rg, size_type __n,
232 const allocator_type& __a)
236 template<__detail::__container_compatible_range<value_type> _Rg>
237 unordered_map(from_range_t, _Rg&& __rg, size_type __n,
238 const hasher& __hf,
const allocator_type& __a)
243 ~unordered_map() =
default;
246 operator=(
const unordered_map&) =
default;
249 operator=(unordered_map&&) =
default;
254 _Base::operator=(__l);
255 this->_M_invalidate_all();
259 using _Base::get_allocator;
262 using _Base::max_size;
265 swap(unordered_map& __x)
276 this->_M_invalidate_all();
281 {
return { _Base::begin(),
this }; }
284 begin()
const noexcept
285 {
return { _Base::begin(),
this }; }
289 {
return { _Base::end(),
this }; }
293 {
return { _Base::end(),
this }; }
296 cbegin()
const noexcept
297 {
return { _Base::cbegin(),
this }; }
300 cend()
const noexcept
301 {
return { _Base::cend(),
this }; }
307 __glibcxx_check_bucket_index(__b);
308 return { _Base::begin(__b),
this };
314 __glibcxx_check_bucket_index(__b);
315 return { _Base::end(__b),
this };
319 begin(size_type __b)
const
321 __glibcxx_check_bucket_index(__b);
322 return { _Base::begin(__b),
this };
326 end(size_type __b)
const
328 __glibcxx_check_bucket_index(__b);
329 return { _Base::end(__b),
this };
333 cbegin(size_type __b)
const
335 __glibcxx_check_bucket_index(__b);
336 return { _Base::cbegin(__b),
this };
340 cend(size_type __b)
const
342 __glibcxx_check_bucket_index(__b);
343 return { _Base::cend(__b),
this };
346 using _Base::bucket_count;
347 using _Base::max_bucket_count;
351 bucket_size(size_type __b)
const
353 __glibcxx_check_bucket_index(__b);
354 return _Base::bucket_size(__b);
357 using _Base::load_factor;
360 max_load_factor()
const noexcept
361 {
return _Base::max_load_factor(); }
364 max_load_factor(
float __f)
366 __glibcxx_check_max_load_factor(__f);
367 _Base::max_load_factor(__f);
370 template<
typename... _Args>
372 emplace(_Args&&... __args)
374 size_type __bucket_count = this->bucket_count();
376 _M_check_rehashed(__bucket_count);
377 return { { __res.first,
this }, __res.second };
380 template<
typename... _Args>
382 emplace_hint(const_iterator __hint, _Args&&... __args)
385 size_type __bucket_count = this->bucket_count();
386 auto __it = _Base::emplace_hint(__hint.
base(),
388 _M_check_rehashed(__bucket_count);
389 return { __it,
this };
393 insert(
const value_type& __obj)
395 size_type __bucket_count = this->bucket_count();
396 auto __res = _Base::insert(__obj);
397 _M_check_rehashed(__bucket_count);
398 return { { __res.first,
this }, __res.second };
404 insert(value_type&& __x)
406 size_type __bucket_count = this->bucket_count();
407 auto __res = _Base::insert(
std::move(__x));
408 _M_check_rehashed(__bucket_count);
409 return { { __res.first,
this }, __res.second };
412 template<
typename _Pair,
typename =
typename
416 insert(_Pair&& __obj)
418 size_type __bucket_count = this->bucket_count();
420 _M_check_rehashed(__bucket_count);
421 return { { __res.first,
this }, __res.second };
425 insert(const_iterator __hint,
const value_type& __obj)
428 size_type __bucket_count = this->bucket_count();
429 auto __it = _Base::insert(__hint.
base(), __obj);
430 _M_check_rehashed(__bucket_count);
431 return { __it,
this };
437 insert(const_iterator __hint, value_type&& __x)
440 size_type __bucket_count = this->bucket_count();
442 _M_check_rehashed(__bucket_count);
443 return { __it,
this };
446 template<
typename _Pair,
typename =
typename
450 insert(const_iterator __hint, _Pair&& __obj)
453 size_type __bucket_count = this->bucket_count();
455 _M_check_rehashed(__bucket_count);
456 return { __it,
this };
462 size_type __bucket_count = this->bucket_count();
464 _M_check_rehashed(__bucket_count);
467 template<
typename _InputIterator>
469 insert(_InputIterator __first, _InputIterator __last)
471 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
472 __glibcxx_check_valid_range2(__first, __last, __dist);
473 size_type __bucket_count = this->bucket_count();
475 if (__dist.second >= __gnu_debug::__dp_sign)
476 _Base::insert(__gnu_debug::__unsafe(__first),
477 __gnu_debug::__unsafe(__last));
479 _Base::insert(__first, __last);
481 _M_check_rehashed(__bucket_count);
484#ifdef __glibcxx_unordered_map_try_emplace
485 template <
typename... _Args>
487 try_emplace(
const key_type& __k, _Args&&... __args)
489 auto __res = _Base::try_emplace(__k,
491 return { { __res.first,
this }, __res.second };
494 template <
typename... _Args>
496 try_emplace(key_type&& __k, _Args&&... __args)
498 auto __res = _Base::try_emplace(
std::move(__k),
500 return { { __res.first,
this }, __res.second };
503 template <
typename... _Args>
505 try_emplace(const_iterator __hint,
const key_type& __k,
509 return { _Base::try_emplace(__hint.
base(), __k,
514 template <
typename... _Args>
516 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
524 template <
typename _Obj>
526 insert_or_assign(
const key_type& __k, _Obj&& __obj)
528 auto __res = _Base::insert_or_assign(__k,
530 return { { __res.first,
this }, __res.second };
533 template <
typename _Obj>
535 insert_or_assign(key_type&& __k, _Obj&& __obj)
537 auto __res = _Base::insert_or_assign(
std::move(__k),
539 return { { __res.first,
this }, __res.second };
542 template <
typename _Obj>
544 insert_or_assign(const_iterator __hint,
const key_type& __k,
548 return { _Base::insert_or_assign(__hint.
base(), __k,
553 template <
typename _Obj>
555 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
558 return { _Base::insert_or_assign(__hint.
base(),
std::move(__k),
564#ifdef __glibcxx_node_extract
565 using node_type =
typename _Base::node_type;
566 using insert_return_type = _Node_insert_return<iterator, node_type>;
569 extract(const_iterator __position)
572 return _M_extract(__position.
base());
576 extract(
const key_type& __key)
578 const auto __position = _Base::find(__key);
579 if (__position != _Base::end())
580 return _M_extract(__position);
585 insert(node_type&& __nh)
587 auto __ret = _Base::insert(
std::move(__nh));
589 { { __ret.position,
this }, __ret.inserted,
std::move(__ret.node) };
593 insert(const_iterator __hint, node_type&& __nh)
596 return { _Base::insert(__hint.
base(),
std::move(__nh)),
this };
599 template<
typename _H2,
typename _P2>
601 merge(unordered_map<_Key, _Tp, _H2, _P2, _Alloc>& __source)
604 = _Safe::_S_uc_guard(std::__detail::_Select1st{}, __source);
605 _Base::merge(__source);
608 template<
typename _H2,
typename _P2>
610 merge(unordered_map<_Key, _Tp, _H2, _P2, _Alloc>&& __source)
613 template<
typename _H2,
typename _P2>
618 = _Safe::_S_umc_guard(std::__detail::_Select1st{}, __source);
619 _Base::merge(__source);
622 template<
typename _H2,
typename _P2>
628 using _Base::hash_function;
632 find(
const key_type& __key)
633 {
return { _Base::find(__key),
this }; }
635#ifdef __glibcxx_generic_unordered_lookup
636 template<
typename _Kt,
637 typename = std::__has_is_transparent_t<_Hash, _Kt>,
638 typename = std::__has_is_transparent_t<_Pred, _Kt>>
641 {
return { _Base::find(__k),
this }; }
645 find(
const key_type& __key)
const
646 {
return { _Base::find(__key),
this }; }
648#ifdef __glibcxx_generic_unordered_lookup
649 template<
typename _Kt,
650 typename = std::__has_is_transparent_t<_Hash, _Kt>,
651 typename = std::__has_is_transparent_t<_Pred, _Kt>>
653 find(
const _Kt& __k)
const
654 {
return { _Base::find(__k),
this }; }
658#if __cplusplus > 201703L
659 using _Base::contains;
663 equal_range(
const key_type& __key)
665 auto __res = _Base::equal_range(__key);
666 return { { __res.first,
this }, { __res.second,
this } };
669#ifdef __glibcxx_generic_unordered_lookup
670 template<
typename _Kt,
671 typename = std::__has_is_transparent_t<_Hash, _Kt>,
672 typename = std::__has_is_transparent_t<_Pred, _Kt>>
674 equal_range(
const _Kt& __k)
676 auto __res = _Base::equal_range(__k);
677 return { { __res.first,
this }, { __res.second,
this } };
682 equal_range(
const key_type& __key)
const
684 auto __res = _Base::equal_range(__key);
685 return { { __res.first,
this }, { __res.second,
this } };
688#ifdef __glibcxx_generic_unordered_lookup
689 template<
typename _Kt,
690 typename = std::__has_is_transparent_t<_Hash, _Kt>,
691 typename = std::__has_is_transparent_t<_Pred, _Kt>>
693 equal_range(
const _Kt& __k)
const
695 auto __res = _Base::equal_range(__k);
696 return { { __res.first,
this }, { __res.second,
this } };
700 using _Base::operator[];
704 erase(
const key_type& __key)
707 auto __victim = _Base::find(__key);
708 if (__victim != _Base::end())
717 erase(const_iterator __it)
720 return { _M_erase(__it.
base()),
this };
724 erase(_Base_const_iterator __it)
726 __glibcxx_check_erase2(__it);
727 return _M_erase(__it);
734 return { _M_erase(__it.
base()),
this };
738 erase(const_iterator __first, const_iterator __last)
741 for (
auto __tmp = __first.base(); __tmp != __last.
base(); ++__tmp)
743 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::cend(),
744 _M_message(__gnu_debug::__msg_valid_range)
745 ._M_iterator(__first,
"first")
746 ._M_iterator(__last,
"last"));
747 _M_invalidate(__tmp);
750 size_type __bucket_count = this->bucket_count();
751 auto __next = _Base::erase(__first.base(), __last.
base());
752 _M_check_rehashed(__bucket_count);
753 return { __next,
this };
757 using _Base::reserve;
760 _M_base()
noexcept {
return *
this; }
763 _M_base()
const noexcept {
return *
this; }
767 _M_check_rehashed(size_type __prev_count)
769 if (__prev_count != this->bucket_count())
770 this->_M_invalidate_all();
774 _M_invalidate(_Base_const_iterator __victim)
776 this->_M_invalidate_if(
777 [__victim](_Base_const_iterator __it) {
return __it == __victim; });
778 this->_M_invalidate_local_if(
779 [__victim](_Base_const_local_iterator __it)
780 {
return __it == __victim; });
784 _M_erase(_Base_const_iterator __victim)
786 _M_invalidate(__victim);
787 size_type __bucket_count = this->bucket_count();
788 _Base_iterator __next = _Base::erase(__victim);
789 _M_check_rehashed(__bucket_count);
793#ifdef __glibcxx_node_extract
795 _M_extract(_Base_const_iterator __victim)
797 _M_invalidate(__victim);
798 return _Base::extract(__victim);
803#if __cpp_deduction_guides >= 201606
805 template<
typename _InputIterator,
809 typename = _RequireInputIter<_InputIterator>,
810 typename = _RequireNotAllocatorOrIntegral<_Hash>,
811 typename = _RequireNotAllocator<_Pred>,
812 typename = _RequireAllocator<_Allocator>>
814 typename unordered_map<int, int>::size_type = {},
815 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
817 __iter_val_t<_InputIterator>,
818 _Hash, _Pred, _Allocator>;
820 template<
typename _Key,
typename _Tp,
typename _Hash = hash<_Key>,
821 typename _Pred = equal_to<_Key>,
822 typename _Allocator = allocator<pair<const _Key, _Tp>>,
823 typename = _RequireNotAllocatorOrIntegral<_Hash>,
824 typename = _RequireNotAllocator<_Pred>,
825 typename = _RequireAllocator<_Allocator>>
828 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
829 -> unordered_map<_Key, _Tp, _Hash, _Pred, _Allocator>;
831 template<
typename _InputIterator,
typename _Allocator,
832 typename = _RequireInputIter<_InputIterator>,
833 typename = _RequireAllocator<_Allocator>>
834 unordered_map(_InputIterator, _InputIterator,
835 typename unordered_map<int, int>::size_type, _Allocator)
836 -> unordered_map<__iter_key_t<_InputIterator>,
837 __iter_val_t<_InputIterator>,
838 hash<__iter_key_t<_InputIterator>>,
839 equal_to<__iter_key_t<_InputIterator>>,
842 template<
typename _InputIterator,
typename _Allocator,
843 typename = _RequireInputIter<_InputIterator>,
844 typename = _RequireAllocator<_Allocator>>
845 unordered_map(_InputIterator, _InputIterator, _Allocator)
846 -> unordered_map<__iter_key_t<_InputIterator>,
847 __iter_val_t<_InputIterator>,
848 hash<__iter_key_t<_InputIterator>>,
849 equal_to<__iter_key_t<_InputIterator>>,
852 template<
typename _InputIterator,
typename _Hash,
typename _Allocator,
853 typename = _RequireInputIter<_InputIterator>,
854 typename = _RequireNotAllocatorOrIntegral<_Hash>,
855 typename = _RequireAllocator<_Allocator>>
856 unordered_map(_InputIterator, _InputIterator,
857 typename unordered_map<int, int>::size_type,
859 -> unordered_map<__iter_key_t<_InputIterator>,
860 __iter_val_t<_InputIterator>, _Hash,
861 equal_to<__iter_key_t<_InputIterator>>, _Allocator>;
863 template<
typename _Key,
typename _Tp,
typename _Allocator,
864 typename = _RequireAllocator<_Allocator>>
866 typename unordered_map<int, int>::size_type,
868 -> unordered_map<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>;
870 template<
typename _Key,
typename _Tp,
typename _Allocator,
871 typename = _RequireAllocator<_Allocator>>
873 -> unordered_map<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>;
875 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Allocator,
876 typename = _RequireNotAllocatorOrIntegral<_Hash>,
877 typename = _RequireAllocator<_Allocator>>
879 typename unordered_map<int, int>::size_type,
881 -> unordered_map<_Key, _Tp, _Hash, equal_to<_Key>, _Allocator>;
883#if __glibcxx_containers_ranges
884 template<ranges::input_range _Rg,
885 __not_allocator_like _Hash = hash<__detail::__range_key_type<_Rg>>,
886 __not_allocator_like _Pred = equal_to<__detail::__range_key_type<_Rg>>,
887 __allocator_like _Allocator =
888 allocator<__detail::__range_to_alloc_type<_Rg>>>
889 unordered_map(from_range_t, _Rg&&, unordered_map<int, int>::size_type = {},
890 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
892 __detail::__range_mapped_type<_Rg>,
893 _Hash, _Pred, _Allocator>;
895 template<ranges::input_range _Rg,
896 __allocator_like _Allocator>
897 unordered_map(from_range_t, _Rg&&, unordered_map<int, int>::size_type,
900 __detail::__range_mapped_type<_Rg>,
901 hash<__detail::__range_key_type<_Rg>>,
902 equal_to<__detail::__range_key_type<_Rg>>,
905 template<ranges::input_range _Rg,
906 __allocator_like _Allocator>
909 __detail::__range_mapped_type<_Rg>,
910 hash<__detail::__range_key_type<_Rg>>,
911 equal_to<__detail::__range_key_type<_Rg>>,
914 template<ranges::input_range _Rg,
915 __not_allocator_like _Hash,
916 __allocator_like _Allocator>
917 unordered_map(from_range_t, _Rg&&, unordered_map<int, int>::size_type,
920 __detail::__range_mapped_type<_Rg>,
921 _Hash, equal_to<__detail::__range_key_type<_Rg>>,
926 template<
typename _Key,
typename _Tp,
typename _Hash,
927 typename _Pred,
typename _Alloc>
931 noexcept(
noexcept(__x.swap(__y)))
934 template<
typename _Key,
typename _Tp,
typename _Hash,
935 typename _Pred,
typename _Alloc>
939 {
return __x._M_base() == __y._M_base(); }
941#if __cpp_impl_three_way_comparison < 201907L
942 template<
typename _Key,
typename _Tp,
typename _Hash,
943 typename _Pred,
typename _Alloc>
947 {
return !(__x == __y); }
951 template<
typename _Key,
typename _Tp,
952 typename _Hash = std::hash<_Key>,
953 typename _Pred = std::equal_to<_Key>,
954 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
955 class unordered_multimap
957 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>, _Alloc,
958 __gnu_debug::_Safe_unordered_container>,
959 public _GLIBCXX_STD_C::unordered_multimap<
960 _Key, _Tp, _Hash, _Pred, _Alloc>
962 typedef _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash,
963 _Pred, _Alloc> _Base;
966 typedef typename _Base::const_iterator _Base_const_iterator;
967 typedef typename _Base::iterator _Base_iterator;
968 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
969 typedef typename _Base::local_iterator _Base_local_iterator;
971 template<
typename _ItT,
typename _SeqT,
typename _CatT>
972 friend class ::__gnu_debug::_Safe_iterator;
973 template<
typename _ItT,
typename _SeqT>
974 friend class ::__gnu_debug::_Safe_local_iterator;
979 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
985 typedef typename _Base::size_type size_type;
986 typedef typename _Base::hasher hasher;
987 typedef typename _Base::key_equal key_equal;
988 typedef typename _Base::allocator_type allocator_type;
990 typedef typename _Base::key_type key_type;
991 typedef typename _Base::value_type value_type;
992 typedef typename _Base::mapped_type mapped_type;
994 typedef typename _Base::pointer pointer;
995 typedef typename _Base::const_pointer const_pointer;
996 typedef typename _Base::reference reference;
997 typedef typename _Base::const_reference const_reference;
999 _Base_iterator, unordered_multimap> iterator;
1001 _Base_const_iterator, unordered_multimap> const_iterator;
1003 _Base_local_iterator, unordered_multimap> local_iterator;
1005 _Base_const_local_iterator, unordered_multimap> const_local_iterator;
1006 typedef typename _Base::difference_type difference_type;
1008 unordered_multimap() =
default;
1011 unordered_multimap(size_type __n,
1012 const hasher& __hf = hasher(),
1013 const key_equal& __eql = key_equal(),
1014 const allocator_type& __a = allocator_type())
1015 : _Base(__n, __hf, __eql, __a) { }
1017 template<
typename _InputIterator>
1018 unordered_multimap(_InputIterator __first, _InputIterator __last,
1020 const hasher& __hf = hasher(),
1021 const key_equal& __eql = key_equal(),
1022 const allocator_type& __a = allocator_type())
1024 __glibcxx_check_valid_constructor_range(__first, __last)),
1026 __hf, __eql, __a) { }
1028 unordered_multimap(
const unordered_multimap&) =
default;
1030 unordered_multimap(_Base_ref __x)
1031 : _Base(__x._M_ref) { }
1033 unordered_multimap(unordered_multimap&&) =
default;
1036 unordered_multimap(
const allocator_type& __a)
1039 unordered_multimap(
const unordered_multimap& __umap,
1040 const allocator_type& __a)
1041 : _Base(__umap, __a) { }
1043 unordered_multimap(unordered_multimap&& __umap,
1044 const allocator_type& __a)
1045 noexcept(
noexcept(_Base(
std::move(__umap), __a)) )
1051 const hasher& __hf = hasher(),
1052 const key_equal& __eql = key_equal(),
1053 const allocator_type& __a = allocator_type())
1054 : _Base(__l, __n, __hf, __eql, __a) { }
1056 unordered_multimap(size_type __n,
const allocator_type& __a)
1057 : unordered_multimap(__n, hasher(), key_equal(), __a)
1060 unordered_multimap(size_type __n,
const hasher& __hf,
1061 const allocator_type& __a)
1062 : unordered_multimap(__n, __hf, key_equal(), __a)
1065 template<
typename _InputIterator>
1066 unordered_multimap(_InputIterator __first, _InputIterator __last,
1067 const allocator_type& __a)
1068 : unordered_multimap(__first, __last, 0, hasher(), key_equal(), __a)
1071 template<
typename _InputIterator>
1072 unordered_multimap(_InputIterator __first, _InputIterator __last,
1074 const allocator_type& __a)
1075 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a)
1078 template<
typename _InputIterator>
1079 unordered_multimap(_InputIterator __first, _InputIterator __last,
1080 size_type __n,
const hasher& __hf,
1081 const allocator_type& __a)
1082 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a)
1086 const allocator_type& __a)
1087 : unordered_multimap(__l, 0, hasher(), key_equal(), __a)
1092 const allocator_type& __a)
1093 : unordered_multimap(__l, __n, hasher(), key_equal(), __a)
1097 size_type __n,
const hasher& __hf,
1098 const allocator_type& __a)
1099 : unordered_multimap(__l, __n, __hf, key_equal(), __a)
1102#if __glibcxx_containers_ranges
1103 template<__detail::__container_compatible_range<value_type> _Rg>
1104 unordered_multimap(from_range_t, _Rg&& __rg,
1106 const hasher& __hf = hasher(),
1107 const key_equal& __eql = key_equal(),
1108 const allocator_type& __a = allocator_type())
1112 template<__detail::__container_compatible_range<value_type> _Rg>
1113 unordered_multimap(from_range_t, _Rg&& __rg,
const allocator_type& __a)
1117 template<__detail::__container_compatible_range<value_type> _Rg>
1118 unordered_multimap(from_range_t, _Rg&& __rg, size_type __n,
1119 const allocator_type& __a)
1123 template<__detail::__container_compatible_range<value_type> _Rg>
1124 unordered_multimap(from_range_t, _Rg&& __rg, size_type __n,
1125 const hasher& __hf,
const allocator_type& __a)
1130 ~unordered_multimap() =
default;
1133 operator=(
const unordered_multimap&) =
default;
1136 operator=(unordered_multimap&&) =
default;
1141 _Base::operator=(__l);
1142 this->_M_invalidate_all();
1146 using _Base::get_allocator;
1149 using _Base::max_size;
1152 swap(unordered_multimap& __x)
1155 _Safe::_M_swap(__x);
1163 this->_M_invalidate_all();
1168 {
return { _Base::begin(),
this }; }
1171 begin()
const noexcept
1172 {
return { _Base::begin(),
this }; }
1176 {
return { _Base::end(),
this }; }
1179 end()
const noexcept
1180 {
return { _Base::end(),
this }; }
1183 cbegin()
const noexcept
1184 {
return { _Base::cbegin(),
this }; }
1187 cend()
const noexcept
1188 {
return { _Base::cend(),
this }; }
1192 begin(size_type __b)
1194 __glibcxx_check_bucket_index(__b);
1195 return { _Base::begin(__b),
this };
1201 __glibcxx_check_bucket_index(__b);
1202 return { _Base::end(__b),
this };
1205 const_local_iterator
1206 begin(size_type __b)
const
1208 __glibcxx_check_bucket_index(__b);
1209 return { _Base::begin(__b),
this };
1212 const_local_iterator
1213 end(size_type __b)
const
1215 __glibcxx_check_bucket_index(__b);
1216 return { _Base::end(__b),
this };
1219 const_local_iterator
1220 cbegin(size_type __b)
const
1222 __glibcxx_check_bucket_index(__b);
1223 return { _Base::cbegin(__b),
this };
1226 const_local_iterator
1227 cend(size_type __b)
const
1229 __glibcxx_check_bucket_index(__b);
1230 return { _Base::cend(__b),
this };
1233 using _Base::bucket_count;
1234 using _Base::max_bucket_count;
1235 using _Base::bucket;
1238 bucket_size(size_type __b)
const
1240 __glibcxx_check_bucket_index(__b);
1241 return _Base::bucket_size(__b);
1245 max_load_factor()
const noexcept
1246 {
return _Base::max_load_factor(); }
1249 max_load_factor(
float __f)
1251 __glibcxx_check_max_load_factor(__f);
1252 _Base::max_load_factor(__f);
1255 template<
typename... _Args>
1257 emplace(_Args&&... __args)
1259 size_type __bucket_count = this->bucket_count();
1261 _M_check_rehashed(__bucket_count);
1262 return { __it,
this };
1265 template<
typename... _Args>
1267 emplace_hint(const_iterator __hint, _Args&&... __args)
1270 size_type __bucket_count = this->bucket_count();
1271 auto __it = _Base::emplace_hint(__hint.
base(),
1273 _M_check_rehashed(__bucket_count);
1274 return { __it,
this };
1278 insert(
const value_type& __obj)
1280 size_type __bucket_count = this->bucket_count();
1281 auto __it = _Base::insert(__obj);
1282 _M_check_rehashed(__bucket_count);
1283 return { __it,
this };
1289 insert(value_type&& __x)
1291 size_type __bucket_count = this->bucket_count();
1292 auto __it = _Base::insert(
std::move(__x));
1293 _M_check_rehashed(__bucket_count);
1294 return { __it,
this };
1298 insert(const_iterator __hint,
const value_type& __obj)
1301 size_type __bucket_count = this->bucket_count();
1302 auto __it = _Base::insert(__hint.
base(), __obj);
1303 _M_check_rehashed(__bucket_count);
1304 return { __it,
this };
1310 insert(const_iterator __hint, value_type&& __x)
1313 size_type __bucket_count = this->bucket_count();
1315 _M_check_rehashed(__bucket_count);
1316 return { __it,
this };
1319 template<
typename _Pair,
typename =
typename
1323 insert(_Pair&& __obj)
1325 size_type __bucket_count = this->bucket_count();
1327 _M_check_rehashed(__bucket_count);
1328 return { __it,
this };
1331 template<
typename _Pair,
typename =
typename
1335 insert(const_iterator __hint, _Pair&& __obj)
1338 size_type __bucket_count = this->bucket_count();
1340 _M_check_rehashed(__bucket_count);
1341 return { __it,
this };
1346 { _Base::insert(__l); }
1348 template<
typename _InputIterator>
1350 insert(_InputIterator __first, _InputIterator __last)
1352 typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
1353 __glibcxx_check_valid_range2(__first, __last, __dist);
1354 size_type __bucket_count = this->bucket_count();
1356 if (__dist.second >= __gnu_debug::__dp_sign)
1357 _Base::insert(__gnu_debug::__unsafe(__first),
1358 __gnu_debug::__unsafe(__last));
1360 _Base::insert(__first, __last);
1362 _M_check_rehashed(__bucket_count);
1365#ifdef __glibcxx_node_extract
1366 using node_type =
typename _Base::node_type;
1369 extract(const_iterator __position)
1372 return _M_extract(__position.
base());
1376 extract(
const key_type& __key)
1378 const auto __position = _Base::find(__key);
1379 if (__position != _Base::end())
1380 return _M_extract(__position);
1385 insert(node_type&& __nh)
1386 {
return { _Base::insert(
std::move(__nh)),
this }; }
1389 insert(const_iterator __hint, node_type&& __nh)
1392 return { _Base::insert(__hint.
base(),
std::move(__nh)),
this };
1395 template<
typename _H2,
typename _P2>
1397 merge(unordered_multimap<_Key, _Tp, _H2, _P2, _Alloc>& __source)
1400 = _Safe::_S_umc_guard(std::__detail::_Select1st{}, __source);
1401 _Base::merge(__source);
1404 template<
typename _H2,
typename _P2>
1406 merge(unordered_multimap<_Key, _Tp, _H2, _P2, _Alloc>&& __source)
1407 { merge(__source); }
1409 template<
typename _H2,
typename _P2>
1414 = _Safe::_S_uc_guard(std::__detail::_Select1st{}, __source);
1415 _Base::merge(__source);
1418 template<
typename _H2,
typename _P2>
1421 { merge(__source); }
1424 using _Base::hash_function;
1425 using _Base::key_eq;
1428 find(
const key_type& __key)
1429 {
return { _Base::find(__key),
this }; }
1431#ifdef __glibcxx_generic_unordered_lookup
1432 template<
typename _Kt,
1433 typename = std::__has_is_transparent_t<_Hash, _Kt>,
1434 typename = std::__has_is_transparent_t<_Pred, _Kt>>
1436 find(
const _Kt& __k)
1437 {
return { _Base::find(__k),
this }; }
1441 find(
const key_type& __key)
const
1442 {
return { _Base::find(__key),
this }; }
1444#ifdef __glibcxx_generic_unordered_lookup
1445 template<
typename _Kt,
1446 typename = std::__has_is_transparent_t<_Hash, _Kt>,
1447 typename = std::__has_is_transparent_t<_Pred, _Kt>>
1449 find(
const _Kt& __k)
const
1450 {
return { _Base::find(__k),
this }; }
1454#if __cplusplus > 201703L
1455 using _Base::contains;
1459 equal_range(
const key_type& __key)
1461 auto __res = _Base::equal_range(__key);
1462 return { { __res.first,
this }, { __res.second,
this } };
1465#ifdef __glibcxx_generic_unordered_lookup
1466 template<
typename _Kt,
1467 typename = std::__has_is_transparent_t<_Hash, _Kt>,
1468 typename = std::__has_is_transparent_t<_Pred, _Kt>>
1470 equal_range(
const _Kt& __k)
1472 auto __res = _Base::equal_range(__k);
1473 return { { __res.first,
this }, { __res.second,
this } };
1478 equal_range(
const key_type& __key)
const
1480 auto __res = _Base::equal_range(__key);
1481 return { { __res.first,
this }, { __res.second,
this } };
1484#ifdef __glibcxx_generic_unordered_lookup
1485 template<
typename _Kt,
1486 typename = std::__has_is_transparent_t<_Hash, _Kt>,
1487 typename = std::__has_is_transparent_t<_Pred, _Kt>>
1489 equal_range(
const _Kt& __k)
const
1491 auto __res = _Base::equal_range(__k);
1492 return { { __res.first,
this }, { __res.second,
this } };
1497 erase(
const key_type& __key)
1500 size_type __bucket_count = this->bucket_count();
1501 auto __pair = _Base::equal_range(__key);
1502 for (
auto __victim = __pair.first; __victim != __pair.second;)
1504 _M_invalidate(__victim);
1505 __victim = _Base::erase(__victim);
1509 _M_check_rehashed(__bucket_count);
1514 erase(const_iterator __it)
1517 return { _M_erase(__it.
base()),
this };
1521 erase(_Base_const_iterator __it)
1523 __glibcxx_check_erase2(__it);
1524 return _M_erase(__it);
1528 erase(iterator __it)
1531 return { _M_erase(__it.
base()),
this };
1535 erase(const_iterator __first, const_iterator __last)
1538 for (
auto __tmp = __first.base(); __tmp != __last.
base(); ++__tmp)
1540 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::cend(),
1541 _M_message(__gnu_debug::__msg_valid_range)
1542 ._M_iterator(__first,
"first")
1543 ._M_iterator(__last,
"last"));
1544 _M_invalidate(__tmp);
1547 size_type __bucket_count = this->bucket_count();
1548 auto __next = _Base::erase(__first.base(), __last.
base());
1549 _M_check_rehashed(__bucket_count);
1550 return { __next,
this };
1553 using _Base::rehash;
1554 using _Base::reserve;
1557 _M_base()
noexcept {
return *
this; }
1560 _M_base()
const noexcept {
return *
this; }
1564 _M_check_rehashed(size_type __prev_count)
1566 if (__prev_count != this->bucket_count())
1567 this->_M_invalidate_all();
1571 _M_invalidate(_Base_const_iterator __victim)
1573 this->_M_invalidate_if(
1574 [__victim](_Base_const_iterator __it) {
return __it == __victim; });
1575 this->_M_invalidate_local_if(
1576 [__victim](_Base_const_local_iterator __it)
1577 {
return __it == __victim; });
1581 _M_erase(_Base_const_iterator __victim)
1583 _M_invalidate(__victim);
1584 size_type __bucket_count = this->bucket_count();
1585 _Base_iterator __next = _Base::erase(__victim);
1586 _M_check_rehashed(__bucket_count);
1590#ifdef __glibcxx_node_extract
1592 _M_extract(_Base_const_iterator __victim)
1594 _M_invalidate(__victim);
1595 return _Base::extract(__victim);
1600#if __cpp_deduction_guides >= 201606
1602 template<
typename _InputIterator,
1606 typename = _RequireInputIter<_InputIterator>,
1607 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1608 typename = _RequireNotAllocator<_Pred>,
1609 typename = _RequireAllocator<_Allocator>>
1611 unordered_multimap<int, int>::size_type = {},
1612 _Hash = _Hash(), _Pred = _Pred(),
1613 _Allocator = _Allocator())
1615 __iter_val_t<_InputIterator>, _Hash, _Pred,
1618 template<
typename _Key,
typename _Tp,
typename _Hash = hash<_Key>,
1619 typename _Pred = equal_to<_Key>,
1620 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1621 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1622 typename = _RequireNotAllocator<_Pred>,
1623 typename = _RequireAllocator<_Allocator>>
1626 _Hash = _Hash(), _Pred = _Pred(),
1627 _Allocator = _Allocator())
1628 -> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Allocator>;
1630 template<
typename _InputIterator,
typename _Allocator,
1631 typename = _RequireInputIter<_InputIterator>,
1632 typename = _RequireAllocator<_Allocator>>
1633 unordered_multimap(_InputIterator, _InputIterator,
1634 unordered_multimap<int, int>::size_type, _Allocator)
1635 -> unordered_multimap<__iter_key_t<_InputIterator>,
1636 __iter_val_t<_InputIterator>,
1637 hash<__iter_key_t<_InputIterator>>,
1638 equal_to<__iter_key_t<_InputIterator>>, _Allocator>;
1640 template<
typename _InputIterator,
typename _Allocator,
1641 typename = _RequireInputIter<_InputIterator>,
1642 typename = _RequireAllocator<_Allocator>>
1643 unordered_multimap(_InputIterator, _InputIterator, _Allocator)
1644 -> unordered_multimap<__iter_key_t<_InputIterator>,
1645 __iter_val_t<_InputIterator>,
1646 hash<__iter_key_t<_InputIterator>>,
1647 equal_to<__iter_key_t<_InputIterator>>, _Allocator>;
1649 template<
typename _InputIterator,
typename _Hash,
typename _Allocator,
1650 typename = _RequireInputIter<_InputIterator>,
1651 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1652 typename = _RequireAllocator<_Allocator>>
1653 unordered_multimap(_InputIterator, _InputIterator,
1654 unordered_multimap<int, int>::size_type, _Hash,
1656 -> unordered_multimap<__iter_key_t<_InputIterator>,
1657 __iter_val_t<_InputIterator>, _Hash,
1658 equal_to<__iter_key_t<_InputIterator>>, _Allocator>;
1660 template<
typename _Key,
typename _Tp,
typename _Allocator,
1661 typename = _RequireAllocator<_Allocator>>
1663 unordered_multimap<int, int>::size_type,
1665 -> unordered_multimap<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>;
1667 template<
typename _Key,
typename _Tp,
typename _Allocator,
1668 typename = _RequireAllocator<_Allocator>>
1670 -> unordered_multimap<_Key, _Tp, hash<_Key>, equal_to<_Key>, _Allocator>;
1672 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Allocator,
1673 typename = _RequireNotAllocatorOrIntegral<_Hash>,
1674 typename = _RequireAllocator<_Allocator>>
1676 unordered_multimap<int, int>::size_type,
1678 -> unordered_multimap<_Key, _Tp, _Hash, equal_to<_Key>, _Allocator>;
1680#if __glibcxx_containers_ranges
1681 template<ranges::input_range _Rg,
1682 __not_allocator_like _Hash = hash<__detail::__range_key_type<_Rg>>,
1683 __not_allocator_like _Pred = equal_to<__detail::__range_key_type<_Rg>>,
1684 __allocator_like _Allocator =
1685 allocator<__detail::__range_to_alloc_type<_Rg>>>
1686 unordered_multimap(from_range_t, _Rg&&,
1687 unordered_multimap<int, int>::size_type = {},
1688 _Hash = _Hash(), _Pred = _Pred(),
1689 _Allocator = _Allocator())
1691 __detail::__range_mapped_type<_Rg>,
1692 _Hash, _Pred, _Allocator>;
1694 template<ranges::input_range _Rg,
1695 __allocator_like _Allocator>
1699 __detail::__range_mapped_type<_Rg>,
1700 hash<__detail::__range_key_type<_Rg>>,
1701 equal_to<__detail::__range_key_type<_Rg>>,
1704 template<ranges::input_range _Rg,
1705 __allocator_like _Allocator>
1708 __detail::__range_mapped_type<_Rg>,
1709 hash<__detail::__range_key_type<_Rg>>,
1710 equal_to<__detail::__range_key_type<_Rg>>,
1713 template<ranges::input_range _Rg,
1714 __not_allocator_like _Hash,
1715 __allocator_like _Allocator>
1717 unordered_multimap<int, int>::size_type,
1720 __detail::__range_mapped_type<_Rg>,
1721 _Hash, equal_to<__detail::__range_key_type<_Rg>>,
1726 template<
typename _Key,
typename _Tp,
typename _Hash,
1727 typename _Pred,
typename _Alloc>
1731 noexcept(
noexcept(__x.swap(__y)))
1734 template<
typename _Key,
typename _Tp,
typename _Hash,
1735 typename _Pred,
typename _Alloc>
1739 {
return __x._M_base() == __y._M_base(); }
1741#if __cpp_impl_three_way_comparison < 201907L
1742 template<
typename _Key,
typename _Tp,
typename _Hash,
1743 typename _Pred,
typename _Alloc>
1747 {
return !(__x == __y); }
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
pair(_T1, _T2) -> pair< _T1, _T2 >
Two pairs are equal iff their members are equal.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
constexpr _Iterator __base(_Iterator __it)
GNU debug code, replaces standard behavior with debug behavior.
Primary class template hash.
Define a member typedef type only if a boolean constant is true.
The standard allocator, as per C++03 [20.4.1].
constexpr _Iterator & base() noexcept
Return the underlying iterator.
One of the comparison functors.
Struct holding two objects of arbitrary type.
A standard container composed of equivalent keys (possibly containing multiple of each key value) tha...
_Hashtable::size_type size_type
Iterator-related typedefs.
A standard container composed of unique keys (containing at most one of each key value) that associat...
_Hashtable::size_type size_type
Iterator-related typedefs.
Safe class dealing with some allocator dependent operations.
Base class for constructing a safe unordered container type that tracks iterators that reference it.
Class std::unordered_map with safety/checking/debug instrumentation.
Class std::unordered_multimap with safety/checking/debug instrumentation.