2 //===-------------------------- unordered_map -----------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_UNORDERED_MAP
12 #define _LIBCPP_UNORDERED_MAP
16 unordered_map synopsis
18 #include <initializer_list>
23 template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
30 typedef T mapped_type;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef pair<const key_type, mapped_type> value_type;
35 typedef value_type& reference;
36 typedef const value_type& const_reference;
37 typedef typename allocator_traits<allocator_type>::pointer pointer;
38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
39 typedef typename allocator_traits<allocator_type>::size_type size_type;
40 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
47 typedef unspecified node_type; // C++17
48 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
52 is_nothrow_default_constructible<hasher>::value &&
53 is_nothrow_default_constructible<key_equal>::value &&
54 is_nothrow_default_constructible<allocator_type>::value);
55 explicit unordered_map(size_type n, const hasher& hf = hasher(),
56 const key_equal& eql = key_equal(),
57 const allocator_type& a = allocator_type());
58 template <class InputIterator>
59 unordered_map(InputIterator f, InputIterator l,
60 size_type n = 0, const hasher& hf = hasher(),
61 const key_equal& eql = key_equal(),
62 const allocator_type& a = allocator_type());
63 explicit unordered_map(const allocator_type&);
64 unordered_map(const unordered_map&);
65 unordered_map(const unordered_map&, const Allocator&);
66 unordered_map(unordered_map&&)
68 is_nothrow_move_constructible<hasher>::value &&
69 is_nothrow_move_constructible<key_equal>::value &&
70 is_nothrow_move_constructible<allocator_type>::value);
71 unordered_map(unordered_map&&, const Allocator&);
72 unordered_map(initializer_list<value_type>, size_type n = 0,
73 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
74 const allocator_type& a = allocator_type());
75 unordered_map(size_type n, const allocator_type& a)
76 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
77 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
78 : unordered_map(n, hf, key_equal(), a) {} // C++14
79 template <class InputIterator>
80 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
81 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
82 template <class InputIterator>
83 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
84 const allocator_type& a)
85 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
86 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
87 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
88 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
89 const allocator_type& a)
90 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
92 unordered_map& operator=(const unordered_map&);
93 unordered_map& operator=(unordered_map&&)
95 allocator_type::propagate_on_container_move_assignment::value &&
96 is_nothrow_move_assignable<allocator_type>::value &&
97 is_nothrow_move_assignable<hasher>::value &&
98 is_nothrow_move_assignable<key_equal>::value);
99 unordered_map& operator=(initializer_list<value_type>);
101 allocator_type get_allocator() const noexcept;
103 bool empty() const noexcept;
104 size_type size() const noexcept;
105 size_type max_size() const noexcept;
107 iterator begin() noexcept;
108 iterator end() noexcept;
109 const_iterator begin() const noexcept;
110 const_iterator end() const noexcept;
111 const_iterator cbegin() const noexcept;
112 const_iterator cend() const noexcept;
114 template <class... Args>
115 pair<iterator, bool> emplace(Args&&... args);
116 template <class... Args>
117 iterator emplace_hint(const_iterator position, Args&&... args);
118 pair<iterator, bool> insert(const value_type& obj);
120 pair<iterator, bool> insert(P&& obj);
121 iterator insert(const_iterator hint, const value_type& obj);
123 iterator insert(const_iterator hint, P&& obj);
124 template <class InputIterator>
125 void insert(InputIterator first, InputIterator last);
126 void insert(initializer_list<value_type>);
128 node_type extract(const_iterator position); // C++17
129 node_type extract(const key_type& x); // C++17
130 insert_return_type insert(node_type&& nh); // C++17
131 iterator insert(const_iterator hint, node_type&& nh); // C++17
133 template <class... Args>
134 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
135 template <class... Args>
136 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
137 template <class... Args>
138 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
139 template <class... Args>
140 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
142 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
144 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
146 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
148 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
150 iterator erase(const_iterator position);
151 iterator erase(iterator position); // C++14
152 size_type erase(const key_type& k);
153 iterator erase(const_iterator first, const_iterator last);
154 void clear() noexcept;
156 void swap(unordered_map&)
158 (!allocator_type::propagate_on_container_swap::value ||
159 __is_nothrow_swappable<allocator_type>::value) &&
160 __is_nothrow_swappable<hasher>::value &&
161 __is_nothrow_swappable<key_equal>::value);
163 hasher hash_function() const;
164 key_equal key_eq() const;
166 iterator find(const key_type& k);
167 const_iterator find(const key_type& k) const;
168 size_type count(const key_type& k) const;
169 pair<iterator, iterator> equal_range(const key_type& k);
170 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
172 mapped_type& operator[](const key_type& k);
173 mapped_type& operator[](key_type&& k);
175 mapped_type& at(const key_type& k);
176 const mapped_type& at(const key_type& k) const;
178 size_type bucket_count() const noexcept;
179 size_type max_bucket_count() const noexcept;
181 size_type bucket_size(size_type n) const;
182 size_type bucket(const key_type& k) const;
184 local_iterator begin(size_type n);
185 local_iterator end(size_type n);
186 const_local_iterator begin(size_type n) const;
187 const_local_iterator end(size_type n) const;
188 const_local_iterator cbegin(size_type n) const;
189 const_local_iterator cend(size_type n) const;
191 float load_factor() const noexcept;
192 float max_load_factor() const noexcept;
193 void max_load_factor(float z);
194 void rehash(size_type n);
195 void reserve(size_type n);
198 template <class Key, class T, class Hash, class Pred, class Alloc>
199 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
200 unordered_map<Key, T, Hash, Pred, Alloc>& y)
201 noexcept(noexcept(x.swap(y)));
203 template <class Key, class T, class Hash, class Pred, class Alloc>
205 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
206 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
208 template <class Key, class T, class Hash, class Pred, class Alloc>
210 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
211 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
213 template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
214 class Alloc = allocator<pair<const Key, T>>>
215 class unordered_multimap
219 typedef Key key_type;
220 typedef T mapped_type;
222 typedef Pred key_equal;
223 typedef Alloc allocator_type;
224 typedef pair<const key_type, mapped_type> value_type;
225 typedef value_type& reference;
226 typedef const value_type& const_reference;
227 typedef typename allocator_traits<allocator_type>::pointer pointer;
228 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
229 typedef typename allocator_traits<allocator_type>::size_type size_type;
230 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
232 typedef /unspecified/ iterator;
233 typedef /unspecified/ const_iterator;
234 typedef /unspecified/ local_iterator;
235 typedef /unspecified/ const_local_iterator;
237 typedef unspecified node_type; // C++17
241 is_nothrow_default_constructible<hasher>::value &&
242 is_nothrow_default_constructible<key_equal>::value &&
243 is_nothrow_default_constructible<allocator_type>::value);
244 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
245 const key_equal& eql = key_equal(),
246 const allocator_type& a = allocator_type());
247 template <class InputIterator>
248 unordered_multimap(InputIterator f, InputIterator l,
249 size_type n = 0, const hasher& hf = hasher(),
250 const key_equal& eql = key_equal(),
251 const allocator_type& a = allocator_type());
252 explicit unordered_multimap(const allocator_type&);
253 unordered_multimap(const unordered_multimap&);
254 unordered_multimap(const unordered_multimap&, const Allocator&);
255 unordered_multimap(unordered_multimap&&)
257 is_nothrow_move_constructible<hasher>::value &&
258 is_nothrow_move_constructible<key_equal>::value &&
259 is_nothrow_move_constructible<allocator_type>::value);
260 unordered_multimap(unordered_multimap&&, const Allocator&);
261 unordered_multimap(initializer_list<value_type>, size_type n = 0,
262 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
263 const allocator_type& a = allocator_type());
264 unordered_multimap(size_type n, const allocator_type& a)
265 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
266 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
267 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
268 template <class InputIterator>
269 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
270 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
271 template <class InputIterator>
272 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
273 const allocator_type& a)
274 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
275 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
276 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
277 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
278 const allocator_type& a)
279 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
280 ~unordered_multimap();
281 unordered_multimap& operator=(const unordered_multimap&);
282 unordered_multimap& operator=(unordered_multimap&&)
284 allocator_type::propagate_on_container_move_assignment::value &&
285 is_nothrow_move_assignable<allocator_type>::value &&
286 is_nothrow_move_assignable<hasher>::value &&
287 is_nothrow_move_assignable<key_equal>::value);
288 unordered_multimap& operator=(initializer_list<value_type>);
290 allocator_type get_allocator() const noexcept;
292 bool empty() const noexcept;
293 size_type size() const noexcept;
294 size_type max_size() const noexcept;
296 iterator begin() noexcept;
297 iterator end() noexcept;
298 const_iterator begin() const noexcept;
299 const_iterator end() const noexcept;
300 const_iterator cbegin() const noexcept;
301 const_iterator cend() const noexcept;
303 template <class... Args>
304 iterator emplace(Args&&... args);
305 template <class... Args>
306 iterator emplace_hint(const_iterator position, Args&&... args);
307 iterator insert(const value_type& obj);
309 iterator insert(P&& obj);
310 iterator insert(const_iterator hint, const value_type& obj);
312 iterator insert(const_iterator hint, P&& obj);
313 template <class InputIterator>
314 void insert(InputIterator first, InputIterator last);
315 void insert(initializer_list<value_type>);
317 node_type extract(const_iterator position); // C++17
318 node_type extract(const key_type& x); // C++17
319 iterator insert(node_type&& nh); // C++17
320 iterator insert(const_iterator hint, node_type&& nh); // C++17
322 iterator erase(const_iterator position);
323 iterator erase(iterator position); // C++14
324 size_type erase(const key_type& k);
325 iterator erase(const_iterator first, const_iterator last);
326 void clear() noexcept;
328 void swap(unordered_multimap&)
330 (!allocator_type::propagate_on_container_swap::value ||
331 __is_nothrow_swappable<allocator_type>::value) &&
332 __is_nothrow_swappable<hasher>::value &&
333 __is_nothrow_swappable<key_equal>::value);
335 hasher hash_function() const;
336 key_equal key_eq() const;
338 iterator find(const key_type& k);
339 const_iterator find(const key_type& k) const;
340 size_type count(const key_type& k) const;
341 pair<iterator, iterator> equal_range(const key_type& k);
342 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
344 size_type bucket_count() const noexcept;
345 size_type max_bucket_count() const noexcept;
347 size_type bucket_size(size_type n) const;
348 size_type bucket(const key_type& k) const;
350 local_iterator begin(size_type n);
351 local_iterator end(size_type n);
352 const_local_iterator begin(size_type n) const;
353 const_local_iterator end(size_type n) const;
354 const_local_iterator cbegin(size_type n) const;
355 const_local_iterator cend(size_type n) const;
357 float load_factor() const noexcept;
358 float max_load_factor() const noexcept;
359 void max_load_factor(float z);
360 void rehash(size_type n);
361 void reserve(size_type n);
364 template <class Key, class T, class Hash, class Pred, class Alloc>
365 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
366 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
367 noexcept(noexcept(x.swap(y)));
369 template <class Key, class T, class Hash, class Pred, class Alloc>
371 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
372 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
374 template <class Key, class T, class Hash, class Pred, class Alloc>
376 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
377 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
384 #include <__hash_table>
385 #include <__node_handle>
386 #include <functional>
392 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
393 #pragma GCC system_header
396 _LIBCPP_BEGIN_NAMESPACE_STD
398 template <class _Key, class _Cp, class _Hash, bool _IsEmpty>
399 class __unordered_map_hasher
403 _LIBCPP_INLINE_VISIBILITY
404 __unordered_map_hasher()
405 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
407 _LIBCPP_INLINE_VISIBILITY
408 __unordered_map_hasher(const _Hash& __h)
409 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
411 _LIBCPP_INLINE_VISIBILITY
412 const _Hash& hash_function() const _NOEXCEPT {return *this;}
413 _LIBCPP_INLINE_VISIBILITY
414 size_t operator()(const _Cp& __x) const
415 {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
416 _LIBCPP_INLINE_VISIBILITY
417 size_t operator()(const _Key& __x) const
418 {return static_cast<const _Hash&>(*this)(__x);}
419 void swap(__unordered_map_hasher&__y)
420 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
423 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
427 template <class _Key, class _Cp, class _Hash>
428 class __unordered_map_hasher<_Key, _Cp, _Hash, false>
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 __hash_;}
442 _LIBCPP_INLINE_VISIBILITY
443 size_t operator()(const _Cp& __x) const
444 {return __hash_(__x.__get_value().first);}
445 _LIBCPP_INLINE_VISIBILITY
446 size_t operator()(const _Key& __x) const
447 {return __hash_(__x);}
448 void swap(__unordered_map_hasher&__y)
449 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
452 swap(__hash_, __y.__hash_);
456 template <class _Key, class _Cp, class _Hash, bool __b>
457 inline _LIBCPP_INLINE_VISIBILITY
459 swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
460 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
461 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
466 template <class _Key, class _Cp, class _Pred, bool _IsEmpty>
467 class __unordered_map_equal
471 _LIBCPP_INLINE_VISIBILITY
472 __unordered_map_equal()
473 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
475 _LIBCPP_INLINE_VISIBILITY
476 __unordered_map_equal(const _Pred& __p)
477 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
479 _LIBCPP_INLINE_VISIBILITY
480 const _Pred& key_eq() const _NOEXCEPT {return *this;}
481 _LIBCPP_INLINE_VISIBILITY
482 bool operator()(const _Cp& __x, const _Cp& __y) const
483 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
484 _LIBCPP_INLINE_VISIBILITY
485 bool operator()(const _Cp& __x, const _Key& __y) const
486 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
487 _LIBCPP_INLINE_VISIBILITY
488 bool operator()(const _Key& __x, const _Cp& __y) const
489 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
490 void swap(__unordered_map_equal&__y)
491 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
494 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
498 template <class _Key, class _Cp, class _Pred>
499 class __unordered_map_equal<_Key, _Cp, _Pred, false>
503 _LIBCPP_INLINE_VISIBILITY
504 __unordered_map_equal()
505 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
507 _LIBCPP_INLINE_VISIBILITY
508 __unordered_map_equal(const _Pred& __p)
509 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
511 _LIBCPP_INLINE_VISIBILITY
512 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
513 _LIBCPP_INLINE_VISIBILITY
514 bool operator()(const _Cp& __x, const _Cp& __y) const
515 {return __pred_(__x.__get_value().first, __y.__get_value().first);}
516 _LIBCPP_INLINE_VISIBILITY
517 bool operator()(const _Cp& __x, const _Key& __y) const
518 {return __pred_(__x.__get_value().first, __y);}
519 _LIBCPP_INLINE_VISIBILITY
520 bool operator()(const _Key& __x, const _Cp& __y) const
521 {return __pred_(__x, __y.__get_value().first);}
522 void swap(__unordered_map_equal&__y)
523 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
526 swap(__pred_, __y.__pred_);
530 template <class _Key, class _Cp, class _Pred, bool __b>
531 inline _LIBCPP_INLINE_VISIBILITY
533 swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
534 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
535 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
540 template <class _Alloc>
541 class __hash_map_node_destructor
543 typedef _Alloc allocator_type;
544 typedef allocator_traits<allocator_type> __alloc_traits;
548 typedef typename __alloc_traits::pointer pointer;
551 allocator_type& __na_;
553 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
556 bool __first_constructed;
557 bool __second_constructed;
559 _LIBCPP_INLINE_VISIBILITY
560 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
562 __first_constructed(false),
563 __second_constructed(false)
566 #ifndef _LIBCPP_CXX03_LANG
567 _LIBCPP_INLINE_VISIBILITY
568 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
571 __first_constructed(__x.__value_constructed),
572 __second_constructed(__x.__value_constructed)
574 __x.__value_constructed = false;
576 #else // _LIBCPP_CXX03_LANG
577 _LIBCPP_INLINE_VISIBILITY
578 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
580 __first_constructed(__x.__value_constructed),
581 __second_constructed(__x.__value_constructed)
583 const_cast<bool&>(__x.__value_constructed) = false;
585 #endif // _LIBCPP_CXX03_LANG
587 _LIBCPP_INLINE_VISIBILITY
588 void operator()(pointer __p) _NOEXCEPT
590 if (__second_constructed)
591 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
592 if (__first_constructed)
593 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
595 __alloc_traits::deallocate(__na_, __p, 1);
599 #ifndef _LIBCPP_CXX03_LANG
600 template <class _Key, class _Tp>
601 struct __hash_value_type
603 typedef _Key key_type;
604 typedef _Tp mapped_type;
605 typedef pair<const key_type, mapped_type> value_type;
606 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
607 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
613 _LIBCPP_INLINE_VISIBILITY
614 value_type& __get_value()
616 #if _LIBCPP_STD_VER > 14
617 return *_VSTD::launder(_VSTD::addressof(__cc));
623 _LIBCPP_INLINE_VISIBILITY
624 const value_type& __get_value() const
626 #if _LIBCPP_STD_VER > 14
627 return *_VSTD::launder(_VSTD::addressof(__cc));
633 _LIBCPP_INLINE_VISIBILITY
634 __nc_ref_pair_type __ref()
636 value_type& __v = __get_value();
637 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
640 _LIBCPP_INLINE_VISIBILITY
641 __nc_rref_pair_type __move()
643 value_type& __v = __get_value();
644 return __nc_rref_pair_type(
645 _VSTD::move(const_cast<key_type&>(__v.first)),
646 _VSTD::move(__v.second));
649 _LIBCPP_INLINE_VISIBILITY
650 __hash_value_type& operator=(const __hash_value_type& __v)
652 __ref() = __v.__get_value();
656 _LIBCPP_INLINE_VISIBILITY
657 __hash_value_type& operator=(__hash_value_type&& __v)
659 __ref() = __v.__move();
663 template <class _ValueTp,
664 class = typename enable_if<
665 __is_same_uncvref<_ValueTp, value_type>::value
668 _LIBCPP_INLINE_VISIBILITY
669 __hash_value_type& operator=(_ValueTp&& __v)
671 __ref() = _VSTD::forward<_ValueTp>(__v);
676 __hash_value_type(const __hash_value_type& __v) = delete;
677 __hash_value_type(__hash_value_type&& __v) = delete;
678 template <class ..._Args>
679 explicit __hash_value_type(_Args&& ...__args) = delete;
681 ~__hash_value_type() = delete;
686 template <class _Key, class _Tp>
687 struct __hash_value_type
689 typedef _Key key_type;
690 typedef _Tp mapped_type;
691 typedef pair<const key_type, mapped_type> value_type;
697 _LIBCPP_INLINE_VISIBILITY
698 value_type& __get_value() { return __cc; }
699 _LIBCPP_INLINE_VISIBILITY
700 const value_type& __get_value() const { return __cc; }
703 ~__hash_value_type();
708 template <class _HashIterator>
709 class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
713 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
716 typedef forward_iterator_tag iterator_category;
717 typedef typename _NodeTypes::__map_value_type value_type;
718 typedef typename _NodeTypes::difference_type difference_type;
719 typedef value_type& reference;
720 typedef typename _NodeTypes::__map_value_type_pointer pointer;
722 _LIBCPP_INLINE_VISIBILITY
723 __hash_map_iterator() _NOEXCEPT {}
725 _LIBCPP_INLINE_VISIBILITY
726 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
728 _LIBCPP_INLINE_VISIBILITY
729 reference operator*() const {return __i_->__get_value();}
730 _LIBCPP_INLINE_VISIBILITY
731 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
733 _LIBCPP_INLINE_VISIBILITY
734 __hash_map_iterator& operator++() {++__i_; return *this;}
735 _LIBCPP_INLINE_VISIBILITY
736 __hash_map_iterator operator++(int)
738 __hash_map_iterator __t(*this);
743 friend _LIBCPP_INLINE_VISIBILITY
744 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
745 {return __x.__i_ == __y.__i_;}
746 friend _LIBCPP_INLINE_VISIBILITY
747 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
748 {return __x.__i_ != __y.__i_;}
750 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
751 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
752 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
753 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
754 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
757 template <class _HashIterator>
758 class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
762 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
765 typedef forward_iterator_tag iterator_category;
766 typedef typename _NodeTypes::__map_value_type value_type;
767 typedef typename _NodeTypes::difference_type difference_type;
768 typedef const value_type& reference;
769 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
771 _LIBCPP_INLINE_VISIBILITY
772 __hash_map_const_iterator() _NOEXCEPT {}
774 _LIBCPP_INLINE_VISIBILITY
775 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
776 _LIBCPP_INLINE_VISIBILITY
777 __hash_map_const_iterator(
778 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
782 _LIBCPP_INLINE_VISIBILITY
783 reference operator*() const {return __i_->__get_value();}
784 _LIBCPP_INLINE_VISIBILITY
785 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
787 _LIBCPP_INLINE_VISIBILITY
788 __hash_map_const_iterator& operator++() {++__i_; return *this;}
789 _LIBCPP_INLINE_VISIBILITY
790 __hash_map_const_iterator operator++(int)
792 __hash_map_const_iterator __t(*this);
797 friend _LIBCPP_INLINE_VISIBILITY
798 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
799 {return __x.__i_ == __y.__i_;}
800 friend _LIBCPP_INLINE_VISIBILITY
801 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
802 {return __x.__i_ != __y.__i_;}
804 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
805 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
806 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
807 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
810 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
811 class _Alloc = allocator<pair<const _Key, _Tp> > >
812 class _LIBCPP_TEMPLATE_VIS unordered_map
816 typedef _Key key_type;
817 typedef _Tp mapped_type;
818 typedef _Hash hasher;
819 typedef _Pred key_equal;
820 typedef _Alloc allocator_type;
821 typedef pair<const key_type, mapped_type> value_type;
822 typedef value_type& reference;
823 typedef const value_type& const_reference;
824 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
825 "Invalid allocator::value_type");
828 typedef __hash_value_type<key_type, mapped_type> __value_type;
829 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
830 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
831 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
832 __value_type>::type __allocator_type;
834 typedef __hash_table<__value_type, __hasher,
835 __key_equal, __allocator_type> __table;
839 typedef typename __table::_NodeTypes _NodeTypes;
840 typedef typename __table::__node_pointer __node_pointer;
841 typedef typename __table::__node_const_pointer __node_const_pointer;
842 typedef typename __table::__node_traits __node_traits;
843 typedef typename __table::__node_allocator __node_allocator;
844 typedef typename __table::__node __node;
845 typedef __hash_map_node_destructor<__node_allocator> _Dp;
846 typedef unique_ptr<__node, _Dp> __node_holder;
847 typedef allocator_traits<allocator_type> __alloc_traits;
849 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
850 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
852 typedef typename __alloc_traits::pointer pointer;
853 typedef typename __alloc_traits::const_pointer const_pointer;
854 typedef typename __table::size_type size_type;
855 typedef typename __table::difference_type difference_type;
857 typedef __hash_map_iterator<typename __table::iterator> iterator;
858 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
859 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
860 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
862 #if _LIBCPP_STD_VER > 14
863 typedef __map_node_handle<__node, allocator_type> node_type;
864 typedef __insert_return_type<iterator, node_type> insert_return_type;
867 _LIBCPP_INLINE_VISIBILITY
869 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
871 #if _LIBCPP_DEBUG_LEVEL >= 2
872 __get_db()->__insert_c(this);
875 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
876 const key_equal& __eql = key_equal());
877 unordered_map(size_type __n, const hasher& __hf,
878 const key_equal& __eql,
879 const allocator_type& __a);
880 template <class _InputIterator>
881 unordered_map(_InputIterator __first, _InputIterator __last);
882 template <class _InputIterator>
883 unordered_map(_InputIterator __first, _InputIterator __last,
884 size_type __n, const hasher& __hf = hasher(),
885 const key_equal& __eql = key_equal());
886 template <class _InputIterator>
887 unordered_map(_InputIterator __first, _InputIterator __last,
888 size_type __n, const hasher& __hf,
889 const key_equal& __eql,
890 const allocator_type& __a);
891 _LIBCPP_INLINE_VISIBILITY
892 explicit unordered_map(const allocator_type& __a);
893 unordered_map(const unordered_map& __u);
894 unordered_map(const unordered_map& __u, const allocator_type& __a);
895 #ifndef _LIBCPP_CXX03_LANG
896 _LIBCPP_INLINE_VISIBILITY
897 unordered_map(unordered_map&& __u)
898 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
899 unordered_map(unordered_map&& __u, const allocator_type& __a);
900 unordered_map(initializer_list<value_type> __il);
901 unordered_map(initializer_list<value_type> __il, size_type __n,
902 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
903 unordered_map(initializer_list<value_type> __il, size_type __n,
904 const hasher& __hf, const key_equal& __eql,
905 const allocator_type& __a);
906 #endif // _LIBCPP_CXX03_LANG
907 #if _LIBCPP_STD_VER > 11
908 _LIBCPP_INLINE_VISIBILITY
909 unordered_map(size_type __n, const allocator_type& __a)
910 : unordered_map(__n, hasher(), key_equal(), __a) {}
911 _LIBCPP_INLINE_VISIBILITY
912 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
913 : unordered_map(__n, __hf, key_equal(), __a) {}
914 template <class _InputIterator>
915 _LIBCPP_INLINE_VISIBILITY
916 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
917 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
918 template <class _InputIterator>
919 _LIBCPP_INLINE_VISIBILITY
920 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
921 const allocator_type& __a)
922 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
923 _LIBCPP_INLINE_VISIBILITY
924 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
925 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
926 _LIBCPP_INLINE_VISIBILITY
927 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
928 const allocator_type& __a)
929 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
931 // ~unordered_map() = default;
932 _LIBCPP_INLINE_VISIBILITY
933 unordered_map& operator=(const unordered_map& __u)
935 #ifndef _LIBCPP_CXX03_LANG
936 __table_ = __u.__table_;
940 __table_.hash_function() = __u.__table_.hash_function();
941 __table_.key_eq() = __u.__table_.key_eq();
942 __table_.max_load_factor() = __u.__table_.max_load_factor();
943 __table_.__copy_assign_alloc(__u.__table_);
944 insert(__u.begin(), __u.end());
949 #ifndef _LIBCPP_CXX03_LANG
950 _LIBCPP_INLINE_VISIBILITY
951 unordered_map& operator=(unordered_map&& __u)
952 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
953 _LIBCPP_INLINE_VISIBILITY
954 unordered_map& operator=(initializer_list<value_type> __il);
955 #endif // _LIBCPP_CXX03_LANG
957 _LIBCPP_INLINE_VISIBILITY
958 allocator_type get_allocator() const _NOEXCEPT
959 {return allocator_type(__table_.__node_alloc());}
961 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
962 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
963 _LIBCPP_INLINE_VISIBILITY
964 size_type size() const _NOEXCEPT {return __table_.size();}
965 _LIBCPP_INLINE_VISIBILITY
966 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
968 _LIBCPP_INLINE_VISIBILITY
969 iterator begin() _NOEXCEPT {return __table_.begin();}
970 _LIBCPP_INLINE_VISIBILITY
971 iterator end() _NOEXCEPT {return __table_.end();}
972 _LIBCPP_INLINE_VISIBILITY
973 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
974 _LIBCPP_INLINE_VISIBILITY
975 const_iterator end() const _NOEXCEPT {return __table_.end();}
976 _LIBCPP_INLINE_VISIBILITY
977 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
978 _LIBCPP_INLINE_VISIBILITY
979 const_iterator cend() const _NOEXCEPT {return __table_.end();}
981 _LIBCPP_INLINE_VISIBILITY
982 pair<iterator, bool> insert(const value_type& __x)
983 {return __table_.__insert_unique(__x);}
985 iterator insert(const_iterator __p, const value_type& __x) {
986 #if _LIBCPP_DEBUG_LEVEL >= 2
987 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
988 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
989 " referring to this unordered_map");
993 return insert(__x).first;
996 template <class _InputIterator>
997 _LIBCPP_INLINE_VISIBILITY
998 void insert(_InputIterator __first, _InputIterator __last);
1000 #ifndef _LIBCPP_CXX03_LANG
1001 _LIBCPP_INLINE_VISIBILITY
1002 void insert(initializer_list<value_type> __il)
1003 {insert(__il.begin(), __il.end());}
1005 _LIBCPP_INLINE_VISIBILITY
1006 pair<iterator, bool> insert(value_type&& __x)
1007 {return __table_.__insert_unique(_VSTD::move(__x));}
1009 iterator insert(const_iterator __p, value_type&& __x) {
1010 #if _LIBCPP_DEBUG_LEVEL >= 2
1011 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1012 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1013 " referring to this unordered_map");
1017 return __table_.__insert_unique(_VSTD::move(__x)).first;
1020 template <class _Pp,
1021 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1022 _LIBCPP_INLINE_VISIBILITY
1023 pair<iterator, bool> insert(_Pp&& __x)
1024 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
1026 template <class _Pp,
1027 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1028 _LIBCPP_INLINE_VISIBILITY
1029 iterator insert(const_iterator __p, _Pp&& __x)
1031 #if _LIBCPP_DEBUG_LEVEL >= 2
1032 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1033 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1034 " referring to this unordered_map");
1038 return insert(_VSTD::forward<_Pp>(__x)).first;
1041 template <class... _Args>
1042 _LIBCPP_INLINE_VISIBILITY
1043 pair<iterator, bool> emplace(_Args&&... __args) {
1044 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1047 template <class... _Args>
1048 _LIBCPP_INLINE_VISIBILITY
1049 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1050 #if _LIBCPP_DEBUG_LEVEL >= 2
1051 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1052 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1053 " referring to this unordered_map");
1057 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
1060 #endif // _LIBCPP_CXX03_LANG
1062 #if _LIBCPP_STD_VER > 14
1063 template <class... _Args>
1064 _LIBCPP_INLINE_VISIBILITY
1065 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1067 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1068 _VSTD::forward_as_tuple(__k),
1069 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1072 template <class... _Args>
1073 _LIBCPP_INLINE_VISIBILITY
1074 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1076 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1077 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1078 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1081 template <class... _Args>
1082 _LIBCPP_INLINE_VISIBILITY
1083 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1085 #if _LIBCPP_DEBUG_LEVEL >= 2
1086 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1087 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1088 " referring to this unordered_map");
1092 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
1095 template <class... _Args>
1096 _LIBCPP_INLINE_VISIBILITY
1097 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1099 #if _LIBCPP_DEBUG_LEVEL >= 2
1100 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1101 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1102 " referring to this unordered_map");
1106 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
1109 template <class _Vp>
1110 _LIBCPP_INLINE_VISIBILITY
1111 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1113 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1114 __k, _VSTD::forward<_Vp>(__v));
1115 if (!__res.second) {
1116 __res.first->second = _VSTD::forward<_Vp>(__v);
1121 template <class _Vp>
1122 _LIBCPP_INLINE_VISIBILITY
1123 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1125 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1126 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1127 if (!__res.second) {
1128 __res.first->second = _VSTD::forward<_Vp>(__v);
1133 template <class _Vp>
1134 _LIBCPP_INLINE_VISIBILITY
1135 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
1137 // FIXME: Add debug mode checking for the iterator input
1138 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
1141 template <class _Vp>
1142 _LIBCPP_INLINE_VISIBILITY
1143 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
1145 // FIXME: Add debug mode checking for the iterator input
1146 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
1148 #endif // _LIBCPP_STD_VER > 14
1150 _LIBCPP_INLINE_VISIBILITY
1151 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
1152 _LIBCPP_INLINE_VISIBILITY
1153 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1154 _LIBCPP_INLINE_VISIBILITY
1155 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
1156 _LIBCPP_INLINE_VISIBILITY
1157 iterator erase(const_iterator __first, const_iterator __last)
1158 {return __table_.erase(__first.__i_, __last.__i_);}
1159 _LIBCPP_INLINE_VISIBILITY
1160 void clear() _NOEXCEPT {__table_.clear();}
1162 #if _LIBCPP_STD_VER > 14
1163 _LIBCPP_INLINE_VISIBILITY
1164 insert_return_type insert(node_type&& __nh)
1166 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1167 "node_type with incompatible allocator passed to unordered_map::insert()");
1168 return __table_.template __node_handle_insert_unique<
1169 node_type, insert_return_type>(_VSTD::move(__nh));
1171 _LIBCPP_INLINE_VISIBILITY
1172 iterator insert(const_iterator __hint, node_type&& __nh)
1174 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1175 "node_type with incompatible allocator passed to unordered_map::insert()");
1176 return __table_.template __node_handle_insert_unique<node_type>(
1177 __hint.__i_, _VSTD::move(__nh));
1179 _LIBCPP_INLINE_VISIBILITY
1180 node_type extract(key_type const& __key)
1182 return __table_.template __node_handle_extract<node_type>(__key);
1184 _LIBCPP_INLINE_VISIBILITY
1185 node_type extract(const_iterator __it)
1187 return __table_.template __node_handle_extract<node_type>(
1192 _LIBCPP_INLINE_VISIBILITY
1193 void swap(unordered_map& __u)
1194 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1195 { __table_.swap(__u.__table_);}
1197 _LIBCPP_INLINE_VISIBILITY
1198 hasher hash_function() const
1199 {return __table_.hash_function().hash_function();}
1200 _LIBCPP_INLINE_VISIBILITY
1201 key_equal key_eq() const
1202 {return __table_.key_eq().key_eq();}
1204 _LIBCPP_INLINE_VISIBILITY
1205 iterator find(const key_type& __k) {return __table_.find(__k);}
1206 _LIBCPP_INLINE_VISIBILITY
1207 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1208 _LIBCPP_INLINE_VISIBILITY
1209 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
1210 _LIBCPP_INLINE_VISIBILITY
1211 pair<iterator, iterator> equal_range(const key_type& __k)
1212 {return __table_.__equal_range_unique(__k);}
1213 _LIBCPP_INLINE_VISIBILITY
1214 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1215 {return __table_.__equal_range_unique(__k);}
1217 mapped_type& operator[](const key_type& __k);
1218 #ifndef _LIBCPP_CXX03_LANG
1219 mapped_type& operator[](key_type&& __k);
1222 mapped_type& at(const key_type& __k);
1223 const mapped_type& at(const key_type& __k) const;
1225 _LIBCPP_INLINE_VISIBILITY
1226 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1227 _LIBCPP_INLINE_VISIBILITY
1228 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
1230 _LIBCPP_INLINE_VISIBILITY
1231 size_type bucket_size(size_type __n) const
1232 {return __table_.bucket_size(__n);}
1233 _LIBCPP_INLINE_VISIBILITY
1234 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1236 _LIBCPP_INLINE_VISIBILITY
1237 local_iterator begin(size_type __n) {return __table_.begin(__n);}
1238 _LIBCPP_INLINE_VISIBILITY
1239 local_iterator end(size_type __n) {return __table_.end(__n);}
1240 _LIBCPP_INLINE_VISIBILITY
1241 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
1242 _LIBCPP_INLINE_VISIBILITY
1243 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
1244 _LIBCPP_INLINE_VISIBILITY
1245 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1246 _LIBCPP_INLINE_VISIBILITY
1247 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1249 _LIBCPP_INLINE_VISIBILITY
1250 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1251 _LIBCPP_INLINE_VISIBILITY
1252 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1253 _LIBCPP_INLINE_VISIBILITY
1254 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1255 _LIBCPP_INLINE_VISIBILITY
1256 void rehash(size_type __n) {__table_.rehash(__n);}
1257 _LIBCPP_INLINE_VISIBILITY
1258 void reserve(size_type __n) {__table_.reserve(__n);}
1260 #if _LIBCPP_DEBUG_LEVEL >= 2
1262 bool __dereferenceable(const const_iterator* __i) const
1263 {return __table_.__dereferenceable(&__i->__i_);}
1264 bool __decrementable(const const_iterator* __i) const
1265 {return __table_.__decrementable(&__i->__i_);}
1266 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1267 {return __table_.__addable(&__i->__i_, __n);}
1268 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1269 {return __table_.__addable(&__i->__i_, __n);}
1271 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1275 #ifdef _LIBCPP_CXX03_LANG
1276 __node_holder __construct_node_with_key(const key_type& __k);
1280 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1281 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1282 size_type __n, const hasher& __hf, const key_equal& __eql)
1283 : __table_(__hf, __eql)
1285 #if _LIBCPP_DEBUG_LEVEL >= 2
1286 __get_db()->__insert_c(this);
1288 __table_.rehash(__n);
1291 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1292 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1293 size_type __n, const hasher& __hf, const key_equal& __eql,
1294 const allocator_type& __a)
1295 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1297 #if _LIBCPP_DEBUG_LEVEL >= 2
1298 __get_db()->__insert_c(this);
1300 __table_.rehash(__n);
1303 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1305 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1306 const allocator_type& __a)
1307 : __table_(typename __table::allocator_type(__a))
1309 #if _LIBCPP_DEBUG_LEVEL >= 2
1310 __get_db()->__insert_c(this);
1314 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1315 template <class _InputIterator>
1316 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1317 _InputIterator __first, _InputIterator __last)
1319 #if _LIBCPP_DEBUG_LEVEL >= 2
1320 __get_db()->__insert_c(this);
1322 insert(__first, __last);
1325 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1326 template <class _InputIterator>
1327 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1328 _InputIterator __first, _InputIterator __last, size_type __n,
1329 const hasher& __hf, const key_equal& __eql)
1330 : __table_(__hf, __eql)
1332 #if _LIBCPP_DEBUG_LEVEL >= 2
1333 __get_db()->__insert_c(this);
1335 __table_.rehash(__n);
1336 insert(__first, __last);
1339 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1340 template <class _InputIterator>
1341 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1342 _InputIterator __first, _InputIterator __last, size_type __n,
1343 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1344 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1346 #if _LIBCPP_DEBUG_LEVEL >= 2
1347 __get_db()->__insert_c(this);
1349 __table_.rehash(__n);
1350 insert(__first, __last);
1353 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1354 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1355 const unordered_map& __u)
1356 : __table_(__u.__table_)
1358 #if _LIBCPP_DEBUG_LEVEL >= 2
1359 __get_db()->__insert_c(this);
1361 __table_.rehash(__u.bucket_count());
1362 insert(__u.begin(), __u.end());
1365 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1366 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1367 const unordered_map& __u, const allocator_type& __a)
1368 : __table_(__u.__table_, typename __table::allocator_type(__a))
1370 #if _LIBCPP_DEBUG_LEVEL >= 2
1371 __get_db()->__insert_c(this);
1373 __table_.rehash(__u.bucket_count());
1374 insert(__u.begin(), __u.end());
1377 #ifndef _LIBCPP_CXX03_LANG
1379 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1381 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1382 unordered_map&& __u)
1383 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1384 : __table_(_VSTD::move(__u.__table_))
1386 #if _LIBCPP_DEBUG_LEVEL >= 2
1387 __get_db()->__insert_c(this);
1388 __get_db()->swap(this, &__u);
1392 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1393 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1394 unordered_map&& __u, const allocator_type& __a)
1395 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
1397 #if _LIBCPP_DEBUG_LEVEL >= 2
1398 __get_db()->__insert_c(this);
1400 if (__a != __u.get_allocator())
1402 iterator __i = __u.begin();
1403 while (__u.size() != 0) {
1404 __table_.__emplace_unique(
1405 __u.__table_.remove((__i++).__i_)->__value_.__move());
1408 #if _LIBCPP_DEBUG_LEVEL >= 2
1410 __get_db()->swap(this, &__u);
1414 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1415 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1416 initializer_list<value_type> __il)
1418 #if _LIBCPP_DEBUG_LEVEL >= 2
1419 __get_db()->__insert_c(this);
1421 insert(__il.begin(), __il.end());
1424 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1425 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1426 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1427 const key_equal& __eql)
1428 : __table_(__hf, __eql)
1430 #if _LIBCPP_DEBUG_LEVEL >= 2
1431 __get_db()->__insert_c(this);
1433 __table_.rehash(__n);
1434 insert(__il.begin(), __il.end());
1437 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1438 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1439 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1440 const key_equal& __eql, 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);
1447 insert(__il.begin(), __il.end());
1450 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1452 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1453 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
1454 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1456 __table_ = _VSTD::move(__u.__table_);
1460 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1462 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1463 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1464 initializer_list<value_type> __il)
1466 __table_.__assign_unique(__il.begin(), __il.end());
1470 #endif // _LIBCPP_CXX03_LANG
1472 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1473 template <class _InputIterator>
1476 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1477 _InputIterator __last)
1479 for (; __first != __last; ++__first)
1480 __table_.__insert_unique(*__first);
1483 #ifndef _LIBCPP_CXX03_LANG
1485 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1487 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1489 return __table_.__emplace_unique_key_args(__k,
1490 std::piecewise_construct, std::forward_as_tuple(__k),
1491 std::forward_as_tuple()).first->__get_value().second;
1494 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1496 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1498 return __table_.__emplace_unique_key_args(__k,
1499 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1500 std::forward_as_tuple()).first->__get_value().second;
1502 #else // _LIBCPP_CXX03_LANG
1504 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1505 typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1506 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1508 __node_allocator& __na = __table_.__node_alloc();
1509 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1510 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
1511 __h.get_deleter().__first_constructed = true;
1512 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
1513 __h.get_deleter().__second_constructed = true;
1514 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1517 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1519 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1521 iterator __i = find(__k);
1524 __node_holder __h = __construct_node_with_key(__k);
1525 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1527 return __r.first->second;
1530 #endif // _LIBCPP_CXX03_MODE
1532 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1534 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1536 iterator __i = find(__k);
1537 #ifndef _LIBCPP_NO_EXCEPTIONS
1539 throw out_of_range("unordered_map::at: key not found");
1540 #endif // _LIBCPP_NO_EXCEPTIONS
1544 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1546 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1548 const_iterator __i = find(__k);
1549 #ifndef _LIBCPP_NO_EXCEPTIONS
1551 throw out_of_range("unordered_map::at: key not found");
1552 #endif // _LIBCPP_NO_EXCEPTIONS
1556 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1557 inline _LIBCPP_INLINE_VISIBILITY
1559 swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1560 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1561 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1566 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1568 operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1569 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1571 if (__x.size() != __y.size())
1573 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1575 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1578 const_iterator __j = __y.find(__i->first);
1579 if (__j == __ey || !(*__i == *__j))
1585 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1586 inline _LIBCPP_INLINE_VISIBILITY
1588 operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1589 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1591 return !(__x == __y);
1594 template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1595 class _Alloc = allocator<pair<const _Key, _Tp> > >
1596 class _LIBCPP_TEMPLATE_VIS unordered_multimap
1600 typedef _Key key_type;
1601 typedef _Tp mapped_type;
1602 typedef _Hash hasher;
1603 typedef _Pred key_equal;
1604 typedef _Alloc allocator_type;
1605 typedef pair<const key_type, mapped_type> value_type;
1606 typedef value_type& reference;
1607 typedef const value_type& const_reference;
1608 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1609 "Invalid allocator::value_type");
1612 typedef __hash_value_type<key_type, mapped_type> __value_type;
1613 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1614 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
1615 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1616 __value_type>::type __allocator_type;
1618 typedef __hash_table<__value_type, __hasher,
1619 __key_equal, __allocator_type> __table;
1623 typedef typename __table::_NodeTypes _NodeTypes;
1624 typedef typename __table::__node_traits __node_traits;
1625 typedef typename __table::__node_allocator __node_allocator;
1626 typedef typename __table::__node __node;
1627 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1628 typedef unique_ptr<__node, _Dp> __node_holder;
1629 typedef allocator_traits<allocator_type> __alloc_traits;
1630 static_assert((is_same<typename __node_traits::size_type,
1631 typename __alloc_traits::size_type>::value),
1632 "Allocator uses different size_type for different types");
1634 typedef typename __alloc_traits::pointer pointer;
1635 typedef typename __alloc_traits::const_pointer const_pointer;
1636 typedef typename __table::size_type size_type;
1637 typedef typename __table::difference_type difference_type;
1639 typedef __hash_map_iterator<typename __table::iterator> iterator;
1640 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1641 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1642 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1644 #if _LIBCPP_STD_VER > 14
1645 typedef __map_node_handle<__node, allocator_type> node_type;
1648 _LIBCPP_INLINE_VISIBILITY
1649 unordered_multimap()
1650 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1652 #if _LIBCPP_DEBUG_LEVEL >= 2
1653 __get_db()->__insert_c(this);
1656 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1657 const key_equal& __eql = key_equal());
1658 unordered_multimap(size_type __n, const hasher& __hf,
1659 const key_equal& __eql,
1660 const allocator_type& __a);
1661 template <class _InputIterator>
1662 unordered_multimap(_InputIterator __first, _InputIterator __last);
1663 template <class _InputIterator>
1664 unordered_multimap(_InputIterator __first, _InputIterator __last,
1665 size_type __n, const hasher& __hf = hasher(),
1666 const key_equal& __eql = key_equal());
1667 template <class _InputIterator>
1668 unordered_multimap(_InputIterator __first, _InputIterator __last,
1669 size_type __n, const hasher& __hf,
1670 const key_equal& __eql,
1671 const allocator_type& __a);
1672 _LIBCPP_INLINE_VISIBILITY
1673 explicit unordered_multimap(const allocator_type& __a);
1674 unordered_multimap(const unordered_multimap& __u);
1675 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
1676 #ifndef _LIBCPP_CXX03_LANG
1677 _LIBCPP_INLINE_VISIBILITY
1678 unordered_multimap(unordered_multimap&& __u)
1679 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
1680 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
1681 unordered_multimap(initializer_list<value_type> __il);
1682 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1683 const hasher& __hf = hasher(),
1684 const key_equal& __eql = key_equal());
1685 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1686 const hasher& __hf, const key_equal& __eql,
1687 const allocator_type& __a);
1688 #endif // _LIBCPP_CXX03_LANG
1689 #if _LIBCPP_STD_VER > 11
1690 _LIBCPP_INLINE_VISIBILITY
1691 unordered_multimap(size_type __n, const allocator_type& __a)
1692 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1693 _LIBCPP_INLINE_VISIBILITY
1694 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1695 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1696 template <class _InputIterator>
1697 _LIBCPP_INLINE_VISIBILITY
1698 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1699 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1700 template <class _InputIterator>
1701 _LIBCPP_INLINE_VISIBILITY
1702 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1703 const allocator_type& __a)
1704 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1705 _LIBCPP_INLINE_VISIBILITY
1706 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1707 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1708 _LIBCPP_INLINE_VISIBILITY
1709 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1710 const allocator_type& __a)
1711 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1713 // ~unordered_multimap() = default;
1714 _LIBCPP_INLINE_VISIBILITY
1715 unordered_multimap& operator=(const unordered_multimap& __u)
1717 #ifndef _LIBCPP_CXX03_LANG
1718 __table_ = __u.__table_;
1722 __table_.hash_function() = __u.__table_.hash_function();
1723 __table_.key_eq() = __u.__table_.key_eq();
1724 __table_.max_load_factor() = __u.__table_.max_load_factor();
1725 __table_.__copy_assign_alloc(__u.__table_);
1726 insert(__u.begin(), __u.end());
1731 #ifndef _LIBCPP_CXX03_LANG
1732 _LIBCPP_INLINE_VISIBILITY
1733 unordered_multimap& operator=(unordered_multimap&& __u)
1734 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
1735 _LIBCPP_INLINE_VISIBILITY
1736 unordered_multimap& operator=(initializer_list<value_type> __il);
1737 #endif // _LIBCPP_CXX03_LANG
1739 _LIBCPP_INLINE_VISIBILITY
1740 allocator_type get_allocator() const _NOEXCEPT
1741 {return allocator_type(__table_.__node_alloc());}
1743 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1744 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
1745 _LIBCPP_INLINE_VISIBILITY
1746 size_type size() const _NOEXCEPT {return __table_.size();}
1747 _LIBCPP_INLINE_VISIBILITY
1748 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1750 _LIBCPP_INLINE_VISIBILITY
1751 iterator begin() _NOEXCEPT {return __table_.begin();}
1752 _LIBCPP_INLINE_VISIBILITY
1753 iterator end() _NOEXCEPT {return __table_.end();}
1754 _LIBCPP_INLINE_VISIBILITY
1755 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
1756 _LIBCPP_INLINE_VISIBILITY
1757 const_iterator end() const _NOEXCEPT {return __table_.end();}
1758 _LIBCPP_INLINE_VISIBILITY
1759 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1760 _LIBCPP_INLINE_VISIBILITY
1761 const_iterator cend() const _NOEXCEPT {return __table_.end();}
1763 _LIBCPP_INLINE_VISIBILITY
1764 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1766 _LIBCPP_INLINE_VISIBILITY
1767 iterator insert(const_iterator __p, const value_type& __x)
1768 {return __table_.__insert_multi(__p.__i_, __x);}
1770 template <class _InputIterator>
1771 _LIBCPP_INLINE_VISIBILITY
1772 void insert(_InputIterator __first, _InputIterator __last);
1774 #ifndef _LIBCPP_CXX03_LANG
1775 _LIBCPP_INLINE_VISIBILITY
1776 void insert(initializer_list<value_type> __il)
1777 {insert(__il.begin(), __il.end());}
1778 _LIBCPP_INLINE_VISIBILITY
1779 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1781 _LIBCPP_INLINE_VISIBILITY
1782 iterator insert(const_iterator __p, value_type&& __x)
1783 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1785 template <class _Pp,
1786 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1787 _LIBCPP_INLINE_VISIBILITY
1788 iterator insert(_Pp&& __x)
1789 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1791 template <class _Pp,
1792 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1793 _LIBCPP_INLINE_VISIBILITY
1794 iterator insert(const_iterator __p, _Pp&& __x)
1795 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1797 template <class... _Args>
1798 iterator emplace(_Args&&... __args) {
1799 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1802 template <class... _Args>
1803 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1804 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1806 #endif // _LIBCPP_CXX03_LANG
1809 _LIBCPP_INLINE_VISIBILITY
1810 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
1811 _LIBCPP_INLINE_VISIBILITY
1812 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1813 _LIBCPP_INLINE_VISIBILITY
1814 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
1815 _LIBCPP_INLINE_VISIBILITY
1816 iterator erase(const_iterator __first, const_iterator __last)
1817 {return __table_.erase(__first.__i_, __last.__i_);}
1818 _LIBCPP_INLINE_VISIBILITY
1819 void clear() _NOEXCEPT {__table_.clear();}
1821 #if _LIBCPP_STD_VER > 14
1822 _LIBCPP_INLINE_VISIBILITY
1823 iterator insert(node_type&& __nh)
1825 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1826 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1827 return __table_.template __node_handle_insert_multi<node_type>(
1830 _LIBCPP_INLINE_VISIBILITY
1831 iterator insert(const_iterator __hint, node_type&& __nh)
1833 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1834 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1835 return __table_.template __node_handle_insert_multi<node_type>(
1836 __hint.__i_, _VSTD::move(__nh));
1838 _LIBCPP_INLINE_VISIBILITY
1839 node_type extract(key_type const& __key)
1841 return __table_.template __node_handle_extract<node_type>(__key);
1843 _LIBCPP_INLINE_VISIBILITY
1844 node_type extract(const_iterator __it)
1846 return __table_.template __node_handle_extract<node_type>(
1851 _LIBCPP_INLINE_VISIBILITY
1852 void swap(unordered_multimap& __u)
1853 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1854 {__table_.swap(__u.__table_);}
1856 _LIBCPP_INLINE_VISIBILITY
1857 hasher hash_function() const
1858 {return __table_.hash_function().hash_function();}
1859 _LIBCPP_INLINE_VISIBILITY
1860 key_equal key_eq() const
1861 {return __table_.key_eq().key_eq();}
1863 _LIBCPP_INLINE_VISIBILITY
1864 iterator find(const key_type& __k) {return __table_.find(__k);}
1865 _LIBCPP_INLINE_VISIBILITY
1866 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1867 _LIBCPP_INLINE_VISIBILITY
1868 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
1869 _LIBCPP_INLINE_VISIBILITY
1870 pair<iterator, iterator> equal_range(const key_type& __k)
1871 {return __table_.__equal_range_multi(__k);}
1872 _LIBCPP_INLINE_VISIBILITY
1873 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1874 {return __table_.__equal_range_multi(__k);}
1876 _LIBCPP_INLINE_VISIBILITY
1877 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1878 _LIBCPP_INLINE_VISIBILITY
1879 size_type max_bucket_count() const _NOEXCEPT
1880 {return __table_.max_bucket_count();}
1882 _LIBCPP_INLINE_VISIBILITY
1883 size_type bucket_size(size_type __n) const
1884 {return __table_.bucket_size(__n);}
1885 _LIBCPP_INLINE_VISIBILITY
1886 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1888 _LIBCPP_INLINE_VISIBILITY
1889 local_iterator begin(size_type __n) {return __table_.begin(__n);}
1890 _LIBCPP_INLINE_VISIBILITY
1891 local_iterator end(size_type __n) {return __table_.end(__n);}
1892 _LIBCPP_INLINE_VISIBILITY
1893 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
1894 _LIBCPP_INLINE_VISIBILITY
1895 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
1896 _LIBCPP_INLINE_VISIBILITY
1897 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1898 _LIBCPP_INLINE_VISIBILITY
1899 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1901 _LIBCPP_INLINE_VISIBILITY
1902 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1903 _LIBCPP_INLINE_VISIBILITY
1904 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1905 _LIBCPP_INLINE_VISIBILITY
1906 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1907 _LIBCPP_INLINE_VISIBILITY
1908 void rehash(size_type __n) {__table_.rehash(__n);}
1909 _LIBCPP_INLINE_VISIBILITY
1910 void reserve(size_type __n) {__table_.reserve(__n);}
1912 #if _LIBCPP_DEBUG_LEVEL >= 2
1914 bool __dereferenceable(const const_iterator* __i) const
1915 {return __table_.__dereferenceable(&__i->__i_);}
1916 bool __decrementable(const const_iterator* __i) const
1917 {return __table_.__decrementable(&__i->__i_);}
1918 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1919 {return __table_.__addable(&__i->__i_, __n);}
1920 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1921 {return __table_.__addable(&__i->__i_, __n);}
1923 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1928 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1929 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1930 size_type __n, const hasher& __hf, const key_equal& __eql)
1931 : __table_(__hf, __eql)
1933 #if _LIBCPP_DEBUG_LEVEL >= 2
1934 __get_db()->__insert_c(this);
1936 __table_.rehash(__n);
1939 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1940 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1941 size_type __n, const hasher& __hf, const key_equal& __eql,
1942 const allocator_type& __a)
1943 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1945 #if _LIBCPP_DEBUG_LEVEL >= 2
1946 __get_db()->__insert_c(this);
1948 __table_.rehash(__n);
1951 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1952 template <class _InputIterator>
1953 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1954 _InputIterator __first, _InputIterator __last)
1956 #if _LIBCPP_DEBUG_LEVEL >= 2
1957 __get_db()->__insert_c(this);
1959 insert(__first, __last);
1962 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1963 template <class _InputIterator>
1964 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1965 _InputIterator __first, _InputIterator __last, size_type __n,
1966 const hasher& __hf, const key_equal& __eql)
1967 : __table_(__hf, __eql)
1969 #if _LIBCPP_DEBUG_LEVEL >= 2
1970 __get_db()->__insert_c(this);
1972 __table_.rehash(__n);
1973 insert(__first, __last);
1976 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1977 template <class _InputIterator>
1978 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1979 _InputIterator __first, _InputIterator __last, size_type __n,
1980 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1981 : __table_(__hf, __eql, typename __table::allocator_type(__a))
1983 #if _LIBCPP_DEBUG_LEVEL >= 2
1984 __get_db()->__insert_c(this);
1986 __table_.rehash(__n);
1987 insert(__first, __last);
1990 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1992 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1993 const allocator_type& __a)
1994 : __table_(typename __table::allocator_type(__a))
1996 #if _LIBCPP_DEBUG_LEVEL >= 2
1997 __get_db()->__insert_c(this);
2001 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2002 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2003 const unordered_multimap& __u)
2004 : __table_(__u.__table_)
2006 #if _LIBCPP_DEBUG_LEVEL >= 2
2007 __get_db()->__insert_c(this);
2009 __table_.rehash(__u.bucket_count());
2010 insert(__u.begin(), __u.end());
2013 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2014 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2015 const unordered_multimap& __u, const allocator_type& __a)
2016 : __table_(__u.__table_, typename __table::allocator_type(__a))
2018 #if _LIBCPP_DEBUG_LEVEL >= 2
2019 __get_db()->__insert_c(this);
2021 __table_.rehash(__u.bucket_count());
2022 insert(__u.begin(), __u.end());
2025 #ifndef _LIBCPP_CXX03_LANG
2027 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2029 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2030 unordered_multimap&& __u)
2031 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
2032 : __table_(_VSTD::move(__u.__table_))
2034 #if _LIBCPP_DEBUG_LEVEL >= 2
2035 __get_db()->__insert_c(this);
2036 __get_db()->swap(this, &__u);
2040 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2041 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2042 unordered_multimap&& __u, const allocator_type& __a)
2043 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
2045 #if _LIBCPP_DEBUG_LEVEL >= 2
2046 __get_db()->__insert_c(this);
2048 if (__a != __u.get_allocator())
2050 iterator __i = __u.begin();
2051 while (__u.size() != 0)
2053 __table_.__insert_multi(
2054 __u.__table_.remove((__i++).__i_)->__value_.__move());
2057 #if _LIBCPP_DEBUG_LEVEL >= 2
2059 __get_db()->swap(this, &__u);
2063 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2064 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2065 initializer_list<value_type> __il)
2067 #if _LIBCPP_DEBUG_LEVEL >= 2
2068 __get_db()->__insert_c(this);
2070 insert(__il.begin(), __il.end());
2073 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2074 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2075 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2076 const key_equal& __eql)
2077 : __table_(__hf, __eql)
2079 #if _LIBCPP_DEBUG_LEVEL >= 2
2080 __get_db()->__insert_c(this);
2082 __table_.rehash(__n);
2083 insert(__il.begin(), __il.end());
2086 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2087 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2088 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2089 const key_equal& __eql, const allocator_type& __a)
2090 : __table_(__hf, __eql, typename __table::allocator_type(__a))
2092 #if _LIBCPP_DEBUG_LEVEL >= 2
2093 __get_db()->__insert_c(this);
2095 __table_.rehash(__n);
2096 insert(__il.begin(), __il.end());
2099 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2101 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2102 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
2103 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
2105 __table_ = _VSTD::move(__u.__table_);
2109 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2111 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2112 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2113 initializer_list<value_type> __il)
2115 __table_.__assign_multi(__il.begin(), __il.end());
2119 #endif // _LIBCPP_CXX03_LANG
2123 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2124 template <class _InputIterator>
2127 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2128 _InputIterator __last)
2130 for (; __first != __last; ++__first)
2131 __table_.__insert_multi(*__first);
2134 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2135 inline _LIBCPP_INLINE_VISIBILITY
2137 swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2138 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2139 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2144 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2146 operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2147 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2149 if (__x.size() != __y.size())
2151 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2153 typedef pair<const_iterator, const_iterator> _EqRng;
2154 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2156 _EqRng __xeq = __x.equal_range(__i->first);
2157 _EqRng __yeq = __y.equal_range(__i->first);
2158 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2159 _VSTD::distance(__yeq.first, __yeq.second) ||
2160 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
2167 template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2168 inline _LIBCPP_INLINE_VISIBILITY
2170 operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2171 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2173 return !(__x == __y);
2176 _LIBCPP_END_NAMESPACE_STD
2178 #endif // _LIBCPP_UNORDERED_MAP