blob: 89407b00f50fb391112153d6f4e89a520b92ac0f [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
Howard Hinnantff7546e2013-09-30 19:08:22 +0000586#if __cplusplus >= 201103L
587
588template <class _Key, class _Tp>
589union __hash_value_type
590{
591 typedef _Key key_type;
592 typedef _Tp mapped_type;
593 typedef pair<const key_type, mapped_type> value_type;
594 typedef pair<key_type, mapped_type> __nc_value_type;
595
596 value_type __cc;
597 __nc_value_type __nc;
598
599 template <class ..._Args>
600 _LIBCPP_INLINE_VISIBILITY
601 __hash_value_type(_Args&& ...__args)
602 : __cc(std::forward<_Args>(__args)...) {}
603
604 _LIBCPP_INLINE_VISIBILITY
605 __hash_value_type(const __hash_value_type& __v)
606 : __cc(__v.__cc) {}
607
608 _LIBCPP_INLINE_VISIBILITY
609 __hash_value_type(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000610 : __nc(_VSTD::move(__v.__nc)) {}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000611
612 _LIBCPP_INLINE_VISIBILITY
613 __hash_value_type& operator=(const __hash_value_type& __v)
614 {__nc = __v.__cc; return *this;}
615
616 _LIBCPP_INLINE_VISIBILITY
617 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000618 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000619
620 _LIBCPP_INLINE_VISIBILITY
621 ~__hash_value_type() {__cc.~value_type();}
622};
623
624#else
625
626template <class _Key, class _Tp>
627struct __hash_value_type
628{
629 typedef _Key key_type;
630 typedef _Tp mapped_type;
631 typedef pair<const key_type, mapped_type> value_type;
632
633 value_type __cc;
634
635 _LIBCPP_INLINE_VISIBILITY
636 __hash_value_type() {}
637
638 template <class _A0>
639 _LIBCPP_INLINE_VISIBILITY
640 __hash_value_type(const _A0& __a0)
641 : __cc(__a0) {}
642
643 template <class _A0, class _A1>
644 _LIBCPP_INLINE_VISIBILITY
645 __hash_value_type(const _A0& __a0, const _A1& __a1)
646 : __cc(__a0, __a1) {}
647};
648
649#endif
650
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000652class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653{
654 _HashIterator __i_;
655
Eric Fiselier774c7c52016-02-10 20:46:23 +0000656 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
657
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658public:
659 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000660 typedef typename _NodeTypes::__map_value_type value_type;
661 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 typedef value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000663 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000666 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000669 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000672 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000674 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 __hash_map_iterator operator++(int)
680 {
681 __hash_map_iterator __t(*this);
682 ++(*this);
683 return __t;
684 }
685
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000686 friend _LIBCPP_INLINE_VISIBILITY
687 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000689 friend _LIBCPP_INLINE_VISIBILITY
690 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 {return __x.__i_ != __y.__i_;}
692
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000693 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
694 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
695 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
696 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
697 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698};
699
700template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000701class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702{
703 _HashIterator __i_;
704
Eric Fiselier774c7c52016-02-10 20:46:23 +0000705 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
706
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707public:
708 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000709 typedef typename _NodeTypes::__map_value_type value_type;
710 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 typedef const value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000712 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000715 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000718 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720 __hash_map_const_iterator(
721 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000722 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 : __i_(__i.__i_) {}
724
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000726 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000728 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733 __hash_map_const_iterator operator++(int)
734 {
735 __hash_map_const_iterator __t(*this);
736 ++(*this);
737 return __t;
738 }
739
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000740 friend _LIBCPP_INLINE_VISIBILITY
741 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000743 friend _LIBCPP_INLINE_VISIBILITY
744 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 {return __x.__i_ != __y.__i_;}
746
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000747 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
748 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
749 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
750 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751};
752
753template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
754 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000755class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756{
757public:
758 // types
759 typedef _Key key_type;
760 typedef _Tp mapped_type;
761 typedef _Hash hasher;
762 typedef _Pred key_equal;
763 typedef _Alloc allocator_type;
764 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000765 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 typedef value_type& reference;
767 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000768 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
769 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770
771private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000772 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000773 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
774 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000775 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
776 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777
778 typedef __hash_table<__value_type, __hasher,
779 __key_equal, __allocator_type> __table;
780
781 __table __table_;
782
783 typedef typename __table::__node_pointer __node_pointer;
784 typedef typename __table::__node_const_pointer __node_const_pointer;
785 typedef typename __table::__node_traits __node_traits;
786 typedef typename __table::__node_allocator __node_allocator;
787 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000788 typedef __hash_map_node_destructor<__node_allocator> _Dp;
789 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790 typedef allocator_traits<allocator_type> __alloc_traits;
791public:
792 typedef typename __alloc_traits::pointer pointer;
793 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000794 typedef typename __table::size_type size_type;
795 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796
797 typedef __hash_map_iterator<typename __table::iterator> iterator;
798 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
799 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
800 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
801
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000803 unordered_map()
804 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000805 {
806#if _LIBCPP_DEBUG_LEVEL >= 2
807 __get_db()->__insert_c(this);
808#endif
809 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
811 const key_equal& __eql = key_equal());
812 unordered_map(size_type __n, const hasher& __hf,
813 const key_equal& __eql,
814 const allocator_type& __a);
815 template <class _InputIterator>
816 unordered_map(_InputIterator __first, _InputIterator __last);
817 template <class _InputIterator>
818 unordered_map(_InputIterator __first, _InputIterator __last,
819 size_type __n, const hasher& __hf = hasher(),
820 const key_equal& __eql = key_equal());
821 template <class _InputIterator>
822 unordered_map(_InputIterator __first, _InputIterator __last,
823 size_type __n, const hasher& __hf,
824 const key_equal& __eql,
825 const allocator_type& __a);
826 explicit unordered_map(const allocator_type& __a);
827 unordered_map(const unordered_map& __u);
828 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000829#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000830 unordered_map(unordered_map&& __u)
831 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000832 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000833#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000834#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835 unordered_map(initializer_list<value_type> __il);
836 unordered_map(initializer_list<value_type> __il, size_type __n,
837 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
838 unordered_map(initializer_list<value_type> __il, size_type __n,
839 const hasher& __hf, const key_equal& __eql,
840 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000841#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000842#if _LIBCPP_STD_VER > 11
843 _LIBCPP_INLINE_VISIBILITY
844 unordered_map(size_type __n, const allocator_type& __a)
845 : unordered_map(__n, hasher(), key_equal(), __a) {}
846 _LIBCPP_INLINE_VISIBILITY
847 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
848 : unordered_map(__n, __hf, key_equal(), __a) {}
849 template <class _InputIterator>
850 _LIBCPP_INLINE_VISIBILITY
851 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
852 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
853 template <class _InputIterator>
854 _LIBCPP_INLINE_VISIBILITY
855 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
856 const allocator_type& __a)
857 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
858 _LIBCPP_INLINE_VISIBILITY
859 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
860 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
861 _LIBCPP_INLINE_VISIBILITY
862 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
863 const allocator_type& __a)
864 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
865#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000867 _LIBCPP_INLINE_VISIBILITY
868 unordered_map& operator=(const unordered_map& __u)
869 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000870#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000871 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000872#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000873 if (this != &__u) {
874 __table_.clear();
875 __table_.hash_function() = __u.__table_.hash_function();
876 __table_.key_eq() = __u.__table_.key_eq();
877 __table_.max_load_factor() = __u.__table_.max_load_factor();
878 __table_.__copy_assign_alloc(__u.__table_);
879 insert(__u.begin(), __u.end());
880 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000881#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000882 return *this;
883 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000884#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000885 unordered_map& operator=(unordered_map&& __u)
886 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000888#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000893 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 {return allocator_type(__table_.__node_alloc());}
895
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000897 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000899 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000901 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000904 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000906 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000908 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000910 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000912 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000914 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915
Howard Hinnant73d21a42010-09-04 23:28:19 +0000916#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000917#ifndef _LIBCPP_HAS_NO_VARIADICS
918
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000919 template <class... _Args>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000920 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000922 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000924#if _LIBCPP_DEBUG_LEVEL >= 2
925 iterator emplace_hint(const_iterator __p, _Args&&... __args)
926 {
927 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
928 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
929 " referring to this unordered_map");
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000930 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000931 }
932#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000933 iterator emplace_hint(const_iterator, _Args&&... __args)
934 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000935#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000936#endif // _LIBCPP_HAS_NO_VARIADICS
937#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939 pair<iterator, bool> insert(const value_type& __x)
940 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000941#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000942 template <class _Pp,
943 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000945 pair<iterator, bool> insert(_Pp&& __x)
946 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000947#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000949#if _LIBCPP_DEBUG_LEVEL >= 2
950 iterator insert(const_iterator __p, const value_type& __x)
951 {
952 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
953 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
954 " referring to this unordered_map");
955 return insert(__x).first;
956 }
957#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 iterator insert(const_iterator, const value_type& __x)
959 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000960#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000961#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000962 template <class _Pp,
963 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000965#if _LIBCPP_DEBUG_LEVEL >= 2
966 iterator insert(const_iterator __p, _Pp&& __x)
967 {
968 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
969 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
970 " referring to this unordered_map");
971 return insert(_VSTD::forward<_Pp>(__x)).first;
972 }
973#else
Howard Hinnant99968442011-11-29 18:15:50 +0000974 iterator insert(const_iterator, _Pp&& __x)
975 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000976#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000977#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 template <class _InputIterator>
979 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000980#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 void insert(initializer_list<value_type> __il)
983 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000984#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985
Marshall Clow0ce05a92015-07-07 05:45:35 +0000986#if _LIBCPP_STD_VER > 14
987#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
988#ifndef _LIBCPP_HAS_NO_VARIADICS
989 template <class... _Args>
990 _LIBCPP_INLINE_VISIBILITY
991 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
992 {
993 iterator __p = __table_.find(__k);
994 if ( __p != end())
995 return _VSTD::make_pair(__p, false);
996 else
997 return _VSTD::make_pair(
998 emplace_hint(__p,
999 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1000 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1001 true);
1002 }
1003
1004 template <class... _Args>
1005 _LIBCPP_INLINE_VISIBILITY
1006 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1007 {
1008 iterator __p = __table_.find(__k);
1009 if ( __p != end())
1010 return _VSTD::make_pair(__p, false);
1011 else
1012 return _VSTD::make_pair(
1013 emplace_hint(__p,
1014 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1015 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1016 true);
1017 }
1018
1019 template <class... _Args>
1020 _LIBCPP_INLINE_VISIBILITY
1021 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1022 {
1023 iterator __p = __table_.find(__k);
1024 if ( __p != end())
1025 return __p;
1026 else
1027 return emplace_hint(__h,
1028 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1029 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1030 }
1031
1032 template <class... _Args>
1033 _LIBCPP_INLINE_VISIBILITY
1034 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1035 {
1036 iterator __p = __table_.find(__k);
1037 if ( __p != end())
1038 return __p;
1039 else
1040 return emplace_hint(__h,
1041 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1042 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1043 }
1044
1045 template <class _Vp>
1046 _LIBCPP_INLINE_VISIBILITY
1047 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1048 {
1049 iterator __p = __table_.find(__k);
1050 if ( __p != end())
1051 {
1052 __p->second = _VSTD::move(__v);
1053 return _VSTD::make_pair(__p, false);
1054 }
1055 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1056 }
1057
1058 template <class _Vp>
1059 _LIBCPP_INLINE_VISIBILITY
1060 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1061 {
1062 iterator __p = __table_.find(__k);
1063 if ( __p != end())
1064 {
1065 __p->second = _VSTD::move(__v);
1066 return _VSTD::make_pair(__p, false);
1067 }
1068 return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
1069 }
1070
1071 template <class _Vp>
1072 _LIBCPP_INLINE_VISIBILITY
1073 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1074 {
1075 iterator __p = __table_.find(__k);
1076 if ( __p != end())
1077 {
1078 __p->second = _VSTD::move(__v);
1079 return __p;
1080 }
1081 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1082 }
1083
1084 template <class _Vp>
1085 _LIBCPP_INLINE_VISIBILITY
1086 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1087 {
1088 iterator __p = __table_.find(__k);
1089 if ( __p != end())
1090 {
1091 __p->second = _VSTD::move(__v);
1092 return __p;
1093 }
1094 return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
1095 }
1096#endif
1097#endif
1098#endif
1099
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001102 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001103 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107 iterator erase(const_iterator __first, const_iterator __last)
1108 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001110 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001113 void swap(unordered_map& __u)
1114 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1115 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118 hasher hash_function() const
1119 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 key_equal key_eq() const
1122 {return __table_.key_eq().key_eq();}
1123
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 pair<iterator, iterator> equal_range(const key_type& __k)
1132 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1135 {return __table_.__equal_range_unique(__k);}
1136
1137 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001138#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 mapped_type& operator[](key_type&& __k);
1140#endif
1141
1142 mapped_type& at(const key_type& __k);
1143 const mapped_type& at(const key_type& __k) const;
1144
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001146 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001148 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 size_type bucket_size(size_type __n) const
1152 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1155
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1168
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001170 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001172 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178 void reserve(size_type __n) {__table_.reserve(__n);}
1179
Howard Hinnant39213642013-07-23 22:01:58 +00001180#if _LIBCPP_DEBUG_LEVEL >= 2
1181
1182 bool __dereferenceable(const const_iterator* __i) const
1183 {return __table_.__dereferenceable(&__i->__i_);}
1184 bool __decrementable(const const_iterator* __i) const
1185 {return __table_.__decrementable(&__i->__i_);}
1186 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1187 {return __table_.__addable(&__i->__i_, __n);}
1188 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1189 {return __table_.__addable(&__i->__i_, __n);}
1190
1191#endif // _LIBCPP_DEBUG_LEVEL >= 2
1192
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001194#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001195 __node_holder __construct_node();
1196 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001197 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001198 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001199 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001200#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001201 template <class _A0, class _A1, class ..._Args>
1202 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001203#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001204#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1205 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206};
1207
1208template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1209unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1210 size_type __n, const hasher& __hf, const key_equal& __eql)
1211 : __table_(__hf, __eql)
1212{
Howard Hinnant39213642013-07-23 22:01:58 +00001213#if _LIBCPP_DEBUG_LEVEL >= 2
1214 __get_db()->__insert_c(this);
1215#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216 __table_.rehash(__n);
1217}
1218
1219template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1220unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1221 size_type __n, const hasher& __hf, const key_equal& __eql,
1222 const allocator_type& __a)
1223 : __table_(__hf, __eql, __a)
1224{
Howard Hinnant39213642013-07-23 22:01:58 +00001225#if _LIBCPP_DEBUG_LEVEL >= 2
1226 __get_db()->__insert_c(this);
1227#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228 __table_.rehash(__n);
1229}
1230
1231template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001232inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1234 const allocator_type& __a)
1235 : __table_(__a)
1236{
Howard Hinnant39213642013-07-23 22:01:58 +00001237#if _LIBCPP_DEBUG_LEVEL >= 2
1238 __get_db()->__insert_c(this);
1239#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240}
1241
1242template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1243template <class _InputIterator>
1244unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1245 _InputIterator __first, _InputIterator __last)
1246{
Howard Hinnant39213642013-07-23 22:01:58 +00001247#if _LIBCPP_DEBUG_LEVEL >= 2
1248 __get_db()->__insert_c(this);
1249#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 insert(__first, __last);
1251}
1252
1253template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1254template <class _InputIterator>
1255unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1256 _InputIterator __first, _InputIterator __last, size_type __n,
1257 const hasher& __hf, const key_equal& __eql)
1258 : __table_(__hf, __eql)
1259{
Howard Hinnant39213642013-07-23 22:01:58 +00001260#if _LIBCPP_DEBUG_LEVEL >= 2
1261 __get_db()->__insert_c(this);
1262#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 __table_.rehash(__n);
1264 insert(__first, __last);
1265}
1266
1267template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1268template <class _InputIterator>
1269unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1270 _InputIterator __first, _InputIterator __last, size_type __n,
1271 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1272 : __table_(__hf, __eql, __a)
1273{
Howard Hinnant39213642013-07-23 22:01:58 +00001274#if _LIBCPP_DEBUG_LEVEL >= 2
1275 __get_db()->__insert_c(this);
1276#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 __table_.rehash(__n);
1278 insert(__first, __last);
1279}
1280
1281template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1282unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1283 const unordered_map& __u)
1284 : __table_(__u.__table_)
1285{
Howard Hinnant39213642013-07-23 22:01:58 +00001286#if _LIBCPP_DEBUG_LEVEL >= 2
1287 __get_db()->__insert_c(this);
1288#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289 __table_.rehash(__u.bucket_count());
1290 insert(__u.begin(), __u.end());
1291}
1292
1293template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1294unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1295 const unordered_map& __u, const allocator_type& __a)
1296 : __table_(__u.__table_, __a)
1297{
Howard Hinnant39213642013-07-23 22:01:58 +00001298#if _LIBCPP_DEBUG_LEVEL >= 2
1299 __get_db()->__insert_c(this);
1300#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301 __table_.rehash(__u.bucket_count());
1302 insert(__u.begin(), __u.end());
1303}
1304
Howard Hinnant73d21a42010-09-04 23:28:19 +00001305#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306
1307template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1310 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001311 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001312 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313{
Howard Hinnant39213642013-07-23 22:01:58 +00001314#if _LIBCPP_DEBUG_LEVEL >= 2
1315 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001316 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001317#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318}
1319
1320template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1321unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1322 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001323 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324{
Howard Hinnant39213642013-07-23 22:01:58 +00001325#if _LIBCPP_DEBUG_LEVEL >= 2
1326 __get_db()->__insert_c(this);
1327#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328 if (__a != __u.get_allocator())
1329 {
1330 iterator __i = __u.begin();
1331 while (__u.size() != 0)
1332 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001333 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 );
1335 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001336#if _LIBCPP_DEBUG_LEVEL >= 2
1337 else
1338 __get_db()->swap(this, &__u);
1339#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340}
1341
Howard Hinnant73d21a42010-09-04 23:28:19 +00001342#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
Howard Hinnante3e32912011-08-12 21:56:02 +00001344#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1345
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1347unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1348 initializer_list<value_type> __il)
1349{
Howard Hinnant39213642013-07-23 22:01:58 +00001350#if _LIBCPP_DEBUG_LEVEL >= 2
1351 __get_db()->__insert_c(this);
1352#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 insert(__il.begin(), __il.end());
1354}
1355
1356template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1357unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1358 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1359 const key_equal& __eql)
1360 : __table_(__hf, __eql)
1361{
Howard Hinnant39213642013-07-23 22:01:58 +00001362#if _LIBCPP_DEBUG_LEVEL >= 2
1363 __get_db()->__insert_c(this);
1364#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365 __table_.rehash(__n);
1366 insert(__il.begin(), __il.end());
1367}
1368
1369template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1370unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1371 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1372 const key_equal& __eql, const allocator_type& __a)
1373 : __table_(__hf, __eql, __a)
1374{
Howard Hinnant39213642013-07-23 22:01:58 +00001375#if _LIBCPP_DEBUG_LEVEL >= 2
1376 __get_db()->__insert_c(this);
1377#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378 __table_.rehash(__n);
1379 insert(__il.begin(), __il.end());
1380}
1381
Howard Hinnante3e32912011-08-12 21:56:02 +00001382#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1383
Howard Hinnant73d21a42010-09-04 23:28:19 +00001384#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385
1386template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1389unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001390 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001392 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 return *this;
1394}
1395
Howard Hinnant73d21a42010-09-04 23:28:19 +00001396#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397
Howard Hinnante3e32912011-08-12 21:56:02 +00001398#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1399
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001401inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1403unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1404 initializer_list<value_type> __il)
1405{
1406 __table_.__assign_unique(__il.begin(), __il.end());
1407 return *this;
1408}
1409
Howard Hinnante3e32912011-08-12 21:56:02 +00001410#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1411
Howard Hinnant73d21a42010-09-04 23:28:19 +00001412#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413
1414template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001416unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
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 Hinnant635ce1d2012-05-25 22:04:21 +00001420 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 __h.get_deleter().__second_constructed = true;
1423 return __h;
1424}
1425
1426template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001427template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001428typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1430{
1431 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001432 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001433 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1434 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435 __h.get_deleter().__first_constructed = true;
1436 __h.get_deleter().__second_constructed = true;
1437 return __h;
1438}
1439
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001440template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001441typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1442unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001443{
1444 __node_allocator& __na = __table_.__node_alloc();
1445 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001446 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001447 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001448 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001449 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001450 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001451}
1452
Howard Hinnant73d21a42010-09-04 23:28:19 +00001453#ifndef _LIBCPP_HAS_NO_VARIADICS
1454
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001456template <class _A0, class _A1, class ..._Args>
1457typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1458unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1459 _A1&& __a1,
1460 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001462 __node_allocator& __na = __table_.__node_alloc();
1463 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1464 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1465 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1466 _VSTD::forward<_Args>(__args)...);
1467 __h.get_deleter().__first_constructed = true;
1468 __h.get_deleter().__second_constructed = true;
1469 return __h;
1470}
1471
1472template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1473template <class... _Args>
1474pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +00001475unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001476{
1477 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1479 if (__r.second)
1480 __h.release();
1481 return __r;
1482}
1483
Howard Hinnant73d21a42010-09-04 23:28:19 +00001484#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001485#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486
1487template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1488typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001489unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490{
1491 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001492 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001493 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001495 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:33 +00001497 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498}
1499
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1501template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001502inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503void
1504unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1505 _InputIterator __last)
1506{
1507 for (; __first != __last; ++__first)
1508 __table_.__insert_unique(*__first);
1509}
1510
1511template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1512_Tp&
1513unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1514{
1515 iterator __i = find(__k);
1516 if (__i != end())
1517 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001518 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1520 __h.release();
1521 return __r.first->second;
1522}
1523
Howard Hinnant73d21a42010-09-04 23:28:19 +00001524#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
1526template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1527_Tp&
1528unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1529{
1530 iterator __i = find(__k);
1531 if (__i != end())
1532 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001533 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1535 __h.release();
1536 return __r.first->second;
1537}
1538
Howard Hinnant73d21a42010-09-04 23:28:19 +00001539#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540
1541template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1542_Tp&
1543unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1544{
1545 iterator __i = find(__k);
1546#ifndef _LIBCPP_NO_EXCEPTIONS
1547 if (__i == end())
1548 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001549#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 return __i->second;
1551}
1552
1553template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1554const _Tp&
1555unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1556{
1557 const_iterator __i = find(__k);
1558#ifndef _LIBCPP_NO_EXCEPTIONS
1559 if (__i == end())
1560 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001561#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562 return __i->second;
1563}
1564
1565template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001566inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567void
1568swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1569 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001570 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571{
1572 __x.swap(__y);
1573}
1574
1575template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1576bool
1577operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1578 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1579{
1580 if (__x.size() != __y.size())
1581 return false;
1582 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1583 const_iterator;
1584 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1585 __i != __ex; ++__i)
1586 {
1587 const_iterator __j = __y.find(__i->first);
1588 if (__j == __ey || !(*__i == *__j))
1589 return false;
1590 }
1591 return true;
1592}
1593
1594template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001595inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596bool
1597operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1598 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1599{
1600 return !(__x == __y);
1601}
1602
1603template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1604 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001605class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606{
1607public:
1608 // types
1609 typedef _Key key_type;
1610 typedef _Tp mapped_type;
1611 typedef _Hash hasher;
1612 typedef _Pred key_equal;
1613 typedef _Alloc allocator_type;
1614 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001615 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 typedef value_type& reference;
1617 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001618 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1619 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620
1621private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001622 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001623 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1624 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001625 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1626 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627
1628 typedef __hash_table<__value_type, __hasher,
1629 __key_equal, __allocator_type> __table;
1630
1631 __table __table_;
1632
1633 typedef typename __table::__node_traits __node_traits;
1634 typedef typename __table::__node_allocator __node_allocator;
1635 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001636 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1637 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001639 static_assert((is_same<typename __node_traits::size_type,
1640 typename __alloc_traits::size_type>::value),
1641 "Allocator uses different size_type for different types");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642public:
1643 typedef typename __alloc_traits::pointer pointer;
1644 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001645 typedef typename __table::size_type size_type;
1646 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647
1648 typedef __hash_map_iterator<typename __table::iterator> iterator;
1649 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1650 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1651 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1652
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001654 unordered_multimap()
1655 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001656 {
1657#if _LIBCPP_DEBUG_LEVEL >= 2
1658 __get_db()->__insert_c(this);
1659#endif
1660 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1662 const key_equal& __eql = key_equal());
1663 unordered_multimap(size_type __n, const hasher& __hf,
1664 const key_equal& __eql,
1665 const allocator_type& __a);
1666 template <class _InputIterator>
1667 unordered_multimap(_InputIterator __first, _InputIterator __last);
1668 template <class _InputIterator>
1669 unordered_multimap(_InputIterator __first, _InputIterator __last,
1670 size_type __n, const hasher& __hf = hasher(),
1671 const key_equal& __eql = key_equal());
1672 template <class _InputIterator>
1673 unordered_multimap(_InputIterator __first, _InputIterator __last,
1674 size_type __n, const hasher& __hf,
1675 const key_equal& __eql,
1676 const allocator_type& __a);
1677 explicit unordered_multimap(const allocator_type& __a);
1678 unordered_multimap(const unordered_multimap& __u);
1679 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001680#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001681 unordered_multimap(unordered_multimap&& __u)
1682 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001683 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001684#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001685#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686 unordered_multimap(initializer_list<value_type> __il);
1687 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1688 const hasher& __hf = hasher(),
1689 const key_equal& __eql = key_equal());
1690 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1691 const hasher& __hf, const key_equal& __eql,
1692 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001693#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001694#if _LIBCPP_STD_VER > 11
1695 _LIBCPP_INLINE_VISIBILITY
1696 unordered_multimap(size_type __n, const allocator_type& __a)
1697 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1698 _LIBCPP_INLINE_VISIBILITY
1699 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1700 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1701 template <class _InputIterator>
1702 _LIBCPP_INLINE_VISIBILITY
1703 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1704 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1705 template <class _InputIterator>
1706 _LIBCPP_INLINE_VISIBILITY
1707 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1708 const allocator_type& __a)
1709 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1710 _LIBCPP_INLINE_VISIBILITY
1711 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1712 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1713 _LIBCPP_INLINE_VISIBILITY
1714 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1715 const allocator_type& __a)
1716 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1717#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001719 _LIBCPP_INLINE_VISIBILITY
1720 unordered_multimap& operator=(const unordered_multimap& __u)
1721 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001722#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001723 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001724#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001725 if (this != &__u) {
1726 __table_.clear();
1727 __table_.hash_function() = __u.__table_.hash_function();
1728 __table_.key_eq() = __u.__table_.key_eq();
1729 __table_.max_load_factor() = __u.__table_.max_load_factor();
1730 __table_.__copy_assign_alloc(__u.__table_);
1731 insert(__u.begin(), __u.end());
1732 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001733#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001734 return *this;
1735 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001736#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001737 unordered_multimap& operator=(unordered_multimap&& __u)
1738 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001740#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001742#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001745 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 {return allocator_type(__table_.__node_alloc());}
1747
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001749 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001751 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001753 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001756 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001758 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001760 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001762 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001764 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001766 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767
Howard Hinnant73d21a42010-09-04 23:28:19 +00001768#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001769#ifndef _LIBCPP_HAS_NO_VARIADICS
1770
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001771 template <class... _Args>
1772 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001774 template <class... _Args>
1775 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001776#endif // _LIBCPP_HAS_NO_VARIADICS
1777#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001780#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001781 template <class _Pp,
1782 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001784 iterator insert(_Pp&& __x)
1785 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001786#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 iterator insert(const_iterator __p, const value_type& __x)
1789 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001790#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001791 template <class _Pp,
1792 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001794 iterator insert(const_iterator __p, _Pp&& __x)
1795 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001796#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 template <class _InputIterator>
1798 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001799#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801 void insert(initializer_list<value_type> __il)
1802 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001803#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001807 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001808 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812 iterator erase(const_iterator __first, const_iterator __last)
1813 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001815 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001818 void swap(unordered_multimap& __u)
1819 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1820 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 hasher hash_function() const
1824 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826 key_equal key_eq() const
1827 {return __table_.key_eq().key_eq();}
1828
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 pair<iterator, iterator> equal_range(const key_type& __k)
1837 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1840 {return __table_.__equal_range_multi(__k);}
1841
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001843 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001845 size_type max_bucket_count() const _NOEXCEPT
1846 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849 size_type bucket_size(size_type __n) const
1850 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1853
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1866
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001868 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001870 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 void reserve(size_type __n) {__table_.reserve(__n);}
1877
Howard Hinnant39213642013-07-23 22:01:58 +00001878#if _LIBCPP_DEBUG_LEVEL >= 2
1879
1880 bool __dereferenceable(const const_iterator* __i) const
1881 {return __table_.__dereferenceable(&__i->__i_);}
1882 bool __decrementable(const const_iterator* __i) const
1883 {return __table_.__decrementable(&__i->__i_);}
1884 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1885 {return __table_.__addable(&__i->__i_, __n);}
1886 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1887 {return __table_.__addable(&__i->__i_, __n);}
1888
1889#endif // _LIBCPP_DEBUG_LEVEL >= 2
1890
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001892#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1893 __node_holder __construct_node();
1894 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001895 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001896 __construct_node(_A0&& __a0);
1897#ifndef _LIBCPP_HAS_NO_VARIADICS
1898 template <class _A0, class _A1, class ..._Args>
1899 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1900#endif // _LIBCPP_HAS_NO_VARIADICS
1901#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902};
1903
1904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1905unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1906 size_type __n, const hasher& __hf, const key_equal& __eql)
1907 : __table_(__hf, __eql)
1908{
Howard Hinnant39213642013-07-23 22:01:58 +00001909#if _LIBCPP_DEBUG_LEVEL >= 2
1910 __get_db()->__insert_c(this);
1911#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912 __table_.rehash(__n);
1913}
1914
1915template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1916unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1917 size_type __n, const hasher& __hf, const key_equal& __eql,
1918 const allocator_type& __a)
1919 : __table_(__hf, __eql, __a)
1920{
Howard Hinnant39213642013-07-23 22:01:58 +00001921#if _LIBCPP_DEBUG_LEVEL >= 2
1922 __get_db()->__insert_c(this);
1923#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924 __table_.rehash(__n);
1925}
1926
1927template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1928template <class _InputIterator>
1929unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1930 _InputIterator __first, _InputIterator __last)
1931{
Howard Hinnant39213642013-07-23 22:01:58 +00001932#if _LIBCPP_DEBUG_LEVEL >= 2
1933 __get_db()->__insert_c(this);
1934#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 insert(__first, __last);
1936}
1937
1938template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1939template <class _InputIterator>
1940unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1941 _InputIterator __first, _InputIterator __last, size_type __n,
1942 const hasher& __hf, const key_equal& __eql)
1943 : __table_(__hf, __eql)
1944{
Howard Hinnant39213642013-07-23 22:01:58 +00001945#if _LIBCPP_DEBUG_LEVEL >= 2
1946 __get_db()->__insert_c(this);
1947#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948 __table_.rehash(__n);
1949 insert(__first, __last);
1950}
1951
1952template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1953template <class _InputIterator>
1954unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1955 _InputIterator __first, _InputIterator __last, size_type __n,
1956 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1957 : __table_(__hf, __eql, __a)
1958{
Howard Hinnant39213642013-07-23 22:01:58 +00001959#if _LIBCPP_DEBUG_LEVEL >= 2
1960 __get_db()->__insert_c(this);
1961#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 __table_.rehash(__n);
1963 insert(__first, __last);
1964}
1965
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1969 const allocator_type& __a)
1970 : __table_(__a)
1971{
Howard Hinnant39213642013-07-23 22:01:58 +00001972#if _LIBCPP_DEBUG_LEVEL >= 2
1973 __get_db()->__insert_c(this);
1974#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001975}
1976
1977template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1978unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1979 const unordered_multimap& __u)
1980 : __table_(__u.__table_)
1981{
Howard Hinnant39213642013-07-23 22:01:58 +00001982#if _LIBCPP_DEBUG_LEVEL >= 2
1983 __get_db()->__insert_c(this);
1984#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001985 __table_.rehash(__u.bucket_count());
1986 insert(__u.begin(), __u.end());
1987}
1988
1989template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1990unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1991 const unordered_multimap& __u, const allocator_type& __a)
1992 : __table_(__u.__table_, __a)
1993{
Howard Hinnant39213642013-07-23 22:01:58 +00001994#if _LIBCPP_DEBUG_LEVEL >= 2
1995 __get_db()->__insert_c(this);
1996#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 __table_.rehash(__u.bucket_count());
1998 insert(__u.begin(), __u.end());
1999}
2000
Howard Hinnant73d21a42010-09-04 23:28:19 +00002001#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002
2003template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2006 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002007 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002008 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009{
Howard Hinnant39213642013-07-23 22:01:58 +00002010#if _LIBCPP_DEBUG_LEVEL >= 2
2011 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002012 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00002013#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014}
2015
2016template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2017unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2018 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002019 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020{
Howard Hinnant39213642013-07-23 22:01:58 +00002021#if _LIBCPP_DEBUG_LEVEL >= 2
2022 __get_db()->__insert_c(this);
2023#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 if (__a != __u.get_allocator())
2025 {
2026 iterator __i = __u.begin();
2027 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00002028 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00002030 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 );
Howard Hinnant39213642013-07-23 22:01:58 +00002032 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002034#if _LIBCPP_DEBUG_LEVEL >= 2
2035 else
2036 __get_db()->swap(this, &__u);
2037#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038}
2039
Howard Hinnant73d21a42010-09-04 23:28:19 +00002040#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041
Howard Hinnante3e32912011-08-12 21:56:02 +00002042#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2043
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002044template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2045unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2046 initializer_list<value_type> __il)
2047{
Howard Hinnant39213642013-07-23 22:01:58 +00002048#if _LIBCPP_DEBUG_LEVEL >= 2
2049 __get_db()->__insert_c(this);
2050#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002051 insert(__il.begin(), __il.end());
2052}
2053
2054template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2055unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2056 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2057 const key_equal& __eql)
2058 : __table_(__hf, __eql)
2059{
Howard Hinnant39213642013-07-23 22:01:58 +00002060#if _LIBCPP_DEBUG_LEVEL >= 2
2061 __get_db()->__insert_c(this);
2062#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 __table_.rehash(__n);
2064 insert(__il.begin(), __il.end());
2065}
2066
2067template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2068unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2069 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2070 const key_equal& __eql, const allocator_type& __a)
2071 : __table_(__hf, __eql, __a)
2072{
Howard Hinnant39213642013-07-23 22:01:58 +00002073#if _LIBCPP_DEBUG_LEVEL >= 2
2074 __get_db()->__insert_c(this);
2075#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076 __table_.rehash(__n);
2077 insert(__il.begin(), __il.end());
2078}
2079
Howard Hinnante3e32912011-08-12 21:56:02 +00002080#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2081
Howard Hinnant73d21a42010-09-04 23:28:19 +00002082#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083
2084template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2087unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002088 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002090 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091 return *this;
2092}
2093
Howard Hinnant73d21a42010-09-04 23:28:19 +00002094#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095
Howard Hinnante3e32912011-08-12 21:56:02 +00002096#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2097
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002099inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2101unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2102 initializer_list<value_type> __il)
2103{
2104 __table_.__assign_multi(__il.begin(), __il.end());
2105 return *this;
2106}
2107
Howard Hinnante3e32912011-08-12 21:56:02 +00002108#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2109
Howard Hinnant73d21a42010-09-04 23:28:19 +00002110#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111
2112template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002114unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115{
2116 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002117 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002118 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002119 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120 __h.get_deleter().__second_constructed = true;
2121 return __h;
2122}
2123
2124template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002125template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00002126typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
2128{
2129 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002130 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002131 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2132 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133 __h.get_deleter().__first_constructed = true;
2134 __h.get_deleter().__second_constructed = true;
2135 return __h;
2136}
2137
Howard Hinnant73d21a42010-09-04 23:28:19 +00002138#ifndef _LIBCPP_HAS_NO_VARIADICS
2139
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002141template <class _A0, class _A1, class ..._Args>
2142typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
2143unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
2144 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002145{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002146 __node_allocator& __na = __table_.__node_alloc();
2147 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2148 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2149 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2150 _VSTD::forward<_Args>(__args)...);
2151 __h.get_deleter().__first_constructed = true;
2152 __h.get_deleter().__second_constructed = true;
2153 return __h;
2154}
2155
2156template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2157template <class... _Args>
2158typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2159unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
2160{
2161 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 iterator __r = __table_.__node_insert_multi(__h.get());
2163 __h.release();
2164 return __r;
2165}
2166
2167template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002168template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002169typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2170unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002171 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002173 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2175 __h.release();
2176 return __r;
2177}
2178
Howard Hinnant73d21a42010-09-04 23:28:19 +00002179#endif // _LIBCPP_HAS_NO_VARIADICS
2180#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181
2182template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2183template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002184inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185void
2186unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2187 _InputIterator __last)
2188{
2189 for (; __first != __last; ++__first)
2190 __table_.__insert_multi(*__first);
2191}
2192
2193template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195void
2196swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2197 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002198 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199{
2200 __x.swap(__y);
2201}
2202
2203template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2204bool
2205operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2206 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2207{
2208 if (__x.size() != __y.size())
2209 return false;
2210 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2211 const_iterator;
2212 typedef pair<const_iterator, const_iterator> _EqRng;
2213 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2214 {
2215 _EqRng __xeq = __x.equal_range(__i->first);
2216 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002217 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2218 _VSTD::distance(__yeq.first, __yeq.second) ||
2219 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220 return false;
2221 __i = __xeq.second;
2222 }
2223 return true;
2224}
2225
2226template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002228bool
2229operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2230 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2231{
2232 return !(__x == __y);
2233}
2234
2235_LIBCPP_END_NAMESPACE_STD
2236
2237#endif // _LIBCPP_UNORDERED_MAP