blob: 7baf638833f0389481d8db22aed300ddc02ae371 [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 Fiselieree187e22015-06-13 07:08:02 +0000382template <class _Key, class _Cp, class _Hash,
383 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value
Howard Hinnant42b8bb52011-12-11 20:31:33 +0000384 >
Howard Hinnant3e519522010-05-11 19:42:16 +0000385class __unordered_map_hasher
386 : private _Hash
387{
388public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000390 __unordered_map_hasher()
391 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
392 : _Hash() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000394 __unordered_map_hasher(const _Hash& __h)
395 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
396 : _Hash(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000398 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000400 size_t operator()(const _Cp& __x) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000401 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000402 _LIBCPP_INLINE_VISIBILITY
403 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000404 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000405 void swap(__unordered_map_hasher&__y)
406 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
407 {
408 using _VSTD::swap;
409 swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y));
410 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000411};
412
Howard Hinnantabb160e2013-07-05 18:06:00 +0000413template <class _Key, class _Cp, class _Hash>
414class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000415{
416 _Hash __hash_;
417public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000419 __unordered_map_hasher()
420 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
421 : __hash_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000423 __unordered_map_hasher(const _Hash& __h)
424 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
425 : __hash_(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000427 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000429 size_t operator()(const _Cp& __x) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000430 {return __hash_(__x.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000431 _LIBCPP_INLINE_VISIBILITY
432 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000433 {return __hash_(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000434 void swap(__unordered_map_hasher&__y)
435 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
436 {
437 using _VSTD::swap;
438 swap(__hash_, __y.__hash_);
439 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000440};
441
Marshall Clowe3fbe142015-07-13 20:04:56 +0000442template <class _Key, class _Cp, class _Hash, bool __b>
443inline _LIBCPP_INLINE_VISIBILITY
444void
445swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
446 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
447 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
448{
449 __x.swap(__y);
450}
451
Eric Fiselieree187e22015-06-13 07:08:02 +0000452template <class _Key, class _Cp, class _Pred,
453 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnant42b8bb52011-12-11 20:31:33 +0000454 >
Howard Hinnant3e519522010-05-11 19:42:16 +0000455class __unordered_map_equal
456 : private _Pred
457{
458public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000460 __unordered_map_equal()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
462 : _Pred() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000464 __unordered_map_equal(const _Pred& __p)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
466 : _Pred(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000468 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000470 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000471 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000472 _LIBCPP_INLINE_VISIBILITY
473 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000474 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000476 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000477 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000478 void swap(__unordered_map_equal&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
483 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000484};
485
Howard Hinnantabb160e2013-07-05 18:06:00 +0000486template <class _Key, class _Cp, class _Pred>
487class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000488{
489 _Pred __pred_;
490public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000492 __unordered_map_equal()
493 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
494 : __pred_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000496 __unordered_map_equal(const _Pred& __p)
497 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
498 : __pred_(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000500 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000502 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000503 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000504 _LIBCPP_INLINE_VISIBILITY
505 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000506 {return __pred_(__x.__cc.first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000508 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnantabb160e2013-07-05 18:06:00 +0000509 {return __pred_(__x, __y.__cc.first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000510 void swap(__unordered_map_equal&__y)
511 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
512 {
513 using _VSTD::swap;
514 swap(__pred_, __y.__pred_);
515 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000516};
517
Marshall Clowe3fbe142015-07-13 20:04:56 +0000518template <class _Key, class _Cp, class _Pred, bool __b>
519inline _LIBCPP_INLINE_VISIBILITY
520void
521swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
522 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
523 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
524{
525 __x.swap(__y);
526}
527
Howard Hinnant3e519522010-05-11 19:42:16 +0000528template <class _Alloc>
529class __hash_map_node_destructor
530{
531 typedef _Alloc allocator_type;
532 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000533
Howard Hinnant3e519522010-05-11 19:42:16 +0000534public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000535
536 typedef typename __alloc_traits::pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000537private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000538
539 allocator_type& __na_;
540
541 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
542
543public:
544 bool __first_constructed;
545 bool __second_constructed;
546
Howard Hinnant789847d2010-09-23 18:58:28 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000548 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000549 : __na_(__na),
550 __first_constructed(false),
551 __second_constructed(false)
552 {}
553
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000554#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000556 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000557 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000558 : __na_(__x.__na_),
559 __first_constructed(__x.__value_constructed),
560 __second_constructed(__x.__value_constructed)
561 {
562 __x.__value_constructed = false;
563 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000564#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000566 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
567 : __na_(__x.__na_),
568 __first_constructed(__x.__value_constructed),
569 __second_constructed(__x.__value_constructed)
570 {
571 const_cast<bool&>(__x.__value_constructed) = false;
572 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000573#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000574
Howard Hinnant789847d2010-09-23 18:58:28 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000576 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000577 {
578 if (__second_constructed)
Howard Hinnant307f8142013-06-22 15:21:29 +0000579 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000580 if (__first_constructed)
Howard Hinnant307f8142013-06-22 15:21:29 +0000581 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000582 if (__p)
583 __alloc_traits::deallocate(__na_, __p, 1);
584 }
585};
586
Eric Fiselierfcd02212016-02-11 11:59:44 +0000587#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000588template <class _Key, class _Tp>
589union __hash_value_type
590{
591 typedef _Key key_type;
592 typedef _Tp mapped_type;
593 typedef pair<const key_type, mapped_type> value_type;
594 typedef pair<key_type, mapped_type> __nc_value_type;
595
596 value_type __cc;
597 __nc_value_type __nc;
598
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000599 _LIBCPP_INLINE_VISIBILITY
600 __hash_value_type& operator=(const __hash_value_type& __v)
601 {__nc = __v.__cc; return *this;}
602
603 _LIBCPP_INLINE_VISIBILITY
604 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clow27647992015-05-06 12:11:22 +0000605 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000606
Eric Fiselierfcd02212016-02-11 11:59:44 +0000607 template <class _ValueTp,
608 class = typename enable_if<
609 __is_same_uncvref<_ValueTp, value_type>::value
610 >::type
611 >
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000612 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfcd02212016-02-11 11:59:44 +0000613 __hash_value_type& operator=(_ValueTp&& __v) {
614 __nc = _VSTD::forward<_ValueTp>(__v); return *this;
615 }
616
617private:
618 __hash_value_type(const __hash_value_type& __v) = delete;
619 __hash_value_type(__hash_value_type&& __v) = delete;
620 template <class ..._Args>
621 explicit __hash_value_type(_Args&& ...__args) = delete;
622
623 ~__hash_value_type() = delete;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000624};
625
626#else
627
628template <class _Key, class _Tp>
629struct __hash_value_type
630{
631 typedef _Key key_type;
632 typedef _Tp mapped_type;
633 typedef pair<const key_type, mapped_type> value_type;
634
635 value_type __cc;
636
Eric Fiselierfcd02212016-02-11 11:59:44 +0000637private:
638 ~__hash_value_type();
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000639};
640
641#endif
642
Howard Hinnant3e519522010-05-11 19:42:16 +0000643template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000644class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000645{
646 _HashIterator __i_;
647
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000648 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
649
Howard Hinnant3e519522010-05-11 19:42:16 +0000650public:
651 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000652 typedef typename _NodeTypes::__map_value_type value_type;
653 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000654 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000655 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000656
Howard Hinnant789847d2010-09-23 18:58:28 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000658 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000659
Howard Hinnant789847d2010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000661 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000662
Howard Hinnant789847d2010-09-23 18:58:28 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000664 reference operator*() const {return __i_->__cc;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000666 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000667
Howard Hinnant789847d2010-09-23 18:58:28 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000669 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000671 __hash_map_iterator operator++(int)
672 {
673 __hash_map_iterator __t(*this);
674 ++(*this);
675 return __t;
676 }
677
Howard Hinnant789847d2010-09-23 18:58:28 +0000678 friend _LIBCPP_INLINE_VISIBILITY
679 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000680 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000681 friend _LIBCPP_INLINE_VISIBILITY
682 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000683 {return __x.__i_ != __y.__i_;}
684
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000685 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
686 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
687 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
688 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
689 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000690};
691
692template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000693class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000694{
695 _HashIterator __i_;
696
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000697 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
698
Howard Hinnant3e519522010-05-11 19:42:16 +0000699public:
700 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000701 typedef typename _NodeTypes::__map_value_type value_type;
702 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000703 typedef const value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000704 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000705
Howard Hinnant789847d2010-09-23 18:58:28 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000707 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000708
Howard Hinnant789847d2010-09-23 18:58:28 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000710 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000712 __hash_map_const_iterator(
713 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant37141072011-06-04 18:54:24 +0000714 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000715 : __i_(__i.__i_) {}
716
Howard Hinnant789847d2010-09-23 18:58:28 +0000717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000718 reference operator*() const {return __i_->__cc;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant307f8142013-06-22 15:21:29 +0000720 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000721
Howard Hinnant789847d2010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000723 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000725 __hash_map_const_iterator operator++(int)
726 {
727 __hash_map_const_iterator __t(*this);
728 ++(*this);
729 return __t;
730 }
731
Howard Hinnant789847d2010-09-23 18:58:28 +0000732 friend _LIBCPP_INLINE_VISIBILITY
733 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000734 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000735 friend _LIBCPP_INLINE_VISIBILITY
736 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000737 {return __x.__i_ != __y.__i_;}
738
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000739 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
740 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
741 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
742 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000743};
744
745template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
746 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000747class _LIBCPP_TEMPLATE_VIS unordered_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000748{
749public:
750 // types
751 typedef _Key key_type;
752 typedef _Tp mapped_type;
753 typedef _Hash hasher;
754 typedef _Pred key_equal;
755 typedef _Alloc allocator_type;
756 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant307f8142013-06-22 15:21:29 +0000757 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000758 typedef value_type& reference;
759 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000760 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
761 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000762
763private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000764 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +0000765 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
766 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +0000767 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
768 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000769
770 typedef __hash_table<__value_type, __hasher,
771 __key_equal, __allocator_type> __table;
772
773 __table __table_;
774
Eric Fiselierfcd02212016-02-11 11:59:44 +0000775 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000776 typedef typename __table::__node_pointer __node_pointer;
777 typedef typename __table::__node_const_pointer __node_const_pointer;
778 typedef typename __table::__node_traits __node_traits;
779 typedef typename __table::__node_allocator __node_allocator;
780 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000781 typedef __hash_map_node_destructor<__node_allocator> _Dp;
782 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000783 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000784
785 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
786 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnant3e519522010-05-11 19:42:16 +0000787public:
788 typedef typename __alloc_traits::pointer pointer;
789 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000790 typedef typename __table::size_type size_type;
791 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000792
793 typedef __hash_map_iterator<typename __table::iterator> iterator;
794 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
795 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
796 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
797
Howard Hinnant789847d2010-09-23 18:58:28 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000799 unordered_map()
800 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000801 {
802#if _LIBCPP_DEBUG_LEVEL >= 2
803 __get_db()->__insert_c(this);
804#endif
805 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000806 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
807 const key_equal& __eql = key_equal());
808 unordered_map(size_type __n, const hasher& __hf,
809 const key_equal& __eql,
810 const allocator_type& __a);
811 template <class _InputIterator>
812 unordered_map(_InputIterator __first, _InputIterator __last);
813 template <class _InputIterator>
814 unordered_map(_InputIterator __first, _InputIterator __last,
815 size_type __n, const hasher& __hf = hasher(),
816 const key_equal& __eql = key_equal());
817 template <class _InputIterator>
818 unordered_map(_InputIterator __first, _InputIterator __last,
819 size_type __n, const hasher& __hf,
820 const key_equal& __eql,
821 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000823 explicit unordered_map(const allocator_type& __a);
824 unordered_map(const unordered_map& __u);
825 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000826#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000828 unordered_map(unordered_map&& __u)
829 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000830 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000831#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000832#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000833 unordered_map(initializer_list<value_type> __il);
834 unordered_map(initializer_list<value_type> __il, size_type __n,
835 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
836 unordered_map(initializer_list<value_type> __il, size_type __n,
837 const hasher& __hf, const key_equal& __eql,
838 const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000839#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow3cd37e62013-09-12 03:00:31 +0000840#if _LIBCPP_STD_VER > 11
841 _LIBCPP_INLINE_VISIBILITY
842 unordered_map(size_type __n, const allocator_type& __a)
843 : unordered_map(__n, hasher(), key_equal(), __a) {}
844 _LIBCPP_INLINE_VISIBILITY
845 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
846 : unordered_map(__n, __hf, key_equal(), __a) {}
847 template <class _InputIterator>
848 _LIBCPP_INLINE_VISIBILITY
849 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
850 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
851 template <class _InputIterator>
852 _LIBCPP_INLINE_VISIBILITY
853 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
854 const allocator_type& __a)
855 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
856 _LIBCPP_INLINE_VISIBILITY
857 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
858 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
859 _LIBCPP_INLINE_VISIBILITY
860 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
861 const allocator_type& __a)
862 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
863#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000864 // ~unordered_map() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000865 _LIBCPP_INLINE_VISIBILITY
866 unordered_map& operator=(const unordered_map& __u)
867 {
Marshall Clow2ee83722016-07-18 13:19:00 +0000868#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +0000869 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +0000870#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +0000871 if (this != &__u) {
872 __table_.clear();
873 __table_.hash_function() = __u.__table_.hash_function();
874 __table_.key_eq() = __u.__table_.key_eq();
875 __table_.max_load_factor() = __u.__table_.max_load_factor();
876 __table_.__copy_assign_alloc(__u.__table_);
877 insert(__u.begin(), __u.end());
878 }
Howard Hinnant307f8142013-06-22 15:21:29 +0000879#endif
Howard Hinnant5a336872011-07-01 19:24:36 +0000880 return *this;
881 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000882#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000884 unordered_map& operator=(unordered_map&& __u)
885 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000886#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000887#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000889 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000891
Howard Hinnant789847d2010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000893 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000894 {return allocator_type(__table_.__node_alloc());}
895
Howard Hinnant789847d2010-09-23 18:58:28 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000897 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000899 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000901 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000902
Howard Hinnant789847d2010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000904 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000906 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000908 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000910 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000912 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000914 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000915
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000916 _LIBCPP_INLINE_VISIBILITY
917 pair<iterator, bool> insert(const value_type& __x)
918 {return __table_.__insert_unique(__x);}
919
920 iterator insert(const_iterator __p, const value_type& __x) {
921#if _LIBCPP_DEBUG_LEVEL >= 2
922 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
923 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
924 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000925#else
926 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000927#endif
928 return insert(__x).first;
929 }
930
931 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000932 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000933 void insert(_InputIterator __first, _InputIterator __last);
934
935#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
936 _LIBCPP_INLINE_VISIBILITY
937 void insert(initializer_list<value_type> __il)
938 {insert(__il.begin(), __il.end());}
939#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
940
Eric Fiselierfcd02212016-02-11 11:59:44 +0000941#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000942 _LIBCPP_INLINE_VISIBILITY
943 pair<iterator, bool> insert(value_type&& __x)
944 {return __table_.__insert_unique(_VSTD::move(__x));}
945
946 iterator insert(const_iterator __p, value_type&& __x) {
947#if _LIBCPP_DEBUG_LEVEL >= 2
948 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
949 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
950 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000951#else
952 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000953#endif
954 return __table_.__insert_unique(_VSTD::move(__x)).first;
955 }
956
957 template <class _Pp,
958 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
959 _LIBCPP_INLINE_VISIBILITY
960 pair<iterator, bool> insert(_Pp&& __x)
961 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
962
963 template <class _Pp,
964 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
965 _LIBCPP_INLINE_VISIBILITY
966 iterator insert(const_iterator __p, _Pp&& __x)
967 {
968#if _LIBCPP_DEBUG_LEVEL >= 2
969 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
970 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
971 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000972#else
973 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000974#endif
975 return insert(_VSTD::forward<_Pp>(__x)).first;
976 }
977
Eric Fiselierfcd02212016-02-11 11:59:44 +0000978 template <class... _Args>
979 _LIBCPP_INLINE_VISIBILITY
980 pair<iterator, bool> emplace(_Args&&... __args) {
981 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
982 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000983
Howard Hinnant8b805c92012-05-25 22:04:21 +0000984 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +0000985 _LIBCPP_INLINE_VISIBILITY
986 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnant4c80bfb2013-07-30 21:04:42 +0000987#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierfcd02212016-02-11 11:59:44 +0000988 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
989 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
990 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000991#else
992 ((void)__p);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +0000993#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +0000994 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
995 }
996
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000997#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000998
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000999#if _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001000 template <class... _Args>
1001 _LIBCPP_INLINE_VISIBILITY
1002 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1003 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001004 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1005 _VSTD::forward_as_tuple(__k),
1006 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001007 }
1008
1009 template <class... _Args>
1010 _LIBCPP_INLINE_VISIBILITY
1011 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1012 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001013 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1014 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1015 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001016 }
1017
1018 template <class... _Args>
1019 _LIBCPP_INLINE_VISIBILITY
1020 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1021 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001022#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001023 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001024 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1025 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001026#else
1027 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001028#endif
Eric Fiselierfd838222016-12-23 23:37:52 +00001029 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001030 }
1031
1032 template <class... _Args>
1033 _LIBCPP_INLINE_VISIBILITY
1034 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1035 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001036#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001037 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001038 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1039 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001040#else
1041 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001042#endif
1043 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001044 }
1045
1046 template <class _Vp>
1047 _LIBCPP_INLINE_VISIBILITY
1048 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1049 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001050 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1051 __k, _VSTD::forward<_Vp>(__v));
1052 if (!__res.second) {
1053 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001054 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001055 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001056 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001057
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001058 template <class _Vp>
1059 _LIBCPP_INLINE_VISIBILITY
1060 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1061 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001062 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1063 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1064 if (!__res.second) {
1065 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001066 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001067 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001068 }
1069
1070 template <class _Vp>
1071 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001072 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001073 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001074 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001075 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001076 }
1077
1078 template <class _Vp>
1079 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001080 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001081 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001082 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001083 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001084 }
1085#endif
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001086
Howard Hinnant789847d2010-09-23 18:58:28 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001088 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001089 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001090 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001092 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001094 iterator erase(const_iterator __first, const_iterator __last)
1095 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001097 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001098
Howard Hinnant789847d2010-09-23 18:58:28 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001100 void swap(unordered_map& __u)
1101 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
Eric Fiselier780b51d2016-12-28 05:53:01 +00001102 { __table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001103
Howard Hinnant789847d2010-09-23 18:58:28 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001105 hasher hash_function() const
1106 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001108 key_equal key_eq() const
1109 {return __table_.key_eq().key_eq();}
1110
Howard Hinnant789847d2010-09-23 18:58:28 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001112 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001114 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001116 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001118 pair<iterator, iterator> equal_range(const key_type& __k)
1119 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001121 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1122 {return __table_.__equal_range_unique(__k);}
1123
1124 mapped_type& operator[](const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001125#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001126 mapped_type& operator[](key_type&& __k);
1127#endif
1128
1129 mapped_type& at(const key_type& __k);
1130 const mapped_type& at(const key_type& __k) const;
1131
Howard Hinnant789847d2010-09-23 18:58:28 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001133 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001135 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001136
Howard Hinnant789847d2010-09-23 18:58:28 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001138 size_type bucket_size(size_type __n) const
1139 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001141 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1142
Howard Hinnant789847d2010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001144 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001146 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001148 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001150 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001152 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001154 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1155
Howard Hinnant789847d2010-09-23 18:58:28 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001157 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001159 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001161 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001163 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001165 void reserve(size_type __n) {__table_.reserve(__n);}
1166
Howard Hinnantb24c8022013-07-23 22:01:58 +00001167#if _LIBCPP_DEBUG_LEVEL >= 2
1168
1169 bool __dereferenceable(const const_iterator* __i) const
1170 {return __table_.__dereferenceable(&__i->__i_);}
1171 bool __decrementable(const const_iterator* __i) const
1172 {return __table_.__decrementable(&__i->__i_);}
1173 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1174 {return __table_.__addable(&__i->__i_, __n);}
1175 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1176 {return __table_.__addable(&__i->__i_, __n);}
1177
1178#endif // _LIBCPP_DEBUG_LEVEL >= 2
1179
Howard Hinnant3e519522010-05-11 19:42:16 +00001180private:
Eric Fiselier0f905672016-02-11 21:45:53 +00001181
1182#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001183 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001184#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001185};
1186
1187template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1188unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1189 size_type __n, const hasher& __hf, const key_equal& __eql)
1190 : __table_(__hf, __eql)
1191{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001192#if _LIBCPP_DEBUG_LEVEL >= 2
1193 __get_db()->__insert_c(this);
1194#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001195 __table_.rehash(__n);
1196}
1197
1198template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1199unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1200 size_type __n, const hasher& __hf, const key_equal& __eql,
1201 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001202 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001203{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001204#if _LIBCPP_DEBUG_LEVEL >= 2
1205 __get_db()->__insert_c(this);
1206#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001207 __table_.rehash(__n);
1208}
1209
1210template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001211inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001212unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1213 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001214 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001215{
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}
1220
1221template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1222template <class _InputIterator>
1223unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1224 _InputIterator __first, _InputIterator __last)
1225{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001226#if _LIBCPP_DEBUG_LEVEL >= 2
1227 __get_db()->__insert_c(this);
1228#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001229 insert(__first, __last);
1230}
1231
1232template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1233template <class _InputIterator>
1234unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1235 _InputIterator __first, _InputIterator __last, size_type __n,
1236 const hasher& __hf, const key_equal& __eql)
1237 : __table_(__hf, __eql)
1238{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001239#if _LIBCPP_DEBUG_LEVEL >= 2
1240 __get_db()->__insert_c(this);
1241#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001242 __table_.rehash(__n);
1243 insert(__first, __last);
1244}
1245
1246template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1247template <class _InputIterator>
1248unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1249 _InputIterator __first, _InputIterator __last, size_type __n,
1250 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001251 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001252{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001253#if _LIBCPP_DEBUG_LEVEL >= 2
1254 __get_db()->__insert_c(this);
1255#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001256 __table_.rehash(__n);
1257 insert(__first, __last);
1258}
1259
1260template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1261unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1262 const unordered_map& __u)
1263 : __table_(__u.__table_)
1264{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001265#if _LIBCPP_DEBUG_LEVEL >= 2
1266 __get_db()->__insert_c(this);
1267#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001268 __table_.rehash(__u.bucket_count());
1269 insert(__u.begin(), __u.end());
1270}
1271
1272template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1273unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1274 const unordered_map& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001275 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001276{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001277#if _LIBCPP_DEBUG_LEVEL >= 2
1278 __get_db()->__insert_c(this);
1279#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001280 __table_.rehash(__u.bucket_count());
1281 insert(__u.begin(), __u.end());
1282}
1283
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001284#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001285
1286template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001287inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001288unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1289 unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001290 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001291 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001292{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001293#if _LIBCPP_DEBUG_LEVEL >= 2
1294 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001295 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001296#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001297}
1298
1299template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1300unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1301 unordered_map&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001302 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001303{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001304#if _LIBCPP_DEBUG_LEVEL >= 2
1305 __get_db()->__insert_c(this);
1306#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001307 if (__a != __u.get_allocator())
1308 {
1309 iterator __i = __u.begin();
Eric Fiselierfcd02212016-02-11 11:59:44 +00001310 while (__u.size() != 0) {
1311 __table_.__emplace_unique(_VSTD::move(
1312 __u.__table_.remove((__i++).__i_)->__value_.__nc));
1313 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001314 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001315#if _LIBCPP_DEBUG_LEVEL >= 2
1316 else
1317 __get_db()->swap(this, &__u);
1318#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001319}
1320
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001321#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001322
Howard Hinnant54976f22011-08-12 21:56:02 +00001323#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1324
Howard Hinnant3e519522010-05-11 19:42:16 +00001325template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1326unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1327 initializer_list<value_type> __il)
1328{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001329#if _LIBCPP_DEBUG_LEVEL >= 2
1330 __get_db()->__insert_c(this);
1331#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001332 insert(__il.begin(), __il.end());
1333}
1334
1335template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1336unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1337 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1338 const key_equal& __eql)
1339 : __table_(__hf, __eql)
1340{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001341#if _LIBCPP_DEBUG_LEVEL >= 2
1342 __get_db()->__insert_c(this);
1343#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001344 __table_.rehash(__n);
1345 insert(__il.begin(), __il.end());
1346}
1347
1348template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1349unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1350 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1351 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001352 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001353{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001354#if _LIBCPP_DEBUG_LEVEL >= 2
1355 __get_db()->__insert_c(this);
1356#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001357 __table_.rehash(__n);
1358 insert(__il.begin(), __il.end());
1359}
1360
Howard Hinnant54976f22011-08-12 21:56:02 +00001361#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1362
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001363#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001364
1365template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001366inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001367unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1368unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001369 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001370{
Howard Hinnantce48a112011-06-30 21:18:19 +00001371 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001372 return *this;
1373}
1374
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001375#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001376
Howard Hinnant54976f22011-08-12 21:56:02 +00001377#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1378
Howard Hinnant3e519522010-05-11 19:42:16 +00001379template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001380inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001381unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1382unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1383 initializer_list<value_type> __il)
1384{
1385 __table_.__assign_unique(__il.begin(), __il.end());
1386 return *this;
1387}
1388
Howard Hinnant54976f22011-08-12 21:56:02 +00001389#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1390
Eric Fiselier0f905672016-02-11 21:45:53 +00001391#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001392template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1393typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001394unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnant3e519522010-05-11 19:42:16 +00001395{
1396 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001397 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant307f8142013-06-22 15:21:29 +00001398 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnant3e519522010-05-11 19:42:16 +00001399 __h.get_deleter().__first_constructed = true;
Howard Hinnant307f8142013-06-22 15:21:29 +00001400 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant3e519522010-05-11 19:42:16 +00001401 __h.get_deleter().__second_constructed = true;
Dimitry Andric251c6292015-08-19 06:43:33 +00001402 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnant3e519522010-05-11 19:42:16 +00001403}
Eric Fiselier0f905672016-02-11 21:45:53 +00001404#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001405
Howard Hinnant3e519522010-05-11 19:42:16 +00001406template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1407template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001408inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001409void
1410unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1411 _InputIterator __last)
1412{
1413 for (; __first != __last; ++__first)
1414 __table_.__insert_unique(*__first);
1415}
1416
Eric Fiselier0f905672016-02-11 21:45:53 +00001417#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001418template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1419_Tp&
1420unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1421{
1422 iterator __i = find(__k);
1423 if (__i != end())
1424 return __i->second;
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001425 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnant3e519522010-05-11 19:42:16 +00001426 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1427 __h.release();
1428 return __r.first->second;
1429}
Eric Fiselier0f905672016-02-11 21:45:53 +00001430#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001431
Eric Fiselier0f905672016-02-11 21:45:53 +00001432template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1433_Tp&
1434unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1435{
1436 return __table_.__emplace_unique_key_args(__k,
1437 std::piecewise_construct, std::forward_as_tuple(__k),
1438 std::forward_as_tuple()).first->__cc.second;
1439}
Howard Hinnant3e519522010-05-11 19:42:16 +00001440
1441template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1442_Tp&
1443unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1444{
Eric Fiselier0f905672016-02-11 21:45:53 +00001445 return __table_.__emplace_unique_key_args(__k,
1446 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1447 std::forward_as_tuple()).first->__cc.second;
Howard Hinnant3e519522010-05-11 19:42:16 +00001448}
1449
Eric Fiselier0f905672016-02-11 21:45:53 +00001450#endif // !_LIBCPP_CXX03_MODE
Howard Hinnant3e519522010-05-11 19:42:16 +00001451
1452template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1453_Tp&
1454unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1455{
1456 iterator __i = find(__k);
1457#ifndef _LIBCPP_NO_EXCEPTIONS
1458 if (__i == end())
1459 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001460#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001461 return __i->second;
1462}
1463
1464template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1465const _Tp&
1466unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1467{
1468 const_iterator __i = find(__k);
1469#ifndef _LIBCPP_NO_EXCEPTIONS
1470 if (__i == end())
1471 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001472#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001473 return __i->second;
1474}
1475
1476template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001477inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001478void
1479swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1480 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00001481 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001482{
1483 __x.swap(__y);
1484}
1485
1486template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1487bool
1488operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1489 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1490{
1491 if (__x.size() != __y.size())
1492 return false;
1493 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1494 const_iterator;
1495 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1496 __i != __ex; ++__i)
1497 {
1498 const_iterator __j = __y.find(__i->first);
1499 if (__j == __ey || !(*__i == *__j))
1500 return false;
1501 }
1502 return true;
1503}
1504
1505template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001507bool
1508operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1509 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1510{
1511 return !(__x == __y);
1512}
1513
1514template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1515 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001516class _LIBCPP_TEMPLATE_VIS unordered_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +00001517{
1518public:
1519 // types
1520 typedef _Key key_type;
1521 typedef _Tp mapped_type;
1522 typedef _Hash hasher;
1523 typedef _Pred key_equal;
1524 typedef _Alloc allocator_type;
1525 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant307f8142013-06-22 15:21:29 +00001526 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001527 typedef value_type& reference;
1528 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001529 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1530 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001531
1532private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +00001533 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +00001534 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1535 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +00001536 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1537 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001538
1539 typedef __hash_table<__value_type, __hasher,
1540 __key_equal, __allocator_type> __table;
1541
1542 __table __table_;
1543
Eric Fiselierfcd02212016-02-11 11:59:44 +00001544 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +00001545 typedef typename __table::__node_traits __node_traits;
1546 typedef typename __table::__node_allocator __node_allocator;
1547 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +00001548 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1549 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001550 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001551 static_assert((is_same<typename __node_traits::size_type,
1552 typename __alloc_traits::size_type>::value),
1553 "Allocator uses different size_type for different types");
Howard Hinnant3e519522010-05-11 19:42:16 +00001554public:
1555 typedef typename __alloc_traits::pointer pointer;
1556 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001557 typedef typename __table::size_type size_type;
1558 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001559
1560 typedef __hash_map_iterator<typename __table::iterator> iterator;
1561 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1562 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1563 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1564
Howard Hinnant789847d2010-09-23 18:58:28 +00001565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001566 unordered_multimap()
1567 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001568 {
1569#if _LIBCPP_DEBUG_LEVEL >= 2
1570 __get_db()->__insert_c(this);
1571#endif
1572 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001573 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1574 const key_equal& __eql = key_equal());
1575 unordered_multimap(size_type __n, const hasher& __hf,
1576 const key_equal& __eql,
1577 const allocator_type& __a);
1578 template <class _InputIterator>
1579 unordered_multimap(_InputIterator __first, _InputIterator __last);
1580 template <class _InputIterator>
1581 unordered_multimap(_InputIterator __first, _InputIterator __last,
1582 size_type __n, const hasher& __hf = hasher(),
1583 const key_equal& __eql = key_equal());
1584 template <class _InputIterator>
1585 unordered_multimap(_InputIterator __first, _InputIterator __last,
1586 size_type __n, const hasher& __hf,
1587 const key_equal& __eql,
1588 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001590 explicit unordered_multimap(const allocator_type& __a);
1591 unordered_multimap(const unordered_multimap& __u);
1592 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001593#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001595 unordered_multimap(unordered_multimap&& __u)
1596 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001597 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001598#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +00001599#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +00001600 unordered_multimap(initializer_list<value_type> __il);
1601 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1602 const hasher& __hf = hasher(),
1603 const key_equal& __eql = key_equal());
1604 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1605 const hasher& __hf, const key_equal& __eql,
1606 const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +00001607#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow3cd37e62013-09-12 03:00:31 +00001608#if _LIBCPP_STD_VER > 11
1609 _LIBCPP_INLINE_VISIBILITY
1610 unordered_multimap(size_type __n, const allocator_type& __a)
1611 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1612 _LIBCPP_INLINE_VISIBILITY
1613 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1614 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1615 template <class _InputIterator>
1616 _LIBCPP_INLINE_VISIBILITY
1617 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1618 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1619 template <class _InputIterator>
1620 _LIBCPP_INLINE_VISIBILITY
1621 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1622 const allocator_type& __a)
1623 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1624 _LIBCPP_INLINE_VISIBILITY
1625 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1626 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1627 _LIBCPP_INLINE_VISIBILITY
1628 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1629 const allocator_type& __a)
1630 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1631#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001632 // ~unordered_multimap() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +00001633 _LIBCPP_INLINE_VISIBILITY
1634 unordered_multimap& operator=(const unordered_multimap& __u)
1635 {
Marshall Clow2ee83722016-07-18 13:19:00 +00001636#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +00001637 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +00001638#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +00001639 if (this != &__u) {
1640 __table_.clear();
1641 __table_.hash_function() = __u.__table_.hash_function();
1642 __table_.key_eq() = __u.__table_.key_eq();
1643 __table_.max_load_factor() = __u.__table_.max_load_factor();
1644 __table_.__copy_assign_alloc(__u.__table_);
1645 insert(__u.begin(), __u.end());
1646 }
Howard Hinnant307f8142013-06-22 15:21:29 +00001647#endif
Howard Hinnant5a336872011-07-01 19:24:36 +00001648 return *this;
1649 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001650#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001652 unordered_multimap& operator=(unordered_multimap&& __u)
1653 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001654#endif
Howard Hinnant54976f22011-08-12 21:56:02 +00001655#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001657 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +00001658#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +00001659
Howard Hinnant789847d2010-09-23 18:58:28 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001661 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001662 {return allocator_type(__table_.__node_alloc());}
1663
Howard Hinnant789847d2010-09-23 18:58:28 +00001664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001665 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +00001666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001667 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001669 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001670
Howard Hinnant789847d2010-09-23 18:58:28 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001672 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001674 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001676 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001678 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001680 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001682 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001683
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001684 _LIBCPP_INLINE_VISIBILITY
1685 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1686
1687 _LIBCPP_INLINE_VISIBILITY
1688 iterator insert(const_iterator __p, const value_type& __x)
1689 {return __table_.__insert_multi(__p.__i_, __x);}
1690
1691 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001692 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001693 void insert(_InputIterator __first, _InputIterator __last);
1694
1695#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1696 _LIBCPP_INLINE_VISIBILITY
1697 void insert(initializer_list<value_type> __il)
1698 {insert(__il.begin(), __il.end());}
1699#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1700
Eric Fiselierfcd02212016-02-11 11:59:44 +00001701#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001702 _LIBCPP_INLINE_VISIBILITY
1703 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1704
1705 _LIBCPP_INLINE_VISIBILITY
1706 iterator insert(const_iterator __p, value_type&& __x)
1707 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1708
1709 template <class _Pp,
1710 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1711 _LIBCPP_INLINE_VISIBILITY
1712 iterator insert(_Pp&& __x)
1713 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1714
1715 template <class _Pp,
1716 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1717 _LIBCPP_INLINE_VISIBILITY
1718 iterator insert(const_iterator __p, _Pp&& __x)
1719 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1720
Eric Fiselierfcd02212016-02-11 11:59:44 +00001721 template <class... _Args>
1722 iterator emplace(_Args&&... __args) {
1723 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1724 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001725
Howard Hinnant8b805c92012-05-25 22:04:21 +00001726 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001727 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1728 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1729 }
1730#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001731
Howard Hinnant3e519522010-05-11 19:42:16 +00001732
Howard Hinnant789847d2010-09-23 18:58:28 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001734 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001735 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001736 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001738 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001740 iterator erase(const_iterator __first, const_iterator __last)
1741 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001743 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001744
Howard Hinnant789847d2010-09-23 18:58:28 +00001745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001746 void swap(unordered_multimap& __u)
1747 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1748 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001749
Howard Hinnant789847d2010-09-23 18:58:28 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001751 hasher hash_function() const
1752 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001754 key_equal key_eq() const
1755 {return __table_.key_eq().key_eq();}
1756
Howard Hinnant789847d2010-09-23 18:58:28 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001758 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001760 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001762 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001764 pair<iterator, iterator> equal_range(const key_type& __k)
1765 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001767 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1768 {return __table_.__equal_range_multi(__k);}
1769
Howard Hinnant789847d2010-09-23 18:58:28 +00001770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001771 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001773 size_type max_bucket_count() const _NOEXCEPT
1774 {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001775
Howard Hinnant789847d2010-09-23 18:58:28 +00001776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001777 size_type bucket_size(size_type __n) const
1778 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001780 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1781
Howard Hinnant789847d2010-09-23 18:58:28 +00001782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001783 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001785 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001787 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001789 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001791 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001793 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1794
Howard Hinnant789847d2010-09-23 18:58:28 +00001795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001796 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001798 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001800 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001802 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001804 void reserve(size_type __n) {__table_.reserve(__n);}
1805
Howard Hinnantb24c8022013-07-23 22:01:58 +00001806#if _LIBCPP_DEBUG_LEVEL >= 2
1807
1808 bool __dereferenceable(const const_iterator* __i) const
1809 {return __table_.__dereferenceable(&__i->__i_);}
1810 bool __decrementable(const const_iterator* __i) const
1811 {return __table_.__decrementable(&__i->__i_);}
1812 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1813 {return __table_.__addable(&__i->__i_, __n);}
1814 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1815 {return __table_.__addable(&__i->__i_, __n);}
1816
1817#endif // _LIBCPP_DEBUG_LEVEL >= 2
1818
Eric Fiselierfcd02212016-02-11 11:59:44 +00001819
Howard Hinnant3e519522010-05-11 19:42:16 +00001820};
1821
1822template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1823unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1824 size_type __n, const hasher& __hf, const key_equal& __eql)
1825 : __table_(__hf, __eql)
1826{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001827#if _LIBCPP_DEBUG_LEVEL >= 2
1828 __get_db()->__insert_c(this);
1829#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001830 __table_.rehash(__n);
1831}
1832
1833template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1834unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1835 size_type __n, const hasher& __hf, const key_equal& __eql,
1836 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001837 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001838{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001839#if _LIBCPP_DEBUG_LEVEL >= 2
1840 __get_db()->__insert_c(this);
1841#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001842 __table_.rehash(__n);
1843}
1844
1845template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1846template <class _InputIterator>
1847unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1848 _InputIterator __first, _InputIterator __last)
1849{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001850#if _LIBCPP_DEBUG_LEVEL >= 2
1851 __get_db()->__insert_c(this);
1852#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001853 insert(__first, __last);
1854}
1855
1856template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1857template <class _InputIterator>
1858unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1859 _InputIterator __first, _InputIterator __last, size_type __n,
1860 const hasher& __hf, const key_equal& __eql)
1861 : __table_(__hf, __eql)
1862{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001863#if _LIBCPP_DEBUG_LEVEL >= 2
1864 __get_db()->__insert_c(this);
1865#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001866 __table_.rehash(__n);
1867 insert(__first, __last);
1868}
1869
1870template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1871template <class _InputIterator>
1872unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1873 _InputIterator __first, _InputIterator __last, size_type __n,
1874 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001875 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001876{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001877#if _LIBCPP_DEBUG_LEVEL >= 2
1878 __get_db()->__insert_c(this);
1879#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001880 __table_.rehash(__n);
1881 insert(__first, __last);
1882}
1883
Howard Hinnant3e519522010-05-11 19:42:16 +00001884template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001885inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001886unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1887 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001888 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001889{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001890#if _LIBCPP_DEBUG_LEVEL >= 2
1891 __get_db()->__insert_c(this);
1892#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001893}
1894
1895template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1896unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1897 const unordered_multimap& __u)
1898 : __table_(__u.__table_)
1899{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001900#if _LIBCPP_DEBUG_LEVEL >= 2
1901 __get_db()->__insert_c(this);
1902#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001903 __table_.rehash(__u.bucket_count());
1904 insert(__u.begin(), __u.end());
1905}
1906
1907template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1908unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1909 const unordered_multimap& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001910 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001911{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001912#if _LIBCPP_DEBUG_LEVEL >= 2
1913 __get_db()->__insert_c(this);
1914#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001915 __table_.rehash(__u.bucket_count());
1916 insert(__u.begin(), __u.end());
1917}
1918
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001919#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001920
1921template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001922inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001923unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1924 unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001925 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001926 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001927{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001928#if _LIBCPP_DEBUG_LEVEL >= 2
1929 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001930 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001931#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001932}
1933
1934template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1935unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1936 unordered_multimap&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001937 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001938{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001939#if _LIBCPP_DEBUG_LEVEL >= 2
1940 __get_db()->__insert_c(this);
1941#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001942 if (__a != __u.get_allocator())
1943 {
1944 iterator __i = __u.begin();
1945 while (__u.size() != 0)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001946 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001947 __table_.__insert_multi(
Eric Fiselierfcd02212016-02-11 11:59:44 +00001948 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
Howard Hinnant3e519522010-05-11 19:42:16 +00001949 );
Howard Hinnantb24c8022013-07-23 22:01:58 +00001950 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001951 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001952#if _LIBCPP_DEBUG_LEVEL >= 2
1953 else
1954 __get_db()->swap(this, &__u);
1955#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001956}
1957
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001958#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001959
Howard Hinnant54976f22011-08-12 21:56:02 +00001960#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1961
Howard Hinnant3e519522010-05-11 19:42:16 +00001962template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1963unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1964 initializer_list<value_type> __il)
1965{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001966#if _LIBCPP_DEBUG_LEVEL >= 2
1967 __get_db()->__insert_c(this);
1968#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001969 insert(__il.begin(), __il.end());
1970}
1971
1972template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1973unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1974 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1975 const key_equal& __eql)
1976 : __table_(__hf, __eql)
1977{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001978#if _LIBCPP_DEBUG_LEVEL >= 2
1979 __get_db()->__insert_c(this);
1980#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001981 __table_.rehash(__n);
1982 insert(__il.begin(), __il.end());
1983}
1984
1985template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1986unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1987 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1988 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001989 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001990{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001991#if _LIBCPP_DEBUG_LEVEL >= 2
1992 __get_db()->__insert_c(this);
1993#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001994 __table_.rehash(__n);
1995 insert(__il.begin(), __il.end());
1996}
1997
Howard Hinnant54976f22011-08-12 21:56:02 +00001998#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1999
Howard Hinnant7609c9b2010-09-04 23:28:19 +00002000#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00002001
2002template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002003inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002004unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2005unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00002006 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00002007{
Howard Hinnantce48a112011-06-30 21:18:19 +00002008 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002009 return *this;
2010}
2011
Howard Hinnant7609c9b2010-09-04 23:28:19 +00002012#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00002013
Howard Hinnant54976f22011-08-12 21:56:02 +00002014#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2015
Howard Hinnant3e519522010-05-11 19:42:16 +00002016template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002017inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002018unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2019unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2020 initializer_list<value_type> __il)
2021{
2022 __table_.__assign_multi(__il.begin(), __il.end());
2023 return *this;
2024}
2025
Howard Hinnant54976f22011-08-12 21:56:02 +00002026#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2027
Howard Hinnant3e519522010-05-11 19:42:16 +00002028
Howard Hinnant3e519522010-05-11 19:42:16 +00002029
2030template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2031template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002032inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002033void
2034unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2035 _InputIterator __last)
2036{
2037 for (; __first != __last; ++__first)
2038 __table_.__insert_multi(*__first);
2039}
2040
2041template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002042inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002043void
2044swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2045 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00002046 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002047{
2048 __x.swap(__y);
2049}
2050
2051template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2052bool
2053operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2054 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2055{
2056 if (__x.size() != __y.size())
2057 return false;
2058 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2059 const_iterator;
2060 typedef pair<const_iterator, const_iterator> _EqRng;
2061 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2062 {
2063 _EqRng __xeq = __x.equal_range(__i->first);
2064 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +00002065 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2066 _VSTD::distance(__yeq.first, __yeq.second) ||
2067 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00002068 return false;
2069 __i = __xeq.second;
2070 }
2071 return true;
2072}
2073
2074template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002076bool
2077operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2078 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2079{
2080 return !(__x == __y);
2081}
2082
2083_LIBCPP_END_NAMESPACE_STD
2084
2085#endif // _LIBCPP_UNORDERED_MAP