blob: f34d82efdc338ebad8120b94c201c9e2c55dc98a [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_MAP
12#define _LIBCPP_UNORDERED_MAP
13
14/*
15
16 unordered_map synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
25class unordered_map
26{
27public:
28 // types
29 typedef Key key_type;
30 typedef T mapped_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef pair<const key_type, mapped_type> value_type;
35 typedef value_type& reference;
36 typedef const value_type& const_reference;
37 typedef typename allocator_traits<allocator_type>::pointer pointer;
38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
39 typedef typename allocator_traits<allocator_type>::size_type size_type;
40 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
41
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
46
Howard Hinnant37141072011-06-04 18:54:24 +000047 unordered_map()
48 noexcept(
49 is_nothrow_default_constructible<hasher>::value &&
50 is_nothrow_default_constructible<key_equal>::value &&
51 is_nothrow_default_constructible<allocator_type>::value);
52 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +000053 const key_equal& eql = key_equal(),
54 const allocator_type& a = allocator_type());
55 template <class InputIterator>
56 unordered_map(InputIterator f, InputIterator l,
57 size_type n = 0, const hasher& hf = hasher(),
58 const key_equal& eql = key_equal(),
59 const allocator_type& a = allocator_type());
60 explicit unordered_map(const allocator_type&);
61 unordered_map(const unordered_map&);
62 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +000063 unordered_map(unordered_map&&)
64 noexcept(
65 is_nothrow_move_constructible<hasher>::value &&
66 is_nothrow_move_constructible<key_equal>::value &&
67 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000068 unordered_map(unordered_map&&, const Allocator&);
69 unordered_map(initializer_list<value_type>, size_type n = 0,
70 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
71 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +000072 unordered_map(size_type n, const allocator_type& a)
73 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
74 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
75 : unordered_map(n, hf, key_equal(), a) {} // C++14
76 template <class InputIterator>
77 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
78 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
79 template <class InputIterator>
80 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
81 const allocator_type& a)
82 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
83 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
84 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
85 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
86 const allocator_type& a)
87 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000088 ~unordered_map();
89 unordered_map& operator=(const unordered_map&);
Howard Hinnant37141072011-06-04 18:54:24 +000090 unordered_map& operator=(unordered_map&&)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
94 is_nothrow_move_assignable<hasher>::value &&
95 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000096 unordered_map& operator=(initializer_list<value_type>);
97
Howard Hinnant37141072011-06-04 18:54:24 +000098 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000099
Howard Hinnant37141072011-06-04 18:54:24 +0000100 bool empty() const noexcept;
101 size_type size() const noexcept;
102 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000103
Howard Hinnant37141072011-06-04 18:54:24 +0000104 iterator begin() noexcept;
105 iterator end() noexcept;
106 const_iterator begin() const noexcept;
107 const_iterator end() const noexcept;
108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000110
111 template <class... Args>
112 pair<iterator, bool> emplace(Args&&... args);
113 template <class... Args>
114 iterator emplace_hint(const_iterator position, Args&&... args);
115 pair<iterator, bool> insert(const value_type& obj);
116 template <class P>
117 pair<iterator, bool> insert(P&& obj);
118 iterator insert(const_iterator hint, const value_type& obj);
119 template <class P>
120 iterator insert(const_iterator hint, P&& obj);
121 template <class InputIterator>
122 void insert(InputIterator first, InputIterator last);
123 void insert(initializer_list<value_type>);
124
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000125 template <class... Args>
126 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
127 template <class... Args>
128 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
129 template <class... Args>
130 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
131 template <class... Args>
132 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
133 template <class M>
134 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
135 template <class M>
136 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
137 template <class M>
138 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
139 template <class M>
140 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
141
Howard Hinnant3e519522010-05-11 19:42:16 +0000142 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000143 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000144 size_type erase(const key_type& k);
145 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000146 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000147
Howard Hinnant37141072011-06-04 18:54:24 +0000148 void swap(unordered_map&)
149 noexcept(
150 (!allocator_type::propagate_on_container_swap::value ||
151 __is_nothrow_swappable<allocator_type>::value) &&
152 __is_nothrow_swappable<hasher>::value &&
153 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000154
155 hasher hash_function() const;
156 key_equal key_eq() const;
157
158 iterator find(const key_type& k);
159 const_iterator find(const key_type& k) const;
160 size_type count(const key_type& k) const;
161 pair<iterator, iterator> equal_range(const key_type& k);
162 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
163
164 mapped_type& operator[](const key_type& k);
165 mapped_type& operator[](key_type&& k);
166
167 mapped_type& at(const key_type& k);
168 const mapped_type& at(const key_type& k) const;
169
Howard Hinnant37141072011-06-04 18:54:24 +0000170 size_type bucket_count() const noexcept;
171 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000172
173 size_type bucket_size(size_type n) const;
174 size_type bucket(const key_type& k) const;
175
176 local_iterator begin(size_type n);
177 local_iterator end(size_type n);
178 const_local_iterator begin(size_type n) const;
179 const_local_iterator end(size_type n) const;
180 const_local_iterator cbegin(size_type n) const;
181 const_local_iterator cend(size_type n) const;
182
Howard Hinnant37141072011-06-04 18:54:24 +0000183 float load_factor() const noexcept;
184 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000185 void max_load_factor(float z);
186 void rehash(size_type n);
187 void reserve(size_type n);
188};
189
190template <class Key, class T, class Hash, class Pred, class Alloc>
191 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000192 unordered_map<Key, T, Hash, Pred, Alloc>& y)
193 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000194
195template <class Key, class T, class Hash, class Pred, class Alloc>
196 bool
197 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
198 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
199
200template <class Key, class T, class Hash, class Pred, class Alloc>
201 bool
202 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
203 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
204
205template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
206 class Alloc = allocator<pair<const Key, T>>>
207class unordered_multimap
208{
209public:
210 // types
211 typedef Key key_type;
212 typedef T mapped_type;
213 typedef Hash hasher;
214 typedef Pred key_equal;
215 typedef Alloc allocator_type;
216 typedef pair<const key_type, mapped_type> value_type;
217 typedef value_type& reference;
218 typedef const value_type& const_reference;
219 typedef typename allocator_traits<allocator_type>::pointer pointer;
220 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
221 typedef typename allocator_traits<allocator_type>::size_type size_type;
222 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
223
224 typedef /unspecified/ iterator;
225 typedef /unspecified/ const_iterator;
226 typedef /unspecified/ local_iterator;
227 typedef /unspecified/ const_local_iterator;
228
Howard Hinnant37141072011-06-04 18:54:24 +0000229 unordered_multimap()
230 noexcept(
231 is_nothrow_default_constructible<hasher>::value &&
232 is_nothrow_default_constructible<key_equal>::value &&
233 is_nothrow_default_constructible<allocator_type>::value);
234 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +0000235 const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
237 template <class InputIterator>
238 unordered_multimap(InputIterator f, InputIterator l,
239 size_type n = 0, const hasher& hf = hasher(),
240 const key_equal& eql = key_equal(),
241 const allocator_type& a = allocator_type());
242 explicit unordered_multimap(const allocator_type&);
243 unordered_multimap(const unordered_multimap&);
244 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +0000245 unordered_multimap(unordered_multimap&&)
246 noexcept(
247 is_nothrow_move_constructible<hasher>::value &&
248 is_nothrow_move_constructible<key_equal>::value &&
249 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000250 unordered_multimap(unordered_multimap&&, const Allocator&);
251 unordered_multimap(initializer_list<value_type>, size_type n = 0,
252 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
253 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +0000254 unordered_multimap(size_type n, const allocator_type& a)
255 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
256 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
257 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
258 template <class InputIterator>
259 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
260 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
261 template <class InputIterator>
262 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
263 const allocator_type& a)
264 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
265 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
266 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
267 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
268 const allocator_type& a)
269 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000270 ~unordered_multimap();
271 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant37141072011-06-04 18:54:24 +0000272 unordered_multimap& operator=(unordered_multimap&&)
273 noexcept(
274 allocator_type::propagate_on_container_move_assignment::value &&
275 is_nothrow_move_assignable<allocator_type>::value &&
276 is_nothrow_move_assignable<hasher>::value &&
277 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000278 unordered_multimap& operator=(initializer_list<value_type>);
279
Howard Hinnant37141072011-06-04 18:54:24 +0000280 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000281
Howard Hinnant37141072011-06-04 18:54:24 +0000282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000285
Howard Hinnant37141072011-06-04 18:54:24 +0000286 iterator begin() noexcept;
287 iterator end() noexcept;
288 const_iterator begin() const noexcept;
289 const_iterator end() const noexcept;
290 const_iterator cbegin() const noexcept;
291 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000292
293 template <class... Args>
294 iterator emplace(Args&&... args);
295 template <class... Args>
296 iterator emplace_hint(const_iterator position, Args&&... args);
297 iterator insert(const value_type& obj);
298 template <class P>
299 iterator insert(P&& obj);
300 iterator insert(const_iterator hint, const value_type& obj);
301 template <class P>
302 iterator insert(const_iterator hint, P&& obj);
303 template <class InputIterator>
304 void insert(InputIterator first, InputIterator last);
305 void insert(initializer_list<value_type>);
306
307 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000308 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000309 size_type erase(const key_type& k);
310 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000311 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000312
Howard Hinnant37141072011-06-04 18:54:24 +0000313 void swap(unordered_multimap&)
314 noexcept(
315 (!allocator_type::propagate_on_container_swap::value ||
316 __is_nothrow_swappable<allocator_type>::value) &&
317 __is_nothrow_swappable<hasher>::value &&
318 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000319
320 hasher hash_function() const;
321 key_equal key_eq() const;
322
323 iterator find(const key_type& k);
324 const_iterator find(const key_type& k) const;
325 size_type count(const key_type& k) const;
326 pair<iterator, iterator> equal_range(const key_type& k);
327 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
328
Howard Hinnant37141072011-06-04 18:54:24 +0000329 size_type bucket_count() const noexcept;
330 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000331
332 size_type bucket_size(size_type n) const;
333 size_type bucket(const key_type& k) const;
334
335 local_iterator begin(size_type n);
336 local_iterator end(size_type n);
337 const_local_iterator begin(size_type n) const;
338 const_local_iterator end(size_type n) const;
339 const_local_iterator cbegin(size_type n) const;
340 const_local_iterator cend(size_type n) const;
341
Howard Hinnant37141072011-06-04 18:54:24 +0000342 float load_factor() const noexcept;
343 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000344 void max_load_factor(float z);
345 void rehash(size_type n);
346 void reserve(size_type n);
347};
348
349template <class Key, class T, class Hash, class Pred, class Alloc>
350 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000351 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
352 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000353
354template <class Key, class T, class Hash, class Pred, class Alloc>
355 bool
356 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
357 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
358
359template <class Key, class T, class Hash, class Pred, class Alloc>
360 bool
361 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
362 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
363
364} // std
365
366*/
367
368#include <__config>
369#include <__hash_table>
370#include <functional>
371#include <stdexcept>
Eric Fiselier0f905672016-02-11 21:45:53 +0000372#include <tuple>
Howard Hinnant3e519522010-05-11 19:42:16 +0000373
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000374#include <__debug>
375
Howard Hinnant073458b2011-10-17 20:05:10 +0000376#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000377#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000378#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000379
380_LIBCPP_BEGIN_NAMESPACE_STD
381
Eric Fiselier04333f92017-01-13 22:42:53 +0000382template <class _Key, class _Cp, class _Hash, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000383class __unordered_map_hasher
384 : private _Hash
385{
386public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000388 __unordered_map_hasher()
389 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
390 : _Hash() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000392 __unordered_map_hasher(const _Hash& __h)
393 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
394 : _Hash(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000396 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000398 size_t operator()(const _Cp& __x) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000399 {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000400 _LIBCPP_INLINE_VISIBILITY
401 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000402 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000403 void swap(__unordered_map_hasher&__y)
404 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
405 {
406 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000407 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000408 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000409};
410
Howard Hinnantabb160e2013-07-05 18:06:00 +0000411template <class _Key, class _Cp, class _Hash>
412class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000413{
414 _Hash __hash_;
415public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000417 __unordered_map_hasher()
418 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
419 : __hash_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000421 __unordered_map_hasher(const _Hash& __h)
422 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
423 : __hash_(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000425 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000427 size_t operator()(const _Cp& __x) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000428 {return __hash_(__x.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000429 _LIBCPP_INLINE_VISIBILITY
430 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000431 {return __hash_(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000432 void swap(__unordered_map_hasher&__y)
433 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
434 {
435 using _VSTD::swap;
436 swap(__hash_, __y.__hash_);
437 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000438};
439
Marshall Clowe3fbe142015-07-13 20:04:56 +0000440template <class _Key, class _Cp, class _Hash, bool __b>
441inline _LIBCPP_INLINE_VISIBILITY
442void
443swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
444 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
445 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
446{
447 __x.swap(__y);
448}
449
Eric Fiselier04333f92017-01-13 22:42:53 +0000450template <class _Key, class _Cp, class _Pred, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000451class __unordered_map_equal
452 : private _Pred
453{
454public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000456 __unordered_map_equal()
457 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
458 : _Pred() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000460 __unordered_map_equal(const _Pred& __p)
461 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
462 : _Pred(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000464 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000466 bool operator()(const _Cp& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000467 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000468 _LIBCPP_INLINE_VISIBILITY
469 bool operator()(const _Cp& __x, const _Key& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000470 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000472 bool operator()(const _Key& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000473 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000474 void swap(__unordered_map_equal&__y)
475 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
476 {
477 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000478 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000479 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000480};
481
Howard Hinnantabb160e2013-07-05 18:06:00 +0000482template <class _Key, class _Cp, class _Pred>
483class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000484{
485 _Pred __pred_;
486public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000488 __unordered_map_equal()
489 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
490 : __pred_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000492 __unordered_map_equal(const _Pred& __p)
493 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
494 : __pred_(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000496 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000498 bool operator()(const _Cp& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000499 {return __pred_(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000500 _LIBCPP_INLINE_VISIBILITY
501 bool operator()(const _Cp& __x, const _Key& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000502 {return __pred_(__x.__get_value().first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000504 bool operator()(const _Key& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000505 {return __pred_(__x, __y.__get_value().first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000506 void swap(__unordered_map_equal&__y)
507 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
508 {
509 using _VSTD::swap;
510 swap(__pred_, __y.__pred_);
511 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000512};
513
Marshall Clowe3fbe142015-07-13 20:04:56 +0000514template <class _Key, class _Cp, class _Pred, bool __b>
515inline _LIBCPP_INLINE_VISIBILITY
516void
517swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
518 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
519 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
520{
521 __x.swap(__y);
522}
523
Howard Hinnant3e519522010-05-11 19:42:16 +0000524template <class _Alloc>
525class __hash_map_node_destructor
526{
527 typedef _Alloc allocator_type;
528 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000529
Howard Hinnant3e519522010-05-11 19:42:16 +0000530public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000531
532 typedef typename __alloc_traits::pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000533private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000534
535 allocator_type& __na_;
536
537 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
538
539public:
540 bool __first_constructed;
541 bool __second_constructed;
542
Howard Hinnant789847d2010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000544 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000545 : __na_(__na),
546 __first_constructed(false),
547 __second_constructed(false)
548 {}
549
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000550#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000552 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000553 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000554 : __na_(__x.__na_),
555 __first_constructed(__x.__value_constructed),
556 __second_constructed(__x.__value_constructed)
557 {
558 __x.__value_constructed = false;
559 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000560#else // _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000562 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
563 : __na_(__x.__na_),
564 __first_constructed(__x.__value_constructed),
565 __second_constructed(__x.__value_constructed)
566 {
567 const_cast<bool&>(__x.__value_constructed) = false;
568 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000569#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000570
Howard Hinnant789847d2010-09-23 18:58:28 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000572 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000573 {
574 if (__second_constructed)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000575 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000576 if (__first_constructed)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000577 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 if (__p)
579 __alloc_traits::deallocate(__na_, __p, 1);
580 }
581};
582
Eric Fiselierfcd02212016-02-11 11:59:44 +0000583#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000584template <class _Key, class _Tp>
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000585struct __hash_value_type
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000586{
587 typedef _Key key_type;
588 typedef _Tp mapped_type;
589 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000590 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
591 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000592
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000593private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000594 value_type __cc;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000595
596public:
597 _LIBCPP_INLINE_VISIBILITY
598 value_type& __get_value()
599 {
600#if _LIBCPP_STD_VER > 14
601 return *_VSTD::launder(_VSTD::addressof(__cc));
602#else
603 return __cc;
604#endif
605 }
606
607 _LIBCPP_INLINE_VISIBILITY
608 const value_type& __get_value() const
609 {
610#if _LIBCPP_STD_VER > 14
611 return *_VSTD::launder(_VSTD::addressof(__cc));
612#else
613 return __cc;
614#endif
615 }
616
617 _LIBCPP_INLINE_VISIBILITY
618 __nc_ref_pair_type __ref()
619 {
620 value_type& __v = __get_value();
621 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
622 }
623
624 _LIBCPP_INLINE_VISIBILITY
625 __nc_rref_pair_type __move()
626 {
627 value_type& __v = __get_value();
628 return __nc_rref_pair_type(
629 _VSTD::move(const_cast<key_type&>(__v.first)),
630 _VSTD::move(__v.second));
631 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000632
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000633 _LIBCPP_INLINE_VISIBILITY
634 __hash_value_type& operator=(const __hash_value_type& __v)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000635 {
636 __ref() = __v.__get_value();
637 return *this;
638 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000639
640 _LIBCPP_INLINE_VISIBILITY
641 __hash_value_type& operator=(__hash_value_type&& __v)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000642 {
643 __ref() = __v.__move();
644 return *this;
645 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000646
Eric Fiselierfcd02212016-02-11 11:59:44 +0000647 template <class _ValueTp,
648 class = typename enable_if<
649 __is_same_uncvref<_ValueTp, value_type>::value
650 >::type
651 >
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000652 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000653 __hash_value_type& operator=(_ValueTp&& __v)
654 {
655 __ref() = _VSTD::forward<_ValueTp>(__v);
656 return *this;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000657 }
658
659private:
660 __hash_value_type(const __hash_value_type& __v) = delete;
661 __hash_value_type(__hash_value_type&& __v) = delete;
662 template <class ..._Args>
663 explicit __hash_value_type(_Args&& ...__args) = delete;
664
665 ~__hash_value_type() = delete;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000666};
667
668#else
669
670template <class _Key, class _Tp>
671struct __hash_value_type
672{
673 typedef _Key key_type;
674 typedef _Tp mapped_type;
675 typedef pair<const key_type, mapped_type> value_type;
676
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000677private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000678 value_type __cc;
679
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000680public:
681 _LIBCPP_INLINE_VISIBILITY
682 value_type& __get_value() { return __cc; }
683 _LIBCPP_INLINE_VISIBILITY
684 const value_type& __get_value() const { return __cc; }
685
Eric Fiselierfcd02212016-02-11 11:59:44 +0000686private:
687 ~__hash_value_type();
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000688};
689
690#endif
691
Howard Hinnant3e519522010-05-11 19:42:16 +0000692template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000693class _LIBCPP_TEMPLATE_VIS __hash_map_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 value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000704 typedef typename _NodeTypes::__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_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_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000711
Howard Hinnant789847d2010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000713 reference operator*() const {return __i_->__get_value();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000715 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000716
Howard Hinnant789847d2010-09-23 18:58:28 +0000717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000718 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000720 __hash_map_iterator operator++(int)
721 {
722 __hash_map_iterator __t(*this);
723 ++(*this);
724 return __t;
725 }
726
Howard Hinnant789847d2010-09-23 18:58:28 +0000727 friend _LIBCPP_INLINE_VISIBILITY
728 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000729 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000730 friend _LIBCPP_INLINE_VISIBILITY
731 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000732 {return __x.__i_ != __y.__i_;}
733
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000734 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
735 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
736 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
737 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
738 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000739};
740
741template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000742class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000743{
744 _HashIterator __i_;
745
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000746 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
747
Howard Hinnant3e519522010-05-11 19:42:16 +0000748public:
749 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000750 typedef typename _NodeTypes::__map_value_type value_type;
751 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000752 typedef const value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000753 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000754
Howard Hinnant789847d2010-09-23 18:58:28 +0000755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000756 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000757
Howard Hinnant789847d2010-09-23 18:58:28 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000759 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000761 __hash_map_const_iterator(
762 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant37141072011-06-04 18:54:24 +0000763 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000764 : __i_(__i.__i_) {}
765
Howard Hinnant789847d2010-09-23 18:58:28 +0000766 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000767 reference operator*() const {return __i_->__get_value();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000768 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000769 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000770
Howard Hinnant789847d2010-09-23 18:58:28 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000772 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000774 __hash_map_const_iterator operator++(int)
775 {
776 __hash_map_const_iterator __t(*this);
777 ++(*this);
778 return __t;
779 }
780
Howard Hinnant789847d2010-09-23 18:58:28 +0000781 friend _LIBCPP_INLINE_VISIBILITY
782 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000783 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000784 friend _LIBCPP_INLINE_VISIBILITY
785 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000786 {return __x.__i_ != __y.__i_;}
787
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000788 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
789 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
790 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
791 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000792};
793
794template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
795 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000796class _LIBCPP_TEMPLATE_VIS unordered_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000797{
798public:
799 // types
800 typedef _Key key_type;
801 typedef _Tp mapped_type;
802 typedef _Hash hasher;
803 typedef _Pred key_equal;
804 typedef _Alloc allocator_type;
805 typedef pair<const key_type, mapped_type> value_type;
806 typedef value_type& reference;
807 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000808 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
809 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000810
811private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000812 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +0000813 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
814 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +0000815 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
816 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000817
818 typedef __hash_table<__value_type, __hasher,
819 __key_equal, __allocator_type> __table;
820
821 __table __table_;
822
Eric Fiselierfcd02212016-02-11 11:59:44 +0000823 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000824 typedef typename __table::__node_pointer __node_pointer;
825 typedef typename __table::__node_const_pointer __node_const_pointer;
826 typedef typename __table::__node_traits __node_traits;
827 typedef typename __table::__node_allocator __node_allocator;
828 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000829 typedef __hash_map_node_destructor<__node_allocator> _Dp;
830 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000831 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000832
833 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
834 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnant3e519522010-05-11 19:42:16 +0000835public:
836 typedef typename __alloc_traits::pointer pointer;
837 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000838 typedef typename __table::size_type size_type;
839 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000840
841 typedef __hash_map_iterator<typename __table::iterator> iterator;
842 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
843 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
844 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
845
Howard Hinnant789847d2010-09-23 18:58:28 +0000846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000847 unordered_map()
848 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000849 {
850#if _LIBCPP_DEBUG_LEVEL >= 2
851 __get_db()->__insert_c(this);
852#endif
853 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000854 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
855 const key_equal& __eql = key_equal());
856 unordered_map(size_type __n, const hasher& __hf,
857 const key_equal& __eql,
858 const allocator_type& __a);
859 template <class _InputIterator>
860 unordered_map(_InputIterator __first, _InputIterator __last);
861 template <class _InputIterator>
862 unordered_map(_InputIterator __first, _InputIterator __last,
863 size_type __n, const hasher& __hf = hasher(),
864 const key_equal& __eql = key_equal());
865 template <class _InputIterator>
866 unordered_map(_InputIterator __first, _InputIterator __last,
867 size_type __n, const hasher& __hf,
868 const key_equal& __eql,
869 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000871 explicit unordered_map(const allocator_type& __a);
872 unordered_map(const unordered_map& __u);
873 unordered_map(const unordered_map& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000874#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000876 unordered_map(unordered_map&& __u)
877 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000878 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +0000879 unordered_map(initializer_list<value_type> __il);
880 unordered_map(initializer_list<value_type> __il, size_type __n,
881 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
882 unordered_map(initializer_list<value_type> __il, size_type __n,
883 const hasher& __hf, const key_equal& __eql,
884 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000885#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +0000886#if _LIBCPP_STD_VER > 11
887 _LIBCPP_INLINE_VISIBILITY
888 unordered_map(size_type __n, const allocator_type& __a)
889 : unordered_map(__n, hasher(), key_equal(), __a) {}
890 _LIBCPP_INLINE_VISIBILITY
891 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
892 : unordered_map(__n, __hf, key_equal(), __a) {}
893 template <class _InputIterator>
894 _LIBCPP_INLINE_VISIBILITY
895 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
896 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
897 template <class _InputIterator>
898 _LIBCPP_INLINE_VISIBILITY
899 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
900 const allocator_type& __a)
901 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
902 _LIBCPP_INLINE_VISIBILITY
903 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
904 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
905 _LIBCPP_INLINE_VISIBILITY
906 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
907 const allocator_type& __a)
908 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
909#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000910 // ~unordered_map() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000911 _LIBCPP_INLINE_VISIBILITY
912 unordered_map& operator=(const unordered_map& __u)
913 {
Marshall Clow2ee83722016-07-18 13:19:00 +0000914#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +0000915 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +0000916#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +0000917 if (this != &__u) {
918 __table_.clear();
919 __table_.hash_function() = __u.__table_.hash_function();
920 __table_.key_eq() = __u.__table_.key_eq();
921 __table_.max_load_factor() = __u.__table_.max_load_factor();
922 __table_.__copy_assign_alloc(__u.__table_);
923 insert(__u.begin(), __u.end());
924 }
Howard Hinnant307f8142013-06-22 15:21:29 +0000925#endif
Howard Hinnant5a336872011-07-01 19:24:36 +0000926 return *this;
927 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000928#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000930 unordered_map& operator=(unordered_map&& __u)
931 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000933 unordered_map& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000934#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000935
Howard Hinnant789847d2010-09-23 18:58:28 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000937 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000938 {return allocator_type(__table_.__node_alloc());}
939
Marshall Clow72c8fad2017-11-15 05:51:26 +0000940 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000941 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000943 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000945 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000946
Howard Hinnant789847d2010-09-23 18:58:28 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000948 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000950 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000952 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000954 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000956 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000958 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000959
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000960 _LIBCPP_INLINE_VISIBILITY
961 pair<iterator, bool> insert(const value_type& __x)
962 {return __table_.__insert_unique(__x);}
963
964 iterator insert(const_iterator __p, const value_type& __x) {
965#if _LIBCPP_DEBUG_LEVEL >= 2
966 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
967 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
968 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000969#else
970 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000971#endif
972 return insert(__x).first;
973 }
974
975 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000976 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000977 void insert(_InputIterator __first, _InputIterator __last);
978
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000979#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000980 _LIBCPP_INLINE_VISIBILITY
981 void insert(initializer_list<value_type> __il)
982 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000983
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000984 _LIBCPP_INLINE_VISIBILITY
985 pair<iterator, bool> insert(value_type&& __x)
986 {return __table_.__insert_unique(_VSTD::move(__x));}
987
988 iterator insert(const_iterator __p, value_type&& __x) {
989#if _LIBCPP_DEBUG_LEVEL >= 2
990 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
991 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
992 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000993#else
994 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000995#endif
996 return __table_.__insert_unique(_VSTD::move(__x)).first;
997 }
998
999 template <class _Pp,
1000 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1001 _LIBCPP_INLINE_VISIBILITY
1002 pair<iterator, bool> insert(_Pp&& __x)
1003 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
1004
1005 template <class _Pp,
1006 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1007 _LIBCPP_INLINE_VISIBILITY
1008 iterator insert(const_iterator __p, _Pp&& __x)
1009 {
1010#if _LIBCPP_DEBUG_LEVEL >= 2
1011 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1012 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1013 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001014#else
1015 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001016#endif
1017 return insert(_VSTD::forward<_Pp>(__x)).first;
1018 }
1019
Eric Fiselierfcd02212016-02-11 11:59:44 +00001020 template <class... _Args>
1021 _LIBCPP_INLINE_VISIBILITY
1022 pair<iterator, bool> emplace(_Args&&... __args) {
1023 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1024 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001025
Howard Hinnant8b805c92012-05-25 22:04:21 +00001026 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001027 _LIBCPP_INLINE_VISIBILITY
1028 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001029#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierfcd02212016-02-11 11:59:44 +00001030 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1031 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1032 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001033#else
1034 ((void)__p);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001035#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +00001036 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
1037 }
1038
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001039#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001040
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001041#if _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001042 template <class... _Args>
1043 _LIBCPP_INLINE_VISIBILITY
1044 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1045 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001046 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1047 _VSTD::forward_as_tuple(__k),
1048 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001049 }
1050
1051 template <class... _Args>
1052 _LIBCPP_INLINE_VISIBILITY
1053 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1054 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001055 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1056 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1057 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001058 }
1059
1060 template <class... _Args>
1061 _LIBCPP_INLINE_VISIBILITY
1062 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1063 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001064#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001065 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001066 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1067 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001068#else
1069 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001070#endif
Eric Fiselierfd838222016-12-23 23:37:52 +00001071 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001072 }
1073
1074 template <class... _Args>
1075 _LIBCPP_INLINE_VISIBILITY
1076 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1077 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001078#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001079 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001080 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1081 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001082#else
1083 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001084#endif
1085 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001086 }
1087
1088 template <class _Vp>
1089 _LIBCPP_INLINE_VISIBILITY
1090 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1091 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001092 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1093 __k, _VSTD::forward<_Vp>(__v));
1094 if (!__res.second) {
1095 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001096 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001097 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001098 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001099
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001100 template <class _Vp>
1101 _LIBCPP_INLINE_VISIBILITY
1102 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1103 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001104 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1105 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1106 if (!__res.second) {
1107 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001108 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001109 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001110 }
1111
1112 template <class _Vp>
1113 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001114 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001115 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001116 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001117 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001118 }
1119
1120 template <class _Vp>
1121 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001122 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001123 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001124 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001125 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001126 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001127#endif // _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001128
Howard Hinnant789847d2010-09-23 18:58:28 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001130 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001131 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001132 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001134 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001136 iterator erase(const_iterator __first, const_iterator __last)
1137 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001139 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001140
Howard Hinnant789847d2010-09-23 18:58:28 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001142 void swap(unordered_map& __u)
1143 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
Eric Fiselier780b51d2016-12-28 05:53:01 +00001144 { __table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001145
Howard Hinnant789847d2010-09-23 18:58:28 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001147 hasher hash_function() const
1148 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001150 key_equal key_eq() const
1151 {return __table_.key_eq().key_eq();}
1152
Howard Hinnant789847d2010-09-23 18:58:28 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001154 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001156 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001158 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001160 pair<iterator, iterator> equal_range(const key_type& __k)
1161 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001163 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1164 {return __table_.__equal_range_unique(__k);}
1165
1166 mapped_type& operator[](const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001167#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001168 mapped_type& operator[](key_type&& __k);
1169#endif
1170
1171 mapped_type& at(const key_type& __k);
1172 const mapped_type& at(const key_type& __k) const;
1173
Howard Hinnant789847d2010-09-23 18:58:28 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001175 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001177 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001178
Howard Hinnant789847d2010-09-23 18:58:28 +00001179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001180 size_type bucket_size(size_type __n) const
1181 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001183 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1184
Howard Hinnant789847d2010-09-23 18:58:28 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001186 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001188 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001190 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001192 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001194 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001196 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1197
Howard Hinnant789847d2010-09-23 18:58:28 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001199 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001201 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001203 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001205 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001207 void reserve(size_type __n) {__table_.reserve(__n);}
1208
Howard Hinnantb24c8022013-07-23 22:01:58 +00001209#if _LIBCPP_DEBUG_LEVEL >= 2
1210
1211 bool __dereferenceable(const const_iterator* __i) const
1212 {return __table_.__dereferenceable(&__i->__i_);}
1213 bool __decrementable(const const_iterator* __i) const
1214 {return __table_.__decrementable(&__i->__i_);}
1215 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1216 {return __table_.__addable(&__i->__i_, __n);}
1217 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1218 {return __table_.__addable(&__i->__i_, __n);}
1219
1220#endif // _LIBCPP_DEBUG_LEVEL >= 2
1221
Howard Hinnant3e519522010-05-11 19:42:16 +00001222private:
Eric Fiselier0f905672016-02-11 21:45:53 +00001223
1224#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001225 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001226#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001227};
1228
1229template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1230unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1231 size_type __n, const hasher& __hf, const key_equal& __eql)
1232 : __table_(__hf, __eql)
1233{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001234#if _LIBCPP_DEBUG_LEVEL >= 2
1235 __get_db()->__insert_c(this);
1236#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001237 __table_.rehash(__n);
1238}
1239
1240template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1241unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1242 size_type __n, const hasher& __hf, const key_equal& __eql,
1243 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001244 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001245{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001246#if _LIBCPP_DEBUG_LEVEL >= 2
1247 __get_db()->__insert_c(this);
1248#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001249 __table_.rehash(__n);
1250}
1251
1252template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001253inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001254unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1255 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001256 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001257{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001258#if _LIBCPP_DEBUG_LEVEL >= 2
1259 __get_db()->__insert_c(this);
1260#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001261}
1262
1263template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1264template <class _InputIterator>
1265unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1266 _InputIterator __first, _InputIterator __last)
1267{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001268#if _LIBCPP_DEBUG_LEVEL >= 2
1269 __get_db()->__insert_c(this);
1270#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001271 insert(__first, __last);
1272}
1273
1274template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1275template <class _InputIterator>
1276unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1277 _InputIterator __first, _InputIterator __last, size_type __n,
1278 const hasher& __hf, const key_equal& __eql)
1279 : __table_(__hf, __eql)
1280{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001281#if _LIBCPP_DEBUG_LEVEL >= 2
1282 __get_db()->__insert_c(this);
1283#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001284 __table_.rehash(__n);
1285 insert(__first, __last);
1286}
1287
1288template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1289template <class _InputIterator>
1290unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1291 _InputIterator __first, _InputIterator __last, size_type __n,
1292 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001293 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001294{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001295#if _LIBCPP_DEBUG_LEVEL >= 2
1296 __get_db()->__insert_c(this);
1297#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001298 __table_.rehash(__n);
1299 insert(__first, __last);
1300}
1301
1302template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1303unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1304 const unordered_map& __u)
1305 : __table_(__u.__table_)
1306{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001307#if _LIBCPP_DEBUG_LEVEL >= 2
1308 __get_db()->__insert_c(this);
1309#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001310 __table_.rehash(__u.bucket_count());
1311 insert(__u.begin(), __u.end());
1312}
1313
1314template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1315unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1316 const unordered_map& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001317 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001318{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001319#if _LIBCPP_DEBUG_LEVEL >= 2
1320 __get_db()->__insert_c(this);
1321#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001322 __table_.rehash(__u.bucket_count());
1323 insert(__u.begin(), __u.end());
1324}
1325
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001326#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001327
1328template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001329inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001330unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1331 unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001332 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001333 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001334{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001335#if _LIBCPP_DEBUG_LEVEL >= 2
1336 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001337 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001338#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001339}
1340
1341template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1342unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1343 unordered_map&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001344 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001345{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001346#if _LIBCPP_DEBUG_LEVEL >= 2
1347 __get_db()->__insert_c(this);
1348#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001349 if (__a != __u.get_allocator())
1350 {
1351 iterator __i = __u.begin();
Eric Fiselierfcd02212016-02-11 11:59:44 +00001352 while (__u.size() != 0) {
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001353 __table_.__emplace_unique(
1354 __u.__table_.remove((__i++).__i_)->__value_.__move());
Eric Fiselierfcd02212016-02-11 11:59:44 +00001355 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001356 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001357#if _LIBCPP_DEBUG_LEVEL >= 2
1358 else
1359 __get_db()->swap(this, &__u);
1360#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001361}
1362
Howard Hinnant3e519522010-05-11 19:42:16 +00001363template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1364unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1365 initializer_list<value_type> __il)
1366{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001367#if _LIBCPP_DEBUG_LEVEL >= 2
1368 __get_db()->__insert_c(this);
1369#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001370 insert(__il.begin(), __il.end());
1371}
1372
1373template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1374unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1375 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1376 const key_equal& __eql)
1377 : __table_(__hf, __eql)
1378{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001379#if _LIBCPP_DEBUG_LEVEL >= 2
1380 __get_db()->__insert_c(this);
1381#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001382 __table_.rehash(__n);
1383 insert(__il.begin(), __il.end());
1384}
1385
1386template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1387unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1388 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1389 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001390 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001391{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001392#if _LIBCPP_DEBUG_LEVEL >= 2
1393 __get_db()->__insert_c(this);
1394#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001395 __table_.rehash(__n);
1396 insert(__il.begin(), __il.end());
1397}
1398
Howard Hinnant3e519522010-05-11 19:42:16 +00001399template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001400inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001401unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1402unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001403 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001404{
Howard Hinnantce48a112011-06-30 21:18:19 +00001405 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001406 return *this;
1407}
1408
Howard Hinnant3e519522010-05-11 19:42:16 +00001409template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001410inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001411unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1412unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1413 initializer_list<value_type> __il)
1414{
1415 __table_.__assign_unique(__il.begin(), __il.end());
1416 return *this;
1417}
1418
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001419#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001420
Howard Hinnant3e519522010-05-11 19:42:16 +00001421template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1422template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001423inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001424void
1425unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1426 _InputIterator __last)
1427{
1428 for (; __first != __last; ++__first)
1429 __table_.__insert_unique(*__first);
1430}
1431
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001432#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001433
Eric Fiselier0f905672016-02-11 21:45:53 +00001434template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1435_Tp&
1436unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1437{
1438 return __table_.__emplace_unique_key_args(__k,
1439 std::piecewise_construct, std::forward_as_tuple(__k),
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001440 std::forward_as_tuple()).first->__get_value().second;
Eric Fiselier0f905672016-02-11 21:45:53 +00001441}
Howard Hinnant3e519522010-05-11 19:42:16 +00001442
1443template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1444_Tp&
1445unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1446{
Eric Fiselier0f905672016-02-11 21:45:53 +00001447 return __table_.__emplace_unique_key_args(__k,
1448 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001449 std::forward_as_tuple()).first->__get_value().second;
Howard Hinnant3e519522010-05-11 19:42:16 +00001450}
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001451#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001452
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001453template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1454typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1455unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1456{
1457 __node_allocator& __na = __table_.__node_alloc();
1458 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001459 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001460 __h.get_deleter().__first_constructed = true;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001461 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001462 __h.get_deleter().__second_constructed = true;
1463 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1464}
1465
1466template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1467_Tp&
1468unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1469{
1470 iterator __i = find(__k);
1471 if (__i != end())
1472 return __i->second;
1473 __node_holder __h = __construct_node_with_key(__k);
1474 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1475 __h.release();
1476 return __r.first->second;
1477}
1478
1479#endif // _LIBCPP_CXX03_MODE
Howard Hinnant3e519522010-05-11 19:42:16 +00001480
1481template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1482_Tp&
1483unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1484{
1485 iterator __i = find(__k);
1486#ifndef _LIBCPP_NO_EXCEPTIONS
1487 if (__i == end())
1488 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001489#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001490 return __i->second;
1491}
1492
1493template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1494const _Tp&
1495unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1496{
1497 const_iterator __i = find(__k);
1498#ifndef _LIBCPP_NO_EXCEPTIONS
1499 if (__i == end())
1500 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001501#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001502 return __i->second;
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 +00001507void
1508swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1509 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00001510 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001511{
1512 __x.swap(__y);
1513}
1514
1515template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1516bool
1517operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1518 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1519{
1520 if (__x.size() != __y.size())
1521 return false;
1522 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1523 const_iterator;
1524 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1525 __i != __ex; ++__i)
1526 {
1527 const_iterator __j = __y.find(__i->first);
1528 if (__j == __ey || !(*__i == *__j))
1529 return false;
1530 }
1531 return true;
1532}
1533
1534template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001536bool
1537operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1538 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1539{
1540 return !(__x == __y);
1541}
1542
1543template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1544 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001545class _LIBCPP_TEMPLATE_VIS unordered_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +00001546{
1547public:
1548 // types
1549 typedef _Key key_type;
1550 typedef _Tp mapped_type;
1551 typedef _Hash hasher;
1552 typedef _Pred key_equal;
1553 typedef _Alloc allocator_type;
1554 typedef pair<const key_type, mapped_type> value_type;
1555 typedef value_type& reference;
1556 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001557 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1558 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001559
1560private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +00001561 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +00001562 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1563 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +00001564 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1565 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001566
1567 typedef __hash_table<__value_type, __hasher,
1568 __key_equal, __allocator_type> __table;
1569
1570 __table __table_;
1571
Eric Fiselierfcd02212016-02-11 11:59:44 +00001572 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +00001573 typedef typename __table::__node_traits __node_traits;
1574 typedef typename __table::__node_allocator __node_allocator;
1575 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +00001576 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1577 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001578 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001579 static_assert((is_same<typename __node_traits::size_type,
1580 typename __alloc_traits::size_type>::value),
1581 "Allocator uses different size_type for different types");
Howard Hinnant3e519522010-05-11 19:42:16 +00001582public:
1583 typedef typename __alloc_traits::pointer pointer;
1584 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001585 typedef typename __table::size_type size_type;
1586 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001587
1588 typedef __hash_map_iterator<typename __table::iterator> iterator;
1589 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1590 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1591 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1592
Howard Hinnant789847d2010-09-23 18:58:28 +00001593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001594 unordered_multimap()
1595 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001596 {
1597#if _LIBCPP_DEBUG_LEVEL >= 2
1598 __get_db()->__insert_c(this);
1599#endif
1600 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001601 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1602 const key_equal& __eql = key_equal());
1603 unordered_multimap(size_type __n, const hasher& __hf,
1604 const key_equal& __eql,
1605 const allocator_type& __a);
1606 template <class _InputIterator>
1607 unordered_multimap(_InputIterator __first, _InputIterator __last);
1608 template <class _InputIterator>
1609 unordered_multimap(_InputIterator __first, _InputIterator __last,
1610 size_type __n, const hasher& __hf = hasher(),
1611 const key_equal& __eql = key_equal());
1612 template <class _InputIterator>
1613 unordered_multimap(_InputIterator __first, _InputIterator __last,
1614 size_type __n, const hasher& __hf,
1615 const key_equal& __eql,
1616 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001618 explicit unordered_multimap(const allocator_type& __a);
1619 unordered_multimap(const unordered_multimap& __u);
1620 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001621#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001623 unordered_multimap(unordered_multimap&& __u)
1624 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001625 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +00001626 unordered_multimap(initializer_list<value_type> __il);
1627 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1628 const hasher& __hf = hasher(),
1629 const key_equal& __eql = key_equal());
1630 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1631 const hasher& __hf, const key_equal& __eql,
1632 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001633#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +00001634#if _LIBCPP_STD_VER > 11
1635 _LIBCPP_INLINE_VISIBILITY
1636 unordered_multimap(size_type __n, const allocator_type& __a)
1637 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1638 _LIBCPP_INLINE_VISIBILITY
1639 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1640 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1641 template <class _InputIterator>
1642 _LIBCPP_INLINE_VISIBILITY
1643 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1644 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1645 template <class _InputIterator>
1646 _LIBCPP_INLINE_VISIBILITY
1647 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1648 const allocator_type& __a)
1649 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1650 _LIBCPP_INLINE_VISIBILITY
1651 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1652 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1653 _LIBCPP_INLINE_VISIBILITY
1654 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1655 const allocator_type& __a)
1656 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1657#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001658 // ~unordered_multimap() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +00001659 _LIBCPP_INLINE_VISIBILITY
1660 unordered_multimap& operator=(const unordered_multimap& __u)
1661 {
Marshall Clow2ee83722016-07-18 13:19:00 +00001662#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +00001663 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +00001664#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +00001665 if (this != &__u) {
1666 __table_.clear();
1667 __table_.hash_function() = __u.__table_.hash_function();
1668 __table_.key_eq() = __u.__table_.key_eq();
1669 __table_.max_load_factor() = __u.__table_.max_load_factor();
1670 __table_.__copy_assign_alloc(__u.__table_);
1671 insert(__u.begin(), __u.end());
1672 }
Howard Hinnant307f8142013-06-22 15:21:29 +00001673#endif
Howard Hinnant5a336872011-07-01 19:24:36 +00001674 return *this;
1675 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001676#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001678 unordered_multimap& operator=(unordered_multimap&& __u)
1679 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001681 unordered_multimap& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001682#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001683
Howard Hinnant789847d2010-09-23 18:58:28 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001685 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001686 {return allocator_type(__table_.__node_alloc());}
1687
Marshall Clow72c8fad2017-11-15 05:51:26 +00001688 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001689 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001691 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001693 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001694
Howard Hinnant789847d2010-09-23 18:58:28 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001696 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001698 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001700 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001702 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001704 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001706 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001707
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001708 _LIBCPP_INLINE_VISIBILITY
1709 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1710
1711 _LIBCPP_INLINE_VISIBILITY
1712 iterator insert(const_iterator __p, const value_type& __x)
1713 {return __table_.__insert_multi(__p.__i_, __x);}
1714
1715 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001716 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001717 void insert(_InputIterator __first, _InputIterator __last);
1718
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001719#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001720 _LIBCPP_INLINE_VISIBILITY
1721 void insert(initializer_list<value_type> __il)
1722 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001723 _LIBCPP_INLINE_VISIBILITY
1724 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1725
1726 _LIBCPP_INLINE_VISIBILITY
1727 iterator insert(const_iterator __p, value_type&& __x)
1728 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1729
1730 template <class _Pp,
1731 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1732 _LIBCPP_INLINE_VISIBILITY
1733 iterator insert(_Pp&& __x)
1734 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1735
1736 template <class _Pp,
1737 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1738 _LIBCPP_INLINE_VISIBILITY
1739 iterator insert(const_iterator __p, _Pp&& __x)
1740 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1741
Eric Fiselierfcd02212016-02-11 11:59:44 +00001742 template <class... _Args>
1743 iterator emplace(_Args&&... __args) {
1744 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1745 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001746
Howard Hinnant8b805c92012-05-25 22:04:21 +00001747 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001748 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1749 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1750 }
1751#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001752
Howard Hinnant3e519522010-05-11 19:42:16 +00001753
Howard Hinnant789847d2010-09-23 18:58:28 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001755 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001756 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001757 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001759 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001761 iterator erase(const_iterator __first, const_iterator __last)
1762 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001764 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001765
Howard Hinnant789847d2010-09-23 18:58:28 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001767 void swap(unordered_multimap& __u)
1768 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1769 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001770
Howard Hinnant789847d2010-09-23 18:58:28 +00001771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001772 hasher hash_function() const
1773 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001775 key_equal key_eq() const
1776 {return __table_.key_eq().key_eq();}
1777
Howard Hinnant789847d2010-09-23 18:58:28 +00001778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001779 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001781 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001783 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001785 pair<iterator, iterator> equal_range(const key_type& __k)
1786 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001788 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1789 {return __table_.__equal_range_multi(__k);}
1790
Howard Hinnant789847d2010-09-23 18:58:28 +00001791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001792 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001794 size_type max_bucket_count() const _NOEXCEPT
1795 {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001796
Howard Hinnant789847d2010-09-23 18:58:28 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001798 size_type bucket_size(size_type __n) const
1799 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001801 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1802
Howard Hinnant789847d2010-09-23 18:58:28 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001804 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001806 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001808 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001810 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001812 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001814 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1815
Howard Hinnant789847d2010-09-23 18:58:28 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001817 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001819 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001821 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001823 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001825 void reserve(size_type __n) {__table_.reserve(__n);}
1826
Howard Hinnantb24c8022013-07-23 22:01:58 +00001827#if _LIBCPP_DEBUG_LEVEL >= 2
1828
1829 bool __dereferenceable(const const_iterator* __i) const
1830 {return __table_.__dereferenceable(&__i->__i_);}
1831 bool __decrementable(const const_iterator* __i) const
1832 {return __table_.__decrementable(&__i->__i_);}
1833 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1834 {return __table_.__addable(&__i->__i_, __n);}
1835 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1836 {return __table_.__addable(&__i->__i_, __n);}
1837
1838#endif // _LIBCPP_DEBUG_LEVEL >= 2
1839
Eric Fiselierfcd02212016-02-11 11:59:44 +00001840
Howard Hinnant3e519522010-05-11 19:42:16 +00001841};
1842
1843template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1844unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1845 size_type __n, const hasher& __hf, const key_equal& __eql)
1846 : __table_(__hf, __eql)
1847{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001848#if _LIBCPP_DEBUG_LEVEL >= 2
1849 __get_db()->__insert_c(this);
1850#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001851 __table_.rehash(__n);
1852}
1853
1854template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1855unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1856 size_type __n, const hasher& __hf, const key_equal& __eql,
1857 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001858 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001859{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001860#if _LIBCPP_DEBUG_LEVEL >= 2
1861 __get_db()->__insert_c(this);
1862#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001863 __table_.rehash(__n);
1864}
1865
1866template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1867template <class _InputIterator>
1868unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1869 _InputIterator __first, _InputIterator __last)
1870{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001871#if _LIBCPP_DEBUG_LEVEL >= 2
1872 __get_db()->__insert_c(this);
1873#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001874 insert(__first, __last);
1875}
1876
1877template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1878template <class _InputIterator>
1879unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1880 _InputIterator __first, _InputIterator __last, size_type __n,
1881 const hasher& __hf, const key_equal& __eql)
1882 : __table_(__hf, __eql)
1883{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001884#if _LIBCPP_DEBUG_LEVEL >= 2
1885 __get_db()->__insert_c(this);
1886#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001887 __table_.rehash(__n);
1888 insert(__first, __last);
1889}
1890
1891template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1892template <class _InputIterator>
1893unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1894 _InputIterator __first, _InputIterator __last, size_type __n,
1895 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001896 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001897{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 __get_db()->__insert_c(this);
1900#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001901 __table_.rehash(__n);
1902 insert(__first, __last);
1903}
1904
Howard Hinnant3e519522010-05-11 19:42:16 +00001905template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001906inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001907unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1908 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001909 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001910{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001911#if _LIBCPP_DEBUG_LEVEL >= 2
1912 __get_db()->__insert_c(this);
1913#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001914}
1915
1916template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1917unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1918 const unordered_multimap& __u)
1919 : __table_(__u.__table_)
1920{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001921#if _LIBCPP_DEBUG_LEVEL >= 2
1922 __get_db()->__insert_c(this);
1923#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001924 __table_.rehash(__u.bucket_count());
1925 insert(__u.begin(), __u.end());
1926}
1927
1928template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1929unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1930 const unordered_multimap& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001931 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001932{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001933#if _LIBCPP_DEBUG_LEVEL >= 2
1934 __get_db()->__insert_c(this);
1935#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001936 __table_.rehash(__u.bucket_count());
1937 insert(__u.begin(), __u.end());
1938}
1939
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001940#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001941
1942template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001943inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001944unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1945 unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001946 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001947 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001948{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001949#if _LIBCPP_DEBUG_LEVEL >= 2
1950 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001951 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001952#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001953}
1954
1955template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1956unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1957 unordered_multimap&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001958 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001959{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001960#if _LIBCPP_DEBUG_LEVEL >= 2
1961 __get_db()->__insert_c(this);
1962#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001963 if (__a != __u.get_allocator())
1964 {
1965 iterator __i = __u.begin();
1966 while (__u.size() != 0)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001967 {
Howard Hinnant3e519522010-05-11 19:42:16 +00001968 __table_.__insert_multi(
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001969 __u.__table_.remove((__i++).__i_)->__value_.__move());
Howard Hinnantb24c8022013-07-23 22:01:58 +00001970 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001971 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001972#if _LIBCPP_DEBUG_LEVEL >= 2
1973 else
1974 __get_db()->swap(this, &__u);
1975#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001976}
1977
Howard Hinnant3e519522010-05-11 19:42:16 +00001978template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1979unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1980 initializer_list<value_type> __il)
1981{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001982#if _LIBCPP_DEBUG_LEVEL >= 2
1983 __get_db()->__insert_c(this);
1984#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001985 insert(__il.begin(), __il.end());
1986}
1987
1988template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1989unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1990 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1991 const key_equal& __eql)
1992 : __table_(__hf, __eql)
1993{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001994#if _LIBCPP_DEBUG_LEVEL >= 2
1995 __get_db()->__insert_c(this);
1996#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001997 __table_.rehash(__n);
1998 insert(__il.begin(), __il.end());
1999}
2000
2001template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2002unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2003 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2004 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00002005 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00002006{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002007#if _LIBCPP_DEBUG_LEVEL >= 2
2008 __get_db()->__insert_c(this);
2009#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002010 __table_.rehash(__n);
2011 insert(__il.begin(), __il.end());
2012}
2013
Howard Hinnant3e519522010-05-11 19:42:16 +00002014template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002015inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002016unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2017unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00002018 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00002019{
Howard Hinnantce48a112011-06-30 21:18:19 +00002020 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002021 return *this;
2022}
2023
Howard Hinnant3e519522010-05-11 19:42:16 +00002024template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002025inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002026unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2027unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2028 initializer_list<value_type> __il)
2029{
2030 __table_.__assign_multi(__il.begin(), __il.end());
2031 return *this;
2032}
2033
Eric Fiselier6a470bc2017-04-18 22:50:56 +00002034#endif // _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +00002035
Howard Hinnant3e519522010-05-11 19:42:16 +00002036
Howard Hinnant3e519522010-05-11 19:42:16 +00002037
2038template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2039template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002040inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002041void
2042unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2043 _InputIterator __last)
2044{
2045 for (; __first != __last; ++__first)
2046 __table_.__insert_multi(*__first);
2047}
2048
2049template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002051void
2052swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2053 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00002054 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002055{
2056 __x.swap(__y);
2057}
2058
2059template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2060bool
2061operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2062 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2063{
2064 if (__x.size() != __y.size())
2065 return false;
2066 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2067 const_iterator;
2068 typedef pair<const_iterator, const_iterator> _EqRng;
2069 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2070 {
2071 _EqRng __xeq = __x.equal_range(__i->first);
2072 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +00002073 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2074 _VSTD::distance(__yeq.first, __yeq.second) ||
2075 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00002076 return false;
2077 __i = __xeq.second;
2078 }
2079 return true;
2080}
2081
2082template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002084bool
2085operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2086 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2087{
2088 return !(__x == __y);
2089}
2090
2091_LIBCPP_END_NAMESPACE_STD
2092
2093#endif // _LIBCPP_UNORDERED_MAP