2 //===-------------------------- unordered_map -----------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_UNORDERED_MAP
11 #define _LIBCPP_UNORDERED_MAP
15 unordered_map synopsis
17 #include <initializer_list>
22 template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
23 class Alloc = allocator<pair<const Key, T>>>
29 typedef T mapped_type;
31 typedef Pred key_equal;
32 typedef Alloc allocator_type;
33 typedef pair<const key_type, mapped_type> value_type;
34 typedef value_type& reference;
35 typedef const value_type& const_reference;
36 typedef typename allocator_traits<allocator_type>::pointer pointer;
37 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
38 typedef typename allocator_traits<allocator_type>::size_type size_type;
39 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
41 typedef /unspecified/ iterator;
42 typedef /unspecified/ const_iterator;
43 typedef /unspecified/ local_iterator;
44 typedef /unspecified/ const_local_iterator;
46 typedef unspecified node_type; // C++17
47 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
51 is_nothrow_default_constructible<hasher>::value &&
52 is_nothrow_default_constructible<key_equal>::value &&
53 is_nothrow_default_constructible<allocator_type>::value);
54 explicit unordered_map(size_type n, const hasher& hf = hasher(),
55 const key_equal& eql = key_equal(),
56 const allocator_type& a = allocator_type());
57 template <class InputIterator>
58 unordered_map(InputIterator f, InputIterator l,
59 size_type n = 0, const hasher& hf = hasher(),
60 const key_equal& eql = key_equal(),
61 const allocator_type& a = allocator_type());
62 explicit unordered_map(const allocator_type&);
63 unordered_map(const unordered_map&);
64 unordered_map(const unordered_map&, const Allocator&);
65 unordered_map(unordered_map&&)
67 is_nothrow_move_constructible<hasher>::value &&
68 is_nothrow_move_constructible<key_equal>::value &&
69 is_nothrow_move_constructible<allocator_type>::value);
70 unordered_map(unordered_map&&, const Allocator&);
71 unordered_map(initializer_list<value_type>, size_type n = 0,
72 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
73 const allocator_type& a = allocator_type());
74 unordered_map(size_type n, const allocator_type& a)
75 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
76 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
77 : unordered_map(n, hf, key_equal(), a) {} // C++14
78 template <class InputIterator>
79 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
80 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
81 template <class InputIterator>
82 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
83 const allocator_type& a)
84 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
85 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
86 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
87 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
88 const allocator_type& a)
89 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
91 unordered_map& operator=(const unordered_map&);
92 unordered_map& operator=(unordered_map&&)
94 allocator_type::propagate_on_container_move_assignment::value &&
95 is_nothrow_move_assignable<allocator_type>::value &&
96 is_nothrow_move_assignable<hasher>::value &&
97 is_nothrow_move_assignable<key_equal>::value);
98 unordered_map& operator=(initializer_list<value_type>);
100 allocator_type get_allocator() const noexcept;
102 bool empty() const noexcept;
103 size_type size() const noexcept;
104 size_type max_size() const noexcept;
106 iterator begin() noexcept;
107 iterator end() noexcept;
108 const_iterator begin() const noexcept;
109 const_iterator end() const noexcept;
110 const_iterator cbegin() const noexcept;
111 const_iterator cend() const noexcept;
113 template <class... Args>
114 pair<iterator, bool> emplace(Args&&... args);
115 template <class... Args>
116 iterator emplace_hint(const_iterator position, Args&&... args);
117 pair<iterator, bool> insert(const value_type& obj);
119 pair<iterator, bool> insert(P&& obj);
120 iterator insert(const_iterator hint, const value_type& obj);
122 iterator insert(const_iterator hint, P&& obj);
123 template <class InputIterator>
124 void insert(InputIterator first, InputIterator last);
125 void insert(initializer_list<value_type>);
127 node_type extract(const_iterator position); // C++17
128 node_type extract(const key_type& x); // C++17
129 insert_return_type insert(node_type&& nh); // C++17
130 iterator insert(const_iterator hint, node_type&& nh); // C++17
132 template <class... Args>
133 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
134 template <class... Args>
135 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
136 template <class... Args>
137 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
138 template <class... Args>
139 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
141 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
143 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
145 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
147 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
149 iterator erase(const_iterator position);
150 iterator erase(iterator position); // C++14
151 size_type erase(const key_type& k);
152 iterator erase(const_iterator first, const_iterator last);
153 void clear() noexcept;
155 template<class H2, class P2>
156 void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
157 template<class H2, class P2>
158 void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
159 template<class H2, class P2>
160 void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17
161 template<class H2, class P2>
162 void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
164 void swap(unordered_map&)
166 (!allocator_type::propagate_on_container_swap::value ||
167 __is_nothrow_swappable<allocator_type>::value) &&
168 __is_nothrow_swappable<hasher>::value &&
169 __is_nothrow_swappable<key_equal>::value);
171 hasher hash_function() const;
172 key_equal key_eq() const;
174 iterator find(const key_type& k);
175 const_iterator find(const key_type& k) const;
176 size_type count(const key_type& k) const;
177 bool contains(const key_type& k) const; // C++20
178 pair<iterator, iterator> equal_range(const key_type& k);
179 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
181 mapped_type& operator[](const key_type& k);
182 mapped_type& operator[](key_type&& k);
184 mapped_type& at(const key_type& k);
185 const mapped_type& at(const key_type& k) const;
187 size_type bucket_count() const noexcept;
188 size_type max_bucket_count() const noexcept;
190 size_type bucket_size(size_type n) const;
191 size_type bucket(const key_type& k) const;
193 local_iterator begin(size_type n);
194 local_iterator end(size_type n);
195 const_local_iterator begin(size_type n) const;
196 const_local_iterator end(size_type n) const;
197 const_local_iterator cbegin(size_type n) const;
198 const_local_iterator cend(size_type n) const;
200 float load_factor() const noexcept;
201 float max_load_factor() const noexcept;
202 void max_load_factor(float z);
203 void rehash(size_type n);
204 void reserve(size_type n);
207 template <class Key, class T, class Hash, class Pred, class Alloc>
208 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
209 unordered_map<Key, T, Hash, Pred, Alloc>& y)
210 noexcept(noexcept(x.swap(y)));
212 template <class Key, class T, class Hash, class Pred, class Alloc>
214 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
215 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
217 template <class Key, class T, class Hash, class Pred, class Alloc>
219 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
220 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
222 template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
223 class Alloc = allocator<pair<const Key, T>>>
224 class unordered_multimap
228 typedef Key key_type;
229 typedef T mapped_type;
231 typedef Pred key_equal;
232 typedef Alloc allocator_type;
233 typedef pair<const key_type, mapped_type> value_type;
234 typedef value_type& reference;
235 typedef const value_type& const_reference;
236 typedef typename allocator_traits<allocator_type>::pointer pointer;
237 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
238 typedef typename allocator_traits<allocator_type>::size_type size_type;
239 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
241 typedef /unspecified/ iterator;
242 typedef /unspecified/ const_iterator;
243 typedef /unspecified/ local_iterator;
244 typedef /unspecified/ const_local_iterator;
246 typedef unspecified node_type; // C++17
250 is_nothrow_default_constructible<hasher>::value &&
251 is_nothrow_default_constructible<key_equal>::value &&
252 is_nothrow_default_constructible<allocator_type>::value);
253 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
254 const key_equal& eql = key_equal(),
255 const allocator_type& a = allocator_type());
256 template <class InputIterator>
257 unordered_multimap(InputIterator f, InputIterator l,
258 size_type n = 0, const hasher& hf = hasher(),
259 const key_equal& eql = key_equal(),
260 const allocator_type& a = allocator_type());
261 explicit unordered_multimap(const allocator_type&);
262 unordered_multimap(const unordered_multimap&);
263 unordered_multimap(const unordered_multimap&, const Allocator&);
264 unordered_multimap(unordered_multimap&&)
266 is_nothrow_move_constructible<hasher>::value &&
267 is_nothrow_move_constructible<key_equal>::value &&
268 is_nothrow_move_constructible<allocator_type>::value);
269 unordered_multimap(unordered_multimap&&, const Allocator&);
270 unordered_multimap(initializer_list<value_type>, size_type n = 0,
271 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
272 const allocator_type& a = allocator_type());
273 unordered_multimap(size_type n, const allocator_type& a)
274 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
275 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
276 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
277 template <class InputIterator>
278 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
279 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
280 template <class InputIterator>
281 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
282 const allocator_type& a)
283 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
284 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
285 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
286 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
287 const allocator_type& a)
288 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
289 ~unordered_multimap();
290 unordered_multimap& operator=(const unordered_multimap&);
291 unordered_multimap& operator=(unordered_multimap&&)
293 allocator_type::propagate_on_container_move_assignment::value &&
294 is_nothrow_move_assignable<allocator_type>::value &&
295 is_nothrow_move_assignable<hasher>::value &&
296 is_nothrow_move_assignable<key_equal>::value);
297 unordered_multimap& operator=(initializer_list<value_type>);
299 allocator_type get_allocator() const noexcept;
301 bool empty() const noexcept;
302 size_type size() const noexcept;
303 size_type max_size() const noexcept;
305 iterator begin() noexcept;
306 iterator end() noexcept;
307 const_iterator begin() const noexcept;
308 const_iterator end() const noexcept;
309 const_iterator cbegin() const noexcept;
310 const_iterator cend() const noexcept;
312 template <class... Args>
313 iterator emplace(Args&&... args);
314 template <class... Args>
315 iterator emplace_hint(const_iterator position, Args&&... args);
316 iterator insert(const value_type& obj);
318 iterator insert(P&& obj);
319 iterator insert(const_iterator hint, const value_type& obj);
321 iterator insert(const_iterator hint, P&& obj);
322 template <class InputIterator>
323 void insert(InputIterator first, InputIterator last);
324 void insert(initializer_list<value_type>);
326 node_type extract(const_iterator position); // C++17
327 node_type extract(const key_type& x); // C++17
328 iterator insert(node_type&& nh); // C++17
329 iterator insert(const_iterator hint, node_type&& nh); // C++17
331 iterator erase(const_iterator position);
332 iterator erase(iterator position); // C++14
333 size_type erase(const key_type& k);
334 iterator erase(const_iterator first, const_iterator last);
335 void clear() noexcept;
337 template<class H2, class P2>
338 void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17
339 template<class H2, class P2>
340 void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
341 template<class H2, class P2>
342 void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
343 template<class H2, class P2>
344 void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
346 void swap(unordered_multimap&)
348 (!allocator_type::propagate_on_container_swap::value ||
349 __is_nothrow_swappable<allocator_type>::value) &&
350 __is_nothrow_swappable<hasher>::value &&
351 __is_nothrow_swappable<key_equal>::value);
353 hasher hash_function() const;
354 key_equal key_eq() const;
356 iterator find(const key_type& k);
357 const_iterator find(const key_type& k) const;
358 size_type count(const key_type& k) const;
359 bool contains(const key_type& k) const; // C++20
360 pair<iterator, iterator> equal_range(const key_type& k);
361 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
363 size_type bucket_count() const noexcept;
364 size_type max_bucket_count() const noexcept;
366 size_type bucket_size(size_type n) const;
367 size_type bucket(const key_type& k) const;
369 local_iterator begin(size_type n);
370 local_iterator end(size_type n);
371 const_local_iterator begin(size_type n) const;
372 const_local_iterator end(size_type n) const;
373 const_local_iterator cbegin(size_type n) const;
374 const_local_iterator cend(size_type n) const;
376 float load_factor() const noexcept;
377 float max_load_factor() const noexcept;
378 void max_load_factor(float z);
379 void rehash(size_type n);
380 void reserve(size_type n);
383 template <class Key, class T, class Hash, class Pred, class Alloc>
384 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
385 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
386 noexcept(noexcept(x.swap(y)));
388 template <class K, class T, class H, class P, class A, class Predicate>
389 typename unordered_map<K, T, H, P, A>::size_type
390 erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred); // C++20
392 template <class K, class T, class H, class P, class A, class Predicate>
393 typename unordered_multimap<K, T, H, P, A>::size_type
394 erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred); // C++20
396 template <class Key, class T, class Hash, class Pred, class Alloc>
398 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
399 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
401 template <class Key, class T, class Hash, class Pred, class Alloc>
403 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
404 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
411 #include <__hash_table>
412 #include <__node_handle>
413 #include <functional>
420 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
421 #pragma GCC system_header
424 _LIBCPP_BEGIN_NAMESPACE_STD
426 template <class _Key, class _Cp, class _Hash,
427 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
428 class __unordered_map_hasher
432 _LIBCPP_INLINE_VISIBILITY
433 __unordered_map_hasher()
434 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
436 _LIBCPP_INLINE_VISIBILITY
437 __unordered_map_hasher(const _Hash& __h)
438 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
440 _LIBCPP_INLINE_VISIBILITY
441 const _Hash& hash_function() const _NOEXCEPT {return *this;}
442 _LIBCPP_INLINE_VISIBILITY
443 size_t operator()(const _Cp& __x) const
444 {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
445 _LIBCPP_INLINE_VISIBILITY
446 size_t operator()(const _Key& __x) const
447 {return static_cast<const _Hash&>(*this)(__x);}
448 void swap(__unordered_map_hasher&__y)
449 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
452 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
456 template <class _Key, class _Cp, class _Hash>
457 class __unordered_map_hasher<_Key, _Cp, _Hash, false>
461 _LIBCPP_INLINE_VISIBILITY
462 __unordered_map_hasher()
463 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
465 _LIBCPP_INLINE_VISIBILITY
466 __unordered_map_hasher(const _Hash& __h)
467 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
469 _LIBCPP_INLINE_VISIBILITY
470 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
471 _LIBCPP_INLINE_VISIBILITY
472 size_t operator()(const _Cp& __x) const
473 {return __hash_(__x.__get_value().first);}
474 _LIBCPP_INLINE_VISIBILITY
475 size_t operator()(const _Key& __x) const
476 {return __hash_(__x);}
477 void swap(__unordered_map_hasher&__y)
478 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
481 swap(__hash_, __y.__hash_);
485 template <class _Key, class _Cp, class _Hash, bool __b>
486 inline _LIBCPP_INLINE_VISIBILITY
488 swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
489 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
490 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
495 template <class _Key, class _Cp, class _Pred,
496 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value>
497 class __unordered_map_equal
501 _LIBCPP_INLINE_VISIBILITY
502 __unordered_map_equal()
503 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
505 _LIBCPP_INLINE_VISIBILITY
506 __unordered_map_equal(const _Pred& __p)
507 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
509 _LIBCPP_INLINE_VISIBILITY
510 const _Pred& key_eq() const _NOEXCEPT {return *this;}
511 _LIBCPP_INLINE_VISIBILITY
512 bool operator()(const _Cp& __x, const _Cp& __y) const
513 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
514 _LIBCPP_INLINE_VISIBILITY
515 bool operator()(const _Cp& __x, const _Key& __y) const
516 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
517 _LIBCPP_INLINE_VISIBILITY
518 bool operator()(const _Key& __x, const _Cp& __y) const
519 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
520 void swap(__unordered_map_equal&__y)
521 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
524 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
528 template <class _Key, class _Cp, class _Pred>
529 class __unordered_map_equal<_Key, _Cp, _Pred, false>
533 _LIBCPP_INLINE_VISIBILITY
534 __unordered_map_equal()
535 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
537 _LIBCPP_INLINE_VISIBILITY
538 __unordered_map_equal(const _Pred& __p)
539 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
541 _LIBCPP_INLINE_VISIBILITY
542 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
543 _LIBCPP_INLINE_VISIBILITY
544 bool operator()(const _Cp& __x, const _Cp& __y) const
545 {return __pred_(__x.__get_value().first, __y.__get_value().first);}
546 _LIBCPP_INLINE_VISIBILITY
547 bool operator()(const _Cp& __x, const _Key& __y) const
548 {return __pred_(__x.__get_value().first, __y);}
549 _LIBCPP_INLINE_VISIBILITY
550 bool operator()(const _Key& __x, const _Cp& __y) const
551 {return __pred_(__x, __y.__get_value().first);}
552 void swap(__unordered_map_equal&__y)
553 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
556 swap(__pred_, __y.__pred_);
560 template <class _Key, class _Cp, class _Pred, bool __b>
561 inline _LIBCPP_INLINE_VISIBILITY
563 swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
564 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
565 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
570 template <class _Alloc>
571 class __hash_map_node_destructor
573 typedef _Alloc allocator_type;
574 typedef allocator_traits<allocator_type> __alloc_traits;
578 typedef typename __alloc_traits::pointer pointer;
581 allocator_type& __na_;
583 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
586 bool __first_constructed;
587 bool __second_constructed;
589 _LIBCPP_INLINE_VISIBILITY
590 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
592 __first_constructed(false),
593 __second_constructed(false)
596 #ifndef _LIBCPP_CXX03_LANG
597 _LIBCPP_INLINE_VISIBILITY
598 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
601 __first_constructed(__x.__value_constructed),
602 __second_constructed(__x.__value_constructed)
604 __x.__value_constructed = false;
606 #else // _LIBCPP_CXX03_LANG
607 _LIBCPP_INLINE_VISIBILITY
608 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
610 __first_constructed(__x.__value_constructed),
611 __second_constructed(__x.__value_constructed)
613 const_cast<bool&>(__x.__value_constructed) = false;
615 #endif // _LIBCPP_CXX03_LANG
617 _LIBCPP_INLINE_VISIBILITY
618 void operator()(pointer __p) _NOEXCEPT
620 if (__second_constructed)
621 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
622 if (__first_constructed)
623 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
625 __alloc_traits::deallocate(__na_, __p, 1);
629 #ifndef _LIBCPP_CXX03_LANG
630 template <class _Key, class _Tp>
631 struct __hash_value_type
633 typedef _Key key_type;
634 typedef _Tp mapped_type;
635 typedef pair<const key_type, mapped_type> value_type;
636 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
637 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
643 _LIBCPP_INLINE_VISIBILITY
644 value_type& __get_value()
646 #if _LIBCPP_STD_VER > 14
647 return *_VSTD::launder(_VSTD::addressof(__cc));
653 _LIBCPP_INLINE_VISIBILITY
654 const value_type& __get_value() const
656 #if _LIBCPP_STD_VER > 14
657 return *_VSTD::launder(_VSTD::addressof(__cc));
663 _LIBCPP_INLINE_VISIBILITY
664 __nc_ref_pair_type __ref()
666 value_type& __v = __get_value();
667 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
670 _LIBCPP_INLINE_VISIBILITY
671 __nc_rref_pair_type __move()
673 value_type& __v = __get_value();
674 return __nc_rref_pair_type(
675 _VSTD::move(const_cast<key_type&>(__v.first)),
676 _VSTD::move(__v.second));
679 _LIBCPP_INLINE_VISIBILITY
680 __hash_value_type& operator=(const __hash_value_type& __v)
682 __ref() = __v.__get_value();
686 _LIBCPP_INLINE_VISIBILITY
687 __hash_value_type& operator=(__hash_value_type&& __v)
689 __ref() = __v.__move();
693 template <class _ValueTp,
694 class = typename enable_if<
695 __is_same_uncvref<_ValueTp, value_type>::value
698 _LIBCPP_INLINE_VISIBILITY
699 __hash_value_type& operator=(_ValueTp&& __v)
701 __ref() = _VSTD::forward<_ValueTp>(__v);
706 __hash_value_type(const __hash_value_type& __v) = delete;
707 __hash_value_type(__hash_value_type&& __v) = delete;
708 template <class ..._Args>
709 explicit __hash_value_type(_Args&& ...__args) = delete;
711 ~__hash_value_type() = delete;
716 template <class _Key, class _Tp>
717 struct __hash_value_type
719 typedef _Key key_type;
720 typedef _Tp mapped_type;
721 typedef pair<const key_type, mapped_type> value_type;
727 _LIBCPP_INLINE_VISIBILITY
728 value_type& __get_value() { return __cc; }
729 _LIBCPP_INLINE_VISIBILITY
730 const value_type& __get_value() const { return __cc; }
733 ~__hash_value_type();
738 template <class _HashIterator>
739 class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
743 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
746 typedef forward_iterator_tag iterator_category;
747 typedef typename _NodeTypes::__map_value_type value_type;
748 typedef typename _NodeTypes::difference_type difference_type;
749 typedef value_type& reference;
750 typedef typename _NodeTypes::__map_value_type_pointer pointer;
752 _LIBCPP_INLINE_VISIBILITY
753 __hash_map_iterator() _NOEXCEPT {}
755 _LIBCPP_INLINE_VISIBILITY
756 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
758 _LIBCPP_INLINE_VISIBILITY
759 reference operator*() const {return __i_->__get_value();}
760 _LIBCPP_INLINE_VISIBILITY
761 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
763 _LIBCPP_INLINE_VISIBILITY
764 __hash_map_iterator& operator++() {++__i_; return *this;}
765 _LIBCPP_INLINE_VISIBILITY
766 __hash_map_iterator operator++(int)
768 __hash_map_iterator __t(*this);
773 friend _LIBCPP_INLINE_VISIBILITY
774 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
775 {return __x.__i_ == __y.__i_;}
776 friend _LIBCPP_INLINE_VISIBILITY
777 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
778 {return __x.__i_ != __y.__i_;}
780 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
781 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
782 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
783 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
784 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
787 template <class _HashIterator>
788 class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
792 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
795 typedef forward_iterator_tag iterator_category;
796 typedef typename _NodeTypes::__map_value_type value_type;
797 typedef typename _NodeTypes::difference_type difference_type;
798 typedef const value_type& reference;
799 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
801 _LIBCPP_INLINE_VISIBILITY
802 __hash_map_const_iterator() _NOEXCEPT {}
804 _LIBCPP_INLINE_VISIBILITY
805 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
806 _LIBCPP_INLINE_VISIBILITY
807 __hash_map_const_iterator(
808 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
812 _LIBCPP_INLINE_VISIBILITY
813 reference operator*() const {return __i_->__get_value();}
814 _LIBCPP_INLINE_VISIBILITY
815 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
817 _LIBCPP_INLINE_VISIBILITY
818 __hash_map_const_iterator& operator++() {++__i_; return *this;}
819 _LIBCPP_INLINE_VISIBILITY
820 __hash_map_const_iterator operator++(int)
822 __hash_map_const_iterator __t(*this);
827 friend _LIBCPP_INLINE_VISIBILITY
828 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
829 {return __x.__i_ == __y.__i_;}
830 friend _LIBCPP_INLINE_VISIBILITY
831 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
832 {return __x.__i_ != __y.__i_;}
834 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
835 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
836 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
837 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
840 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
841 class unordered_multimap;
843 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
844 class _Alloc = allocator<pair<const _Key, _Tp> > >
845 class _LIBCPP_TEMPLATE_VIS unordered_map
849 typedef _Key key_type;
850 typedef _Tp mapped_type;
851 typedef typename __identity<_Hash>::type hasher;
852 typedef typename __identity<_Pred>::type key_equal;
853 typedef typename __identity<_Alloc>::type allocator_type;
854 typedef pair<const key_type, mapped_type> value_type;
855 typedef value_type& reference;
856 typedef const value_type& const_reference;
857 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
858 "Invalid allocator::value_type");
861 typedef __hash_value_type<key_type, mapped_type> __value_type;
862 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
863 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
864 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
865 __value_type>::type __allocator_type;
867 typedef __hash_table<__value_type, __hasher,
868 __key_equal, __allocator_type> __table;
872 typedef typename __table::_NodeTypes _NodeTypes;
873 typedef typename __table::__node_pointer __node_pointer;
874 typedef typename __table::__node_const_pointer __node_const_pointer;
875 typedef typename __table::__node_traits __node_traits;
876 typedef typename __table::__node_allocator __node_allocator;
877 typedef typename __table::__node __node;
878 typedef __hash_map_node_destructor<__node_allocator> _Dp;
879 typedef unique_ptr<__node, _Dp> __node_holder;
880 typedef allocator_traits<allocator_type> __alloc_traits;
882 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
883 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
885 typedef typename __alloc_traits::pointer pointer;
886 typedef typename __alloc_traits::const_pointer const_pointer;
887 typedef typename __table::size_type size_type;
888 typedef typename __table::difference_type difference_type;
890 typedef __hash_map_iterator<typename __table::iterator> iterator;
891 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
892 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
893 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
895 #if _LIBCPP_STD_VER > 14
896 typedef __map_node_handle<__node, allocator_type> node_type;
897 typedef __insert_return_type<iterator, node_type> insert_return_type;
900 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
901 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
902 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
903 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
905 _LIBCPP_INLINE_VISIBILITY
907 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
909 #if _LIBCPP_DEBUG_LEVEL >= 2
910 __get_db()->__insert_c(this);
913 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
914 const key_equal& __eql = key_equal());
915 unordered_map(size_type __n, const hasher& __hf,
916 const key_equal& __eql,
917 const allocator_type& __a);
918 template <class _InputIterator>
919 unordered_map(_InputIterator __first, _InputIterator __last);
920 template <class _InputIterator>
921 unordered_map(_InputIterator __first, _InputIterator __last,
922 size_type __n, const hasher& __hf = hasher(),
923 const key_equal& __eql = key_equal());
924 template <class _InputIterator>
925 unordered_map(_InputIterator __first, _InputIterator __last,
926 size_type __n, const hasher& __hf,
927 const key_equal& __eql,
928 const allocator_type& __a);
929 _LIBCPP_INLINE_VISIBILITY
930 explicit unordered_map(const allocator_type& __a);
931 unordered_map(const unordered_map& __u);
932 unordered_map(const unordered_map& __u, const allocator_type& __a);
933 #ifndef _LIBCPP_CXX03_LANG
934 _LIBCPP_INLINE_VISIBILITY
935 unordered_map(unordered_map&& __u)
936 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
937 unordered_map(unordered_map&& __u, const allocator_type& __a);
938 unordered_map(initializer_list<value_type> __il);
939 unordered_map(initializer_list<value_type> __il, size_type __n,
940 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
941 unordered_map(initializer_list<value_type> __il, size_type __n,
942 const hasher& __hf, const key_equal& __eql,
943 const allocator_type& __a);
944 #endif // _LIBCPP_CXX03_LANG
945 #if _LIBCPP_STD_VER > 11
946 _LIBCPP_INLINE_VISIBILITY
947 unordered_map(size_type __n, const allocator_type& __a)
948 : unordered_map(__n, hasher(), key_equal(), __a) {}
949 _LIBCPP_INLINE_VISIBILITY
950 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
951 : unordered_map(__n, __hf, key_equal(), __a) {}
952 template <class _InputIterator>
953 _LIBCPP_INLINE_VISIBILITY
954 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
955 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
956 template <class _InputIterator>
957 _LIBCPP_INLINE_VISIBILITY
958 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
959 const allocator_type& __a)
960 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
961 _LIBCPP_INLINE_VISIBILITY
962 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
963 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
964 _LIBCPP_INLINE_VISIBILITY
965 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
966 const allocator_type& __a)
967 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
969 _LIBCPP_INLINE_VISIBILITY
971 static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
974 _LIBCPP_INLINE_VISIBILITY
975 unordered_map& operator=(const unordered_map& __u)
977 #ifndef _LIBCPP_CXX03_LANG
978 __table_ = __u.__table_;
982 __table_.hash_function() = __u.__table_.hash_function();
983 __table_.key_eq() = __u.__table_.key_eq();
984 __table_.max_load_factor() = __u.__table_.max_load_factor();
985 __table_.__copy_assign_alloc(__u.__table_);
986 insert(__u.begin(), __u.end());
991 #ifndef _LIBCPP_CXX03_LANG
992 _LIBCPP_INLINE_VISIBILITY
993 unordered_map& operator=(unordered_map&& __u)
994 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
995 _LIBCPP_INLINE_VISIBILITY
996 unordered_map& operator=(initializer_list<value_type> __il);
997 #endif // _LIBCPP_CXX03_LANG
999 _LIBCPP_INLINE_VISIBILITY
1000 allocator_type get_allocator() const _NOEXCEPT
1001 {return allocator_type(__table_.__node_alloc());}
1003 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1004 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
1005 _LIBCPP_INLINE_VISIBILITY
1006 size_type size() const _NOEXCEPT {return __table_.size();}
1007 _LIBCPP_INLINE_VISIBILITY
1008 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1010 _LIBCPP_INLINE_VISIBILITY
1011 iterator begin() _NOEXCEPT {return __table_.begin();}
1012 _LIBCPP_INLINE_VISIBILITY
1013 iterator end() _NOEXCEPT {return __table_.end();}
1014 _LIBCPP_INLINE_VISIBILITY
1015 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
1016 _LIBCPP_INLINE_VISIBILITY
1017 const_iterator end() const _NOEXCEPT {return __table_.end();}
1018 _LIBCPP_INLINE_VISIBILITY
1019 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1020 _LIBCPP_INLINE_VISIBILITY
1021 const_iterator cend() const _NOEXCEPT {return __table_.end();}
1023 _LIBCPP_INLINE_VISIBILITY
1024 pair<iterator, bool> insert(const value_type& __x)
1025 {return __table_.__insert_unique(__x);}
1027 iterator insert(const_iterator __p, const value_type& __x) {
1028 #if _LIBCPP_DEBUG_LEVEL >= 2
1029 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1030 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1031 " referring to this unordered_map");
1035 return insert(__x).first;
1038 template <class _InputIterator>
1039 _LIBCPP_INLINE_VISIBILITY
1040 void insert(_InputIterator __first, _InputIterator __last);
1042 #ifndef _LIBCPP_CXX03_LANG
1043 _LIBCPP_INLINE_VISIBILITY
1044 void insert(initializer_list<value_type> __il)
1045 {insert(__il.begin(), __il.end());}
1047 _LIBCPP_INLINE_VISIBILITY
1048 pair<iterator, bool> insert(value_type&& __x)
1049 {return __table_.__insert_unique(_VSTD::move(__x));}
1051 iterator insert(const_iterator __p, value_type&& __x) {
1052 #if _LIBCPP_DEBUG_LEVEL >= 2
1053 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1054 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1055 " referring to this unordered_map");
1059 return __table_.__insert_unique(_VSTD::move(__x)).first;
1062 template <class _Pp,
1063 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1064 _LIBCPP_INLINE_VISIBILITY
1065 pair<iterator, bool> insert(_Pp&& __x)
1066 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
1068 template <class _Pp,
1069 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1070 _LIBCPP_INLINE_VISIBILITY
1071 iterator insert(const_iterator __p, _Pp&& __x)
1073 #if _LIBCPP_DEBUG_LEVEL >= 2
1074 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1075 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1076 " referring to this unordered_map");
1080 return insert(_VSTD::forward<_Pp>(__x)).first;
1083 template <class... _Args>
1084 _LIBCPP_INLINE_VISIBILITY
1085 pair<iterator, bool> emplace(_Args&&... __args) {
1086 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1089 template <class... _Args>
1090 _LIBCPP_INLINE_VISIBILITY
1091 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1092 #if _LIBCPP_DEBUG_LEVEL >= 2
1093 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1094 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1095 " referring to this unordered_map");
1099 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
1102 #endif // _LIBCPP_CXX03_LANG
1104 #if _LIBCPP_STD_VER > 14
1105 template <class... _Args>
1106 _LIBCPP_INLINE_VISIBILITY
1107 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1109 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1110 _VSTD::forward_as_tuple(__k),
1111 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1114 template <class... _Args>
1115 _LIBCPP_INLINE_VISIBILITY
1116 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1118 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1119 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1120 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1123 template <class... _Args>
1124 _LIBCPP_INLINE_VISIBILITY
1125 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1127 #if _LIBCPP_DEBUG_LEVEL >= 2
1128 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1129 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1130 " referring to this unordered_map");
1134 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
1137 template <class... _Args>
1138 _LIBCPP_INLINE_VISIBILITY
1139 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1141 #if _LIBCPP_DEBUG_LEVEL >= 2
1142 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1143 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1144 " referring to this unordered_map");
1148 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
1151 template <class _Vp>
1152 _LIBCPP_INLINE_VISIBILITY
1153 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1155 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1156 __k, _VSTD::forward<_Vp>(__v));
1157 if (!__res.second) {
1158 __res.first->second = _VSTD::forward<_Vp>(__v);
1163 template <class _Vp>
1164 _LIBCPP_INLINE_VISIBILITY
1165 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1167 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1168 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1169 if (!__res.second) {
1170 __res.first->second = _VSTD::forward<_Vp>(__v);
1175 template <class _Vp>
1176 _LIBCPP_INLINE_VISIBILITY
1177 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
1179 // FIXME: Add debug mode checking for the iterator input
1180 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
1183 template <class _Vp>
1184 _LIBCPP_INLINE_VISIBILITY
1185 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
1187 // FIXME: Add debug mode checking for the iterator input
1188 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
1190 #endif // _LIBCPP_STD_VER > 14
1192 _LIBCPP_INLINE_VISIBILITY
1193 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
1194 _LIBCPP_INLINE_VISIBILITY
1195 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1196 _LIBCPP_INLINE_VISIBILITY
1197 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
1198 _LIBCPP_INLINE_VISIBILITY
1199 iterator erase(const_iterator __first, const_iterator __last)
1200 {return __table_.erase(__first.__i_, __last.__i_);}
1201 _LIBCPP_INLINE_VISIBILITY
1202 void clear() _NOEXCEPT {__table_.clear();}
1204 #if _LIBCPP_STD_VER > 14
1205 _LIBCPP_INLINE_VISIBILITY
1206 insert_return_type insert(node_type&& __nh)
1208 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1209 "node_type with incompatible allocator passed to unordered_map::insert()");
1210 return __table_.template __node_handle_insert_unique<
1211 node_type, insert_return_type>(_VSTD::move(__nh));
1213 _LIBCPP_INLINE_VISIBILITY
1214 iterator insert(const_iterator __hint, node_type&& __nh)
1216 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1217 "node_type with incompatible allocator passed to unordered_map::insert()");
1218 return __table_.template __node_handle_insert_unique<node_type>(
1219 __hint.__i_, _VSTD::move(__nh));
1221 _LIBCPP_INLINE_VISIBILITY
1222 node_type extract(key_type const& __key)
1224 return __table_.template __node_handle_extract<node_type>(__key);
1226 _LIBCPP_INLINE_VISIBILITY
1227 node_type extract(const_iterator __it)
1229 return __table_.template __node_handle_extract<node_type>(
1233 template <class _H2, class _P2>
1234 _LIBCPP_INLINE_VISIBILITY
1235 void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
1237 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1238 "merging container with incompatible allocator");
1239 return __table_.__node_handle_merge_unique(__source.__table_);
1241 template <class _H2, class _P2>
1242 _LIBCPP_INLINE_VISIBILITY
1243 void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
1245 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1246 "merging container with incompatible allocator");
1247 return __table_.__node_handle_merge_unique(__source.__table_);
1249 template <class _H2, class _P2>
1250 _LIBCPP_INLINE_VISIBILITY
1251 void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
1253 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1254 "merging container with incompatible allocator");
1255 return __table_.__node_handle_merge_unique(__source.__table_);
1257 template <class _H2, class _P2>
1258 _LIBCPP_INLINE_VISIBILITY
1259 void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
1261 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1262 "merging container with incompatible allocator");
1263 return __table_.__node_handle_merge_unique(__source.__table_);
1267 _LIBCPP_INLINE_VISIBILITY
1268 void swap(unordered_map& __u)
1269 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1270 { __table_.swap(__u.__table_);}
1272 _LIBCPP_INLINE_VISIBILITY
1273 hasher hash_function() const
1274 {return __table_.hash_function().hash_function();}
1275 _LIBCPP_INLINE_VISIBILITY
1276 key_equal key_eq() const
1277 {return __table_.key_eq().key_eq();}
1279 _LIBCPP_INLINE_VISIBILITY
1280 iterator find(const key_type& __k) {return __table_.find(__k);}
1281 _LIBCPP_INLINE_VISIBILITY
1282 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1283 _LIBCPP_INLINE_VISIBILITY
1284 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
1285 #if _LIBCPP_STD_VER > 17
1286 _LIBCPP_INLINE_VISIBILITY
1287 bool contains(const key_type& __k) const {return find(__k) != end();}
1288 #endif // _LIBCPP_STD_VER > 17
1289 _LIBCPP_INLINE_VISIBILITY
1290 pair<iterator, iterator> equal_range(const key_type& __k)
1291 {return __table_.__equal_range_unique(__k);}
1292 _LIBCPP_INLINE_VISIBILITY
1293 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1294 {return __table_.__equal_range_unique(__k);}
1296 mapped_type& operator[](const key_type& __k);
1297 #ifndef _LIBCPP_CXX03_LANG
1298 mapped_type& operator[](key_type&& __k);
1301 mapped_type& at(const key_type& __k);
1302 const mapped_type& at(const key_type& __k) const;
1304 _LIBCPP_INLINE_VISIBILITY
1305 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1306 _LIBCPP_INLINE_VISIBILITY
1307 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
1309 _LIBCPP_INLINE_VISIBILITY
1310 size_type bucket_size(size_type __n) const
1311 {return __table_.bucket_size(__n);}
1312 _LIBCPP_INLINE_VISIBILITY
1313 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1315 _LIBCPP_INLINE_VISIBILITY
1316 local_iterator begin(size_type __n) {return __table_.begin(__n);}
1317 _LIBCPP_INLINE_VISIBILITY
1318 local_iterator end(size_type __n) {return __table_.end(__n);}
1319 _LIBCPP_INLINE_VISIBILITY
1320 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
1321 _LIBCPP_INLINE_VISIBILITY
1322 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
1323 _LIBCPP_INLINE_VISIBILITY
1324 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1325 _LIBCPP_INLINE_VISIBILITY
1326 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1328 _LIBCPP_INLINE_VISIBILITY
1329 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1330 _LIBCPP_INLINE_VISIBILITY
1331 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1332 _LIBCPP_INLINE_VISIBILITY
1333 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1334 _LIBCPP_INLINE_VISIBILITY
1335 void rehash(size_type __n) {__table_.rehash(__n);}
1336 _LIBCPP_INLINE_VISIBILITY
1337 void reserve(size_type __n) {__table_.reserve(__n);}
1339 #if _LIBCPP_DEBUG_LEVEL >= 2
1341 bool __dereferenceable(const const_iterator* __i) const
1342 {return __table_.__dereferenceable(&__i->__i_);}
1343 bool __decrementable(const const_iterator* __i) const
1344 {return __table_.__decrementable(&__i->__i_);}
1345 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1346 {return __table_.__addable(&__i->__i_, __n);}
1347 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1348 {return __table_.__addable(&__i->__i_, __n);}
1350 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1354 #ifdef _LIBCPP_CXX03_LANG
1355 __node_holder __construct_node_with_key(const key_type& __k);
1359 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1360 template<class _InputIterator,
1361 class _Hash = hash<__iter_key_type<_InputIterator>>,
1362 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
1363 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1364 class = _EnableIf<!__is_allocator<_Hash>::value>,
1365 class = _EnableIf<!is_integral<_Hash>::value>,
1366 class = _EnableIf<!__is_allocator<_Pred>::value>,
1367 class = _EnableIf<__is_allocator<_Allocator>::value>>
1368 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
1369 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1370 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
1372 template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
1373 class _Pred = equal_to<remove_const_t<_Key>>,
1374 class _Allocator = allocator<pair<const _Key, _Tp>>,
1375 class = _EnableIf<!__is_allocator<_Hash>::value>,
1376 class = _EnableIf<!is_integral<_Hash>::value>,
1377 class = _EnableIf<!__is_allocator<_Pred>::value>,
1378 class = _EnableIf<__is_allocator<_Allocator>::value>>
1379 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
1380 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1381 -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
1383 template<class _InputIterator, class _Allocator,
1384 class = _EnableIf<__is_allocator<_Allocator>::value>>
1385 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
1386 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1387 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1389 template<class _InputIterator, class _Allocator,
1390 class = _EnableIf<__is_allocator<_Allocator>::value>>
1391 unordered_map(_InputIterator, _InputIterator, _Allocator)
1392 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1393 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1395 template<class _InputIterator, class _Hash, class _Allocator,
1396 class = _EnableIf<!__is_allocator<_Hash>::value>,
1397 class = _EnableIf<!is_integral<_Hash>::value>,
1398 class = _EnableIf<__is_allocator<_Allocator>::value>>
1399 unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1400 -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1401 _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1403 template<class _Key, class _Tp, class _Allocator,
1404 class = _EnableIf<__is_allocator<_Allocator>::value>>
1405 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
1406 -> unordered_map<remove_const_t<_Key>, _Tp,
1407 hash<remove_const_t<_Key>>,
1408 equal_to<remove_const_t<_Key>>, _Allocator>;
1410 template<class _Key, class _Tp, class _Allocator,
1411 class = _EnableIf<__is_allocator<_Allocator>::value>>
1412 unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1413 -> unordered_map<remove_const_t<_Key>, _Tp,
1414 hash<remove_const_t<_Key>>,
1415 equal_to<remove_const_t<_Key>>, _Allocator>;
1417 template<class _Key, class _Tp, class _Hash, class _Allocator,
1418 class = _EnableIf<!__is_allocator<_Hash>::value>,
1419 class = _EnableIf<!is_integral<_Hash>::value>,
1420 class = _EnableIf<__is_allocator<_Allocator>::value>>
1421 unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1422 -> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
1423 equal_to<remove_const_t<_Key>>, _Allocator>;
1426 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1427 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1428 size_type __n, const hasher& __hf, const key_equal& __eql)
1429 : __table_(__hf, __eql)
1431 #if _LIBCPP_DEBUG_LEVEL >= 2
1432 __get_db()->__insert_c(this);
1434 __table_.rehash(__n);
1437 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1438 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1439 size_type __n, const hasher& __hf, const key_equal& __eql,
1440 const allocator_type& __a)
1441 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1443 #if _LIBCPP_DEBUG_LEVEL >= 2
1444 __get_db()->__insert_c(this);
1446 __table_.rehash(__n);
1449 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1451 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1452 const allocator_type& __a)
1453 : __table_(typename __table::allocator_type(__a))
1455 #if _LIBCPP_DEBUG_LEVEL >= 2
1456 __get_db()->__insert_c(this);
1460 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1461 template <class _InputIterator>
1462 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1463 _InputIterator __first, _InputIterator __last)
1465 #if _LIBCPP_DEBUG_LEVEL >= 2
1466 __get_db()->__insert_c(this);
1468 insert(__first, __last);
1471 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1472 template <class _InputIterator>
1473 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1474 _InputIterator __first, _InputIterator __last, size_type __n,
1475 const hasher& __hf, const key_equal& __eql)
1476 : __table_(__hf, __eql)
1478 #if _LIBCPP_DEBUG_LEVEL >= 2
1479 __get_db()->__insert_c(this);
1481 __table_.rehash(__n);
1482 insert(__first, __last);
1485 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1486 template <class _InputIterator>
1487 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1488 _InputIterator __first, _InputIterator __last, size_type __n,
1489 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1490 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1492 #if _LIBCPP_DEBUG_LEVEL >= 2
1493 __get_db()->__insert_c(this);
1495 __table_.rehash(__n);
1496 insert(__first, __last);
1499 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1500 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1501 const unordered_map& __u)
1502 : __table_(__u.__table_)
1504 #if _LIBCPP_DEBUG_LEVEL >= 2
1505 __get_db()->__insert_c(this);
1507 __table_.rehash(__u.bucket_count());
1508 insert(__u.begin(), __u.end());
1511 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1512 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1513 const unordered_map& __u, const allocator_type& __a)
1514 : __table_(__u.__table_, typename __table::allocator_type(__a))
1516 #if _LIBCPP_DEBUG_LEVEL >= 2
1517 __get_db()->__insert_c(this);
1519 __table_.rehash(__u.bucket_count());
1520 insert(__u.begin(), __u.end());
1523 #ifndef _LIBCPP_CXX03_LANG
1525 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1527 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1528 unordered_map&& __u)
1529 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1530 : __table_(_VSTD::move(__u.__table_))
1532 #if _LIBCPP_DEBUG_LEVEL >= 2
1533 __get_db()->__insert_c(this);
1534 __get_db()->swap(this, &__u);
1538 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1539 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1540 unordered_map&& __u, const allocator_type& __a)
1541 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
1543 #if _LIBCPP_DEBUG_LEVEL >= 2
1544 __get_db()->__insert_c(this);
1546 if (__a != __u.get_allocator())
1548 iterator __i = __u.begin();
1549 while (__u.size() != 0) {
1550 __table_.__emplace_unique(
1551 __u.__table_.remove((__i++).__i_)->__value_.__move());
1554 #if _LIBCPP_DEBUG_LEVEL >= 2
1556 __get_db()->swap(this, &__u);
1560 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1561 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1562 initializer_list<value_type> __il)
1564 #if _LIBCPP_DEBUG_LEVEL >= 2
1565 __get_db()->__insert_c(this);
1567 insert(__il.begin(), __il.end());
1570 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1571 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1572 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1573 const key_equal& __eql)
1574 : __table_(__hf, __eql)
1576 #if _LIBCPP_DEBUG_LEVEL >= 2
1577 __get_db()->__insert_c(this);
1579 __table_.rehash(__n);
1580 insert(__il.begin(), __il.end());
1583 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1584 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1585 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1586 const key_equal& __eql, const allocator_type& __a)
1587 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1589 #if _LIBCPP_DEBUG_LEVEL >= 2
1590 __get_db()->__insert_c(this);
1592 __table_.rehash(__n);
1593 insert(__il.begin(), __il.end());
1596 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1598 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1599 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
1600 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1602 __table_ = _VSTD::move(__u.__table_);
1606 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1608 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1609 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1610 initializer_list<value_type> __il)
1612 __table_.__assign_unique(__il.begin(), __il.end());
1616 #endif // _LIBCPP_CXX03_LANG
1618 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1619 template <class _InputIterator>
1622 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1623 _InputIterator __last)
1625 for (; __first != __last; ++__first)
1626 __table_.__insert_unique(*__first);
1629 #ifndef _LIBCPP_CXX03_LANG
1631 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1633 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1635 return __table_.__emplace_unique_key_args(__k,
1636 std::piecewise_construct, std::forward_as_tuple(__k),
1637 std::forward_as_tuple()).first->__get_value().second;
1640 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1642 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1644 return __table_.__emplace_unique_key_args(__k,
1645 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1646 std::forward_as_tuple()).first->__get_value().second;
1648 #else // _LIBCPP_CXX03_LANG
1650 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1651 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1652 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1654 __node_allocator& __na = __table_.__node_alloc();
1655 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1656 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
1657 __h.get_deleter().__first_constructed = true;
1658 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
1659 __h.get_deleter().__second_constructed = true;
1660 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1663 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1665 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1667 iterator __i = find(__k);
1670 __node_holder __h = __construct_node_with_key(__k);
1671 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1673 return __r.first->second;
1676 #endif // _LIBCPP_CXX03_MODE
1678 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1680 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1682 iterator __i = find(__k);
1684 __throw_out_of_range("unordered_map::at: key not found");
1688 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1690 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1692 const_iterator __i = find(__k);
1694 __throw_out_of_range("unordered_map::at: key not found");
1698 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1699 inline _LIBCPP_INLINE_VISIBILITY
1701 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1702 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1703 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1708 #if _LIBCPP_STD_VER > 17
1709 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
1711 inline _LIBCPP_INLINE_VISIBILITY
1712 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
1713 erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
1714 _Predicate __pred) {
1715 return __libcpp_erase_if_container(__c, __pred);
1719 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1721 operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1722 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1724 if (__x.size() != __y.size())
1726 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1728 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1731 const_iterator __j = __y.find(__i->first);
1732 if (__j == __ey || !(*__i == *__j))
1738 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1739 inline _LIBCPP_INLINE_VISIBILITY
1741 operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1742 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1744 return !(__x == __y);
1747 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1748 class _Alloc = allocator<pair<const _Key, _Tp> > >
1749 class _LIBCPP_TEMPLATE_VIS unordered_multimap
1753 typedef _Key key_type;
1754 typedef _Tp mapped_type;
1755 typedef typename __identity<_Hash>::type hasher;
1756 typedef typename __identity<_Pred>::type key_equal;
1757 typedef typename __identity<_Alloc>::type allocator_type;
1758 typedef pair<const key_type, mapped_type> value_type;
1759 typedef value_type& reference;
1760 typedef const value_type& const_reference;
1761 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1762 "Invalid allocator::value_type");
1765 typedef __hash_value_type<key_type, mapped_type> __value_type;
1766 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1767 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
1768 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1769 __value_type>::type __allocator_type;
1771 typedef __hash_table<__value_type, __hasher,
1772 __key_equal, __allocator_type> __table;
1776 typedef typename __table::_NodeTypes _NodeTypes;
1777 typedef typename __table::__node_traits __node_traits;
1778 typedef typename __table::__node_allocator __node_allocator;
1779 typedef typename __table::__node __node;
1780 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1781 typedef unique_ptr<__node, _Dp> __node_holder;
1782 typedef allocator_traits<allocator_type> __alloc_traits;
1783 static_assert((is_same<typename __node_traits::size_type,
1784 typename __alloc_traits::size_type>::value),
1785 "Allocator uses different size_type for different types");
1787 typedef typename __alloc_traits::pointer pointer;
1788 typedef typename __alloc_traits::const_pointer const_pointer;
1789 typedef typename __table::size_type size_type;
1790 typedef typename __table::difference_type difference_type;
1792 typedef __hash_map_iterator<typename __table::iterator> iterator;
1793 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1794 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1795 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1797 #if _LIBCPP_STD_VER > 14
1798 typedef __map_node_handle<__node, allocator_type> node_type;
1801 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1802 friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1803 template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1804 friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1806 _LIBCPP_INLINE_VISIBILITY
1807 unordered_multimap()
1808 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1810 #if _LIBCPP_DEBUG_LEVEL >= 2
1811 __get_db()->__insert_c(this);
1814 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1815 const key_equal& __eql = key_equal());
1816 unordered_multimap(size_type __n, const hasher& __hf,
1817 const key_equal& __eql,
1818 const allocator_type& __a);
1819 template <class _InputIterator>
1820 unordered_multimap(_InputIterator __first, _InputIterator __last);
1821 template <class _InputIterator>
1822 unordered_multimap(_InputIterator __first, _InputIterator __last,
1823 size_type __n, const hasher& __hf = hasher(),
1824 const key_equal& __eql = key_equal());
1825 template <class _InputIterator>
1826 unordered_multimap(_InputIterator __first, _InputIterator __last,
1827 size_type __n, const hasher& __hf,
1828 const key_equal& __eql,
1829 const allocator_type& __a);
1830 _LIBCPP_INLINE_VISIBILITY
1831 explicit unordered_multimap(const allocator_type& __a);
1832 unordered_multimap(const unordered_multimap& __u);
1833 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
1834 #ifndef _LIBCPP_CXX03_LANG
1835 _LIBCPP_INLINE_VISIBILITY
1836 unordered_multimap(unordered_multimap&& __u)
1837 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
1838 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
1839 unordered_multimap(initializer_list<value_type> __il);
1840 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1841 const hasher& __hf = hasher(),
1842 const key_equal& __eql = key_equal());
1843 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1844 const hasher& __hf, const key_equal& __eql,
1845 const allocator_type& __a);
1846 #endif // _LIBCPP_CXX03_LANG
1847 #if _LIBCPP_STD_VER > 11
1848 _LIBCPP_INLINE_VISIBILITY
1849 unordered_multimap(size_type __n, const allocator_type& __a)
1850 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1851 _LIBCPP_INLINE_VISIBILITY
1852 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1853 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1854 template <class _InputIterator>
1855 _LIBCPP_INLINE_VISIBILITY
1856 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1857 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1858 template <class _InputIterator>
1859 _LIBCPP_INLINE_VISIBILITY
1860 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1861 const allocator_type& __a)
1862 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1863 _LIBCPP_INLINE_VISIBILITY
1864 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1865 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1866 _LIBCPP_INLINE_VISIBILITY
1867 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1868 const allocator_type& __a)
1869 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1871 _LIBCPP_INLINE_VISIBILITY
1872 ~unordered_multimap() {
1873 static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
1876 _LIBCPP_INLINE_VISIBILITY
1877 unordered_multimap& operator=(const unordered_multimap& __u)
1879 #ifndef _LIBCPP_CXX03_LANG
1880 __table_ = __u.__table_;
1884 __table_.hash_function() = __u.__table_.hash_function();
1885 __table_.key_eq() = __u.__table_.key_eq();
1886 __table_.max_load_factor() = __u.__table_.max_load_factor();
1887 __table_.__copy_assign_alloc(__u.__table_);
1888 insert(__u.begin(), __u.end());
1893 #ifndef _LIBCPP_CXX03_LANG
1894 _LIBCPP_INLINE_VISIBILITY
1895 unordered_multimap& operator=(unordered_multimap&& __u)
1896 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
1897 _LIBCPP_INLINE_VISIBILITY
1898 unordered_multimap& operator=(initializer_list<value_type> __il);
1899 #endif // _LIBCPP_CXX03_LANG
1901 _LIBCPP_INLINE_VISIBILITY
1902 allocator_type get_allocator() const _NOEXCEPT
1903 {return allocator_type(__table_.__node_alloc());}
1905 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1906 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
1907 _LIBCPP_INLINE_VISIBILITY
1908 size_type size() const _NOEXCEPT {return __table_.size();}
1909 _LIBCPP_INLINE_VISIBILITY
1910 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1912 _LIBCPP_INLINE_VISIBILITY
1913 iterator begin() _NOEXCEPT {return __table_.begin();}
1914 _LIBCPP_INLINE_VISIBILITY
1915 iterator end() _NOEXCEPT {return __table_.end();}
1916 _LIBCPP_INLINE_VISIBILITY
1917 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
1918 _LIBCPP_INLINE_VISIBILITY
1919 const_iterator end() const _NOEXCEPT {return __table_.end();}
1920 _LIBCPP_INLINE_VISIBILITY
1921 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1922 _LIBCPP_INLINE_VISIBILITY
1923 const_iterator cend() const _NOEXCEPT {return __table_.end();}
1925 _LIBCPP_INLINE_VISIBILITY
1926 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1928 _LIBCPP_INLINE_VISIBILITY
1929 iterator insert(const_iterator __p, const value_type& __x)
1930 {return __table_.__insert_multi(__p.__i_, __x);}
1932 template <class _InputIterator>
1933 _LIBCPP_INLINE_VISIBILITY
1934 void insert(_InputIterator __first, _InputIterator __last);
1936 #ifndef _LIBCPP_CXX03_LANG
1937 _LIBCPP_INLINE_VISIBILITY
1938 void insert(initializer_list<value_type> __il)
1939 {insert(__il.begin(), __il.end());}
1940 _LIBCPP_INLINE_VISIBILITY
1941 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1943 _LIBCPP_INLINE_VISIBILITY
1944 iterator insert(const_iterator __p, value_type&& __x)
1945 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1947 template <class _Pp,
1948 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1949 _LIBCPP_INLINE_VISIBILITY
1950 iterator insert(_Pp&& __x)
1951 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1953 template <class _Pp,
1954 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1955 _LIBCPP_INLINE_VISIBILITY
1956 iterator insert(const_iterator __p, _Pp&& __x)
1957 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1959 template <class... _Args>
1960 iterator emplace(_Args&&... __args) {
1961 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1964 template <class... _Args>
1965 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1966 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1968 #endif // _LIBCPP_CXX03_LANG
1971 _LIBCPP_INLINE_VISIBILITY
1972 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
1973 _LIBCPP_INLINE_VISIBILITY
1974 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1975 _LIBCPP_INLINE_VISIBILITY
1976 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
1977 _LIBCPP_INLINE_VISIBILITY
1978 iterator erase(const_iterator __first, const_iterator __last)
1979 {return __table_.erase(__first.__i_, __last.__i_);}
1980 _LIBCPP_INLINE_VISIBILITY
1981 void clear() _NOEXCEPT {__table_.clear();}
1983 #if _LIBCPP_STD_VER > 14
1984 _LIBCPP_INLINE_VISIBILITY
1985 iterator insert(node_type&& __nh)
1987 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1988 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1989 return __table_.template __node_handle_insert_multi<node_type>(
1992 _LIBCPP_INLINE_VISIBILITY
1993 iterator insert(const_iterator __hint, node_type&& __nh)
1995 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1996 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1997 return __table_.template __node_handle_insert_multi<node_type>(
1998 __hint.__i_, _VSTD::move(__nh));
2000 _LIBCPP_INLINE_VISIBILITY
2001 node_type extract(key_type const& __key)
2003 return __table_.template __node_handle_extract<node_type>(__key);
2005 _LIBCPP_INLINE_VISIBILITY
2006 node_type extract(const_iterator __it)
2008 return __table_.template __node_handle_extract<node_type>(
2012 template <class _H2, class _P2>
2013 _LIBCPP_INLINE_VISIBILITY
2014 void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
2016 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2017 "merging container with incompatible allocator");
2018 return __table_.__node_handle_merge_multi(__source.__table_);
2020 template <class _H2, class _P2>
2021 _LIBCPP_INLINE_VISIBILITY
2022 void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
2024 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2025 "merging container with incompatible allocator");
2026 return __table_.__node_handle_merge_multi(__source.__table_);
2028 template <class _H2, class _P2>
2029 _LIBCPP_INLINE_VISIBILITY
2030 void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
2032 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2033 "merging container with incompatible allocator");
2034 return __table_.__node_handle_merge_multi(__source.__table_);
2036 template <class _H2, class _P2>
2037 _LIBCPP_INLINE_VISIBILITY
2038 void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
2040 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2041 "merging container with incompatible allocator");
2042 return __table_.__node_handle_merge_multi(__source.__table_);
2046 _LIBCPP_INLINE_VISIBILITY
2047 void swap(unordered_multimap& __u)
2048 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
2049 {__table_.swap(__u.__table_);}
2051 _LIBCPP_INLINE_VISIBILITY
2052 hasher hash_function() const
2053 {return __table_.hash_function().hash_function();}
2054 _LIBCPP_INLINE_VISIBILITY
2055 key_equal key_eq() const
2056 {return __table_.key_eq().key_eq();}
2058 _LIBCPP_INLINE_VISIBILITY
2059 iterator find(const key_type& __k) {return __table_.find(__k);}
2060 _LIBCPP_INLINE_VISIBILITY
2061 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
2062 _LIBCPP_INLINE_VISIBILITY
2063 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
2064 #if _LIBCPP_STD_VER > 17
2065 _LIBCPP_INLINE_VISIBILITY
2066 bool contains(const key_type& __k) const {return find(__k) != end();}
2067 #endif // _LIBCPP_STD_VER > 17
2068 _LIBCPP_INLINE_VISIBILITY
2069 pair<iterator, iterator> equal_range(const key_type& __k)
2070 {return __table_.__equal_range_multi(__k);}
2071 _LIBCPP_INLINE_VISIBILITY
2072 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
2073 {return __table_.__equal_range_multi(__k);}
2075 _LIBCPP_INLINE_VISIBILITY
2076 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
2077 _LIBCPP_INLINE_VISIBILITY
2078 size_type max_bucket_count() const _NOEXCEPT
2079 {return __table_.max_bucket_count();}
2081 _LIBCPP_INLINE_VISIBILITY
2082 size_type bucket_size(size_type __n) const
2083 {return __table_.bucket_size(__n);}
2084 _LIBCPP_INLINE_VISIBILITY
2085 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
2087 _LIBCPP_INLINE_VISIBILITY
2088 local_iterator begin(size_type __n) {return __table_.begin(__n);}
2089 _LIBCPP_INLINE_VISIBILITY
2090 local_iterator end(size_type __n) {return __table_.end(__n);}
2091 _LIBCPP_INLINE_VISIBILITY
2092 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
2093 _LIBCPP_INLINE_VISIBILITY
2094 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
2095 _LIBCPP_INLINE_VISIBILITY
2096 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
2097 _LIBCPP_INLINE_VISIBILITY
2098 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
2100 _LIBCPP_INLINE_VISIBILITY
2101 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
2102 _LIBCPP_INLINE_VISIBILITY
2103 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
2104 _LIBCPP_INLINE_VISIBILITY
2105 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
2106 _LIBCPP_INLINE_VISIBILITY
2107 void rehash(size_type __n) {__table_.rehash(__n);}
2108 _LIBCPP_INLINE_VISIBILITY
2109 void reserve(size_type __n) {__table_.reserve(__n);}
2111 #if _LIBCPP_DEBUG_LEVEL >= 2
2113 bool __dereferenceable(const const_iterator* __i) const
2114 {return __table_.__dereferenceable(&__i->__i_);}
2115 bool __decrementable(const const_iterator* __i) const
2116 {return __table_.__decrementable(&__i->__i_);}
2117 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
2118 {return __table_.__addable(&__i->__i_, __n);}
2119 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2120 {return __table_.__addable(&__i->__i_, __n);}
2122 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2127 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2128 template<class _InputIterator,
2129 class _Hash = hash<__iter_key_type<_InputIterator>>,
2130 class _Pred = equal_to<__iter_key_type<_InputIterator>>,
2131 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2132 class = _EnableIf<!__is_allocator<_Hash>::value>,
2133 class = _EnableIf<!is_integral<_Hash>::value>,
2134 class = _EnableIf<!__is_allocator<_Pred>::value>,
2135 class = _EnableIf<__is_allocator<_Allocator>::value>>
2136 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
2137 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
2138 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
2140 template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
2141 class _Pred = equal_to<remove_const_t<_Key>>,
2142 class _Allocator = allocator<pair<const _Key, _Tp>>,
2143 class = _EnableIf<!__is_allocator<_Hash>::value>,
2144 class = _EnableIf<!is_integral<_Hash>::value>,
2145 class = _EnableIf<!__is_allocator<_Pred>::value>,
2146 class = _EnableIf<__is_allocator<_Allocator>::value>>
2147 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
2148 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
2149 -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
2151 template<class _InputIterator, class _Allocator,
2152 class = _EnableIf<__is_allocator<_Allocator>::value>>
2153 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
2154 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2155 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2157 template<class _InputIterator, class _Allocator,
2158 class = _EnableIf<__is_allocator<_Allocator>::value>>
2159 unordered_multimap(_InputIterator, _InputIterator, _Allocator)
2160 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2161 hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2163 template<class _InputIterator, class _Hash, class _Allocator,
2164 class = _EnableIf<!__is_allocator<_Hash>::value>,
2165 class = _EnableIf<!is_integral<_Hash>::value>,
2166 class = _EnableIf<__is_allocator<_Allocator>::value>>
2167 unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
2168 -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2169 _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2171 template<class _Key, class _Tp, class _Allocator,
2172 class = _EnableIf<__is_allocator<_Allocator>::value>>
2173 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
2174 -> unordered_multimap<remove_const_t<_Key>, _Tp,
2175 hash<remove_const_t<_Key>>,
2176 equal_to<remove_const_t<_Key>>, _Allocator>;
2178 template<class _Key, class _Tp, class _Allocator,
2179 class = _EnableIf<__is_allocator<_Allocator>::value>>
2180 unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2181 -> unordered_multimap<remove_const_t<_Key>, _Tp,
2182 hash<remove_const_t<_Key>>,
2183 equal_to<remove_const_t<_Key>>, _Allocator>;
2185 template<class _Key, class _Tp, class _Hash, class _Allocator,
2186 class = _EnableIf<!__is_allocator<_Hash>::value>,
2187 class = _EnableIf<!is_integral<_Hash>::value>,
2188 class = _EnableIf<__is_allocator<_Allocator>::value>>
2189 unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
2190 -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
2191 equal_to<remove_const_t<_Key>>, _Allocator>;
2194 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2195 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2196 size_type __n, const hasher& __hf, const key_equal& __eql)
2197 : __table_(__hf, __eql)
2199 #if _LIBCPP_DEBUG_LEVEL >= 2
2200 __get_db()->__insert_c(this);
2202 __table_.rehash(__n);
2205 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2206 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2207 size_type __n, const hasher& __hf, const key_equal& __eql,
2208 const allocator_type& __a)
2209 : __table_(__hf, __eql, typename __table::allocator_type(__a))
2211 #if _LIBCPP_DEBUG_LEVEL >= 2
2212 __get_db()->__insert_c(this);
2214 __table_.rehash(__n);
2217 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2218 template <class _InputIterator>
2219 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2220 _InputIterator __first, _InputIterator __last)
2222 #if _LIBCPP_DEBUG_LEVEL >= 2
2223 __get_db()->__insert_c(this);
2225 insert(__first, __last);
2228 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2229 template <class _InputIterator>
2230 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2231 _InputIterator __first, _InputIterator __last, size_type __n,
2232 const hasher& __hf, const key_equal& __eql)
2233 : __table_(__hf, __eql)
2235 #if _LIBCPP_DEBUG_LEVEL >= 2
2236 __get_db()->__insert_c(this);
2238 __table_.rehash(__n);
2239 insert(__first, __last);
2242 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2243 template <class _InputIterator>
2244 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2245 _InputIterator __first, _InputIterator __last, size_type __n,
2246 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
2247 : __table_(__hf, __eql, typename __table::allocator_type(__a))
2249 #if _LIBCPP_DEBUG_LEVEL >= 2
2250 __get_db()->__insert_c(this);
2252 __table_.rehash(__n);
2253 insert(__first, __last);
2256 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2258 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2259 const allocator_type& __a)
2260 : __table_(typename __table::allocator_type(__a))
2262 #if _LIBCPP_DEBUG_LEVEL >= 2
2263 __get_db()->__insert_c(this);
2267 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2268 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2269 const unordered_multimap& __u)
2270 : __table_(__u.__table_)
2272 #if _LIBCPP_DEBUG_LEVEL >= 2
2273 __get_db()->__insert_c(this);
2275 __table_.rehash(__u.bucket_count());
2276 insert(__u.begin(), __u.end());
2279 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2280 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2281 const unordered_multimap& __u, const allocator_type& __a)
2282 : __table_(__u.__table_, typename __table::allocator_type(__a))
2284 #if _LIBCPP_DEBUG_LEVEL >= 2
2285 __get_db()->__insert_c(this);
2287 __table_.rehash(__u.bucket_count());
2288 insert(__u.begin(), __u.end());
2291 #ifndef _LIBCPP_CXX03_LANG
2293 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2295 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2296 unordered_multimap&& __u)
2297 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
2298 : __table_(_VSTD::move(__u.__table_))
2300 #if _LIBCPP_DEBUG_LEVEL >= 2
2301 __get_db()->__insert_c(this);
2302 __get_db()->swap(this, &__u);
2306 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2307 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2308 unordered_multimap&& __u, const allocator_type& __a)
2309 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
2311 #if _LIBCPP_DEBUG_LEVEL >= 2
2312 __get_db()->__insert_c(this);
2314 if (__a != __u.get_allocator())
2316 iterator __i = __u.begin();
2317 while (__u.size() != 0)
2319 __table_.__insert_multi(
2320 __u.__table_.remove((__i++).__i_)->__value_.__move());
2323 #if _LIBCPP_DEBUG_LEVEL >= 2
2325 __get_db()->swap(this, &__u);
2329 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2330 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2331 initializer_list<value_type> __il)
2333 #if _LIBCPP_DEBUG_LEVEL >= 2
2334 __get_db()->__insert_c(this);
2336 insert(__il.begin(), __il.end());
2339 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2340 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2341 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2342 const key_equal& __eql)
2343 : __table_(__hf, __eql)
2345 #if _LIBCPP_DEBUG_LEVEL >= 2
2346 __get_db()->__insert_c(this);
2348 __table_.rehash(__n);
2349 insert(__il.begin(), __il.end());
2352 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2353 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2354 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2355 const key_equal& __eql, const allocator_type& __a)
2356 : __table_(__hf, __eql, typename __table::allocator_type(__a))
2358 #if _LIBCPP_DEBUG_LEVEL >= 2
2359 __get_db()->__insert_c(this);
2361 __table_.rehash(__n);
2362 insert(__il.begin(), __il.end());
2365 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2367 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2368 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
2369 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
2371 __table_ = _VSTD::move(__u.__table_);
2375 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2377 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2378 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2379 initializer_list<value_type> __il)
2381 __table_.__assign_multi(__il.begin(), __il.end());
2385 #endif // _LIBCPP_CXX03_LANG
2389 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2390 template <class _InputIterator>
2393 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2394 _InputIterator __last)
2396 for (; __first != __last; ++__first)
2397 __table_.__insert_multi(*__first);
2400 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2401 inline _LIBCPP_INLINE_VISIBILITY
2403 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2404 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2405 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2410 #if _LIBCPP_STD_VER > 17
2411 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
2413 inline _LIBCPP_INLINE_VISIBILITY
2414 typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
2415 erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
2416 _Predicate __pred) {
2417 return __libcpp_erase_if_container(__c, __pred);
2421 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2423 operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2424 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2426 if (__x.size() != __y.size())
2428 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2430 typedef pair<const_iterator, const_iterator> _EqRng;
2431 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2433 _EqRng __xeq = __x.equal_range(__i->first);
2434 _EqRng __yeq = __y.equal_range(__i->first);
2435 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2436 _VSTD::distance(__yeq.first, __yeq.second) ||
2437 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
2444 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2445 inline _LIBCPP_INLINE_VISIBILITY
2447 operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2448 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2450 return !(__x == __y);
2453 _LIBCPP_END_NAMESPACE_STD
2455 #endif // _LIBCPP_UNORDERED_MAP