blob: 7e84f74d7e656faadf95397e3f8af5e1a66b8d9d [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_MAP
12#define _LIBCPP_UNORDERED_MAP
13
14/*
15
16 unordered_map synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
25class unordered_map
26{
27public:
28 // types
29 typedef Key key_type;
30 typedef T mapped_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef pair<const key_type, mapped_type> value_type;
35 typedef value_type& reference;
36 typedef const value_type& const_reference;
37 typedef typename allocator_traits<allocator_type>::pointer pointer;
38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
39 typedef typename allocator_traits<allocator_type>::size_type size_type;
40 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
41
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
46
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000047 unordered_map()
48 noexcept(
49 is_nothrow_default_constructible<hasher>::value &&
50 is_nothrow_default_constructible<key_equal>::value &&
51 is_nothrow_default_constructible<allocator_type>::value);
52 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 const key_equal& eql = key_equal(),
54 const allocator_type& a = allocator_type());
55 template <class InputIterator>
56 unordered_map(InputIterator f, InputIterator l,
57 size_type n = 0, const hasher& hf = hasher(),
58 const key_equal& eql = key_equal(),
59 const allocator_type& a = allocator_type());
60 explicit unordered_map(const allocator_type&);
61 unordered_map(const unordered_map&);
62 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000063 unordered_map(unordered_map&&)
64 noexcept(
65 is_nothrow_move_constructible<hasher>::value &&
66 is_nothrow_move_constructible<key_equal>::value &&
67 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 unordered_map(unordered_map&&, const Allocator&);
69 unordered_map(initializer_list<value_type>, size_type n = 0,
70 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
71 const allocator_type& a = allocator_type());
Marshall Clow6dff6182013-09-12 03:00:31 +000072 unordered_map(size_type n, const allocator_type& a)
73 : unordered_map(n, hasher(), key_equal(), a) {} // C++14
74 unordered_map(size_type n, const hasher& hf, const allocator_type& a)
75 : unordered_map(n, hf, key_equal(), a) {} // C++14
76 template <class InputIterator>
77 unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
78 : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
79 template <class InputIterator>
80 unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
81 const allocator_type& a)
82 : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
83 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
84 : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
85 unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
86 const allocator_type& a)
87 : unordered_map(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000088 ~unordered_map();
89 unordered_map& operator=(const unordered_map&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000090 unordered_map& operator=(unordered_map&&)
91 noexcept(
92 allocator_type::propagate_on_container_move_assignment::value &&
93 is_nothrow_move_assignable<allocator_type>::value &&
94 is_nothrow_move_assignable<hasher>::value &&
95 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096 unordered_map& operator=(initializer_list<value_type>);
97
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000098 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000099
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000100 bool empty() const noexcept;
101 size_type size() const noexcept;
102 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000103
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000104 iterator begin() noexcept;
105 iterator end() noexcept;
106 const_iterator begin() const noexcept;
107 const_iterator end() const noexcept;
108 const_iterator cbegin() const noexcept;
109 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110
111 template <class... Args>
112 pair<iterator, bool> emplace(Args&&... args);
113 template <class... Args>
114 iterator emplace_hint(const_iterator position, Args&&... args);
115 pair<iterator, bool> insert(const value_type& obj);
116 template <class P>
117 pair<iterator, bool> insert(P&& obj);
118 iterator insert(const_iterator hint, const value_type& obj);
119 template <class P>
120 iterator insert(const_iterator hint, P&& obj);
121 template <class InputIterator>
122 void insert(InputIterator first, InputIterator last);
123 void insert(initializer_list<value_type>);
124
Marshall Clow0ce05a92015-07-07 05:45:35 +0000125 template <class... Args>
126 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
127 template <class... Args>
128 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
129 template <class... Args>
130 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
131 template <class... Args>
132 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
133 template <class M>
134 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
135 template <class M>
136 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
137 template <class M>
138 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
139 template <class M>
140 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
141
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000142 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000143 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144 size_type erase(const key_type& k);
145 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000146 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000147
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000148 void swap(unordered_map&)
149 noexcept(
150 (!allocator_type::propagate_on_container_swap::value ||
151 __is_nothrow_swappable<allocator_type>::value) &&
152 __is_nothrow_swappable<hasher>::value &&
153 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154
155 hasher hash_function() const;
156 key_equal key_eq() const;
157
158 iterator find(const key_type& k);
159 const_iterator find(const key_type& k) const;
160 size_type count(const key_type& k) const;
161 pair<iterator, iterator> equal_range(const key_type& k);
162 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
163
164 mapped_type& operator[](const key_type& k);
165 mapped_type& operator[](key_type&& k);
166
167 mapped_type& at(const key_type& k);
168 const mapped_type& at(const key_type& k) const;
169
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000170 size_type bucket_count() const noexcept;
171 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172
173 size_type bucket_size(size_type n) const;
174 size_type bucket(const key_type& k) const;
175
176 local_iterator begin(size_type n);
177 local_iterator end(size_type n);
178 const_local_iterator begin(size_type n) const;
179 const_local_iterator end(size_type n) const;
180 const_local_iterator cbegin(size_type n) const;
181 const_local_iterator cend(size_type n) const;
182
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000183 float load_factor() const noexcept;
184 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185 void max_load_factor(float z);
186 void rehash(size_type n);
187 void reserve(size_type n);
188};
189
190template <class Key, class T, class Hash, class Pred, class Alloc>
191 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000192 unordered_map<Key, T, Hash, Pred, Alloc>& y)
193 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194
195template <class Key, class T, class Hash, class Pred, class Alloc>
196 bool
197 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
198 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
199
200template <class Key, class T, class Hash, class Pred, class Alloc>
201 bool
202 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
203 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
204
205template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
206 class Alloc = allocator<pair<const Key, T>>>
207class unordered_multimap
208{
209public:
210 // types
211 typedef Key key_type;
212 typedef T mapped_type;
213 typedef Hash hasher;
214 typedef Pred key_equal;
215 typedef Alloc allocator_type;
216 typedef pair<const key_type, mapped_type> value_type;
217 typedef value_type& reference;
218 typedef const value_type& const_reference;
219 typedef typename allocator_traits<allocator_type>::pointer pointer;
220 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
221 typedef typename allocator_traits<allocator_type>::size_type size_type;
222 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
223
224 typedef /unspecified/ iterator;
225 typedef /unspecified/ const_iterator;
226 typedef /unspecified/ local_iterator;
227 typedef /unspecified/ const_local_iterator;
228
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000229 unordered_multimap()
230 noexcept(
231 is_nothrow_default_constructible<hasher>::value &&
232 is_nothrow_default_constructible<key_equal>::value &&
233 is_nothrow_default_constructible<allocator_type>::value);
234 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235 const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
237 template <class InputIterator>
238 unordered_multimap(InputIterator f, InputIterator l,
239 size_type n = 0, const hasher& hf = hasher(),
240 const key_equal& eql = key_equal(),
241 const allocator_type& a = allocator_type());
242 explicit unordered_multimap(const allocator_type&);
243 unordered_multimap(const unordered_multimap&);
244 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000245 unordered_multimap(unordered_multimap&&)
246 noexcept(
247 is_nothrow_move_constructible<hasher>::value &&
248 is_nothrow_move_constructible<key_equal>::value &&
249 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250 unordered_multimap(unordered_multimap&&, const Allocator&);
251 unordered_multimap(initializer_list<value_type>, size_type n = 0,
252 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
253 const allocator_type& a = allocator_type());
Marshall Clow6dff6182013-09-12 03:00:31 +0000254 unordered_multimap(size_type n, const allocator_type& a)
255 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
256 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
257 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
258 template <class InputIterator>
259 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
260 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
261 template <class InputIterator>
262 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
263 const allocator_type& a)
264 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
265 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
266 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
267 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
268 const allocator_type& a)
269 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 ~unordered_multimap();
271 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000272 unordered_multimap& operator=(unordered_multimap&&)
273 noexcept(
274 allocator_type::propagate_on_container_move_assignment::value &&
275 is_nothrow_move_assignable<allocator_type>::value &&
276 is_nothrow_move_assignable<hasher>::value &&
277 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278 unordered_multimap& operator=(initializer_list<value_type>);
279
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000280 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000286 iterator begin() noexcept;
287 iterator end() noexcept;
288 const_iterator begin() const noexcept;
289 const_iterator end() const noexcept;
290 const_iterator cbegin() const noexcept;
291 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000292
293 template <class... Args>
294 iterator emplace(Args&&... args);
295 template <class... Args>
296 iterator emplace_hint(const_iterator position, Args&&... args);
297 iterator insert(const value_type& obj);
298 template <class P>
299 iterator insert(P&& obj);
300 iterator insert(const_iterator hint, const value_type& obj);
301 template <class P>
302 iterator insert(const_iterator hint, P&& obj);
303 template <class InputIterator>
304 void insert(InputIterator first, InputIterator last);
305 void insert(initializer_list<value_type>);
306
307 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000308 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309 size_type erase(const key_type& k);
310 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000311 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000313 void swap(unordered_multimap&)
314 noexcept(
315 (!allocator_type::propagate_on_container_swap::value ||
316 __is_nothrow_swappable<allocator_type>::value) &&
317 __is_nothrow_swappable<hasher>::value &&
318 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320 hasher hash_function() const;
321 key_equal key_eq() const;
322
323 iterator find(const key_type& k);
324 const_iterator find(const key_type& k) const;
325 size_type count(const key_type& k) const;
326 pair<iterator, iterator> equal_range(const key_type& k);
327 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
328
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000329 size_type bucket_count() const noexcept;
330 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331
332 size_type bucket_size(size_type n) const;
333 size_type bucket(const key_type& k) const;
334
335 local_iterator begin(size_type n);
336 local_iterator end(size_type n);
337 const_local_iterator begin(size_type n) const;
338 const_local_iterator end(size_type n) const;
339 const_local_iterator cbegin(size_type n) const;
340 const_local_iterator cend(size_type n) const;
341
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000342 float load_factor() const noexcept;
343 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344 void max_load_factor(float z);
345 void rehash(size_type n);
346 void reserve(size_type n);
347};
348
349template <class Key, class T, class Hash, class Pred, class Alloc>
350 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000351 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
352 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
354template <class Key, class T, class Hash, class Pred, class Alloc>
355 bool
356 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
357 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
358
359template <class Key, class T, class Hash, class Pred, class Alloc>
360 bool
361 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
362 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
363
364} // std
365
366*/
367
368#include <__config>
369#include <__hash_table>
370#include <functional>
371#include <stdexcept>
372
Eric Fiselierb9536102014-08-10 23:53:08 +0000373#include <__debug>
374
Howard Hinnant08e17472011-10-17 20:05:10 +0000375#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000377#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
379_LIBCPP_BEGIN_NAMESPACE_STD
380
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000381template <class _Key, class _Cp, class _Hash,
382 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000383 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384class __unordered_map_hasher
385 : private _Hash
386{
387public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000389 __unordered_map_hasher()
390 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
391 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000393 __unordered_map_hasher(const _Hash& __h)
394 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
395 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000397 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000399 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000400 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000401 _LIBCPP_INLINE_VISIBILITY
402 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000404 void swap(__unordered_map_hasher&__y)
405 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
406 {
407 using _VSTD::swap;
408 swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y));
409 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410};
411
Howard Hinnant9b128e02013-07-05 18:06:00 +0000412template <class _Key, class _Cp, class _Hash>
413class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414{
415 _Hash __hash_;
416public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000418 __unordered_map_hasher()
419 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
420 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000422 __unordered_map_hasher(const _Hash& __h)
423 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
424 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000426 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000428 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000429 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000430 _LIBCPP_INLINE_VISIBILITY
431 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 {return __hash_(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000433 void swap(__unordered_map_hasher&__y)
434 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
435 {
436 using _VSTD::swap;
437 swap(__hash_, __y.__hash_);
438 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439};
440
Marshall Clow7d914d12015-07-13 20:04:56 +0000441template <class _Key, class _Cp, class _Hash, bool __b>
442inline _LIBCPP_INLINE_VISIBILITY
443void
444swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
445 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
446 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
447{
448 __x.swap(__y);
449}
450
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000451template <class _Key, class _Cp, class _Pred,
452 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000453 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454class __unordered_map_equal
455 : private _Pred
456{
457public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000459 __unordered_map_equal()
460 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
461 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000463 __unordered_map_equal(const _Pred& __p)
464 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
465 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000467 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000469 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000470 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000471 _LIBCPP_INLINE_VISIBILITY
472 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000473 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000475 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000476 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000477 void swap(__unordered_map_equal&__y)
478 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
479 {
480 using _VSTD::swap;
481 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
482 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483};
484
Howard Hinnant9b128e02013-07-05 18:06:00 +0000485template <class _Key, class _Cp, class _Pred>
486class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487{
488 _Pred __pred_;
489public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000491 __unordered_map_equal()
492 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
493 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000495 __unordered_map_equal(const _Pred& __p)
496 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
497 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000499 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000501 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000502 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000503 _LIBCPP_INLINE_VISIBILITY
504 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000505 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000507 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000508 {return __pred_(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000509 void swap(__unordered_map_equal&__y)
510 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
511 {
512 using _VSTD::swap;
513 swap(__pred_, __y.__pred_);
514 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515};
516
Marshall Clow7d914d12015-07-13 20:04:56 +0000517template <class _Key, class _Cp, class _Pred, bool __b>
518inline _LIBCPP_INLINE_VISIBILITY
519void
520swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
521 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
522 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
523{
524 __x.swap(__y);
525}
526
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527template <class _Alloc>
528class __hash_map_node_destructor
529{
530 typedef _Alloc allocator_type;
531 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000532
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533public:
Eric Fiselier774c7c52016-02-10 20:46:23 +0000534
535 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537
538 allocator_type& __na_;
539
540 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
541
542public:
543 bool __first_constructed;
544 bool __second_constructed;
545
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000547 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548 : __na_(__na),
549 __first_constructed(false),
550 __second_constructed(false)
551 {}
552
Howard Hinnant73d21a42010-09-04 23:28:19 +0000553#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000556 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557 : __na_(__x.__na_),
558 __first_constructed(__x.__value_constructed),
559 __second_constructed(__x.__value_constructed)
560 {
561 __x.__value_constructed = false;
562 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000563#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
566 : __na_(__x.__na_),
567 __first_constructed(__x.__value_constructed),
568 __second_constructed(__x.__value_constructed)
569 {
570 const_cast<bool&>(__x.__value_constructed) = false;
571 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000572#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000575 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576 {
577 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000578 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000580 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581 if (__p)
582 __alloc_traits::deallocate(__na_, __p, 1);
583 }
584};
585
Eric Fiselier2960ae22016-02-11 11:59:44 +0000586#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantff7546e2013-09-30 19:08:22 +0000587template <class _Key, class _Tp>
588union __hash_value_type
589{
590 typedef _Key key_type;
591 typedef _Tp mapped_type;
592 typedef pair<const key_type, mapped_type> value_type;
593 typedef pair<key_type, mapped_type> __nc_value_type;
594
595 value_type __cc;
596 __nc_value_type __nc;
597
Howard Hinnantff7546e2013-09-30 19:08:22 +0000598 _LIBCPP_INLINE_VISIBILITY
599 __hash_value_type& operator=(const __hash_value_type& __v)
600 {__nc = __v.__cc; return *this;}
601
602 _LIBCPP_INLINE_VISIBILITY
603 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000604 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000605
Eric Fiselier2960ae22016-02-11 11:59:44 +0000606 template <class _ValueTp,
607 class = typename enable_if<
608 __is_same_uncvref<_ValueTp, value_type>::value
609 >::type
610 >
Howard Hinnantff7546e2013-09-30 19:08:22 +0000611 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2960ae22016-02-11 11:59:44 +0000612 __hash_value_type& operator=(_ValueTp&& __v) {
613 __nc = _VSTD::forward<_ValueTp>(__v); return *this;
614 }
615
616private:
617 __hash_value_type(const __hash_value_type& __v) = delete;
618 __hash_value_type(__hash_value_type&& __v) = delete;
619 template <class ..._Args>
620 explicit __hash_value_type(_Args&& ...__args) = delete;
621
622 ~__hash_value_type() = delete;
Howard Hinnantff7546e2013-09-30 19:08:22 +0000623};
624
625#else
626
627template <class _Key, class _Tp>
628struct __hash_value_type
629{
630 typedef _Key key_type;
631 typedef _Tp mapped_type;
632 typedef pair<const key_type, mapped_type> value_type;
633
634 value_type __cc;
635
Eric Fiselier2960ae22016-02-11 11:59:44 +0000636private:
637 ~__hash_value_type();
Howard Hinnantff7546e2013-09-30 19:08:22 +0000638};
639
640#endif
641
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000643class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644{
645 _HashIterator __i_;
646
Eric Fiselier774c7c52016-02-10 20:46:23 +0000647 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
648
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649public:
650 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000651 typedef typename _NodeTypes::__map_value_type value_type;
652 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653 typedef value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000654 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000657 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000660 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000663 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000665 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 __hash_map_iterator operator++(int)
671 {
672 __hash_map_iterator __t(*this);
673 ++(*this);
674 return __t;
675 }
676
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000677 friend _LIBCPP_INLINE_VISIBILITY
678 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000680 friend _LIBCPP_INLINE_VISIBILITY
681 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 {return __x.__i_ != __y.__i_;}
683
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000684 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
685 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
686 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
687 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
688 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689};
690
691template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000692class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693{
694 _HashIterator __i_;
695
Eric Fiselier774c7c52016-02-10 20:46:23 +0000696 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
697
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698public:
699 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000700 typedef typename _NodeTypes::__map_value_type value_type;
701 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 typedef const value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000703 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000706 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000709 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 __hash_map_const_iterator(
712 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000713 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 : __i_(__i.__i_) {}
715
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000717 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000719 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 __hash_map_const_iterator operator++(int)
725 {
726 __hash_map_const_iterator __t(*this);
727 ++(*this);
728 return __t;
729 }
730
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000731 friend _LIBCPP_INLINE_VISIBILITY
732 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000734 friend _LIBCPP_INLINE_VISIBILITY
735 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736 {return __x.__i_ != __y.__i_;}
737
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000738 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
739 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
740 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
741 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742};
743
744template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
745 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000746class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747{
748public:
749 // types
750 typedef _Key key_type;
751 typedef _Tp mapped_type;
752 typedef _Hash hasher;
753 typedef _Pred key_equal;
754 typedef _Alloc allocator_type;
755 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000756 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757 typedef value_type& reference;
758 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000759 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
760 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761
762private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000763 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000764 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
765 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000766 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
767 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768
769 typedef __hash_table<__value_type, __hasher,
770 __key_equal, __allocator_type> __table;
771
772 __table __table_;
773
Eric Fiselier2960ae22016-02-11 11:59:44 +0000774 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 typedef typename __table::__node_pointer __node_pointer;
776 typedef typename __table::__node_const_pointer __node_const_pointer;
777 typedef typename __table::__node_traits __node_traits;
778 typedef typename __table::__node_allocator __node_allocator;
779 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000780 typedef __hash_map_node_destructor<__node_allocator> _Dp;
781 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier2960ae22016-02-11 11:59:44 +0000783
784 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
785 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786public:
787 typedef typename __alloc_traits::pointer pointer;
788 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000789 typedef typename __table::size_type size_type;
790 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791
792 typedef __hash_map_iterator<typename __table::iterator> iterator;
793 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
794 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
795 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
796
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000798 unordered_map()
799 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000800 {
801#if _LIBCPP_DEBUG_LEVEL >= 2
802 __get_db()->__insert_c(this);
803#endif
804 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
806 const key_equal& __eql = key_equal());
807 unordered_map(size_type __n, const hasher& __hf,
808 const key_equal& __eql,
809 const allocator_type& __a);
810 template <class _InputIterator>
811 unordered_map(_InputIterator __first, _InputIterator __last);
812 template <class _InputIterator>
813 unordered_map(_InputIterator __first, _InputIterator __last,
814 size_type __n, const hasher& __hf = hasher(),
815 const key_equal& __eql = key_equal());
816 template <class _InputIterator>
817 unordered_map(_InputIterator __first, _InputIterator __last,
818 size_type __n, const hasher& __hf,
819 const key_equal& __eql,
820 const allocator_type& __a);
821 explicit unordered_map(const allocator_type& __a);
822 unordered_map(const unordered_map& __u);
823 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000824#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000825 unordered_map(unordered_map&& __u)
826 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000828#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000829#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 unordered_map(initializer_list<value_type> __il);
831 unordered_map(initializer_list<value_type> __il, size_type __n,
832 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
833 unordered_map(initializer_list<value_type> __il, size_type __n,
834 const hasher& __hf, const key_equal& __eql,
835 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000836#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000837#if _LIBCPP_STD_VER > 11
838 _LIBCPP_INLINE_VISIBILITY
839 unordered_map(size_type __n, const allocator_type& __a)
840 : unordered_map(__n, hasher(), key_equal(), __a) {}
841 _LIBCPP_INLINE_VISIBILITY
842 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
843 : unordered_map(__n, __hf, key_equal(), __a) {}
844 template <class _InputIterator>
845 _LIBCPP_INLINE_VISIBILITY
846 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
847 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
848 template <class _InputIterator>
849 _LIBCPP_INLINE_VISIBILITY
850 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
851 const allocator_type& __a)
852 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
853 _LIBCPP_INLINE_VISIBILITY
854 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
855 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
856 _LIBCPP_INLINE_VISIBILITY
857 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
858 const allocator_type& __a)
859 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
860#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000862 _LIBCPP_INLINE_VISIBILITY
863 unordered_map& operator=(const unordered_map& __u)
864 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000865#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000866 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000867#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000868 if (this != &__u) {
869 __table_.clear();
870 __table_.hash_function() = __u.__table_.hash_function();
871 __table_.key_eq() = __u.__table_.key_eq();
872 __table_.max_load_factor() = __u.__table_.max_load_factor();
873 __table_.__copy_assign_alloc(__u.__table_);
874 insert(__u.begin(), __u.end());
875 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000876#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000877 return *this;
878 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000879#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000880 unordered_map& operator=(unordered_map&& __u)
881 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000882#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000883#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000885#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000888 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 {return allocator_type(__table_.__node_alloc());}
890
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000892 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000894 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000896 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000899 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000901 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000903 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000905 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000907 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000909 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000910
Eric Fiselier2960ae22016-02-11 11:59:44 +0000911#ifndef _LIBCPP_CXX03_LANG
912 template <class... _Args>
913 _LIBCPP_INLINE_VISIBILITY
914 pair<iterator, bool> emplace(_Args&&... __args) {
915 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
916 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000917
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000918 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:44 +0000919 _LIBCPP_INLINE_VISIBILITY
920 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000921#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier2960ae22016-02-11 11:59:44 +0000922 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
923 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
924 " referring to this unordered_map");
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000925#endif
Eric Fiselier2960ae22016-02-11 11:59:44 +0000926 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
927 }
928
929#endif // _LIBCPP_CXX03_LANG
930
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 pair<iterator, bool> insert(const value_type& __x)
933 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000934#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000935 template <class _Pp,
936 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000938 pair<iterator, bool> insert(_Pp&& __x)
939 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000940#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000942#if _LIBCPP_DEBUG_LEVEL >= 2
943 iterator insert(const_iterator __p, const value_type& __x)
944 {
945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
946 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
947 " referring to this unordered_map");
948 return insert(__x).first;
949 }
950#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 iterator insert(const_iterator, const value_type& __x)
952 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000953#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000954#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000955 template <class _Pp,
956 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000958#if _LIBCPP_DEBUG_LEVEL >= 2
959 iterator insert(const_iterator __p, _Pp&& __x)
960 {
961 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
962 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
963 " referring to this unordered_map");
964 return insert(_VSTD::forward<_Pp>(__x)).first;
965 }
966#else
Howard Hinnant99968442011-11-29 18:15:50 +0000967 iterator insert(const_iterator, _Pp&& __x)
968 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000969#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000970#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 template <class _InputIterator>
972 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000973#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975 void insert(initializer_list<value_type> __il)
976 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000977#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978
Marshall Clow0ce05a92015-07-07 05:45:35 +0000979#if _LIBCPP_STD_VER > 14
980#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
981#ifndef _LIBCPP_HAS_NO_VARIADICS
982 template <class... _Args>
983 _LIBCPP_INLINE_VISIBILITY
984 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
985 {
986 iterator __p = __table_.find(__k);
987 if ( __p != end())
988 return _VSTD::make_pair(__p, false);
989 else
990 return _VSTD::make_pair(
991 emplace_hint(__p,
992 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
993 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
994 true);
995 }
996
997 template <class... _Args>
998 _LIBCPP_INLINE_VISIBILITY
999 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1000 {
1001 iterator __p = __table_.find(__k);
1002 if ( __p != end())
1003 return _VSTD::make_pair(__p, false);
1004 else
1005 return _VSTD::make_pair(
1006 emplace_hint(__p,
1007 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1008 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1009 true);
1010 }
1011
1012 template <class... _Args>
1013 _LIBCPP_INLINE_VISIBILITY
1014 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1015 {
1016 iterator __p = __table_.find(__k);
1017 if ( __p != end())
1018 return __p;
1019 else
1020 return emplace_hint(__h,
1021 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1022 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1023 }
1024
1025 template <class... _Args>
1026 _LIBCPP_INLINE_VISIBILITY
1027 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1028 {
1029 iterator __p = __table_.find(__k);
1030 if ( __p != end())
1031 return __p;
1032 else
1033 return emplace_hint(__h,
1034 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1035 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1036 }
1037
1038 template <class _Vp>
1039 _LIBCPP_INLINE_VISIBILITY
1040 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1041 {
1042 iterator __p = __table_.find(__k);
1043 if ( __p != end())
1044 {
1045 __p->second = _VSTD::move(__v);
1046 return _VSTD::make_pair(__p, false);
1047 }
1048 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1049 }
1050
1051 template <class _Vp>
1052 _LIBCPP_INLINE_VISIBILITY
1053 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1054 {
1055 iterator __p = __table_.find(__k);
1056 if ( __p != end())
1057 {
1058 __p->second = _VSTD::move(__v);
1059 return _VSTD::make_pair(__p, false);
1060 }
1061 return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
1062 }
1063
1064 template <class _Vp>
1065 _LIBCPP_INLINE_VISIBILITY
1066 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1067 {
1068 iterator __p = __table_.find(__k);
1069 if ( __p != end())
1070 {
1071 __p->second = _VSTD::move(__v);
1072 return __p;
1073 }
1074 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1075 }
1076
1077 template <class _Vp>
1078 _LIBCPP_INLINE_VISIBILITY
1079 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1080 {
1081 iterator __p = __table_.find(__k);
1082 if ( __p != end())
1083 {
1084 __p->second = _VSTD::move(__v);
1085 return __p;
1086 }
1087 return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
1088 }
1089#endif
1090#endif
1091#endif
1092
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001095 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001096 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001098 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 iterator erase(const_iterator __first, const_iterator __last)
1101 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001103 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001106 void swap(unordered_map& __u)
1107 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1108 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111 hasher hash_function() const
1112 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 key_equal key_eq() const
1115 {return __table_.key_eq().key_eq();}
1116
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001124 pair<iterator, iterator> equal_range(const key_type& __k)
1125 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1128 {return __table_.__equal_range_unique(__k);}
1129
1130 mapped_type& operator[](const key_type& __k);
Eric Fiselierab414822016-02-11 18:21:18 +00001131#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132 mapped_type& operator[](key_type&& __k);
1133#endif
1134
1135 mapped_type& at(const key_type& __k);
1136 const mapped_type& at(const key_type& __k) const;
1137
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001139 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001141 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 size_type bucket_size(size_type __n) const
1145 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1148
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1161
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001163 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001165 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 void reserve(size_type __n) {__table_.reserve(__n);}
1172
Howard Hinnant39213642013-07-23 22:01:58 +00001173#if _LIBCPP_DEBUG_LEVEL >= 2
1174
1175 bool __dereferenceable(const const_iterator* __i) const
1176 {return __table_.__dereferenceable(&__i->__i_);}
1177 bool __decrementable(const const_iterator* __i) const
1178 {return __table_.__decrementable(&__i->__i_);}
1179 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1180 {return __table_.__addable(&__i->__i_, __n);}
1181 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1182 {return __table_.__addable(&__i->__i_, __n);}
1183
1184#endif // _LIBCPP_DEBUG_LEVEL >= 2
1185
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186private:
Eric Fiselierab414822016-02-11 18:21:18 +00001187#ifndef _LIBCPP_CXX03_LANG
1188 __node_holder __construct_node_with_key(key_type&& __k);
1189#endif // _LIBCPP_CXX03_LANG
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001190 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191};
1192
1193template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1194unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1195 size_type __n, const hasher& __hf, const key_equal& __eql)
1196 : __table_(__hf, __eql)
1197{
Howard Hinnant39213642013-07-23 22:01:58 +00001198#if _LIBCPP_DEBUG_LEVEL >= 2
1199 __get_db()->__insert_c(this);
1200#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 __table_.rehash(__n);
1202}
1203
1204template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1205unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1206 size_type __n, const hasher& __hf, const key_equal& __eql,
1207 const allocator_type& __a)
1208 : __table_(__hf, __eql, __a)
1209{
Howard Hinnant39213642013-07-23 22:01:58 +00001210#if _LIBCPP_DEBUG_LEVEL >= 2
1211 __get_db()->__insert_c(this);
1212#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 __table_.rehash(__n);
1214}
1215
1216template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001217inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1219 const allocator_type& __a)
1220 : __table_(__a)
1221{
Howard Hinnant39213642013-07-23 22:01:58 +00001222#if _LIBCPP_DEBUG_LEVEL >= 2
1223 __get_db()->__insert_c(this);
1224#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225}
1226
1227template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1228template <class _InputIterator>
1229unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1230 _InputIterator __first, _InputIterator __last)
1231{
Howard Hinnant39213642013-07-23 22:01:58 +00001232#if _LIBCPP_DEBUG_LEVEL >= 2
1233 __get_db()->__insert_c(this);
1234#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235 insert(__first, __last);
1236}
1237
1238template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1239template <class _InputIterator>
1240unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1241 _InputIterator __first, _InputIterator __last, size_type __n,
1242 const hasher& __hf, const key_equal& __eql)
1243 : __table_(__hf, __eql)
1244{
Howard Hinnant39213642013-07-23 22:01:58 +00001245#if _LIBCPP_DEBUG_LEVEL >= 2
1246 __get_db()->__insert_c(this);
1247#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 __table_.rehash(__n);
1249 insert(__first, __last);
1250}
1251
1252template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1253template <class _InputIterator>
1254unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1255 _InputIterator __first, _InputIterator __last, size_type __n,
1256 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1257 : __table_(__hf, __eql, __a)
1258{
Howard Hinnant39213642013-07-23 22:01:58 +00001259#if _LIBCPP_DEBUG_LEVEL >= 2
1260 __get_db()->__insert_c(this);
1261#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262 __table_.rehash(__n);
1263 insert(__first, __last);
1264}
1265
1266template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1267unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1268 const unordered_map& __u)
1269 : __table_(__u.__table_)
1270{
Howard Hinnant39213642013-07-23 22:01:58 +00001271#if _LIBCPP_DEBUG_LEVEL >= 2
1272 __get_db()->__insert_c(this);
1273#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274 __table_.rehash(__u.bucket_count());
1275 insert(__u.begin(), __u.end());
1276}
1277
1278template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1279unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1280 const unordered_map& __u, const allocator_type& __a)
1281 : __table_(__u.__table_, __a)
1282{
Howard Hinnant39213642013-07-23 22:01:58 +00001283#if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
1285#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 __table_.rehash(__u.bucket_count());
1287 insert(__u.begin(), __u.end());
1288}
1289
Howard Hinnant73d21a42010-09-04 23:28:19 +00001290#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291
1292template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001293inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1295 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001296 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001297 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298{
Howard Hinnant39213642013-07-23 22:01:58 +00001299#if _LIBCPP_DEBUG_LEVEL >= 2
1300 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001301 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001302#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303}
1304
1305template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1306unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1307 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001308 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309{
Howard Hinnant39213642013-07-23 22:01:58 +00001310#if _LIBCPP_DEBUG_LEVEL >= 2
1311 __get_db()->__insert_c(this);
1312#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 if (__a != __u.get_allocator())
1314 {
1315 iterator __i = __u.begin();
Eric Fiselier2960ae22016-02-11 11:59:44 +00001316 while (__u.size() != 0) {
1317 __table_.__emplace_unique(_VSTD::move(
1318 __u.__table_.remove((__i++).__i_)->__value_.__nc));
1319 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001321#if _LIBCPP_DEBUG_LEVEL >= 2
1322 else
1323 __get_db()->swap(this, &__u);
1324#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001325}
1326
Howard Hinnant73d21a42010-09-04 23:28:19 +00001327#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328
Howard Hinnante3e32912011-08-12 21:56:02 +00001329#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1330
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1332unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1333 initializer_list<value_type> __il)
1334{
Howard Hinnant39213642013-07-23 22:01:58 +00001335#if _LIBCPP_DEBUG_LEVEL >= 2
1336 __get_db()->__insert_c(this);
1337#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 insert(__il.begin(), __il.end());
1339}
1340
1341template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1342unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1343 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1344 const key_equal& __eql)
1345 : __table_(__hf, __eql)
1346{
Howard Hinnant39213642013-07-23 22:01:58 +00001347#if _LIBCPP_DEBUG_LEVEL >= 2
1348 __get_db()->__insert_c(this);
1349#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350 __table_.rehash(__n);
1351 insert(__il.begin(), __il.end());
1352}
1353
1354template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1355unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1356 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1357 const key_equal& __eql, const allocator_type& __a)
1358 : __table_(__hf, __eql, __a)
1359{
Howard Hinnant39213642013-07-23 22:01:58 +00001360#if _LIBCPP_DEBUG_LEVEL >= 2
1361 __get_db()->__insert_c(this);
1362#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363 __table_.rehash(__n);
1364 insert(__il.begin(), __il.end());
1365}
1366
Howard Hinnante3e32912011-08-12 21:56:02 +00001367#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1368
Howard Hinnant73d21a42010-09-04 23:28:19 +00001369#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370
1371template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1374unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001375 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001377 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378 return *this;
1379}
1380
Howard Hinnant73d21a42010-09-04 23:28:19 +00001381#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382
Howard Hinnante3e32912011-08-12 21:56:02 +00001383#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1384
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1388unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1389 initializer_list<value_type> __il)
1390{
1391 __table_.__assign_unique(__il.begin(), __il.end());
1392 return *this;
1393}
1394
Howard Hinnante3e32912011-08-12 21:56:02 +00001395#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1396
Eric Fiselierab414822016-02-11 18:21:18 +00001397#ifndef _LIBCPP_CXX03_LANG
1398
1399template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1400typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1401unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
1402{
1403 __node_allocator& __na = __table_.__node_alloc();
1404 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1405 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
1406 __h.get_deleter().__first_constructed = true;
1407 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
1408 __h.get_deleter().__second_constructed = true;
1409 return __h;
1410}
1411
1412#endif
1413
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1415typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001416unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417{
1418 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001419 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001420 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001422 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:33 +00001424 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425}
1426
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1428template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430void
1431unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1432 _InputIterator __last)
1433{
1434 for (; __first != __last; ++__first)
1435 __table_.__insert_unique(*__first);
1436}
1437
1438template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1439_Tp&
1440unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1441{
1442 iterator __i = find(__k);
1443 if (__i != end())
1444 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001445 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001446 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1447 __h.release();
1448 return __r.first->second;
1449}
1450
Eric Fiselierab414822016-02-11 18:21:18 +00001451#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452
1453template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1454_Tp&
1455unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1456{
Eric Fiselierab414822016-02-11 18:21:18 +00001457 iterator __i = find(__k);
1458 if (__i != end())
1459 return __i->second;
1460 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
1461 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1462 __h.release();
1463 return __r.first->second;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464}
1465
Eric Fiselierab414822016-02-11 18:21:18 +00001466#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467
1468template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1469_Tp&
1470unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1471{
1472 iterator __i = find(__k);
1473#ifndef _LIBCPP_NO_EXCEPTIONS
1474 if (__i == end())
1475 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001476#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 return __i->second;
1478}
1479
1480template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1481const _Tp&
1482unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1483{
1484 const_iterator __i = find(__k);
1485#ifndef _LIBCPP_NO_EXCEPTIONS
1486 if (__i == end())
1487 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001488#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489 return __i->second;
1490}
1491
1492template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494void
1495swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1496 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001497 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498{
1499 __x.swap(__y);
1500}
1501
1502template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1503bool
1504operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1505 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1506{
1507 if (__x.size() != __y.size())
1508 return false;
1509 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1510 const_iterator;
1511 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1512 __i != __ex; ++__i)
1513 {
1514 const_iterator __j = __y.find(__i->first);
1515 if (__j == __ey || !(*__i == *__j))
1516 return false;
1517 }
1518 return true;
1519}
1520
1521template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523bool
1524operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1525 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1526{
1527 return !(__x == __y);
1528}
1529
1530template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1531 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001532class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533{
1534public:
1535 // types
1536 typedef _Key key_type;
1537 typedef _Tp mapped_type;
1538 typedef _Hash hasher;
1539 typedef _Pred key_equal;
1540 typedef _Alloc allocator_type;
1541 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001542 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 typedef value_type& reference;
1544 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001545 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1546 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547
1548private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001549 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001550 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1551 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001552 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1553 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554
1555 typedef __hash_table<__value_type, __hasher,
1556 __key_equal, __allocator_type> __table;
1557
1558 __table __table_;
1559
Eric Fiselier2960ae22016-02-11 11:59:44 +00001560 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561 typedef typename __table::__node_traits __node_traits;
1562 typedef typename __table::__node_allocator __node_allocator;
1563 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001564 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1565 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001567 static_assert((is_same<typename __node_traits::size_type,
1568 typename __alloc_traits::size_type>::value),
1569 "Allocator uses different size_type for different types");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570public:
1571 typedef typename __alloc_traits::pointer pointer;
1572 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001573 typedef typename __table::size_type size_type;
1574 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001575
1576 typedef __hash_map_iterator<typename __table::iterator> iterator;
1577 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1578 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1579 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1580
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001582 unordered_multimap()
1583 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001584 {
1585#if _LIBCPP_DEBUG_LEVEL >= 2
1586 __get_db()->__insert_c(this);
1587#endif
1588 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1590 const key_equal& __eql = key_equal());
1591 unordered_multimap(size_type __n, const hasher& __hf,
1592 const key_equal& __eql,
1593 const allocator_type& __a);
1594 template <class _InputIterator>
1595 unordered_multimap(_InputIterator __first, _InputIterator __last);
1596 template <class _InputIterator>
1597 unordered_multimap(_InputIterator __first, _InputIterator __last,
1598 size_type __n, const hasher& __hf = hasher(),
1599 const key_equal& __eql = key_equal());
1600 template <class _InputIterator>
1601 unordered_multimap(_InputIterator __first, _InputIterator __last,
1602 size_type __n, const hasher& __hf,
1603 const key_equal& __eql,
1604 const allocator_type& __a);
1605 explicit unordered_multimap(const allocator_type& __a);
1606 unordered_multimap(const unordered_multimap& __u);
1607 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001608#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001609 unordered_multimap(unordered_multimap&& __u)
1610 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001612#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001613#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 unordered_multimap(initializer_list<value_type> __il);
1615 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1616 const hasher& __hf = hasher(),
1617 const key_equal& __eql = key_equal());
1618 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1619 const hasher& __hf, const key_equal& __eql,
1620 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001621#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001622#if _LIBCPP_STD_VER > 11
1623 _LIBCPP_INLINE_VISIBILITY
1624 unordered_multimap(size_type __n, const allocator_type& __a)
1625 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1626 _LIBCPP_INLINE_VISIBILITY
1627 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1628 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1629 template <class _InputIterator>
1630 _LIBCPP_INLINE_VISIBILITY
1631 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1632 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1633 template <class _InputIterator>
1634 _LIBCPP_INLINE_VISIBILITY
1635 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1636 const allocator_type& __a)
1637 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1638 _LIBCPP_INLINE_VISIBILITY
1639 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1640 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1641 _LIBCPP_INLINE_VISIBILITY
1642 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1643 const allocator_type& __a)
1644 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1645#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001647 _LIBCPP_INLINE_VISIBILITY
1648 unordered_multimap& operator=(const unordered_multimap& __u)
1649 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001650#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001651 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001652#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001653 if (this != &__u) {
1654 __table_.clear();
1655 __table_.hash_function() = __u.__table_.hash_function();
1656 __table_.key_eq() = __u.__table_.key_eq();
1657 __table_.max_load_factor() = __u.__table_.max_load_factor();
1658 __table_.__copy_assign_alloc(__u.__table_);
1659 insert(__u.begin(), __u.end());
1660 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001661#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001662 return *this;
1663 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001664#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001665 unordered_multimap& operator=(unordered_multimap&& __u)
1666 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001668#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001670#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001673 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001674 {return allocator_type(__table_.__node_alloc());}
1675
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001677 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001679 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001681 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001684 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001686 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001688 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001690 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001692 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001694 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695
Eric Fiselier2960ae22016-02-11 11:59:44 +00001696#ifndef _LIBCPP_CXX03_LANG
1697 template <class... _Args>
1698 iterator emplace(_Args&&... __args) {
1699 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1700 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001701
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001702 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:44 +00001703 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1704 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1705 }
1706#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001710#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001711 template <class _Pp,
1712 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001714 iterator insert(_Pp&& __x)
1715 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001716#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 iterator insert(const_iterator __p, const value_type& __x)
1719 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001720#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001721 template <class _Pp,
1722 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001724 iterator insert(const_iterator __p, _Pp&& __x)
1725 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001726#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727 template <class _InputIterator>
1728 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001729#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731 void insert(initializer_list<value_type> __il)
1732 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001733#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001737 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001738 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 iterator erase(const_iterator __first, const_iterator __last)
1743 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001745 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001748 void swap(unordered_multimap& __u)
1749 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1750 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753 hasher hash_function() const
1754 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 key_equal key_eq() const
1757 {return __table_.key_eq().key_eq();}
1758
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766 pair<iterator, iterator> equal_range(const key_type& __k)
1767 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1770 {return __table_.__equal_range_multi(__k);}
1771
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001773 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001775 size_type max_bucket_count() const _NOEXCEPT
1776 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 size_type bucket_size(size_type __n) const
1780 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1783
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1796
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001798 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001800 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 void reserve(size_type __n) {__table_.reserve(__n);}
1807
Howard Hinnant39213642013-07-23 22:01:58 +00001808#if _LIBCPP_DEBUG_LEVEL >= 2
1809
1810 bool __dereferenceable(const const_iterator* __i) const
1811 {return __table_.__dereferenceable(&__i->__i_);}
1812 bool __decrementable(const const_iterator* __i) const
1813 {return __table_.__decrementable(&__i->__i_);}
1814 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1815 {return __table_.__addable(&__i->__i_, __n);}
1816 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1817 {return __table_.__addable(&__i->__i_, __n);}
1818
1819#endif // _LIBCPP_DEBUG_LEVEL >= 2
1820
Eric Fiselier2960ae22016-02-11 11:59:44 +00001821
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822};
1823
1824template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1825unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1826 size_type __n, const hasher& __hf, const key_equal& __eql)
1827 : __table_(__hf, __eql)
1828{
Howard Hinnant39213642013-07-23 22:01:58 +00001829#if _LIBCPP_DEBUG_LEVEL >= 2
1830 __get_db()->__insert_c(this);
1831#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 __table_.rehash(__n);
1833}
1834
1835template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1836unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1837 size_type __n, const hasher& __hf, const key_equal& __eql,
1838 const allocator_type& __a)
1839 : __table_(__hf, __eql, __a)
1840{
Howard Hinnant39213642013-07-23 22:01:58 +00001841#if _LIBCPP_DEBUG_LEVEL >= 2
1842 __get_db()->__insert_c(this);
1843#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844 __table_.rehash(__n);
1845}
1846
1847template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1848template <class _InputIterator>
1849unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1850 _InputIterator __first, _InputIterator __last)
1851{
Howard Hinnant39213642013-07-23 22:01:58 +00001852#if _LIBCPP_DEBUG_LEVEL >= 2
1853 __get_db()->__insert_c(this);
1854#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855 insert(__first, __last);
1856}
1857
1858template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1859template <class _InputIterator>
1860unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1861 _InputIterator __first, _InputIterator __last, size_type __n,
1862 const hasher& __hf, const key_equal& __eql)
1863 : __table_(__hf, __eql)
1864{
Howard Hinnant39213642013-07-23 22:01:58 +00001865#if _LIBCPP_DEBUG_LEVEL >= 2
1866 __get_db()->__insert_c(this);
1867#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 __table_.rehash(__n);
1869 insert(__first, __last);
1870}
1871
1872template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1873template <class _InputIterator>
1874unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1875 _InputIterator __first, _InputIterator __last, size_type __n,
1876 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1877 : __table_(__hf, __eql, __a)
1878{
Howard Hinnant39213642013-07-23 22:01:58 +00001879#if _LIBCPP_DEBUG_LEVEL >= 2
1880 __get_db()->__insert_c(this);
1881#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 __table_.rehash(__n);
1883 insert(__first, __last);
1884}
1885
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001888unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1889 const allocator_type& __a)
1890 : __table_(__a)
1891{
Howard Hinnant39213642013-07-23 22:01:58 +00001892#if _LIBCPP_DEBUG_LEVEL >= 2
1893 __get_db()->__insert_c(this);
1894#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895}
1896
1897template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1898unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1899 const unordered_multimap& __u)
1900 : __table_(__u.__table_)
1901{
Howard Hinnant39213642013-07-23 22:01:58 +00001902#if _LIBCPP_DEBUG_LEVEL >= 2
1903 __get_db()->__insert_c(this);
1904#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905 __table_.rehash(__u.bucket_count());
1906 insert(__u.begin(), __u.end());
1907}
1908
1909template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1910unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1911 const unordered_multimap& __u, const allocator_type& __a)
1912 : __table_(__u.__table_, __a)
1913{
Howard Hinnant39213642013-07-23 22:01:58 +00001914#if _LIBCPP_DEBUG_LEVEL >= 2
1915 __get_db()->__insert_c(this);
1916#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 __table_.rehash(__u.bucket_count());
1918 insert(__u.begin(), __u.end());
1919}
1920
Howard Hinnant73d21a42010-09-04 23:28:19 +00001921#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922
1923template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1926 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001927 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001928 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929{
Howard Hinnant39213642013-07-23 22:01:58 +00001930#if _LIBCPP_DEBUG_LEVEL >= 2
1931 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001932 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001933#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934}
1935
1936template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1937unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1938 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001939 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940{
Howard Hinnant39213642013-07-23 22:01:58 +00001941#if _LIBCPP_DEBUG_LEVEL >= 2
1942 __get_db()->__insert_c(this);
1943#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 if (__a != __u.get_allocator())
1945 {
1946 iterator __i = __u.begin();
1947 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00001948 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949 __table_.__insert_multi(
Eric Fiselier2960ae22016-02-11 11:59:44 +00001950 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 );
Howard Hinnant39213642013-07-23 22:01:58 +00001952 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001954#if _LIBCPP_DEBUG_LEVEL >= 2
1955 else
1956 __get_db()->swap(this, &__u);
1957#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958}
1959
Howard Hinnant73d21a42010-09-04 23:28:19 +00001960#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961
Howard Hinnante3e32912011-08-12 21:56:02 +00001962#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1963
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1965unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1966 initializer_list<value_type> __il)
1967{
Howard Hinnant39213642013-07-23 22:01:58 +00001968#if _LIBCPP_DEBUG_LEVEL >= 2
1969 __get_db()->__insert_c(this);
1970#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971 insert(__il.begin(), __il.end());
1972}
1973
1974template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1975unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1976 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1977 const key_equal& __eql)
1978 : __table_(__hf, __eql)
1979{
Howard Hinnant39213642013-07-23 22:01:58 +00001980#if _LIBCPP_DEBUG_LEVEL >= 2
1981 __get_db()->__insert_c(this);
1982#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001983 __table_.rehash(__n);
1984 insert(__il.begin(), __il.end());
1985}
1986
1987template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1988unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1989 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1990 const key_equal& __eql, const allocator_type& __a)
1991 : __table_(__hf, __eql, __a)
1992{
Howard Hinnant39213642013-07-23 22:01:58 +00001993#if _LIBCPP_DEBUG_LEVEL >= 2
1994 __get_db()->__insert_c(this);
1995#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996 __table_.rehash(__n);
1997 insert(__il.begin(), __il.end());
1998}
1999
Howard Hinnante3e32912011-08-12 21:56:02 +00002000#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2001
Howard Hinnant73d21a42010-09-04 23:28:19 +00002002#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003
2004template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2007unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002008 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002010 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011 return *this;
2012}
2013
Howard Hinnant73d21a42010-09-04 23:28:19 +00002014#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015
Howard Hinnante3e32912011-08-12 21:56:02 +00002016#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2017
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002018template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002019inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2021unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2022 initializer_list<value_type> __il)
2023{
2024 __table_.__assign_multi(__il.begin(), __il.end());
2025 return *this;
2026}
2027
Howard Hinnante3e32912011-08-12 21:56:02 +00002028#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2029
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031
2032template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2033template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002035void
2036unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2037 _InputIterator __last)
2038{
2039 for (; __first != __last; ++__first)
2040 __table_.__insert_multi(*__first);
2041}
2042
2043template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002044inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045void
2046swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2047 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002048 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002049{
2050 __x.swap(__y);
2051}
2052
2053template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2054bool
2055operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2056 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2057{
2058 if (__x.size() != __y.size())
2059 return false;
2060 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2061 const_iterator;
2062 typedef pair<const_iterator, const_iterator> _EqRng;
2063 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2064 {
2065 _EqRng __xeq = __x.equal_range(__i->first);
2066 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002067 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2068 _VSTD::distance(__yeq.first, __yeq.second) ||
2069 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070 return false;
2071 __i = __xeq.second;
2072 }
2073 return true;
2074}
2075
2076template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078bool
2079operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2080 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2081{
2082 return !(__x == __y);
2083}
2084
2085_LIBCPP_END_NAMESPACE_STD
2086
2087#endif // _LIBCPP_UNORDERED_MAP