blob: fc3cfb6a950eb5a6c89a5a44f5e584636226b429 [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
Erik Pilkingtonb0386a52018-08-01 01:33:38 +000047 typedef unspecified node_type; // C++17
48 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
49
Howard Hinnant37141072011-06-04 18:54:24 +000050 unordered_map()
51 noexcept(
52 is_nothrow_default_constructible<hasher>::value &&
53 is_nothrow_default_constructible<key_equal>::value &&
54 is_nothrow_default_constructible<allocator_type>::value);
55 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +000056 const key_equal& eql = key_equal(),
57 const allocator_type& a = allocator_type());
58 template <class InputIterator>
59 unordered_map(InputIterator f, InputIterator l,
60 size_type n = 0, const hasher& hf = hasher(),
61 const key_equal& eql = key_equal(),
62 const allocator_type& a = allocator_type());
63 explicit unordered_map(const allocator_type&);
64 unordered_map(const unordered_map&);
65 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +000066 unordered_map(unordered_map&&)
67 noexcept(
68 is_nothrow_move_constructible<hasher>::value &&
69 is_nothrow_move_constructible<key_equal>::value &&
70 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000071 unordered_map(unordered_map&&, const Allocator&);
72 unordered_map(initializer_list<value_type>, size_type n = 0,
73 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
74 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +000075 unordered_map(size_type n, const allocator_type& a)
76 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
77 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
78 : unordered_map(n, hf, key_equal(), a) {} // C++14
79 template <class InputIterator>
80 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
81 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
82 template <class InputIterator>
83 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
84 const allocator_type& a)
85 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
86 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
87 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
88 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
89 const allocator_type& a)
90 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000091 ~unordered_map();
92 unordered_map& operator=(const unordered_map&);
Howard Hinnant37141072011-06-04 18:54:24 +000093 unordered_map& operator=(unordered_map&&)
94 noexcept(
95 allocator_type::propagate_on_container_move_assignment::value &&
96 is_nothrow_move_assignable<allocator_type>::value &&
97 is_nothrow_move_assignable<hasher>::value &&
98 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000099 unordered_map& operator=(initializer_list<value_type>);
100
Howard Hinnant37141072011-06-04 18:54:24 +0000101 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000102
Howard Hinnant37141072011-06-04 18:54:24 +0000103 bool empty() const noexcept;
104 size_type size() const noexcept;
105 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000106
Howard Hinnant37141072011-06-04 18:54:24 +0000107 iterator begin() noexcept;
108 iterator end() noexcept;
109 const_iterator begin() const noexcept;
110 const_iterator end() const noexcept;
111 const_iterator cbegin() const noexcept;
112 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000113
114 template <class... Args>
115 pair<iterator, bool> emplace(Args&&... args);
116 template <class... Args>
117 iterator emplace_hint(const_iterator position, Args&&... args);
118 pair<iterator, bool> insert(const value_type& obj);
119 template <class P>
120 pair<iterator, bool> insert(P&& obj);
121 iterator insert(const_iterator hint, const value_type& obj);
122 template <class P>
123 iterator insert(const_iterator hint, P&& obj);
124 template <class InputIterator>
125 void insert(InputIterator first, InputIterator last);
126 void insert(initializer_list<value_type>);
127
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000128 node_type extract(const_iterator position); // C++17
129 node_type extract(const key_type& x); // C++17
130 insert_return_type insert(node_type&& nh); // C++17
131 iterator insert(const_iterator hint, node_type&& nh); // C++17
132
Marshall Clowbc4c89a2015-07-07 05:45:35 +0000133 template <class... Args>
134 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
135 template <class... Args>
136 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
137 template <class... Args>
138 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
139 template <class... Args>
140 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
141 template <class M>
142 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
143 template <class M>
144 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
145 template <class M>
146 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
147 template <class M>
148 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
149
Howard Hinnant3e519522010-05-11 19:42:16 +0000150 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000151 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000152 size_type erase(const key_type& k);
153 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000154 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000155
Howard Hinnant37141072011-06-04 18:54:24 +0000156 void swap(unordered_map&)
157 noexcept(
158 (!allocator_type::propagate_on_container_swap::value ||
159 __is_nothrow_swappable<allocator_type>::value) &&
160 __is_nothrow_swappable<hasher>::value &&
161 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000162
163 hasher hash_function() const;
164 key_equal key_eq() const;
165
166 iterator find(const key_type& k);
167 const_iterator find(const key_type& k) const;
168 size_type count(const key_type& k) const;
169 pair<iterator, iterator> equal_range(const key_type& k);
170 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
171
172 mapped_type& operator[](const key_type& k);
173 mapped_type& operator[](key_type&& k);
174
175 mapped_type& at(const key_type& k);
176 const mapped_type& at(const key_type& k) const;
177
Howard Hinnant37141072011-06-04 18:54:24 +0000178 size_type bucket_count() const noexcept;
179 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000180
181 size_type bucket_size(size_type n) const;
182 size_type bucket(const key_type& k) const;
183
184 local_iterator begin(size_type n);
185 local_iterator end(size_type n);
186 const_local_iterator begin(size_type n) const;
187 const_local_iterator end(size_type n) const;
188 const_local_iterator cbegin(size_type n) const;
189 const_local_iterator cend(size_type n) const;
190
Howard Hinnant37141072011-06-04 18:54:24 +0000191 float load_factor() const noexcept;
192 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000193 void max_load_factor(float z);
194 void rehash(size_type n);
195 void reserve(size_type n);
196};
197
198template <class Key, class T, class Hash, class Pred, class Alloc>
199 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000200 unordered_map<Key, T, Hash, Pred, Alloc>& y)
201 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000202
203template <class Key, class T, class Hash, class Pred, class Alloc>
204 bool
205 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
206 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
207
208template <class Key, class T, class Hash, class Pred, class Alloc>
209 bool
210 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
211 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
212
213template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
214 class Alloc = allocator<pair<const Key, T>>>
215class unordered_multimap
216{
217public:
218 // types
219 typedef Key key_type;
220 typedef T mapped_type;
221 typedef Hash hasher;
222 typedef Pred key_equal;
223 typedef Alloc allocator_type;
224 typedef pair<const key_type, mapped_type> value_type;
225 typedef value_type& reference;
226 typedef const value_type& const_reference;
227 typedef typename allocator_traits<allocator_type>::pointer pointer;
228 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
229 typedef typename allocator_traits<allocator_type>::size_type size_type;
230 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
231
232 typedef /unspecified/ iterator;
233 typedef /unspecified/ const_iterator;
234 typedef /unspecified/ local_iterator;
235 typedef /unspecified/ const_local_iterator;
236
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000237 typedef unspecified node_type; // C++17
238
Howard Hinnant37141072011-06-04 18:54:24 +0000239 unordered_multimap()
240 noexcept(
241 is_nothrow_default_constructible<hasher>::value &&
242 is_nothrow_default_constructible<key_equal>::value &&
243 is_nothrow_default_constructible<allocator_type>::value);
244 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +0000245 const key_equal& eql = key_equal(),
246 const allocator_type& a = allocator_type());
247 template <class InputIterator>
248 unordered_multimap(InputIterator f, InputIterator l,
249 size_type n = 0, const hasher& hf = hasher(),
250 const key_equal& eql = key_equal(),
251 const allocator_type& a = allocator_type());
252 explicit unordered_multimap(const allocator_type&);
253 unordered_multimap(const unordered_multimap&);
254 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:24 +0000255 unordered_multimap(unordered_multimap&&)
256 noexcept(
257 is_nothrow_move_constructible<hasher>::value &&
258 is_nothrow_move_constructible<key_equal>::value &&
259 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000260 unordered_multimap(unordered_multimap&&, const Allocator&);
261 unordered_multimap(initializer_list<value_type>, size_type n = 0,
262 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
263 const allocator_type& a = allocator_type());
Marshall Clow3cd37e62013-09-12 03:00:31 +0000264 unordered_multimap(size_type n, const allocator_type& a)
265 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
266 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
267 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
268 template <class InputIterator>
269 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
270 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
271 template <class InputIterator>
272 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
273 const allocator_type& a)
274 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
275 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
276 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
277 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
278 const allocator_type& a)
279 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000280 ~unordered_multimap();
281 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant37141072011-06-04 18:54:24 +0000282 unordered_multimap& operator=(unordered_multimap&&)
283 noexcept(
284 allocator_type::propagate_on_container_move_assignment::value &&
285 is_nothrow_move_assignable<allocator_type>::value &&
286 is_nothrow_move_assignable<hasher>::value &&
287 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000288 unordered_multimap& operator=(initializer_list<value_type>);
289
Howard Hinnant37141072011-06-04 18:54:24 +0000290 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000291
Howard Hinnant37141072011-06-04 18:54:24 +0000292 bool empty() const noexcept;
293 size_type size() const noexcept;
294 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000295
Howard Hinnant37141072011-06-04 18:54:24 +0000296 iterator begin() noexcept;
297 iterator end() noexcept;
298 const_iterator begin() const noexcept;
299 const_iterator end() const noexcept;
300 const_iterator cbegin() const noexcept;
301 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000302
303 template <class... Args>
304 iterator emplace(Args&&... args);
305 template <class... Args>
306 iterator emplace_hint(const_iterator position, Args&&... args);
307 iterator insert(const value_type& obj);
308 template <class P>
309 iterator insert(P&& obj);
310 iterator insert(const_iterator hint, const value_type& obj);
311 template <class P>
312 iterator insert(const_iterator hint, P&& obj);
313 template <class InputIterator>
314 void insert(InputIterator first, InputIterator last);
315 void insert(initializer_list<value_type>);
316
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000317 node_type extract(const_iterator position); // C++17
318 node_type extract(const key_type& x); // C++17
319 iterator insert(node_type&& nh); // C++17
320 iterator insert(const_iterator hint, node_type&& nh); // C++17
321
Howard Hinnant3e519522010-05-11 19:42:16 +0000322 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000323 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000324 size_type erase(const key_type& k);
325 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant37141072011-06-04 18:54:24 +0000326 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000327
Howard Hinnant37141072011-06-04 18:54:24 +0000328 void swap(unordered_multimap&)
329 noexcept(
330 (!allocator_type::propagate_on_container_swap::value ||
331 __is_nothrow_swappable<allocator_type>::value) &&
332 __is_nothrow_swappable<hasher>::value &&
333 __is_nothrow_swappable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000334
335 hasher hash_function() const;
336 key_equal key_eq() const;
337
338 iterator find(const key_type& k);
339 const_iterator find(const key_type& k) const;
340 size_type count(const key_type& k) const;
341 pair<iterator, iterator> equal_range(const key_type& k);
342 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
343
Howard Hinnant37141072011-06-04 18:54:24 +0000344 size_type bucket_count() const noexcept;
345 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000346
347 size_type bucket_size(size_type n) const;
348 size_type bucket(const key_type& k) const;
349
350 local_iterator begin(size_type n);
351 local_iterator end(size_type n);
352 const_local_iterator begin(size_type n) const;
353 const_local_iterator end(size_type n) const;
354 const_local_iterator cbegin(size_type n) const;
355 const_local_iterator cend(size_type n) const;
356
Howard Hinnant37141072011-06-04 18:54:24 +0000357 float load_factor() const noexcept;
358 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000359 void max_load_factor(float z);
360 void rehash(size_type n);
361 void reserve(size_type n);
362};
363
364template <class Key, class T, class Hash, class Pred, class Alloc>
365 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant37141072011-06-04 18:54:24 +0000366 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
367 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000368
369template <class Key, class T, class Hash, class Pred, class Alloc>
370 bool
371 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
372 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
373
374template <class Key, class T, class Hash, class Pred, class Alloc>
375 bool
376 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
377 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
378
379} // std
380
381*/
382
383#include <__config>
384#include <__hash_table>
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000385#include <__node_handle>
Howard Hinnant3e519522010-05-11 19:42:16 +0000386#include <functional>
387#include <stdexcept>
Eric Fiselier0f905672016-02-11 21:45:53 +0000388#include <tuple>
Marshall Clowf56972e2018-09-12 19:41:40 +0000389#include <version>
Howard Hinnant3e519522010-05-11 19:42:16 +0000390
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000391#include <__debug>
392
Howard Hinnant073458b2011-10-17 20:05:10 +0000393#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000394#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000395#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000396
397_LIBCPP_BEGIN_NAMESPACE_STD
398
Eric Fiselier04333f92017-01-13 22:42:53 +0000399template <class _Key, class _Cp, class _Hash, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000400class __unordered_map_hasher
401 : private _Hash
402{
403public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000405 __unordered_map_hasher()
406 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
407 : _Hash() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000409 __unordered_map_hasher(const _Hash& __h)
410 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
411 : _Hash(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000413 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000415 size_t operator()(const _Cp& __x) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000416 {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000417 _LIBCPP_INLINE_VISIBILITY
418 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000419 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000420 void swap(__unordered_map_hasher&__y)
421 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
422 {
423 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000424 swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000425 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000426};
427
Howard Hinnantabb160e2013-07-05 18:06:00 +0000428template <class _Key, class _Cp, class _Hash>
429class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000430{
431 _Hash __hash_;
432public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000434 __unordered_map_hasher()
435 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
436 : __hash_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000438 __unordered_map_hasher(const _Hash& __h)
439 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
440 : __hash_(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000442 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000444 size_t operator()(const _Cp& __x) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000445 {return __hash_(__x.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000446 _LIBCPP_INLINE_VISIBILITY
447 size_t operator()(const _Key& __x) const
Howard Hinnant3e519522010-05-11 19:42:16 +0000448 {return __hash_(__x);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000449 void swap(__unordered_map_hasher&__y)
450 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
451 {
452 using _VSTD::swap;
453 swap(__hash_, __y.__hash_);
454 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000455};
456
Marshall Clowe3fbe142015-07-13 20:04:56 +0000457template <class _Key, class _Cp, class _Hash, bool __b>
458inline _LIBCPP_INLINE_VISIBILITY
459void
460swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
461 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
462 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
463{
464 __x.swap(__y);
465}
466
Eric Fiselier04333f92017-01-13 22:42:53 +0000467template <class _Key, class _Cp, class _Pred, bool _IsEmpty>
Howard Hinnant3e519522010-05-11 19:42:16 +0000468class __unordered_map_equal
469 : private _Pred
470{
471public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000473 __unordered_map_equal()
474 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
475 : _Pred() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000477 __unordered_map_equal(const _Pred& __p)
478 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
479 : _Pred(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000481 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000483 bool operator()(const _Cp& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000484 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000485 _LIBCPP_INLINE_VISIBILITY
486 bool operator()(const _Cp& __x, const _Key& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000487 {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000489 bool operator()(const _Key& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000490 {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000491 void swap(__unordered_map_equal&__y)
492 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
493 {
494 using _VSTD::swap;
Eric Fiselierb3f57422017-04-13 01:02:41 +0000495 swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
Marshall Clowe3fbe142015-07-13 20:04:56 +0000496 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000497};
498
Howard Hinnantabb160e2013-07-05 18:06:00 +0000499template <class _Key, class _Cp, class _Pred>
500class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnant3e519522010-05-11 19:42:16 +0000501{
502 _Pred __pred_;
503public:
Howard Hinnant789847d2010-09-23 18:58:28 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000505 __unordered_map_equal()
506 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
507 : __pred_() {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000509 __unordered_map_equal(const _Pred& __p)
510 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
511 : __pred_(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000513 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000515 bool operator()(const _Cp& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000516 {return __pred_(__x.__get_value().first, __y.__get_value().first);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000517 _LIBCPP_INLINE_VISIBILITY
518 bool operator()(const _Cp& __x, const _Key& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000519 {return __pred_(__x.__get_value().first, __y);}
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta1a9e772011-12-12 17:26:24 +0000521 bool operator()(const _Key& __x, const _Cp& __y) const
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000522 {return __pred_(__x, __y.__get_value().first);}
Marshall Clowe3fbe142015-07-13 20:04:56 +0000523 void swap(__unordered_map_equal&__y)
524 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
525 {
526 using _VSTD::swap;
527 swap(__pred_, __y.__pred_);
528 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000529};
530
Marshall Clowe3fbe142015-07-13 20:04:56 +0000531template <class _Key, class _Cp, class _Pred, bool __b>
532inline _LIBCPP_INLINE_VISIBILITY
533void
534swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
535 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
536 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
537{
538 __x.swap(__y);
539}
540
Howard Hinnant3e519522010-05-11 19:42:16 +0000541template <class _Alloc>
542class __hash_map_node_destructor
543{
544 typedef _Alloc allocator_type;
545 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000546
Howard Hinnant3e519522010-05-11 19:42:16 +0000547public:
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000548
549 typedef typename __alloc_traits::pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000550private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000551
552 allocator_type& __na_;
553
554 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
555
556public:
557 bool __first_constructed;
558 bool __second_constructed;
559
Howard Hinnant789847d2010-09-23 18:58:28 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000561 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000562 : __na_(__na),
563 __first_constructed(false),
564 __second_constructed(false)
565 {}
566
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000567#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000569 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant37141072011-06-04 18:54:24 +0000570 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000571 : __na_(__x.__na_),
572 __first_constructed(__x.__value_constructed),
573 __second_constructed(__x.__value_constructed)
574 {
575 __x.__value_constructed = false;
576 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000577#else // _LIBCPP_CXX03_LANG
Howard Hinnant789847d2010-09-23 18:58:28 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000579 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
580 : __na_(__x.__na_),
581 __first_constructed(__x.__value_constructed),
582 __second_constructed(__x.__value_constructed)
583 {
584 const_cast<bool&>(__x.__value_constructed) = false;
585 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000586#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000587
Howard Hinnant789847d2010-09-23 18:58:28 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000589 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 {
591 if (__second_constructed)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000592 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
Howard Hinnant3e519522010-05-11 19:42:16 +0000593 if (__first_constructed)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000594 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
Howard Hinnant3e519522010-05-11 19:42:16 +0000595 if (__p)
596 __alloc_traits::deallocate(__na_, __p, 1);
597 }
598};
599
Eric Fiselierfcd02212016-02-11 11:59:44 +0000600#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000601template <class _Key, class _Tp>
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000602struct __hash_value_type
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000603{
604 typedef _Key key_type;
605 typedef _Tp mapped_type;
606 typedef pair<const key_type, mapped_type> value_type;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000607 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
608 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000609
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000610private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000611 value_type __cc;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000612
613public:
614 _LIBCPP_INLINE_VISIBILITY
615 value_type& __get_value()
616 {
617#if _LIBCPP_STD_VER > 14
618 return *_VSTD::launder(_VSTD::addressof(__cc));
619#else
620 return __cc;
621#endif
622 }
623
624 _LIBCPP_INLINE_VISIBILITY
625 const value_type& __get_value() const
626 {
627#if _LIBCPP_STD_VER > 14
628 return *_VSTD::launder(_VSTD::addressof(__cc));
629#else
630 return __cc;
631#endif
632 }
633
634 _LIBCPP_INLINE_VISIBILITY
635 __nc_ref_pair_type __ref()
636 {
637 value_type& __v = __get_value();
638 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
639 }
640
641 _LIBCPP_INLINE_VISIBILITY
642 __nc_rref_pair_type __move()
643 {
644 value_type& __v = __get_value();
645 return __nc_rref_pair_type(
646 _VSTD::move(const_cast<key_type&>(__v.first)),
647 _VSTD::move(__v.second));
648 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000649
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000650 _LIBCPP_INLINE_VISIBILITY
651 __hash_value_type& operator=(const __hash_value_type& __v)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000652 {
653 __ref() = __v.__get_value();
654 return *this;
655 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000656
657 _LIBCPP_INLINE_VISIBILITY
658 __hash_value_type& operator=(__hash_value_type&& __v)
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000659 {
660 __ref() = __v.__move();
661 return *this;
662 }
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000663
Eric Fiselierfcd02212016-02-11 11:59:44 +0000664 template <class _ValueTp,
665 class = typename enable_if<
666 __is_same_uncvref<_ValueTp, value_type>::value
667 >::type
668 >
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000669 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000670 __hash_value_type& operator=(_ValueTp&& __v)
671 {
672 __ref() = _VSTD::forward<_ValueTp>(__v);
673 return *this;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000674 }
675
676private:
677 __hash_value_type(const __hash_value_type& __v) = delete;
678 __hash_value_type(__hash_value_type&& __v) = delete;
679 template <class ..._Args>
680 explicit __hash_value_type(_Args&& ...__args) = delete;
681
682 ~__hash_value_type() = delete;
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000683};
684
685#else
686
687template <class _Key, class _Tp>
688struct __hash_value_type
689{
690 typedef _Key key_type;
691 typedef _Tp mapped_type;
692 typedef pair<const key_type, mapped_type> value_type;
693
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000694private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000695 value_type __cc;
696
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000697public:
698 _LIBCPP_INLINE_VISIBILITY
699 value_type& __get_value() { return __cc; }
700 _LIBCPP_INLINE_VISIBILITY
701 const value_type& __get_value() const { return __cc; }
702
Eric Fiselierfcd02212016-02-11 11:59:44 +0000703private:
704 ~__hash_value_type();
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000705};
706
707#endif
708
Howard Hinnant3e519522010-05-11 19:42:16 +0000709template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000710class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000711{
712 _HashIterator __i_;
713
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000714 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
715
Howard Hinnant3e519522010-05-11 19:42:16 +0000716public:
717 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000718 typedef typename _NodeTypes::__map_value_type value_type;
719 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000720 typedef value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000721 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000722
Howard Hinnant789847d2010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000724 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000725
Howard Hinnant789847d2010-09-23 18:58:28 +0000726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000727 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000728
Howard Hinnant789847d2010-09-23 18:58:28 +0000729 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000730 reference operator*() const {return __i_->__get_value();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000731 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000732 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000733
Howard Hinnant789847d2010-09-23 18:58:28 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000735 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000737 __hash_map_iterator operator++(int)
738 {
739 __hash_map_iterator __t(*this);
740 ++(*this);
741 return __t;
742 }
743
Howard Hinnant789847d2010-09-23 18:58:28 +0000744 friend _LIBCPP_INLINE_VISIBILITY
745 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000746 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000747 friend _LIBCPP_INLINE_VISIBILITY
748 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000749 {return __x.__i_ != __y.__i_;}
750
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000751 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
752 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
753 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
754 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
755 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000756};
757
758template <class _HashIterator>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000759class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000760{
761 _HashIterator __i_;
762
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000763 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
764
Howard Hinnant3e519522010-05-11 19:42:16 +0000765public:
766 typedef forward_iterator_tag iterator_category;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000767 typedef typename _NodeTypes::__map_value_type value_type;
768 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000769 typedef const value_type& reference;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000770 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000771
Howard Hinnant789847d2010-09-23 18:58:28 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000773 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000774
Howard Hinnant789847d2010-09-23 18:58:28 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000776 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant789847d2010-09-23 18:58:28 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000778 __hash_map_const_iterator(
779 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant37141072011-06-04 18:54:24 +0000780 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000781 : __i_(__i.__i_) {}
782
Howard Hinnant789847d2010-09-23 18:58:28 +0000783 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000784 reference operator*() const {return __i_->__get_value();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000785 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonf52318b2018-06-04 20:38:23 +0000786 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000787
Howard Hinnant789847d2010-09-23 18:58:28 +0000788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000789 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000791 __hash_map_const_iterator operator++(int)
792 {
793 __hash_map_const_iterator __t(*this);
794 ++(*this);
795 return __t;
796 }
797
Howard Hinnant789847d2010-09-23 18:58:28 +0000798 friend _LIBCPP_INLINE_VISIBILITY
799 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000800 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000801 friend _LIBCPP_INLINE_VISIBILITY
802 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000803 {return __x.__i_ != __y.__i_;}
804
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000805 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
806 template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
807 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
808 template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000809};
810
811template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
812 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000813class _LIBCPP_TEMPLATE_VIS unordered_map
Howard Hinnant3e519522010-05-11 19:42:16 +0000814{
815public:
816 // types
817 typedef _Key key_type;
818 typedef _Tp mapped_type;
819 typedef _Hash hasher;
820 typedef _Pred key_equal;
821 typedef _Alloc allocator_type;
822 typedef pair<const key_type, mapped_type> value_type;
823 typedef value_type& reference;
824 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000825 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
826 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000827
828private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +0000829 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +0000830 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
831 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +0000832 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
833 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000834
835 typedef __hash_table<__value_type, __hasher,
836 __key_equal, __allocator_type> __table;
837
838 __table __table_;
839
Eric Fiselierfcd02212016-02-11 11:59:44 +0000840 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +0000841 typedef typename __table::__node_pointer __node_pointer;
842 typedef typename __table::__node_const_pointer __node_const_pointer;
843 typedef typename __table::__node_traits __node_traits;
844 typedef typename __table::__node_allocator __node_allocator;
845 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +0000846 typedef __hash_map_node_destructor<__node_allocator> _Dp;
847 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +0000848 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselierfcd02212016-02-11 11:59:44 +0000849
850 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
851 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnant3e519522010-05-11 19:42:16 +0000852public:
853 typedef typename __alloc_traits::pointer pointer;
854 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +0000855 typedef typename __table::size_type size_type;
856 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000857
858 typedef __hash_map_iterator<typename __table::iterator> iterator;
859 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
860 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
861 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
862
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000863#if _LIBCPP_STD_VER > 14
864 typedef __map_node_handle<__node, allocator_type> node_type;
865 typedef __insert_return_type<iterator, node_type> insert_return_type;
866#endif
867
Howard Hinnant789847d2010-09-23 18:58:28 +0000868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000869 unordered_map()
870 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000871 {
872#if _LIBCPP_DEBUG_LEVEL >= 2
873 __get_db()->__insert_c(this);
874#endif
875 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000876 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
877 const key_equal& __eql = key_equal());
878 unordered_map(size_type __n, const hasher& __hf,
879 const key_equal& __eql,
880 const allocator_type& __a);
881 template <class _InputIterator>
882 unordered_map(_InputIterator __first, _InputIterator __last);
883 template <class _InputIterator>
884 unordered_map(_InputIterator __first, _InputIterator __last,
885 size_type __n, const hasher& __hf = hasher(),
886 const key_equal& __eql = key_equal());
887 template <class _InputIterator>
888 unordered_map(_InputIterator __first, _InputIterator __last,
889 size_type __n, const hasher& __hf,
890 const key_equal& __eql,
891 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000893 explicit unordered_map(const allocator_type& __a);
894 unordered_map(const unordered_map& __u);
895 unordered_map(const unordered_map& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000896#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000898 unordered_map(unordered_map&& __u)
899 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000900 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +0000901 unordered_map(initializer_list<value_type> __il);
902 unordered_map(initializer_list<value_type> __il, size_type __n,
903 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
904 unordered_map(initializer_list<value_type> __il, size_type __n,
905 const hasher& __hf, const key_equal& __eql,
906 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000907#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +0000908#if _LIBCPP_STD_VER > 11
909 _LIBCPP_INLINE_VISIBILITY
910 unordered_map(size_type __n, const allocator_type& __a)
911 : unordered_map(__n, hasher(), key_equal(), __a) {}
912 _LIBCPP_INLINE_VISIBILITY
913 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
914 : unordered_map(__n, __hf, key_equal(), __a) {}
915 template <class _InputIterator>
916 _LIBCPP_INLINE_VISIBILITY
917 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
918 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
919 template <class _InputIterator>
920 _LIBCPP_INLINE_VISIBILITY
921 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
922 const allocator_type& __a)
923 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
924 _LIBCPP_INLINE_VISIBILITY
925 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
926 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
927 _LIBCPP_INLINE_VISIBILITY
928 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
929 const allocator_type& __a)
930 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
931#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000932 // ~unordered_map() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000933 _LIBCPP_INLINE_VISIBILITY
934 unordered_map& operator=(const unordered_map& __u)
935 {
Marshall Clow2ee83722016-07-18 13:19:00 +0000936#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +0000937 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +0000938#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +0000939 if (this != &__u) {
940 __table_.clear();
941 __table_.hash_function() = __u.__table_.hash_function();
942 __table_.key_eq() = __u.__table_.key_eq();
943 __table_.max_load_factor() = __u.__table_.max_load_factor();
944 __table_.__copy_assign_alloc(__u.__table_);
945 insert(__u.begin(), __u.end());
946 }
Howard Hinnant307f8142013-06-22 15:21:29 +0000947#endif
Howard Hinnant5a336872011-07-01 19:24:36 +0000948 return *this;
949 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000950#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000952 unordered_map& operator=(unordered_map&& __u)
953 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000955 unordered_map& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +0000956#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000957
Howard Hinnant789847d2010-09-23 18:58:28 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000959 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000960 {return allocator_type(__table_.__node_alloc());}
961
Marshall Clow72c8fad2017-11-15 05:51:26 +0000962 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000963 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000965 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000967 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000968
Howard Hinnant789847d2010-09-23 18:58:28 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000970 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000972 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000974 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000976 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000978 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +0000980 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000981
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000982 _LIBCPP_INLINE_VISIBILITY
983 pair<iterator, bool> insert(const value_type& __x)
984 {return __table_.__insert_unique(__x);}
985
986 iterator insert(const_iterator __p, const value_type& __x) {
987#if _LIBCPP_DEBUG_LEVEL >= 2
988 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
989 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
990 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +0000991#else
992 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000993#endif
994 return insert(__x).first;
995 }
996
997 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000998 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +0000999 void insert(_InputIterator __first, _InputIterator __last);
1000
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001001#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001002 _LIBCPP_INLINE_VISIBILITY
1003 void insert(initializer_list<value_type> __il)
1004 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001005
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001006 _LIBCPP_INLINE_VISIBILITY
1007 pair<iterator, bool> insert(value_type&& __x)
1008 {return __table_.__insert_unique(_VSTD::move(__x));}
1009
1010 iterator insert(const_iterator __p, value_type&& __x) {
1011#if _LIBCPP_DEBUG_LEVEL >= 2
1012 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1013 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1014 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001015#else
1016 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001017#endif
1018 return __table_.__insert_unique(_VSTD::move(__x)).first;
1019 }
1020
1021 template <class _Pp,
1022 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1023 _LIBCPP_INLINE_VISIBILITY
1024 pair<iterator, bool> insert(_Pp&& __x)
1025 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
1026
1027 template <class _Pp,
1028 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1029 _LIBCPP_INLINE_VISIBILITY
1030 iterator insert(const_iterator __p, _Pp&& __x)
1031 {
1032#if _LIBCPP_DEBUG_LEVEL >= 2
1033 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1034 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1035 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001036#else
1037 ((void)__p);
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001038#endif
1039 return insert(_VSTD::forward<_Pp>(__x)).first;
1040 }
1041
Eric Fiselierfcd02212016-02-11 11:59:44 +00001042 template <class... _Args>
1043 _LIBCPP_INLINE_VISIBILITY
1044 pair<iterator, bool> emplace(_Args&&... __args) {
1045 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1046 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001047
Howard Hinnant8b805c92012-05-25 22:04:21 +00001048 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001049 _LIBCPP_INLINE_VISIBILITY
1050 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001051#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierfcd02212016-02-11 11:59:44 +00001052 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1053 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1054 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001055#else
1056 ((void)__p);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001057#endif
Eric Fiselierfcd02212016-02-11 11:59:44 +00001058 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
1059 }
1060
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001061#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001062
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001063#if _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001064 template <class... _Args>
1065 _LIBCPP_INLINE_VISIBILITY
1066 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1067 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001068 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1069 _VSTD::forward_as_tuple(__k),
1070 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001071 }
1072
1073 template <class... _Args>
1074 _LIBCPP_INLINE_VISIBILITY
1075 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1076 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001077 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1078 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1079 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001080 }
1081
1082 template <class... _Args>
1083 _LIBCPP_INLINE_VISIBILITY
1084 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1085 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001086#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001087 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001088 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1089 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001090#else
1091 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001092#endif
Eric Fiselierfd838222016-12-23 23:37:52 +00001093 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001094 }
1095
1096 template <class... _Args>
1097 _LIBCPP_INLINE_VISIBILITY
1098 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1099 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001100#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyyeef9b352016-09-26 21:39:38 +00001101 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier87c41042016-04-18 06:51:33 +00001102 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1103 " referring to this unordered_map");
Eric Fiselierfd838222016-12-23 23:37:52 +00001104#else
1105 ((void)__h);
Eric Fiselier87c41042016-04-18 06:51:33 +00001106#endif
1107 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001108 }
1109
1110 template <class _Vp>
1111 _LIBCPP_INLINE_VISIBILITY
1112 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1113 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001114 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1115 __k, _VSTD::forward<_Vp>(__v));
1116 if (!__res.second) {
1117 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001118 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001119 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001120 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001121
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001122 template <class _Vp>
1123 _LIBCPP_INLINE_VISIBILITY
1124 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1125 {
Eric Fiselier87c41042016-04-18 06:51:33 +00001126 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1127 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1128 if (!__res.second) {
1129 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001130 }
Eric Fiselier87c41042016-04-18 06:51:33 +00001131 return __res;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001132 }
1133
1134 template <class _Vp>
1135 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001136 iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001137 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001138 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001139 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001140 }
1141
1142 template <class _Vp>
1143 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:52 +00001144 iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001145 {
Eric Fiselierfd838222016-12-23 23:37:52 +00001146 // FIXME: Add debug mode checking for the iterator input
Eric Fiselier87c41042016-04-18 06:51:33 +00001147 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001148 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001149#endif // _LIBCPP_STD_VER > 14
Marshall Clowbc4c89a2015-07-07 05:45:35 +00001150
Howard Hinnant789847d2010-09-23 18:58:28 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001152 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001153 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001154 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001156 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001158 iterator erase(const_iterator __first, const_iterator __last)
1159 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001160 _LIBCPP_INLINE_VISIBILITY
Erik Pilkingtonb0386a52018-08-01 01:33:38 +00001161 void clear() _NOEXCEPT {__table_.clear();}
1162
1163#if _LIBCPP_STD_VER > 14
1164 _LIBCPP_INLINE_VISIBILITY
1165 insert_return_type insert(node_type&& __nh)
1166 {
1167 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1168 "node_type with incompatible allocator passed to unordered_map::insert()");
1169 return __table_.template __node_handle_insert_unique<
1170 node_type, insert_return_type>(_VSTD::move(__nh));
1171 }
1172 _LIBCPP_INLINE_VISIBILITY
1173 iterator insert(const_iterator __hint, node_type&& __nh)
1174 {
1175 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1176 "node_type with incompatible allocator passed to unordered_map::insert()");
1177 return __table_.template __node_handle_insert_unique<node_type>(
1178 __hint.__i_, _VSTD::move(__nh));
1179 }
1180 _LIBCPP_INLINE_VISIBILITY
1181 node_type extract(key_type const& __key)
1182 {
1183 return __table_.template __node_handle_extract<node_type>(__key);
1184 }
1185 _LIBCPP_INLINE_VISIBILITY
1186 node_type extract(const_iterator __it)
1187 {
1188 return __table_.template __node_handle_extract<node_type>(
1189 __it.__i_);
1190 }
1191#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001192
Howard Hinnant789847d2010-09-23 18:58:28 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001194 void swap(unordered_map& __u)
1195 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
Eric Fiselier780b51d2016-12-28 05:53:01 +00001196 { __table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001197
Howard Hinnant789847d2010-09-23 18:58:28 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001199 hasher hash_function() const
1200 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001202 key_equal key_eq() const
1203 {return __table_.key_eq().key_eq();}
1204
Howard Hinnant789847d2010-09-23 18:58:28 +00001205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001206 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001208 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001210 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001212 pair<iterator, iterator> equal_range(const key_type& __k)
1213 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001215 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1216 {return __table_.__equal_range_unique(__k);}
1217
1218 mapped_type& operator[](const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001219#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001220 mapped_type& operator[](key_type&& __k);
1221#endif
1222
1223 mapped_type& at(const key_type& __k);
1224 const mapped_type& at(const key_type& __k) const;
1225
Howard Hinnant789847d2010-09-23 18:58:28 +00001226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001227 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001229 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001230
Howard Hinnant789847d2010-09-23 18:58:28 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001232 size_type bucket_size(size_type __n) const
1233 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001235 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1236
Howard Hinnant789847d2010-09-23 18:58:28 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001238 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001240 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001242 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001244 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001246 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001248 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1249
Howard Hinnant789847d2010-09-23 18:58:28 +00001250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001251 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001253 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001255 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001257 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001259 void reserve(size_type __n) {__table_.reserve(__n);}
1260
Howard Hinnantb24c8022013-07-23 22:01:58 +00001261#if _LIBCPP_DEBUG_LEVEL >= 2
1262
1263 bool __dereferenceable(const const_iterator* __i) const
1264 {return __table_.__dereferenceable(&__i->__i_);}
1265 bool __decrementable(const const_iterator* __i) const
1266 {return __table_.__decrementable(&__i->__i_);}
1267 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1268 {return __table_.__addable(&__i->__i_, __n);}
1269 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1270 {return __table_.__addable(&__i->__i_, __n);}
1271
1272#endif // _LIBCPP_DEBUG_LEVEL >= 2
1273
Howard Hinnant3e519522010-05-11 19:42:16 +00001274private:
Eric Fiselier0f905672016-02-11 21:45:53 +00001275
1276#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant4a95f9e2013-07-04 20:59:16 +00001277 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier0f905672016-02-11 21:45:53 +00001278#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001279};
1280
1281template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1282unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1283 size_type __n, const hasher& __hf, const key_equal& __eql)
1284 : __table_(__hf, __eql)
1285{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001286#if _LIBCPP_DEBUG_LEVEL >= 2
1287 __get_db()->__insert_c(this);
1288#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001289 __table_.rehash(__n);
1290}
1291
1292template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1293unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1294 size_type __n, const hasher& __hf, const key_equal& __eql,
1295 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001296 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001297{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001298#if _LIBCPP_DEBUG_LEVEL >= 2
1299 __get_db()->__insert_c(this);
1300#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001301 __table_.rehash(__n);
1302}
1303
1304template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001305inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001306unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1307 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001308 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001309{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001310#if _LIBCPP_DEBUG_LEVEL >= 2
1311 __get_db()->__insert_c(this);
1312#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001313}
1314
1315template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1316template <class _InputIterator>
1317unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1318 _InputIterator __first, _InputIterator __last)
1319{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001320#if _LIBCPP_DEBUG_LEVEL >= 2
1321 __get_db()->__insert_c(this);
1322#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001323 insert(__first, __last);
1324}
1325
1326template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1327template <class _InputIterator>
1328unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1329 _InputIterator __first, _InputIterator __last, size_type __n,
1330 const hasher& __hf, const key_equal& __eql)
1331 : __table_(__hf, __eql)
1332{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001333#if _LIBCPP_DEBUG_LEVEL >= 2
1334 __get_db()->__insert_c(this);
1335#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001336 __table_.rehash(__n);
1337 insert(__first, __last);
1338}
1339
1340template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1341template <class _InputIterator>
1342unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1343 _InputIterator __first, _InputIterator __last, size_type __n,
1344 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001345 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001346{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001347#if _LIBCPP_DEBUG_LEVEL >= 2
1348 __get_db()->__insert_c(this);
1349#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001350 __table_.rehash(__n);
1351 insert(__first, __last);
1352}
1353
1354template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1355unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1356 const unordered_map& __u)
1357 : __table_(__u.__table_)
1358{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001359#if _LIBCPP_DEBUG_LEVEL >= 2
1360 __get_db()->__insert_c(this);
1361#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001362 __table_.rehash(__u.bucket_count());
1363 insert(__u.begin(), __u.end());
1364}
1365
1366template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1367unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1368 const unordered_map& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001369 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001370{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001371#if _LIBCPP_DEBUG_LEVEL >= 2
1372 __get_db()->__insert_c(this);
1373#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001374 __table_.rehash(__u.bucket_count());
1375 insert(__u.begin(), __u.end());
1376}
1377
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001378#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001379
1380template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001381inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001382unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1383 unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001384 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001385 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001386{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001387#if _LIBCPP_DEBUG_LEVEL >= 2
1388 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001389 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00001390#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001391}
1392
1393template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1394unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1395 unordered_map&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001396 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001397{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001398#if _LIBCPP_DEBUG_LEVEL >= 2
1399 __get_db()->__insert_c(this);
1400#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001401 if (__a != __u.get_allocator())
1402 {
1403 iterator __i = __u.begin();
Eric Fiselierfcd02212016-02-11 11:59:44 +00001404 while (__u.size() != 0) {
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001405 __table_.__emplace_unique(
1406 __u.__table_.remove((__i++).__i_)->__value_.__move());
Eric Fiselierfcd02212016-02-11 11:59:44 +00001407 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001408 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00001409#if _LIBCPP_DEBUG_LEVEL >= 2
1410 else
1411 __get_db()->swap(this, &__u);
1412#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001413}
1414
Howard Hinnant3e519522010-05-11 19:42:16 +00001415template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1416unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1417 initializer_list<value_type> __il)
1418{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001419#if _LIBCPP_DEBUG_LEVEL >= 2
1420 __get_db()->__insert_c(this);
1421#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001422 insert(__il.begin(), __il.end());
1423}
1424
1425template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1426unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1427 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1428 const key_equal& __eql)
1429 : __table_(__hf, __eql)
1430{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001431#if _LIBCPP_DEBUG_LEVEL >= 2
1432 __get_db()->__insert_c(this);
1433#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001434 __table_.rehash(__n);
1435 insert(__il.begin(), __il.end());
1436}
1437
1438template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1439unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1440 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1441 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001442 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001443{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001444#if _LIBCPP_DEBUG_LEVEL >= 2
1445 __get_db()->__insert_c(this);
1446#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001447 __table_.rehash(__n);
1448 insert(__il.begin(), __il.end());
1449}
1450
Howard Hinnant3e519522010-05-11 19:42:16 +00001451template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001452inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001453unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1454unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00001455 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001456{
Howard Hinnantce48a112011-06-30 21:18:19 +00001457 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001458 return *this;
1459}
1460
Howard Hinnant3e519522010-05-11 19:42:16 +00001461template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001462inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001463unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1464unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1465 initializer_list<value_type> __il)
1466{
1467 __table_.__assign_unique(__il.begin(), __il.end());
1468 return *this;
1469}
1470
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001471#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001472
Howard Hinnant3e519522010-05-11 19:42:16 +00001473template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1474template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001475inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001476void
1477unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1478 _InputIterator __last)
1479{
1480 for (; __first != __last; ++__first)
1481 __table_.__insert_unique(*__first);
1482}
1483
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001484#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001485
Eric Fiselier0f905672016-02-11 21:45:53 +00001486template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1487_Tp&
1488unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1489{
1490 return __table_.__emplace_unique_key_args(__k,
1491 std::piecewise_construct, std::forward_as_tuple(__k),
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001492 std::forward_as_tuple()).first->__get_value().second;
Eric Fiselier0f905672016-02-11 21:45:53 +00001493}
Howard Hinnant3e519522010-05-11 19:42:16 +00001494
1495template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1496_Tp&
1497unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1498{
Eric Fiselier0f905672016-02-11 21:45:53 +00001499 return __table_.__emplace_unique_key_args(__k,
1500 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001501 std::forward_as_tuple()).first->__get_value().second;
Howard Hinnant3e519522010-05-11 19:42:16 +00001502}
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001503#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001504
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001505template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1506typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1507unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1508{
1509 __node_allocator& __na = __table_.__node_alloc();
1510 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001511 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001512 __h.get_deleter().__first_constructed = true;
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00001513 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001514 __h.get_deleter().__second_constructed = true;
1515 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
1516}
1517
1518template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1519_Tp&
1520unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1521{
1522 iterator __i = find(__k);
1523 if (__i != end())
1524 return __i->second;
1525 __node_holder __h = __construct_node_with_key(__k);
1526 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1527 __h.release();
1528 return __r.first->second;
1529}
1530
1531#endif // _LIBCPP_CXX03_MODE
Howard Hinnant3e519522010-05-11 19:42:16 +00001532
1533template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1534_Tp&
1535unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1536{
1537 iterator __i = find(__k);
1538#ifndef _LIBCPP_NO_EXCEPTIONS
1539 if (__i == end())
1540 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001541#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001542 return __i->second;
1543}
1544
1545template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1546const _Tp&
1547unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1548{
1549 const_iterator __i = find(__k);
1550#ifndef _LIBCPP_NO_EXCEPTIONS
1551 if (__i == end())
1552 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:43 +00001553#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001554 return __i->second;
1555}
1556
1557template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001558inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001559void
1560swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1561 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00001562 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001563{
1564 __x.swap(__y);
1565}
1566
1567template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1568bool
1569operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1570 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1571{
1572 if (__x.size() != __y.size())
1573 return false;
1574 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1575 const_iterator;
1576 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1577 __i != __ex; ++__i)
1578 {
1579 const_iterator __j = __y.find(__i->first);
1580 if (__j == __ey || !(*__i == *__j))
1581 return false;
1582 }
1583 return true;
1584}
1585
1586template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001588bool
1589operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1590 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1591{
1592 return !(__x == __y);
1593}
1594
1595template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1596 class _Alloc = allocator<pair<const _Key, _Tp> > >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +00001597class _LIBCPP_TEMPLATE_VIS unordered_multimap
Howard Hinnant3e519522010-05-11 19:42:16 +00001598{
1599public:
1600 // types
1601 typedef _Key key_type;
1602 typedef _Tp mapped_type;
1603 typedef _Hash hasher;
1604 typedef _Pred key_equal;
1605 typedef _Alloc allocator_type;
1606 typedef pair<const key_type, mapped_type> value_type;
1607 typedef value_type& reference;
1608 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +00001609 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1610 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +00001611
1612private:
Howard Hinnant9fd9f842013-09-30 19:08:22 +00001613 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnantabb160e2013-07-05 18:06:00 +00001614 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1615 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow1f508012015-04-07 05:21:38 +00001616 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1617 __value_type>::type __allocator_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001618
1619 typedef __hash_table<__value_type, __hasher,
1620 __key_equal, __allocator_type> __table;
1621
1622 __table __table_;
1623
Eric Fiselierfcd02212016-02-11 11:59:44 +00001624 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnant3e519522010-05-11 19:42:16 +00001625 typedef typename __table::__node_traits __node_traits;
1626 typedef typename __table::__node_allocator __node_allocator;
1627 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50 +00001628 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1629 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16 +00001630 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001631 static_assert((is_same<typename __node_traits::size_type,
1632 typename __alloc_traits::size_type>::value),
1633 "Allocator uses different size_type for different types");
Howard Hinnant3e519522010-05-11 19:42:16 +00001634public:
1635 typedef typename __alloc_traits::pointer pointer;
1636 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier75d0dcf2016-02-10 20:46:23 +00001637 typedef typename __table::size_type size_type;
1638 typedef typename __table::difference_type difference_type;
Howard Hinnant3e519522010-05-11 19:42:16 +00001639
1640 typedef __hash_map_iterator<typename __table::iterator> iterator;
1641 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1642 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1643 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1644
Erik Pilkingtonb0386a52018-08-01 01:33:38 +00001645#if _LIBCPP_STD_VER > 14
1646 typedef __map_node_handle<__node, allocator_type> node_type;
1647#endif
1648
Howard Hinnant789847d2010-09-23 18:58:28 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001650 unordered_multimap()
1651 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +00001652 {
1653#if _LIBCPP_DEBUG_LEVEL >= 2
1654 __get_db()->__insert_c(this);
1655#endif
1656 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001657 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1658 const key_equal& __eql = key_equal());
1659 unordered_multimap(size_type __n, const hasher& __hf,
1660 const key_equal& __eql,
1661 const allocator_type& __a);
1662 template <class _InputIterator>
1663 unordered_multimap(_InputIterator __first, _InputIterator __last);
1664 template <class _InputIterator>
1665 unordered_multimap(_InputIterator __first, _InputIterator __last,
1666 size_type __n, const hasher& __hf = hasher(),
1667 const key_equal& __eql = key_equal());
1668 template <class _InputIterator>
1669 unordered_multimap(_InputIterator __first, _InputIterator __last,
1670 size_type __n, const hasher& __hf,
1671 const key_equal& __eql,
1672 const allocator_type& __a);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001674 explicit unordered_multimap(const allocator_type& __a);
1675 unordered_multimap(const unordered_multimap& __u);
1676 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001677#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001679 unordered_multimap(unordered_multimap&& __u)
1680 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001681 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +00001682 unordered_multimap(initializer_list<value_type> __il);
1683 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1684 const hasher& __hf = hasher(),
1685 const key_equal& __eql = key_equal());
1686 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1687 const hasher& __hf, const key_equal& __eql,
1688 const allocator_type& __a);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001689#endif // _LIBCPP_CXX03_LANG
Marshall Clow3cd37e62013-09-12 03:00:31 +00001690#if _LIBCPP_STD_VER > 11
1691 _LIBCPP_INLINE_VISIBILITY
1692 unordered_multimap(size_type __n, const allocator_type& __a)
1693 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1694 _LIBCPP_INLINE_VISIBILITY
1695 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1696 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1697 template <class _InputIterator>
1698 _LIBCPP_INLINE_VISIBILITY
1699 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1700 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1701 template <class _InputIterator>
1702 _LIBCPP_INLINE_VISIBILITY
1703 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1704 const allocator_type& __a)
1705 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1706 _LIBCPP_INLINE_VISIBILITY
1707 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1708 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1709 _LIBCPP_INLINE_VISIBILITY
1710 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1711 const allocator_type& __a)
1712 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1713#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001714 // ~unordered_multimap() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +00001715 _LIBCPP_INLINE_VISIBILITY
1716 unordered_multimap& operator=(const unordered_multimap& __u)
1717 {
Marshall Clow2ee83722016-07-18 13:19:00 +00001718#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant5a336872011-07-01 19:24:36 +00001719 __table_ = __u.__table_;
Howard Hinnant307f8142013-06-22 15:21:29 +00001720#else
Marshall Clow74cf6ff2014-02-08 04:03:14 +00001721 if (this != &__u) {
1722 __table_.clear();
1723 __table_.hash_function() = __u.__table_.hash_function();
1724 __table_.key_eq() = __u.__table_.key_eq();
1725 __table_.max_load_factor() = __u.__table_.max_load_factor();
1726 __table_.__copy_assign_alloc(__u.__table_);
1727 insert(__u.begin(), __u.end());
1728 }
Howard Hinnant307f8142013-06-22 15:21:29 +00001729#endif
Howard Hinnant5a336872011-07-01 19:24:36 +00001730 return *this;
1731 }
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001732#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001734 unordered_multimap& operator=(unordered_multimap&& __u)
1735 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001737 unordered_multimap& operator=(initializer_list<value_type> __il);
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001738#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001739
Howard Hinnant789847d2010-09-23 18:58:28 +00001740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001741 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001742 {return allocator_type(__table_.__node_alloc());}
1743
Marshall Clow72c8fad2017-11-15 05:51:26 +00001744 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001745 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001747 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001749 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001750
Howard Hinnant789847d2010-09-23 18:58:28 +00001751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001752 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001754 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001756 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001758 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001760 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001762 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001763
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001764 _LIBCPP_INLINE_VISIBILITY
1765 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1766
1767 _LIBCPP_INLINE_VISIBILITY
1768 iterator insert(const_iterator __p, const value_type& __x)
1769 {return __table_.__insert_multi(__p.__i_, __x);}
1770
1771 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001772 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001773 void insert(_InputIterator __first, _InputIterator __last);
1774
Eric Fiselier6a470bc2017-04-18 22:50:56 +00001775#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001776 _LIBCPP_INLINE_VISIBILITY
1777 void insert(initializer_list<value_type> __il)
1778 {insert(__il.begin(), __il.end());}
Eric Fiselier7a9f5002016-04-18 01:40:45 +00001779 _LIBCPP_INLINE_VISIBILITY
1780 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1781
1782 _LIBCPP_INLINE_VISIBILITY
1783 iterator insert(const_iterator __p, value_type&& __x)
1784 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1785
1786 template <class _Pp,
1787 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1788 _LIBCPP_INLINE_VISIBILITY
1789 iterator insert(_Pp&& __x)
1790 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1791
1792 template <class _Pp,
1793 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1794 _LIBCPP_INLINE_VISIBILITY
1795 iterator insert(const_iterator __p, _Pp&& __x)
1796 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1797
Eric Fiselierfcd02212016-02-11 11:59:44 +00001798 template <class... _Args>
1799 iterator emplace(_Args&&... __args) {
1800 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1801 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001802
Howard Hinnant8b805c92012-05-25 22:04:21 +00001803 template <class... _Args>
Eric Fiselierfcd02212016-02-11 11:59:44 +00001804 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1805 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1806 }
1807#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001808
Howard Hinnant3e519522010-05-11 19:42:16 +00001809
Howard Hinnant789847d2010-09-23 18:58:28 +00001810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001811 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001812 _LIBCPP_INLINE_VISIBILITY
Marshall Clowec392962015-05-10 13:35:00 +00001813 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001815 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001817 iterator erase(const_iterator __first, const_iterator __last)
1818 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001820 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001821
Erik Pilkingtonb0386a52018-08-01 01:33:38 +00001822#if _LIBCPP_STD_VER > 14
1823 _LIBCPP_INLINE_VISIBILITY
1824 iterator insert(node_type&& __nh)
1825 {
1826 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1827 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1828 return __table_.template __node_handle_insert_multi<node_type>(
1829 _VSTD::move(__nh));
1830 }
1831 _LIBCPP_INLINE_VISIBILITY
1832 iterator insert(const_iterator __hint, node_type&& __nh)
1833 {
1834 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1835 "node_type with incompatible allocator passed to unordered_multimap::insert()");
1836 return __table_.template __node_handle_insert_multi<node_type>(
1837 __hint.__i_, _VSTD::move(__nh));
1838 }
1839 _LIBCPP_INLINE_VISIBILITY
1840 node_type extract(key_type const& __key)
1841 {
1842 return __table_.template __node_handle_extract<node_type>(__key);
1843 }
1844 _LIBCPP_INLINE_VISIBILITY
1845 node_type extract(const_iterator __it)
1846 {
1847 return __table_.template __node_handle_extract<node_type>(
1848 __it.__i_);
1849 }
1850#endif
1851
Howard Hinnant789847d2010-09-23 18:58:28 +00001852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001853 void swap(unordered_multimap& __u)
1854 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1855 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001856
Howard Hinnant789847d2010-09-23 18:58:28 +00001857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001858 hasher hash_function() const
1859 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001861 key_equal key_eq() const
1862 {return __table_.key_eq().key_eq();}
1863
Howard Hinnant789847d2010-09-23 18:58:28 +00001864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001865 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001867 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001869 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001871 pair<iterator, iterator> equal_range(const key_type& __k)
1872 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001874 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1875 {return __table_.__equal_range_multi(__k);}
1876
Howard Hinnant789847d2010-09-23 18:58:28 +00001877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001878 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001880 size_type max_bucket_count() const _NOEXCEPT
1881 {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001882
Howard Hinnant789847d2010-09-23 18:58:28 +00001883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001884 size_type bucket_size(size_type __n) const
1885 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001887 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1888
Howard Hinnant789847d2010-09-23 18:58:28 +00001889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001890 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001892 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001894 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001896 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001898 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001900 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1901
Howard Hinnant789847d2010-09-23 18:58:28 +00001902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001903 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24 +00001905 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001907 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001909 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001911 void reserve(size_type __n) {__table_.reserve(__n);}
1912
Howard Hinnantb24c8022013-07-23 22:01:58 +00001913#if _LIBCPP_DEBUG_LEVEL >= 2
1914
1915 bool __dereferenceable(const const_iterator* __i) const
1916 {return __table_.__dereferenceable(&__i->__i_);}
1917 bool __decrementable(const const_iterator* __i) const
1918 {return __table_.__decrementable(&__i->__i_);}
1919 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1920 {return __table_.__addable(&__i->__i_, __n);}
1921 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1922 {return __table_.__addable(&__i->__i_, __n);}
1923
1924#endif // _LIBCPP_DEBUG_LEVEL >= 2
1925
Eric Fiselierfcd02212016-02-11 11:59:44 +00001926
Howard Hinnant3e519522010-05-11 19:42:16 +00001927};
1928
1929template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1930unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1931 size_type __n, const hasher& __hf, const key_equal& __eql)
1932 : __table_(__hf, __eql)
1933{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001934#if _LIBCPP_DEBUG_LEVEL >= 2
1935 __get_db()->__insert_c(this);
1936#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001937 __table_.rehash(__n);
1938}
1939
1940template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1941unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1942 size_type __n, const hasher& __hf, const key_equal& __eql,
1943 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001944 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001945{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001946#if _LIBCPP_DEBUG_LEVEL >= 2
1947 __get_db()->__insert_c(this);
1948#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001949 __table_.rehash(__n);
1950}
1951
1952template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1953template <class _InputIterator>
1954unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1955 _InputIterator __first, _InputIterator __last)
1956{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001957#if _LIBCPP_DEBUG_LEVEL >= 2
1958 __get_db()->__insert_c(this);
1959#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001960 insert(__first, __last);
1961}
1962
1963template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1964template <class _InputIterator>
1965unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1966 _InputIterator __first, _InputIterator __last, size_type __n,
1967 const hasher& __hf, const key_equal& __eql)
1968 : __table_(__hf, __eql)
1969{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001970#if _LIBCPP_DEBUG_LEVEL >= 2
1971 __get_db()->__insert_c(this);
1972#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001973 __table_.rehash(__n);
1974 insert(__first, __last);
1975}
1976
1977template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1978template <class _InputIterator>
1979unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1980 _InputIterator __first, _InputIterator __last, size_type __n,
1981 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001982 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001983{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001984#if _LIBCPP_DEBUG_LEVEL >= 2
1985 __get_db()->__insert_c(this);
1986#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001987 __table_.rehash(__n);
1988 insert(__first, __last);
1989}
1990
Howard Hinnant3e519522010-05-11 19:42:16 +00001991template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001992inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001993unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1994 const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00001995 : __table_(typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00001996{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001997#if _LIBCPP_DEBUG_LEVEL >= 2
1998 __get_db()->__insert_c(this);
1999#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002000}
2001
2002template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2003unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2004 const unordered_multimap& __u)
2005 : __table_(__u.__table_)
2006{
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(__u.bucket_count());
2011 insert(__u.begin(), __u.end());
2012}
2013
2014template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2015unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2016 const unordered_multimap& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00002017 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00002018{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002019#if _LIBCPP_DEBUG_LEVEL >= 2
2020 __get_db()->__insert_c(this);
2021#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002022 __table_.rehash(__u.bucket_count());
2023 insert(__u.begin(), __u.end());
2024}
2025
Eric Fiselier6a470bc2017-04-18 22:50:56 +00002026#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00002027
2028template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002029inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002030unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2031 unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00002032 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00002033 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00002034{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002035#if _LIBCPP_DEBUG_LEVEL >= 2
2036 __get_db()->__insert_c(this);
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00002037 __get_db()->swap(this, &__u);
Howard Hinnantb24c8022013-07-23 22:01:58 +00002038#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002039}
2040
2041template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2042unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2043 unordered_multimap&& __u, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00002044 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00002045{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002046#if _LIBCPP_DEBUG_LEVEL >= 2
2047 __get_db()->__insert_c(this);
2048#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002049 if (__a != __u.get_allocator())
2050 {
2051 iterator __i = __u.begin();
2052 while (__u.size() != 0)
Howard Hinnantb24c8022013-07-23 22:01:58 +00002053 {
Howard Hinnant3e519522010-05-11 19:42:16 +00002054 __table_.__insert_multi(
Erik Pilkingtonf52318b2018-06-04 20:38:23 +00002055 __u.__table_.remove((__i++).__i_)->__value_.__move());
Howard Hinnantb24c8022013-07-23 22:01:58 +00002056 }
Howard Hinnant3e519522010-05-11 19:42:16 +00002057 }
Howard Hinnant4c80bfb2013-07-30 21:04:42 +00002058#if _LIBCPP_DEBUG_LEVEL >= 2
2059 else
2060 __get_db()->swap(this, &__u);
2061#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002062}
2063
Howard Hinnant3e519522010-05-11 19:42:16 +00002064template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2065unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2066 initializer_list<value_type> __il)
2067{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002068#if _LIBCPP_DEBUG_LEVEL >= 2
2069 __get_db()->__insert_c(this);
2070#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002071 insert(__il.begin(), __il.end());
2072}
2073
2074template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2075unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2076 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2077 const key_equal& __eql)
2078 : __table_(__hf, __eql)
2079{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002080#if _LIBCPP_DEBUG_LEVEL >= 2
2081 __get_db()->__insert_c(this);
2082#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002083 __table_.rehash(__n);
2084 insert(__il.begin(), __il.end());
2085}
2086
2087template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2088unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2089 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2090 const key_equal& __eql, const allocator_type& __a)
Marshall Clow2a10c962016-08-17 05:58:40 +00002091 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnant3e519522010-05-11 19:42:16 +00002092{
Howard Hinnantb24c8022013-07-23 22:01:58 +00002093#if _LIBCPP_DEBUG_LEVEL >= 2
2094 __get_db()->__insert_c(this);
2095#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002096 __table_.rehash(__n);
2097 insert(__il.begin(), __il.end());
2098}
2099
Howard Hinnant3e519522010-05-11 19:42:16 +00002100template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002101inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002102unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2103unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:24 +00002104 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00002105{
Howard Hinnantce48a112011-06-30 21:18:19 +00002106 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002107 return *this;
2108}
2109
Howard Hinnant3e519522010-05-11 19:42:16 +00002110template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002111inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002112unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2113unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2114 initializer_list<value_type> __il)
2115{
2116 __table_.__assign_multi(__il.begin(), __il.end());
2117 return *this;
2118}
2119
Eric Fiselier6a470bc2017-04-18 22:50:56 +00002120#endif // _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +00002121
Howard Hinnant3e519522010-05-11 19:42:16 +00002122
Howard Hinnant3e519522010-05-11 19:42:16 +00002123
2124template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2125template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00002126inline
Howard Hinnant3e519522010-05-11 19:42:16 +00002127void
2128unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2129 _InputIterator __last)
2130{
2131 for (; __first != __last; ++__first)
2132 __table_.__insert_multi(*__first);
2133}
2134
2135template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002136inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002137void
2138swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2139 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:24 +00002140 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002141{
2142 __x.swap(__y);
2143}
2144
2145template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2146bool
2147operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2148 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2149{
2150 if (__x.size() != __y.size())
2151 return false;
2152 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2153 const_iterator;
2154 typedef pair<const_iterator, const_iterator> _EqRng;
2155 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2156 {
2157 _EqRng __xeq = __x.equal_range(__i->first);
2158 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:19 +00002159 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2160 _VSTD::distance(__yeq.first, __yeq.second) ||
2161 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00002162 return false;
2163 __i = __xeq.second;
2164 }
2165 return true;
2166}
2167
2168template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00002169inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002170bool
2171operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2172 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2173{
2174 return !(__x == __y);
2175}
2176
2177_LIBCPP_END_NAMESPACE_STD
2178
2179#endif // _LIBCPP_UNORDERED_MAP