blob: 725cb6af275996f367fefba1812c99cee5182f01 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_MAP
12#define _LIBCPP_UNORDERED_MAP
13
14/*
15
16 unordered_map synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
25class unordered_map
26{
27public:
28 // types
29 typedef Key key_type;
30 typedef T mapped_type;
31 typedef Hash hasher;
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;
41
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
46
Howard Hinnant37141072011-06-04 18:54:24 +000047 unordered_map()
48 noexcept(
49 is_nothrow_default_constructible<hasher>::value &&
50 is_nothrow_default_constructible<key_equal>::value &&
51 is_nothrow_default_constructible<allocator_type>::value);
52 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +000053 const key_equal& eql = key_equal(),
54 const allocator_type& a = allocator_type());
55 template <class InputIterator>
56 unordered_map(InputIterator f, InputIterator l,
57 size_type n = 0, const hasher& hf = hasher(),
58 const key_equal& eql = key_equal(),
59 const allocator_type& a = allocator_type());
60 explicit unordered_map(const allocator_type&);
61 unordered_map(const unordered_map&);
62 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +000063 unordered_map(unordered_map&&)
64 noexcept(
65 is_nothrow_move_constructible<hasher>::value &&
66 is_nothrow_move_constructible<key_equal>::value &&
67 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000068 unordered_map(unordered_map&&, const Allocator&);
69 unordered_map(initializer_list<value_type>, size_type n = 0,
70 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
71 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +000072 unordered_map(size_type n, const allocator_type& a)
73 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
74 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
75 : unordered_map(n, hf, key_equal(), a) {} // C++14
76 template <class InputIterator>
77 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
78 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
79 template <class InputIterator>
80 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
81 const allocator_type& a)
82 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
83 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
84 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
85 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
86 const allocator_type& a)
87 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000088 ~unordered_map();
89 unordered_map& operator=(const unordered_map&);
Howard Hinnant37141072011-06-04 18:54:24 +000090 unordered_map& operator=(unordered_map&&)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
94 is_nothrow_move_assignable<hasher>::value &&
95 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000096 unordered_map& operator=(initializer_list<value_type>);
97
Howard Hinnant37141072011-06-04 18:54:24 +000098 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000099
Howard Hinnant37141072011-06-04 18:54:24 +0000100 bool empty() const noexcept;
101 size_type size() const noexcept;
102 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000103
Howard Hinnant37141072011-06-04 18:54:24 +0000104 iterator begin() noexcept;
105 iterator end() noexcept;
106 const_iterator begin() const noexcept;
107 const_iterator end() const noexcept;
108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000110
111 template <class... Args>
112 pair<iterator, bool> emplace(Args&&... args);
113 template <class... Args>
114 iterator emplace_hint(const_iterator position, Args&&... args);
115 pair<iterator, bool> insert(const value_type& obj);
116 template <class P>
117 pair<iterator, bool> insert(P&& obj);
118 iterator insert(const_iterator hint, const value_type& obj);
119 template <class P>
120 iterator insert(const_iterator hint, P&& obj);
121 template <class InputIterator>
122 void insert(InputIterator first, InputIterator last);
123 void insert(initializer_list<value_type>);
124
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000125 template <class... Args>
126 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
127 template <class... Args>
128 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
129 template <class... Args>
130 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
131 template <class... Args>
132 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
133 template <class M>
134 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
135 template <class M>
136 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
137 template <class M>
138 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
139 template <class M>
140 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
141
Howard Hinnant3e519522010-05-11 19:42:16 +0000142 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000143 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000144 size_type erase(const key_type& k);
145 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000146 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000147
Howard Hinnant37141072011-06-04 18:54:24 +0000148 void swap(unordered_map&)
149 noexcept(
150 (!allocator_type::propagate_on_container_swap::value ||
151 __is_nothrow_swappable<allocator_type>::value) &&
152 __is_nothrow_swappable<hasher>::value &&
153 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000154
155 hasher hash_function() const;
156 key_equal key_eq() const;
157
158 iterator find(const key_type& k);
159 const_iterator find(const key_type& k) const;
160 size_type count(const key_type& k) const;
161 pair<iterator, iterator> equal_range(const key_type& k);
162 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
163
164 mapped_type& operator[](const key_type& k);
165 mapped_type& operator[](key_type&& k);
166
167 mapped_type& at(const key_type& k);
168 const mapped_type& at(const key_type& k) const;
169
Howard Hinnant37141072011-06-04 18:54:24 +0000170 size_type bucket_count() const noexcept;
171 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000172
173 size_type bucket_size(size_type n) const;
174 size_type bucket(const key_type& k) const;
175
176 local_iterator begin(size_type n);
177 local_iterator end(size_type n);
178 const_local_iterator begin(size_type n) const;
179 const_local_iterator end(size_type n) const;
180 const_local_iterator cbegin(size_type n) const;
181 const_local_iterator cend(size_type n) const;
182
Howard Hinnant37141072011-06-04 18:54:24 +0000183 float load_factor() const noexcept;
184 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000185 void max_load_factor(float z);
186 void rehash(size_type n);
187 void reserve(size_type n);
188};
189
190template <class Key, class T, class Hash, class Pred, class Alloc>
191 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000192 unordered_map<Key, T, Hash, Pred, Alloc>& y)
193 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000194
195template <class Key, class T, class Hash, class Pred, class Alloc>
196 bool
197 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
198 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
199
200template <class Key, class T, class Hash, class Pred, class Alloc>
201 bool
202 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
203 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
204
205template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
206 class Alloc = allocator<pair<const Key, T>>>
207class unordered_multimap
208{
209public:
210 // types
211 typedef Key key_type;
212 typedef T mapped_type;
213 typedef Hash hasher;
214 typedef Pred key_equal;
215 typedef Alloc allocator_type;
216 typedef pair<const key_type, mapped_type> value_type;
217 typedef value_type& reference;
218 typedef const value_type& const_reference;
219 typedef typename allocator_traits<allocator_type>::pointer pointer;
220 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
221 typedef typename allocator_traits<allocator_type>::size_type size_type;
222 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
223
224 typedef /unspecified/ iterator;
225 typedef /unspecified/ const_iterator;
226 typedef /unspecified/ local_iterator;
227 typedef /unspecified/ const_local_iterator;
228
Howard Hinnant37141072011-06-04 18:54:24 +0000229 unordered_multimap()
230 noexcept(
231 is_nothrow_default_constructible<hasher>::value &&
232 is_nothrow_default_constructible<key_equal>::value &&
233 is_nothrow_default_constructible<allocator_type>::value);
234 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +0000235 const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
237 template <class InputIterator>
238 unordered_multimap(InputIterator f, InputIterator l,
239 size_type n = 0, const hasher& hf = hasher(),
240 const key_equal& eql = key_equal(),
241 const allocator_type& a = allocator_type());
242 explicit unordered_multimap(const allocator_type&);
243 unordered_multimap(const unordered_multimap&);
244 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +0000245 unordered_multimap(unordered_multimap&&)
246 noexcept(
247 is_nothrow_move_constructible<hasher>::value &&
248 is_nothrow_move_constructible<key_equal>::value &&
249 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000250 unordered_multimap(unordered_multimap&&, const Allocator&);
251 unordered_multimap(initializer_list<value_type>, size_type n = 0,
252 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
253 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +0000254 unordered_multimap(size_type n, const allocator_type& a)
255 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
256 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
257 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
258 template <class InputIterator>
259 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
260 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
261 template <class InputIterator>
262 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
263 const allocator_type& a)
264 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
265 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
266 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
267 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
268 const allocator_type& a)
269 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000270 ~unordered_multimap();
271 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant37141072011-06-04 18:54:24 +0000272 unordered_multimap& operator=(unordered_multimap&&)
273 noexcept(
274 allocator_type::propagate_on_container_move_assignment::value &&
275 is_nothrow_move_assignable<allocator_type>::value &&
276 is_nothrow_move_assignable<hasher>::value &&
277 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000278 unordered_multimap& operator=(initializer_list<value_type>);
279
Howard Hinnant37141072011-06-04 18:54:24 +0000280 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000281
Howard Hinnant37141072011-06-04 18:54:24 +0000282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000285
Howard Hinnant37141072011-06-04 18:54:24 +0000286 iterator begin() noexcept;
287 iterator end() noexcept;
288 const_iterator begin() const noexcept;
289 const_iterator end() const noexcept;
290 const_iterator cbegin() const noexcept;
291 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000292
293 template <class... Args>
294 iterator emplace(Args&&... args);
295 template <class... Args>
296 iterator emplace_hint(const_iterator position, Args&&... args);
297 iterator insert(const value_type& obj);
298 template <class P>
299 iterator insert(P&& obj);
300 iterator insert(const_iterator hint, const value_type& obj);
301 template <class P>
302 iterator insert(const_iterator hint, P&& obj);
303 template <class InputIterator>
304 void insert(InputIterator first, InputIterator last);
305 void insert(initializer_list<value_type>);
306
307 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000308 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000309 size_type erase(const key_type& k);
310 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000311 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000312
Howard Hinnant37141072011-06-04 18:54:24 +0000313 void swap(unordered_multimap&)
314 noexcept(
315 (!allocator_type::propagate_on_container_swap::value ||
316 __is_nothrow_swappable<allocator_type>::value) &&
317 __is_nothrow_swappable<hasher>::value &&
318 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000319
320 hasher hash_function() const;
321 key_equal key_eq() const;
322
323 iterator find(const key_type& k);
324 const_iterator find(const key_type& k) const;
325 size_type count(const key_type& k) const;
326 pair<iterator, iterator> equal_range(const key_type& k);
327 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
328
Howard Hinnant37141072011-06-04 18:54:24 +0000329 size_type bucket_count() const noexcept;
330 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000331
332 size_type bucket_size(size_type n) const;
333 size_type bucket(const key_type& k) const;
334
335 local_iterator begin(size_type n);
336 local_iterator end(size_type n);
337 const_local_iterator begin(size_type n) const;
338 const_local_iterator end(size_type n) const;
339 const_local_iterator cbegin(size_type n) const;
340 const_local_iterator cend(size_type n) const;
341
Howard Hinnant37141072011-06-04 18:54:24 +0000342 float load_factor() const noexcept;
343 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000344 void max_load_factor(float z);
345 void rehash(size_type n);
346 void reserve(size_type n);
347};
348
349template <class Key, class T, class Hash, class Pred, class Alloc>
350 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000351 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
352 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000353
354template <class Key, class T, class Hash, class Pred, class Alloc>
355 bool
356 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
357 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
358
359template <class Key, class T, class Hash, class Pred, class Alloc>
360 bool
361 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
362 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
363
364} // std
365
366*/
367
368#include <__config>
369#include <__hash_table>
370#include <functional>
371#include <stdexcept>
Eric Fiselier0f905672016-02-11 21:45:53 +0000372#include <tuple>
Howard Hinnant3e519522010-05-11 19:42:16 +0000373
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000374#include <__debug>
375
Howard Hinnant073458b2011-10-17 20:05:10 +0000376#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000377#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000378#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000379
380_LIBCPP_BEGIN_NAMESPACE_STD
381
Eric Fiselier04333f92017-01-13 22:42:53 +0000382template <class _Key, class _Cp, class _Hash, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000383class __unordered_map_hasher
384 : private _Hash
385{
386public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000388 __unordered_map_hasher()
389 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
390 : _Hash() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000392 __unordered_map_hasher(const _Hash& __h)
393 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
394 : _Hash(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000396 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000398 size_t operator()(const _Cp& __x) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000399 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000400 _LIBCPP_INLINE_VISIBILITY
401 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000402 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000403 void swap(__unordered_map_hasher&__y)
404 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
405 {
406 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000407 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000408 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000409};
410
Howard Hinnantabb160e2013-07-05 18:06:00 +0000411template <class _Key, class _Cp, class _Hash>
412class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000413{
414 _Hash __hash_;
415public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000417 __unordered_map_hasher()
418 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
419 : __hash_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000421 __unordered_map_hasher(const _Hash& __h)
422 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
423 : __hash_(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000425 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000427 size_t operator()(const _Cp& __x) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000428 {return __hash_(__x.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000429 _LIBCPP_INLINE_VISIBILITY
430 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000431 {return __hash_(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000432 void swap(__unordered_map_hasher&__y)
433 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
434 {
435 using _VSTD::swap;
436 swap(__hash_, __y.__hash_);
437 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000438};
439
Marshall Clowe3fbe142015-07-13 20:04:56 +0000440template <class _Key, class _Cp, class _Hash, bool __b>
441inline _LIBCPP_INLINE_VISIBILITY
442void
443swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
444 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
445 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
446{
447 __x.swap(__y);
448}
449
Eric Fiselier04333f92017-01-13 22:42:53 +0000450template <class _Key, class _Cp, class _Pred, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000451class __unordered_map_equal
452 : private _Pred
453{
454public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000456 __unordered_map_equal()
457 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
458 : _Pred() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000460 __unordered_map_equal(const _Pred& __p)
461 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
462 : _Pred(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000464 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000466 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000467 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000468 _LIBCPP_INLINE_VISIBILITY
469 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000470 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000472 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000473 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000474 void swap(__unordered_map_equal&__y)
475 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
476 {
477 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000478 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000479 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000480};
481
Howard Hinnantabb160e2013-07-05 18:06:00 +0000482template <class _Key, class _Cp, class _Pred>
483class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000484{
485 _Pred __pred_;
486public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000488 __unordered_map_equal()
489 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
490 : __pred_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000492 __unordered_map_equal(const _Pred& __p)
493 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
494 : __pred_(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000496 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000498 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000499 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000500 _LIBCPP_INLINE_VISIBILITY
501 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000502 {return __pred_(__x.__cc.first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000504 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000505 {return __pred_(__x, __y.__cc.first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000506 void swap(__unordered_map_equal&__y)
507 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
508 {
509 using _VSTD::swap;
510 swap(__pred_, __y.__pred_);
511 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000512};
513
Marshall Clowe3fbe142015-07-13 20:04:56 +0000514template <class _Key, class _Cp, class _Pred, bool __b>
515inline _LIBCPP_INLINE_VISIBILITY
516void
517swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
518 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
519 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
520{
521 __x.swap(__y);
522}
523
Howard Hinnant3e519522010-05-11 19:42:16 +0000524template <class _Alloc>
525class __hash_map_node_destructor
526{
527 typedef _Alloc allocator_type;
528 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000529
Howard Hinnant3e519522010-05-11 19:42:16 +0000530public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000531
532 typedef typename __alloc_traits::pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000533private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000534
535 allocator_type& __na_;
536
537 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
538
539public:
540 bool __first_constructed;
541 bool __second_constructed;
542
Howard Hinnant789847d2010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000544 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000545 : __na_(__na),
546 __first_constructed(false),
547 __second_constructed(false)
548 {}
549
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000550#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000552 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000553 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000554 : __na_(__x.__na_),
555 __first_constructed(__x.__value_constructed),
556 __second_constructed(__x.__value_constructed)
557 {
558 __x.__value_constructed = false;
559 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000560#else // _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000562 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
563 : __na_(__x.__na_),
564 __first_constructed(__x.__value_constructed),
565 __second_constructed(__x.__value_constructed)
566 {
567 const_cast<bool&>(__x.__value_constructed) = false;
568 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000569#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000570
Howard Hinnant789847d2010-09-23 18:58:28 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000572 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000573 {
574 if (__second_constructed)
Howard Hinnant307f8142013-06-22 15:21:29 +0000575 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000576 if (__first_constructed)
Howard Hinnant307f8142013-06-22 15:21:29 +0000577 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 if (__p)
579 __alloc_traits::deallocate(__na_, __p, 1);
580 }
581};
582
Eric Fiselierfcd02212016-02-11 11:59:44 +0000583#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000584template <class _Key, class _Tp>
585union __hash_value_type
586{
587 typedef _Key key_type;
588 typedef _Tp mapped_type;
589 typedef pair<const key_type, mapped_type> value_type;
590 typedef pair<key_type, mapped_type> __nc_value_type;
591
592 value_type __cc;
593 __nc_value_type __nc;
594
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000595 _LIBCPP_INLINE_VISIBILITY
596 __hash_value_type& operator=(const __hash_value_type& __v)
597 {__nc = __v.__cc; return *this;}
598
599 _LIBCPP_INLINE_VISIBILITY
600 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clow27647992015-05-06 12:11:22 +0000601 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000602
Eric Fiselierfcd02212016-02-11 11:59:44 +0000603 template <class _ValueTp,
604 class = typename enable_if<
605 __is_same_uncvref<_ValueTp, value_type>::value
606 >::type
607 >
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000608 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +0000609 __hash_value_type& operator=(_ValueTp&& __v) {
610 __nc = _VSTD::forward<_ValueTp>(__v); return *this;
611 }
612
613private:
614 __hash_value_type(const __hash_value_type& __v) = delete;
615 __hash_value_type(__hash_value_type&& __v) = delete;
616 template <class ..._Args>
617 explicit __hash_value_type(_Args&& ...__args) = delete;
618
619 ~__hash_value_type() = delete;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000620};
621
622#else
623
624template <class _Key, class _Tp>
625struct __hash_value_type
626{
627 typedef _Key key_type;
628 typedef _Tp mapped_type;
629 typedef pair<const key_type, mapped_type> value_type;
630
631 value_type __cc;
632
Eric Fiselierfcd02212016-02-11 11:59:44 +0000633private:
634 ~__hash_value_type();
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000635};
636
637#endif
638
Howard Hinnant3e519522010-05-11 19:42:16 +0000639template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000640class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000641{
642 _HashIterator __i_;
643
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000644 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
645
Howard Hinnant3e519522010-05-11 19:42:16 +0000646public:
647 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000648 typedef typename _NodeTypes::__map_value_type value_type;
649 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000650 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000651 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000652
Howard Hinnant789847d2010-09-23 18:58:28 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000654 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000655
Howard Hinnant789847d2010-09-23 18:58:28 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000657 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000658
Howard Hinnant789847d2010-09-23 18:58:28 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000660 reference operator*() const {return __i_->__cc;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000662 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000663
Howard Hinnant789847d2010-09-23 18:58:28 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000665 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000667 __hash_map_iterator operator++(int)
668 {
669 __hash_map_iterator __t(*this);
670 ++(*this);
671 return __t;
672 }
673
Howard Hinnant789847d2010-09-23 18:58:28 +0000674 friend _LIBCPP_INLINE_VISIBILITY
675 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000676 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000677 friend _LIBCPP_INLINE_VISIBILITY
678 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000679 {return __x.__i_ != __y.__i_;}
680
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000681 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
682 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
683 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
684 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
685 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000686};
687
688template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000689class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000690{
691 _HashIterator __i_;
692
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000693 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
694
Howard Hinnant3e519522010-05-11 19:42:16 +0000695public:
696 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000697 typedef typename _NodeTypes::__map_value_type value_type;
698 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000699 typedef const value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000700 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000701
Howard Hinnant789847d2010-09-23 18:58:28 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000703 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000704
Howard Hinnant789847d2010-09-23 18:58:28 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000706 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000708 __hash_map_const_iterator(
709 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant37141072011-06-04 18:54:24 +0000710 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000711 : __i_(__i.__i_) {}
712
Howard Hinnant789847d2010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000714 reference operator*() const {return __i_->__cc;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000716 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000717
Howard Hinnant789847d2010-09-23 18:58:28 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000719 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000721 __hash_map_const_iterator operator++(int)
722 {
723 __hash_map_const_iterator __t(*this);
724 ++(*this);
725 return __t;
726 }
727
Howard Hinnant789847d2010-09-23 18:58:28 +0000728 friend _LIBCPP_INLINE_VISIBILITY
729 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000730 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000731 friend _LIBCPP_INLINE_VISIBILITY
732 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000733 {return __x.__i_ != __y.__i_;}
734
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000735 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
736 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
737 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
738 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000739};
740
741template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
742 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000743class _LIBCPP_TEMPLATE_VIS unordered_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000744{
745public:
746 // types
747 typedef _Key key_type;
748 typedef _Tp mapped_type;
749 typedef _Hash hasher;
750 typedef _Pred key_equal;
751 typedef _Alloc allocator_type;
752 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant307f8142013-06-22 15:21:29 +0000753 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000754 typedef value_type& reference;
755 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000756 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
757 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000758
759private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000760 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +0000761 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
762 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +0000763 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
764 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000765
766 typedef __hash_table<__value_type, __hasher,
767 __key_equal, __allocator_type> __table;
768
769 __table __table_;
770
Eric Fiselierfcd02212016-02-11 11:59:44 +0000771 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000772 typedef typename __table::__node_pointer __node_pointer;
773 typedef typename __table::__node_const_pointer __node_const_pointer;
774 typedef typename __table::__node_traits __node_traits;
775 typedef typename __table::__node_allocator __node_allocator;
776 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000777 typedef __hash_map_node_destructor<__node_allocator> _Dp;
778 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000779 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000780
781 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
782 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnant3e519522010-05-11 19:42:16 +0000783public:
784 typedef typename __alloc_traits::pointer pointer;
785 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000786 typedef typename __table::size_type size_type;
787 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000788
789 typedef __hash_map_iterator<typename __table::iterator> iterator;
790 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
791 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
792 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
793
Howard Hinnant789847d2010-09-23 18:58:28 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000795 unordered_map()
796 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000797 {
798#if _LIBCPP_DEBUG_LEVEL >= 2
799 __get_db()->__insert_c(this);
800#endif
801 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000802 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
803 const key_equal& __eql = key_equal());
804 unordered_map(size_type __n, const hasher& __hf,
805 const key_equal& __eql,
806 const allocator_type& __a);
807 template <class _InputIterator>
808 unordered_map(_InputIterator __first, _InputIterator __last);
809 template <class _InputIterator>
810 unordered_map(_InputIterator __first, _InputIterator __last,
811 size_type __n, const hasher& __hf = hasher(),
812 const key_equal& __eql = key_equal());
813 template <class _InputIterator>
814 unordered_map(_InputIterator __first, _InputIterator __last,
815 size_type __n, const hasher& __hf,
816 const key_equal& __eql,
817 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000819 explicit unordered_map(const allocator_type& __a);
820 unordered_map(const unordered_map& __u);
821 unordered_map(const unordered_map& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000822#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000824 unordered_map(unordered_map&& __u)
825 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000826 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +0000827 unordered_map(initializer_list<value_type> __il);
828 unordered_map(initializer_list<value_type> __il, size_type __n,
829 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
830 unordered_map(initializer_list<value_type> __il, size_type __n,
831 const hasher& __hf, const key_equal& __eql,
832 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000833#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +0000834#if _LIBCPP_STD_VER > 11
835 _LIBCPP_INLINE_VISIBILITY
836 unordered_map(size_type __n, const allocator_type& __a)
837 : unordered_map(__n, hasher(), key_equal(), __a) {}
838 _LIBCPP_INLINE_VISIBILITY
839 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
840 : unordered_map(__n, __hf, key_equal(), __a) {}
841 template <class _InputIterator>
842 _LIBCPP_INLINE_VISIBILITY
843 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
844 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
845 template <class _InputIterator>
846 _LIBCPP_INLINE_VISIBILITY
847 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
848 const allocator_type& __a)
849 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
850 _LIBCPP_INLINE_VISIBILITY
851 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
852 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
853 _LIBCPP_INLINE_VISIBILITY
854 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
855 const allocator_type& __a)
856 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
857#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000858 // ~unordered_map() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000859 _LIBCPP_INLINE_VISIBILITY
860 unordered_map& operator=(const unordered_map& __u)
861 {
Marshall Clow2ee83722016-07-18 13:19:00 +0000862#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +0000863 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +0000864#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +0000865 if (this != &__u) {
866 __table_.clear();
867 __table_.hash_function() = __u.__table_.hash_function();
868 __table_.key_eq() = __u.__table_.key_eq();
869 __table_.max_load_factor() = __u.__table_.max_load_factor();
870 __table_.__copy_assign_alloc(__u.__table_);
871 insert(__u.begin(), __u.end());
872 }
Howard Hinnant307f8142013-06-22 15:21:29 +0000873#endif
Howard Hinnant5a336872011-07-01 19:24:36 +0000874 return *this;
875 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000876#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000878 unordered_map& operator=(unordered_map&& __u)
879 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000881 unordered_map& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000882#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000883
Howard Hinnant789847d2010-09-23 18:58:28 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000885 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000886 {return allocator_type(__table_.__node_alloc());}
887
Marshall Clow72c8fad2017-11-15 05:51:26 +0000888 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000889 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000891 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000893 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000894
Howard Hinnant789847d2010-09-23 18:58:28 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000896 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000898 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000900 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000902 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000904 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000906 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000907
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000908 _LIBCPP_INLINE_VISIBILITY
909 pair<iterator, bool> insert(const value_type& __x)
910 {return __table_.__insert_unique(__x);}
911
912 iterator insert(const_iterator __p, const value_type& __x) {
913#if _LIBCPP_DEBUG_LEVEL >= 2
914 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
915 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
916 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000917#else
918 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000919#endif
920 return insert(__x).first;
921 }
922
923 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000924 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000925 void insert(_InputIterator __first, _InputIterator __last);
926
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000927#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000928 _LIBCPP_INLINE_VISIBILITY
929 void insert(initializer_list<value_type> __il)
930 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000931
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000932 _LIBCPP_INLINE_VISIBILITY
933 pair<iterator, bool> insert(value_type&& __x)
934 {return __table_.__insert_unique(_VSTD::move(__x));}
935
936 iterator insert(const_iterator __p, value_type&& __x) {
937#if _LIBCPP_DEBUG_LEVEL >= 2
938 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
939 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
940 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000941#else
942 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000943#endif
944 return __table_.__insert_unique(_VSTD::move(__x)).first;
945 }
946
947 template <class _Pp,
948 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
949 _LIBCPP_INLINE_VISIBILITY
950 pair<iterator, bool> insert(_Pp&& __x)
951 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
952
953 template <class _Pp,
954 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
955 _LIBCPP_INLINE_VISIBILITY
956 iterator insert(const_iterator __p, _Pp&& __x)
957 {
958#if _LIBCPP_DEBUG_LEVEL >= 2
959 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
960 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
961 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000962#else
963 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000964#endif
965 return insert(_VSTD::forward<_Pp>(__x)).first;
966 }
967
Eric Fiselierfcd02212016-02-11 11:59:44 +0000968 template <class... _Args>
969 _LIBCPP_INLINE_VISIBILITY
970 pair<iterator, bool> emplace(_Args&&... __args) {
971 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
972 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000973
Howard Hinnant8b805c92012-05-25 22:04:21 +0000974 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +0000975 _LIBCPP_INLINE_VISIBILITY
976 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnant4c80bfb2013-07-30 21:04:42 +0000977#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierfcd02212016-02-11 11:59:44 +0000978 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
979 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
980 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000981#else
982 ((void)__p);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +0000983#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +0000984 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
985 }
986
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000987#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000988
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000989#if _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000990 template <class... _Args>
991 _LIBCPP_INLINE_VISIBILITY
992 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
993 {
Eric Fiselier87c41042016-04-18 06:51:33 +0000994 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
995 _VSTD::forward_as_tuple(__k),
996 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000997 }
998
999 template <class... _Args>
1000 _LIBCPP_INLINE_VISIBILITY
1001 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1002 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001003 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1004 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1005 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001006 }
1007
1008 template <class... _Args>
1009 _LIBCPP_INLINE_VISIBILITY
1010 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1011 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001012#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001013 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001014 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1015 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001016#else
1017 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001018#endif
Eric Fiselierfd838222016-12-23 23:37:52 +00001019 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001020 }
1021
1022 template <class... _Args>
1023 _LIBCPP_INLINE_VISIBILITY
1024 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1025 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001026#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001027 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001028 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1029 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001030#else
1031 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001032#endif
1033 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001034 }
1035
1036 template <class _Vp>
1037 _LIBCPP_INLINE_VISIBILITY
1038 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1039 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001040 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1041 __k, _VSTD::forward<_Vp>(__v));
1042 if (!__res.second) {
1043 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001044 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001045 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001046 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001047
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001048 template <class _Vp>
1049 _LIBCPP_INLINE_VISIBILITY
1050 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1051 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001052 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1053 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1054 if (!__res.second) {
1055 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001056 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001057 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001058 }
1059
1060 template <class _Vp>
1061 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001062 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001063 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001064 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001065 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001066 }
1067
1068 template <class _Vp>
1069 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001070 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001071 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001072 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001073 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001074 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001075#endif // _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001076
Howard Hinnant789847d2010-09-23 18:58:28 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001078 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001079 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001080 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001082 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001084 iterator erase(const_iterator __first, const_iterator __last)
1085 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001087 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001088
Howard Hinnant789847d2010-09-23 18:58:28 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001090 void swap(unordered_map& __u)
1091 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
Eric Fiselier780b51d2016-12-28 05:53:01 +00001092 { __table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001093
Howard Hinnant789847d2010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001095 hasher hash_function() const
1096 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001098 key_equal key_eq() const
1099 {return __table_.key_eq().key_eq();}
1100
Howard Hinnant789847d2010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001102 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001104 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001106 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001108 pair<iterator, iterator> equal_range(const key_type& __k)
1109 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001111 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1112 {return __table_.__equal_range_unique(__k);}
1113
1114 mapped_type& operator[](const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001115#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001116 mapped_type& operator[](key_type&& __k);
1117#endif
1118
1119 mapped_type& at(const key_type& __k);
1120 const mapped_type& at(const key_type& __k) const;
1121
Howard Hinnant789847d2010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001123 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001125 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001126
Howard Hinnant789847d2010-09-23 18:58:28 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001128 size_type bucket_size(size_type __n) const
1129 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001131 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1132
Howard Hinnant789847d2010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001134 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001136 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001138 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001140 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001142 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001144 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1145
Howard Hinnant789847d2010-09-23 18:58:28 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001147 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001149 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001151 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001153 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001155 void reserve(size_type __n) {__table_.reserve(__n);}
1156
Howard Hinnantb24c8022013-07-23 22:01:58 +00001157#if _LIBCPP_DEBUG_LEVEL >= 2
1158
1159 bool __dereferenceable(const const_iterator* __i) const
1160 {return __table_.__dereferenceable(&__i->__i_);}
1161 bool __decrementable(const const_iterator* __i) const
1162 {return __table_.__decrementable(&__i->__i_);}
1163 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1164 {return __table_.__addable(&__i->__i_, __n);}
1165 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1166 {return __table_.__addable(&__i->__i_, __n);}
1167
1168#endif // _LIBCPP_DEBUG_LEVEL >= 2
1169
Howard Hinnant3e519522010-05-11 19:42:16 +00001170private:
Eric Fiselier0f905672016-02-11 21:45:53 +00001171
1172#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001173 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001174#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001175};
1176
1177template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1178unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1179 size_type __n, const hasher& __hf, const key_equal& __eql)
1180 : __table_(__hf, __eql)
1181{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001182#if _LIBCPP_DEBUG_LEVEL >= 2
1183 __get_db()->__insert_c(this);
1184#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001185 __table_.rehash(__n);
1186}
1187
1188template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1189unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1190 size_type __n, const hasher& __hf, const key_equal& __eql,
1191 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001192 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001193{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001194#if _LIBCPP_DEBUG_LEVEL >= 2
1195 __get_db()->__insert_c(this);
1196#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001197 __table_.rehash(__n);
1198}
1199
1200template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001201inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001202unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1203 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001204 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001205{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001206#if _LIBCPP_DEBUG_LEVEL >= 2
1207 __get_db()->__insert_c(this);
1208#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001209}
1210
1211template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1212template <class _InputIterator>
1213unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1214 _InputIterator __first, _InputIterator __last)
1215{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001216#if _LIBCPP_DEBUG_LEVEL >= 2
1217 __get_db()->__insert_c(this);
1218#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001219 insert(__first, __last);
1220}
1221
1222template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1223template <class _InputIterator>
1224unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1225 _InputIterator __first, _InputIterator __last, size_type __n,
1226 const hasher& __hf, const key_equal& __eql)
1227 : __table_(__hf, __eql)
1228{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001229#if _LIBCPP_DEBUG_LEVEL >= 2
1230 __get_db()->__insert_c(this);
1231#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001232 __table_.rehash(__n);
1233 insert(__first, __last);
1234}
1235
1236template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1237template <class _InputIterator>
1238unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1239 _InputIterator __first, _InputIterator __last, size_type __n,
1240 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001241 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001242{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001243#if _LIBCPP_DEBUG_LEVEL >= 2
1244 __get_db()->__insert_c(this);
1245#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001246 __table_.rehash(__n);
1247 insert(__first, __last);
1248}
1249
1250template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1251unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1252 const unordered_map& __u)
1253 : __table_(__u.__table_)
1254{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001255#if _LIBCPP_DEBUG_LEVEL >= 2
1256 __get_db()->__insert_c(this);
1257#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001258 __table_.rehash(__u.bucket_count());
1259 insert(__u.begin(), __u.end());
1260}
1261
1262template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1263unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1264 const unordered_map& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001265 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001266{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001267#if _LIBCPP_DEBUG_LEVEL >= 2
1268 __get_db()->__insert_c(this);
1269#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001270 __table_.rehash(__u.bucket_count());
1271 insert(__u.begin(), __u.end());
1272}
1273
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001274#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001275
1276template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001277inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001278unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1279 unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001280 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001281 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001282{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001283#if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001285 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001286#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001287}
1288
1289template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1290unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1291 unordered_map&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001292 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001293{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001294#if _LIBCPP_DEBUG_LEVEL >= 2
1295 __get_db()->__insert_c(this);
1296#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001297 if (__a != __u.get_allocator())
1298 {
1299 iterator __i = __u.begin();
Eric Fiselierfcd02212016-02-11 11:59:44 +00001300 while (__u.size() != 0) {
1301 __table_.__emplace_unique(_VSTD::move(
1302 __u.__table_.remove((__i++).__i_)->__value_.__nc));
1303 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001304 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001305#if _LIBCPP_DEBUG_LEVEL >= 2
1306 else
1307 __get_db()->swap(this, &__u);
1308#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001309}
1310
Howard Hinnant3e519522010-05-11 19:42:16 +00001311template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1312unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1313 initializer_list<value_type> __il)
1314{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001315#if _LIBCPP_DEBUG_LEVEL >= 2
1316 __get_db()->__insert_c(this);
1317#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001318 insert(__il.begin(), __il.end());
1319}
1320
1321template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1322unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1323 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1324 const key_equal& __eql)
1325 : __table_(__hf, __eql)
1326{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001327#if _LIBCPP_DEBUG_LEVEL >= 2
1328 __get_db()->__insert_c(this);
1329#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001330 __table_.rehash(__n);
1331 insert(__il.begin(), __il.end());
1332}
1333
1334template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1335unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1336 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1337 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001338 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001339{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001340#if _LIBCPP_DEBUG_LEVEL >= 2
1341 __get_db()->__insert_c(this);
1342#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001343 __table_.rehash(__n);
1344 insert(__il.begin(), __il.end());
1345}
1346
Howard Hinnant3e519522010-05-11 19:42:16 +00001347template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001348inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001349unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1350unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001351 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001352{
Howard Hinnantce48a112011-06-30 21:18:19 +00001353 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001354 return *this;
1355}
1356
Howard Hinnant3e519522010-05-11 19:42:16 +00001357template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001358inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001359unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1360unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1361 initializer_list<value_type> __il)
1362{
1363 __table_.__assign_unique(__il.begin(), __il.end());
1364 return *this;
1365}
1366
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001367#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001368
Howard Hinnant3e519522010-05-11 19:42:16 +00001369template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1370template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001371inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001372void
1373unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1374 _InputIterator __last)
1375{
1376 for (; __first != __last; ++__first)
1377 __table_.__insert_unique(*__first);
1378}
1379
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001380#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001381
Eric Fiselier0f905672016-02-11 21:45:53 +00001382template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1383_Tp&
1384unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1385{
1386 return __table_.__emplace_unique_key_args(__k,
1387 std::piecewise_construct, std::forward_as_tuple(__k),
1388 std::forward_as_tuple()).first->__cc.second;
1389}
Howard Hinnant3e519522010-05-11 19:42:16 +00001390
1391template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1392_Tp&
1393unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1394{
Eric Fiselier0f905672016-02-11 21:45:53 +00001395 return __table_.__emplace_unique_key_args(__k,
1396 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1397 std::forward_as_tuple()).first->__cc.second;
Howard Hinnant3e519522010-05-11 19:42:16 +00001398}
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001399#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001400
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001401template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1402typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1403unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1404{
1405 __node_allocator& __na = __table_.__node_alloc();
1406 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1407 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
1408 __h.get_deleter().__first_constructed = true;
1409 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1410 __h.get_deleter().__second_constructed = true;
1411 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1412}
1413
1414template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1415_Tp&
1416unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1417{
1418 iterator __i = find(__k);
1419 if (__i != end())
1420 return __i->second;
1421 __node_holder __h = __construct_node_with_key(__k);
1422 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1423 __h.release();
1424 return __r.first->second;
1425}
1426
1427#endif // _LIBCPP_CXX03_MODE
Howard Hinnant3e519522010-05-11 19:42:16 +00001428
1429template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1430_Tp&
1431unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1432{
1433 iterator __i = find(__k);
1434#ifndef _LIBCPP_NO_EXCEPTIONS
1435 if (__i == end())
1436 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001437#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001438 return __i->second;
1439}
1440
1441template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1442const _Tp&
1443unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1444{
1445 const_iterator __i = find(__k);
1446#ifndef _LIBCPP_NO_EXCEPTIONS
1447 if (__i == end())
1448 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001449#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001450 return __i->second;
1451}
1452
1453template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001454inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001455void
1456swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1457 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00001458 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001459{
1460 __x.swap(__y);
1461}
1462
1463template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1464bool
1465operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1466 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1467{
1468 if (__x.size() != __y.size())
1469 return false;
1470 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1471 const_iterator;
1472 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1473 __i != __ex; ++__i)
1474 {
1475 const_iterator __j = __y.find(__i->first);
1476 if (__j == __ey || !(*__i == *__j))
1477 return false;
1478 }
1479 return true;
1480}
1481
1482template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001483inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001484bool
1485operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1486 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1487{
1488 return !(__x == __y);
1489}
1490
1491template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1492 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001493class _LIBCPP_TEMPLATE_VIS unordered_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +00001494{
1495public:
1496 // types
1497 typedef _Key key_type;
1498 typedef _Tp mapped_type;
1499 typedef _Hash hasher;
1500 typedef _Pred key_equal;
1501 typedef _Alloc allocator_type;
1502 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant307f8142013-06-22 15:21:29 +00001503 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001504 typedef value_type& reference;
1505 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001506 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1507 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001508
1509private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +00001510 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +00001511 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1512 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +00001513 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1514 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001515
1516 typedef __hash_table<__value_type, __hasher,
1517 __key_equal, __allocator_type> __table;
1518
1519 __table __table_;
1520
Eric Fiselierfcd02212016-02-11 11:59:44 +00001521 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +00001522 typedef typename __table::__node_traits __node_traits;
1523 typedef typename __table::__node_allocator __node_allocator;
1524 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +00001525 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1526 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001527 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001528 static_assert((is_same<typename __node_traits::size_type,
1529 typename __alloc_traits::size_type>::value),
1530 "Allocator uses different size_type for different types");
Howard Hinnant3e519522010-05-11 19:42:16 +00001531public:
1532 typedef typename __alloc_traits::pointer pointer;
1533 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001534 typedef typename __table::size_type size_type;
1535 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001536
1537 typedef __hash_map_iterator<typename __table::iterator> iterator;
1538 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1539 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1540 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1541
Howard Hinnant789847d2010-09-23 18:58:28 +00001542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001543 unordered_multimap()
1544 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001545 {
1546#if _LIBCPP_DEBUG_LEVEL >= 2
1547 __get_db()->__insert_c(this);
1548#endif
1549 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001550 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1551 const key_equal& __eql = key_equal());
1552 unordered_multimap(size_type __n, const hasher& __hf,
1553 const key_equal& __eql,
1554 const allocator_type& __a);
1555 template <class _InputIterator>
1556 unordered_multimap(_InputIterator __first, _InputIterator __last);
1557 template <class _InputIterator>
1558 unordered_multimap(_InputIterator __first, _InputIterator __last,
1559 size_type __n, const hasher& __hf = hasher(),
1560 const key_equal& __eql = key_equal());
1561 template <class _InputIterator>
1562 unordered_multimap(_InputIterator __first, _InputIterator __last,
1563 size_type __n, const hasher& __hf,
1564 const key_equal& __eql,
1565 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001567 explicit unordered_multimap(const allocator_type& __a);
1568 unordered_multimap(const unordered_multimap& __u);
1569 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001570#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001572 unordered_multimap(unordered_multimap&& __u)
1573 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001574 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +00001575 unordered_multimap(initializer_list<value_type> __il);
1576 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1577 const hasher& __hf = hasher(),
1578 const key_equal& __eql = key_equal());
1579 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1580 const hasher& __hf, const key_equal& __eql,
1581 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001582#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +00001583#if _LIBCPP_STD_VER > 11
1584 _LIBCPP_INLINE_VISIBILITY
1585 unordered_multimap(size_type __n, const allocator_type& __a)
1586 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1587 _LIBCPP_INLINE_VISIBILITY
1588 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1589 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1590 template <class _InputIterator>
1591 _LIBCPP_INLINE_VISIBILITY
1592 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1593 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1594 template <class _InputIterator>
1595 _LIBCPP_INLINE_VISIBILITY
1596 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1597 const allocator_type& __a)
1598 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1599 _LIBCPP_INLINE_VISIBILITY
1600 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1601 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1602 _LIBCPP_INLINE_VISIBILITY
1603 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1604 const allocator_type& __a)
1605 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1606#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001607 // ~unordered_multimap() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +00001608 _LIBCPP_INLINE_VISIBILITY
1609 unordered_multimap& operator=(const unordered_multimap& __u)
1610 {
Marshall Clow2ee83722016-07-18 13:19:00 +00001611#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +00001612 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +00001613#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +00001614 if (this != &__u) {
1615 __table_.clear();
1616 __table_.hash_function() = __u.__table_.hash_function();
1617 __table_.key_eq() = __u.__table_.key_eq();
1618 __table_.max_load_factor() = __u.__table_.max_load_factor();
1619 __table_.__copy_assign_alloc(__u.__table_);
1620 insert(__u.begin(), __u.end());
1621 }
Howard Hinnant307f8142013-06-22 15:21:29 +00001622#endif
Howard Hinnant5a336872011-07-01 19:24:36 +00001623 return *this;
1624 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001625#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001627 unordered_multimap& operator=(unordered_multimap&& __u)
1628 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001630 unordered_multimap& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001631#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001632
Howard Hinnant789847d2010-09-23 18:58:28 +00001633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001634 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001635 {return allocator_type(__table_.__node_alloc());}
1636
Marshall Clow72c8fad2017-11-15 05:51:26 +00001637 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001638 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001640 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001642 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001643
Howard Hinnant789847d2010-09-23 18:58:28 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001645 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001647 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001649 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001651 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001653 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001655 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001656
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001657 _LIBCPP_INLINE_VISIBILITY
1658 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1659
1660 _LIBCPP_INLINE_VISIBILITY
1661 iterator insert(const_iterator __p, const value_type& __x)
1662 {return __table_.__insert_multi(__p.__i_, __x);}
1663
1664 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001665 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001666 void insert(_InputIterator __first, _InputIterator __last);
1667
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001668#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001669 _LIBCPP_INLINE_VISIBILITY
1670 void insert(initializer_list<value_type> __il)
1671 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001672 _LIBCPP_INLINE_VISIBILITY
1673 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1674
1675 _LIBCPP_INLINE_VISIBILITY
1676 iterator insert(const_iterator __p, value_type&& __x)
1677 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1678
1679 template <class _Pp,
1680 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1681 _LIBCPP_INLINE_VISIBILITY
1682 iterator insert(_Pp&& __x)
1683 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1684
1685 template <class _Pp,
1686 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1687 _LIBCPP_INLINE_VISIBILITY
1688 iterator insert(const_iterator __p, _Pp&& __x)
1689 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1690
Eric Fiselierfcd02212016-02-11 11:59:44 +00001691 template <class... _Args>
1692 iterator emplace(_Args&&... __args) {
1693 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1694 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001695
Howard Hinnant8b805c92012-05-25 22:04:21 +00001696 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001697 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1698 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1699 }
1700#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001701
Howard Hinnant3e519522010-05-11 19:42:16 +00001702
Howard Hinnant789847d2010-09-23 18:58:28 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001704 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001705 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001706 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001708 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001710 iterator erase(const_iterator __first, const_iterator __last)
1711 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001713 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001714
Howard Hinnant789847d2010-09-23 18:58:28 +00001715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001716 void swap(unordered_multimap& __u)
1717 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1718 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001719
Howard Hinnant789847d2010-09-23 18:58:28 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001721 hasher hash_function() const
1722 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001724 key_equal key_eq() const
1725 {return __table_.key_eq().key_eq();}
1726
Howard Hinnant789847d2010-09-23 18:58:28 +00001727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001728 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001730 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001732 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001734 pair<iterator, iterator> equal_range(const key_type& __k)
1735 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001737 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1738 {return __table_.__equal_range_multi(__k);}
1739
Howard Hinnant789847d2010-09-23 18:58:28 +00001740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001741 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001743 size_type max_bucket_count() const _NOEXCEPT
1744 {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001745
Howard Hinnant789847d2010-09-23 18:58:28 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001747 size_type bucket_size(size_type __n) const
1748 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001750 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1751
Howard Hinnant789847d2010-09-23 18:58:28 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001753 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001755 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001757 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001759 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001761 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001763 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1764
Howard Hinnant789847d2010-09-23 18:58:28 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001766 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001768 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001770 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001772 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001774 void reserve(size_type __n) {__table_.reserve(__n);}
1775
Howard Hinnantb24c8022013-07-23 22:01:58 +00001776#if _LIBCPP_DEBUG_LEVEL >= 2
1777
1778 bool __dereferenceable(const const_iterator* __i) const
1779 {return __table_.__dereferenceable(&__i->__i_);}
1780 bool __decrementable(const const_iterator* __i) const
1781 {return __table_.__decrementable(&__i->__i_);}
1782 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1783 {return __table_.__addable(&__i->__i_, __n);}
1784 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1785 {return __table_.__addable(&__i->__i_, __n);}
1786
1787#endif // _LIBCPP_DEBUG_LEVEL >= 2
1788
Eric Fiselierfcd02212016-02-11 11:59:44 +00001789
Howard Hinnant3e519522010-05-11 19:42:16 +00001790};
1791
1792template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1793unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1794 size_type __n, const hasher& __hf, const key_equal& __eql)
1795 : __table_(__hf, __eql)
1796{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001797#if _LIBCPP_DEBUG_LEVEL >= 2
1798 __get_db()->__insert_c(this);
1799#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001800 __table_.rehash(__n);
1801}
1802
1803template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1804unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1805 size_type __n, const hasher& __hf, const key_equal& __eql,
1806 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001807 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001808{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001809#if _LIBCPP_DEBUG_LEVEL >= 2
1810 __get_db()->__insert_c(this);
1811#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001812 __table_.rehash(__n);
1813}
1814
1815template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1816template <class _InputIterator>
1817unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1818 _InputIterator __first, _InputIterator __last)
1819{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001820#if _LIBCPP_DEBUG_LEVEL >= 2
1821 __get_db()->__insert_c(this);
1822#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001823 insert(__first, __last);
1824}
1825
1826template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1827template <class _InputIterator>
1828unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1829 _InputIterator __first, _InputIterator __last, size_type __n,
1830 const hasher& __hf, const key_equal& __eql)
1831 : __table_(__hf, __eql)
1832{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001833#if _LIBCPP_DEBUG_LEVEL >= 2
1834 __get_db()->__insert_c(this);
1835#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001836 __table_.rehash(__n);
1837 insert(__first, __last);
1838}
1839
1840template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1841template <class _InputIterator>
1842unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1843 _InputIterator __first, _InputIterator __last, size_type __n,
1844 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001845 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001846{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001847#if _LIBCPP_DEBUG_LEVEL >= 2
1848 __get_db()->__insert_c(this);
1849#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001850 __table_.rehash(__n);
1851 insert(__first, __last);
1852}
1853
Howard Hinnant3e519522010-05-11 19:42:16 +00001854template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001855inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001856unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1857 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001858 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001859{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001860#if _LIBCPP_DEBUG_LEVEL >= 2
1861 __get_db()->__insert_c(this);
1862#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001863}
1864
1865template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1866unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1867 const unordered_multimap& __u)
1868 : __table_(__u.__table_)
1869{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001870#if _LIBCPP_DEBUG_LEVEL >= 2
1871 __get_db()->__insert_c(this);
1872#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001873 __table_.rehash(__u.bucket_count());
1874 insert(__u.begin(), __u.end());
1875}
1876
1877template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1878unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1879 const unordered_multimap& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001880 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001881{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001882#if _LIBCPP_DEBUG_LEVEL >= 2
1883 __get_db()->__insert_c(this);
1884#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001885 __table_.rehash(__u.bucket_count());
1886 insert(__u.begin(), __u.end());
1887}
1888
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001889#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001890
1891template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001892inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001893unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1894 unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001895 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001896 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001897{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001900 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001901#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001902}
1903
1904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1905unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1906 unordered_multimap&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001907 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001908{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001909#if _LIBCPP_DEBUG_LEVEL >= 2
1910 __get_db()->__insert_c(this);
1911#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001912 if (__a != __u.get_allocator())
1913 {
1914 iterator __i = __u.begin();
1915 while (__u.size() != 0)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001916 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001917 __table_.__insert_multi(
Eric Fiselierfcd02212016-02-11 11:59:44 +00001918 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
Howard Hinnant3e519522010-05-11 19:42:16 +00001919 );
Howard Hinnantb24c8022013-07-23 22:01:58 +00001920 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001921 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001922#if _LIBCPP_DEBUG_LEVEL >= 2
1923 else
1924 __get_db()->swap(this, &__u);
1925#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001926}
1927
Howard Hinnant3e519522010-05-11 19:42:16 +00001928template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1929unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1930 initializer_list<value_type> __il)
1931{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001932#if _LIBCPP_DEBUG_LEVEL >= 2
1933 __get_db()->__insert_c(this);
1934#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001935 insert(__il.begin(), __il.end());
1936}
1937
1938template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1939unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1940 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1941 const key_equal& __eql)
1942 : __table_(__hf, __eql)
1943{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001944#if _LIBCPP_DEBUG_LEVEL >= 2
1945 __get_db()->__insert_c(this);
1946#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001947 __table_.rehash(__n);
1948 insert(__il.begin(), __il.end());
1949}
1950
1951template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1952unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1953 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1954 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001955 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001956{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001957#if _LIBCPP_DEBUG_LEVEL >= 2
1958 __get_db()->__insert_c(this);
1959#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001960 __table_.rehash(__n);
1961 insert(__il.begin(), __il.end());
1962}
1963
Howard Hinnant3e519522010-05-11 19:42:16 +00001964template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001965inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001966unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1967unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001968 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001969{
Howard Hinnantce48a112011-06-30 21:18:19 +00001970 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001971 return *this;
1972}
1973
Howard Hinnant3e519522010-05-11 19:42:16 +00001974template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001975inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001976unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1977unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1978 initializer_list<value_type> __il)
1979{
1980 __table_.__assign_multi(__il.begin(), __il.end());
1981 return *this;
1982}
1983
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001984#endif // _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +00001985
Howard Hinnant3e519522010-05-11 19:42:16 +00001986
Howard Hinnant3e519522010-05-11 19:42:16 +00001987
1988template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1989template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001990inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001991void
1992unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1993 _InputIterator __last)
1994{
1995 for (; __first != __last; ++__first)
1996 __table_.__insert_multi(*__first);
1997}
1998
1999template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002000inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002001void
2002swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2003 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00002004 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002005{
2006 __x.swap(__y);
2007}
2008
2009template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2010bool
2011operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2012 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2013{
2014 if (__x.size() != __y.size())
2015 return false;
2016 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2017 const_iterator;
2018 typedef pair<const_iterator, const_iterator> _EqRng;
2019 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2020 {
2021 _EqRng __xeq = __x.equal_range(__i->first);
2022 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +00002023 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2024 _VSTD::distance(__yeq.first, __yeq.second) ||
2025 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00002026 return false;
2027 __i = __xeq.second;
2028 }
2029 return true;
2030}
2031
2032template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002033inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002034bool
2035operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2036 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2037{
2038 return !(__x == __y);
2039}
2040
2041_LIBCPP_END_NAMESPACE_STD
2042
2043#endif // _LIBCPP_UNORDERED_MAP