blob: 85a54a7b6ddba4d0ce6b5fd6cf3e4750f3562d9f [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_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000416
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000419 __unordered_map_hasher()
420 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
421 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000423 __unordered_map_hasher(const _Hash& __h)
424 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
425 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000427 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000429 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000430 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000431 _LIBCPP_INLINE_VISIBILITY
432 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 {return __hash_(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000434 void swap(__unordered_map_hasher&__y)
435 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
436 {
437 using _VSTD::swap;
438 swap(__hash_, __y.__hash_);
439 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440};
441
Marshall Clow7d914d12015-07-13 20:04:56 +0000442template <class _Key, class _Cp, class _Hash, bool __b>
443inline _LIBCPP_INLINE_VISIBILITY
444void
445swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
446 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
447 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
448{
449 __x.swap(__y);
450}
451
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000452template <class _Key, class _Cp, class _Pred,
453 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000454 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455class __unordered_map_equal
456 : private _Pred
457{
458public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000460 __unordered_map_equal()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
462 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000464 __unordered_map_equal(const _Pred& __p)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
466 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000468 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000470 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000471 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000472 _LIBCPP_INLINE_VISIBILITY
473 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000474 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000476 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000477 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000478 void swap(__unordered_map_equal&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
483 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484};
485
Howard Hinnant9b128e02013-07-05 18:06:00 +0000486template <class _Key, class _Cp, class _Pred>
487class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488{
489 _Pred __pred_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000490
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000493 __unordered_map_equal()
494 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
495 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000497 __unordered_map_equal(const _Pred& __p)
498 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
499 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000501 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000503 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000504 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000505 _LIBCPP_INLINE_VISIBILITY
506 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000507 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000509 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000510 {return __pred_(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000511 void swap(__unordered_map_equal&__y)
512 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
513 {
514 using _VSTD::swap;
515 swap(__pred_, __y.__pred_);
516 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517};
518
Marshall Clow7d914d12015-07-13 20:04:56 +0000519template <class _Key, class _Cp, class _Pred, bool __b>
520inline _LIBCPP_INLINE_VISIBILITY
521void
522swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
523 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
524 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
525{
526 __x.swap(__y);
527}
528
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529template <class _Alloc>
530class __hash_map_node_destructor
531{
532 typedef _Alloc allocator_type;
533 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier398588c2016-02-08 23:47:13 +0000534 typedef typename __alloc_traits::value_type::value_type value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535public:
Eric Fiselier398588c2016-02-08 23:47:13 +0000536 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537private:
Eric Fiselier398588c2016-02-08 23:47:13 +0000538 typedef typename value_type::value_type::first_type first_type;
539 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540
541 allocator_type& __na_;
542
543 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
544
545public:
546 bool __first_constructed;
547 bool __second_constructed;
548
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000550 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551 : __na_(__na),
552 __first_constructed(false),
553 __second_constructed(false)
554 {}
555
Howard Hinnant73d21a42010-09-04 23:28:19 +0000556#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000559 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 : __na_(__x.__na_),
561 __first_constructed(__x.__value_constructed),
562 __second_constructed(__x.__value_constructed)
563 {
564 __x.__value_constructed = false;
565 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000566#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
569 : __na_(__x.__na_),
570 __first_constructed(__x.__value_constructed),
571 __second_constructed(__x.__value_constructed)
572 {
573 const_cast<bool&>(__x.__value_constructed) = false;
574 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000575#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000578 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 {
580 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000581 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000583 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 if (__p)
585 __alloc_traits::deallocate(__na_, __p, 1);
586 }
587};
588
Howard Hinnantff7546e2013-09-30 19:08:22 +0000589#if __cplusplus >= 201103L
590
591template <class _Key, class _Tp>
592union __hash_value_type
593{
594 typedef _Key key_type;
595 typedef _Tp mapped_type;
596 typedef pair<const key_type, mapped_type> value_type;
597 typedef pair<key_type, mapped_type> __nc_value_type;
598
599 value_type __cc;
600 __nc_value_type __nc;
601
602 template <class ..._Args>
603 _LIBCPP_INLINE_VISIBILITY
604 __hash_value_type(_Args&& ...__args)
605 : __cc(std::forward<_Args>(__args)...) {}
606
607 _LIBCPP_INLINE_VISIBILITY
608 __hash_value_type(const __hash_value_type& __v)
609 : __cc(__v.__cc) {}
610
611 _LIBCPP_INLINE_VISIBILITY
612 __hash_value_type(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000613 : __nc(_VSTD::move(__v.__nc)) {}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000614
615 _LIBCPP_INLINE_VISIBILITY
616 __hash_value_type& operator=(const __hash_value_type& __v)
617 {__nc = __v.__cc; return *this;}
618
619 _LIBCPP_INLINE_VISIBILITY
620 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000621 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000622
623 _LIBCPP_INLINE_VISIBILITY
624 ~__hash_value_type() {__cc.~value_type();}
625};
626
627#else
628
629template <class _Key, class _Tp>
630struct __hash_value_type
631{
632 typedef _Key key_type;
633 typedef _Tp mapped_type;
634 typedef pair<const key_type, mapped_type> value_type;
635
636 value_type __cc;
637
638 _LIBCPP_INLINE_VISIBILITY
639 __hash_value_type() {}
640
641 template <class _A0>
642 _LIBCPP_INLINE_VISIBILITY
643 __hash_value_type(const _A0& __a0)
644 : __cc(__a0) {}
645
646 template <class _A0, class _A1>
647 _LIBCPP_INLINE_VISIBILITY
648 __hash_value_type(const _A0& __a0, const _A1& __a1)
649 : __cc(__a0, __a1) {}
650};
651
652#endif
653
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000655class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656{
657 _HashIterator __i_;
658
Eric Fiselier398588c2016-02-08 23:47:13 +0000659 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
660 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661public:
662 typedef forward_iterator_tag iterator_category;
Eric Fiselier398588c2016-02-08 23:47:13 +0000663 typedef pair<key_type, mapped_type> value_type;
664 typedef typename _HashIterator::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 typedef value_type& reference;
Eric Fiselier398588c2016-02-08 23:47:13 +0000666 typedef typename __rebind_pointer<typename _HashIterator::pointer, value_type>::type
667 pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000670 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000673 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000676 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000678 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 __hash_map_iterator operator++(int)
684 {
685 __hash_map_iterator __t(*this);
686 ++(*this);
687 return __t;
688 }
689
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000690 friend _LIBCPP_INLINE_VISIBILITY
691 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000692 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000693 friend _LIBCPP_INLINE_VISIBILITY
694 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 {return __x.__i_ != __y.__i_;}
696
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000697 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
698 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
699 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
700 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
701 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702};
703
704template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000705class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706{
707 _HashIterator __i_;
708
Eric Fiselier398588c2016-02-08 23:47:13 +0000709 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
710 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711public:
712 typedef forward_iterator_tag iterator_category;
Eric Fiselier398588c2016-02-08 23:47:13 +0000713 typedef pair<key_type, mapped_type> value_type;
714 typedef typename _HashIterator::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 typedef const value_type& reference;
Eric Fiselier398588c2016-02-08 23:47:13 +0000716 typedef typename __rebind_pointer<typename _HashIterator::pointer, const value_type>::type
717 pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000720 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000723 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 __hash_map_const_iterator(
726 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000727 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 : __i_(__i.__i_) {}
729
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000731 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000733 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 __hash_map_const_iterator operator++(int)
739 {
740 __hash_map_const_iterator __t(*this);
741 ++(*this);
742 return __t;
743 }
744
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000745 friend _LIBCPP_INLINE_VISIBILITY
746 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000748 friend _LIBCPP_INLINE_VISIBILITY
749 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 {return __x.__i_ != __y.__i_;}
751
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000752 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
753 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
754 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
755 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756};
757
758template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
759 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000760class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761{
762public:
763 // types
764 typedef _Key key_type;
765 typedef _Tp mapped_type;
766 typedef _Hash hasher;
767 typedef _Pred key_equal;
768 typedef _Alloc allocator_type;
769 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000770 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 typedef value_type& reference;
772 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000773 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
774 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775
776private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000777 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000778 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
779 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000780 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
781 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782
783 typedef __hash_table<__value_type, __hasher,
784 __key_equal, __allocator_type> __table;
785
786 __table __table_;
787
788 typedef typename __table::__node_pointer __node_pointer;
789 typedef typename __table::__node_const_pointer __node_const_pointer;
790 typedef typename __table::__node_traits __node_traits;
791 typedef typename __table::__node_allocator __node_allocator;
792 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000793 typedef __hash_map_node_destructor<__node_allocator> _Dp;
794 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 typedef allocator_traits<allocator_type> __alloc_traits;
796public:
797 typedef typename __alloc_traits::pointer pointer;
798 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier398588c2016-02-08 23:47:13 +0000799 typedef typename __alloc_traits::size_type size_type;
800 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801
802 typedef __hash_map_iterator<typename __table::iterator> iterator;
803 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
804 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
805 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
806
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000808 unordered_map()
809 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000810 {
811#if _LIBCPP_DEBUG_LEVEL >= 2
812 __get_db()->__insert_c(this);
813#endif
814 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
816 const key_equal& __eql = key_equal());
817 unordered_map(size_type __n, const hasher& __hf,
818 const key_equal& __eql,
819 const allocator_type& __a);
820 template <class _InputIterator>
821 unordered_map(_InputIterator __first, _InputIterator __last);
822 template <class _InputIterator>
823 unordered_map(_InputIterator __first, _InputIterator __last,
824 size_type __n, const hasher& __hf = hasher(),
825 const key_equal& __eql = key_equal());
826 template <class _InputIterator>
827 unordered_map(_InputIterator __first, _InputIterator __last,
828 size_type __n, const hasher& __hf,
829 const key_equal& __eql,
830 const allocator_type& __a);
831 explicit unordered_map(const allocator_type& __a);
832 unordered_map(const unordered_map& __u);
833 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000834#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000835 unordered_map(unordered_map&& __u)
836 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000838#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000839#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840 unordered_map(initializer_list<value_type> __il);
841 unordered_map(initializer_list<value_type> __il, size_type __n,
842 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
843 unordered_map(initializer_list<value_type> __il, size_type __n,
844 const hasher& __hf, const key_equal& __eql,
845 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000846#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000847#if _LIBCPP_STD_VER > 11
848 _LIBCPP_INLINE_VISIBILITY
849 unordered_map(size_type __n, const allocator_type& __a)
850 : unordered_map(__n, hasher(), key_equal(), __a) {}
851 _LIBCPP_INLINE_VISIBILITY
852 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
853 : unordered_map(__n, __hf, key_equal(), __a) {}
854 template <class _InputIterator>
855 _LIBCPP_INLINE_VISIBILITY
856 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
857 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
858 template <class _InputIterator>
859 _LIBCPP_INLINE_VISIBILITY
860 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
861 const allocator_type& __a)
862 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
863 _LIBCPP_INLINE_VISIBILITY
864 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
865 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
866 _LIBCPP_INLINE_VISIBILITY
867 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
868 const allocator_type& __a)
869 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
870#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000872 _LIBCPP_INLINE_VISIBILITY
873 unordered_map& operator=(const unordered_map& __u)
874 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000875#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000876 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000877#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000878 if (this != &__u) {
879 __table_.clear();
880 __table_.hash_function() = __u.__table_.hash_function();
881 __table_.key_eq() = __u.__table_.key_eq();
882 __table_.max_load_factor() = __u.__table_.max_load_factor();
883 __table_.__copy_assign_alloc(__u.__table_);
884 insert(__u.begin(), __u.end());
885 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000886#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000887 return *this;
888 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000889#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000890 unordered_map& operator=(unordered_map&& __u)
891 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000893#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000895#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000898 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 {return allocator_type(__table_.__node_alloc());}
900
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000902 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000904 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000906 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000909 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000911 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000913 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000915 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000917 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000919 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920
Howard Hinnant73d21a42010-09-04 23:28:19 +0000921#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000922#ifndef _LIBCPP_HAS_NO_VARIADICS
923
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000924 template <class... _Args>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000925 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000927 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000929#if _LIBCPP_DEBUG_LEVEL >= 2
930 iterator emplace_hint(const_iterator __p, _Args&&... __args)
931 {
932 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
933 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
934 " referring to this unordered_map");
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000935 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000936 }
937#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000938 iterator emplace_hint(const_iterator, _Args&&... __args)
939 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000940#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000941#endif // _LIBCPP_HAS_NO_VARIADICS
942#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000944 pair<iterator, bool> insert(const value_type& __x)
945 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000946#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000947 template <class _Pp,
948 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000950 pair<iterator, bool> insert(_Pp&& __x)
951 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000952#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000954#if _LIBCPP_DEBUG_LEVEL >= 2
955 iterator insert(const_iterator __p, const value_type& __x)
956 {
957 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
958 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
959 " referring to this unordered_map");
960 return insert(__x).first;
961 }
962#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 iterator insert(const_iterator, const value_type& __x)
964 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000965#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000966#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000967 template <class _Pp,
968 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000970#if _LIBCPP_DEBUG_LEVEL >= 2
971 iterator insert(const_iterator __p, _Pp&& __x)
972 {
973 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
974 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
975 " referring to this unordered_map");
976 return insert(_VSTD::forward<_Pp>(__x)).first;
977 }
978#else
Howard Hinnant99968442011-11-29 18:15:50 +0000979 iterator insert(const_iterator, _Pp&& __x)
980 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000981#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000982#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 template <class _InputIterator>
984 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000985#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 void insert(initializer_list<value_type> __il)
988 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000989#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990
Marshall Clow0ce05a92015-07-07 05:45:35 +0000991#if _LIBCPP_STD_VER > 14
992#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
993#ifndef _LIBCPP_HAS_NO_VARIADICS
994 template <class... _Args>
995 _LIBCPP_INLINE_VISIBILITY
996 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
997 {
998 iterator __p = __table_.find(__k);
999 if ( __p != end())
1000 return _VSTD::make_pair(__p, false);
1001 else
1002 return _VSTD::make_pair(
1003 emplace_hint(__p,
1004 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1005 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1006 true);
1007 }
1008
1009 template <class... _Args>
1010 _LIBCPP_INLINE_VISIBILITY
1011 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1012 {
1013 iterator __p = __table_.find(__k);
1014 if ( __p != end())
1015 return _VSTD::make_pair(__p, false);
1016 else
1017 return _VSTD::make_pair(
1018 emplace_hint(__p,
1019 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1020 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1021 true);
1022 }
1023
1024 template <class... _Args>
1025 _LIBCPP_INLINE_VISIBILITY
1026 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1027 {
1028 iterator __p = __table_.find(__k);
1029 if ( __p != end())
1030 return __p;
1031 else
1032 return emplace_hint(__h,
1033 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1034 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1035 }
1036
1037 template <class... _Args>
1038 _LIBCPP_INLINE_VISIBILITY
1039 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1040 {
1041 iterator __p = __table_.find(__k);
1042 if ( __p != end())
1043 return __p;
1044 else
1045 return emplace_hint(__h,
1046 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1047 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1048 }
1049
1050 template <class _Vp>
1051 _LIBCPP_INLINE_VISIBILITY
1052 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1053 {
1054 iterator __p = __table_.find(__k);
1055 if ( __p != end())
1056 {
1057 __p->second = _VSTD::move(__v);
1058 return _VSTD::make_pair(__p, false);
1059 }
1060 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1061 }
1062
1063 template <class _Vp>
1064 _LIBCPP_INLINE_VISIBILITY
1065 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1066 {
1067 iterator __p = __table_.find(__k);
1068 if ( __p != end())
1069 {
1070 __p->second = _VSTD::move(__v);
1071 return _VSTD::make_pair(__p, false);
1072 }
1073 return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
1074 }
1075
1076 template <class _Vp>
1077 _LIBCPP_INLINE_VISIBILITY
1078 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1079 {
1080 iterator __p = __table_.find(__k);
1081 if ( __p != end())
1082 {
1083 __p->second = _VSTD::move(__v);
1084 return __p;
1085 }
1086 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1087 }
1088
1089 template <class _Vp>
1090 _LIBCPP_INLINE_VISIBILITY
1091 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1092 {
1093 iterator __p = __table_.find(__k);
1094 if ( __p != end())
1095 {
1096 __p->second = _VSTD::move(__v);
1097 return __p;
1098 }
1099 return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
1100 }
1101#endif
1102#endif
1103#endif
1104
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001108 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 iterator erase(const_iterator __first, const_iterator __last)
1113 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001115 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001118 void swap(unordered_map& __u)
1119 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1120 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 hasher hash_function() const
1124 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126 key_equal key_eq() const
1127 {return __table_.key_eq().key_eq();}
1128
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 pair<iterator, iterator> equal_range(const key_type& __k)
1137 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1140 {return __table_.__equal_range_unique(__k);}
1141
1142 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001143#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 mapped_type& operator[](key_type&& __k);
1145#endif
1146
1147 mapped_type& at(const key_type& __k);
1148 const mapped_type& at(const key_type& __k) const;
1149
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001151 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001153 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156 size_type bucket_size(size_type __n) const
1157 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1160
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1173
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001175 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001177 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 void reserve(size_type __n) {__table_.reserve(__n);}
1184
Howard Hinnant39213642013-07-23 22:01:58 +00001185#if _LIBCPP_DEBUG_LEVEL >= 2
1186
1187 bool __dereferenceable(const const_iterator* __i) const
1188 {return __table_.__dereferenceable(&__i->__i_);}
1189 bool __decrementable(const const_iterator* __i) const
1190 {return __table_.__decrementable(&__i->__i_);}
1191 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1192 {return __table_.__addable(&__i->__i_, __n);}
1193 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1194 {return __table_.__addable(&__i->__i_, __n);}
1195
1196#endif // _LIBCPP_DEBUG_LEVEL >= 2
1197
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001199#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001200 __node_holder __construct_node();
1201 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001202 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001203 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001204 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001205#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001206 template <class _A0, class _A1, class ..._Args>
1207 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001208#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001209#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1210 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211};
1212
1213template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1214unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1215 size_type __n, const hasher& __hf, const key_equal& __eql)
1216 : __table_(__hf, __eql)
1217{
Howard Hinnant39213642013-07-23 22:01:58 +00001218#if _LIBCPP_DEBUG_LEVEL >= 2
1219 __get_db()->__insert_c(this);
1220#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221 __table_.rehash(__n);
1222}
1223
1224template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1225unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1226 size_type __n, const hasher& __hf, const key_equal& __eql,
1227 const allocator_type& __a)
1228 : __table_(__hf, __eql, __a)
1229{
Howard Hinnant39213642013-07-23 22:01:58 +00001230#if _LIBCPP_DEBUG_LEVEL >= 2
1231 __get_db()->__insert_c(this);
1232#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233 __table_.rehash(__n);
1234}
1235
1236template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1239 const allocator_type& __a)
1240 : __table_(__a)
1241{
Howard Hinnant39213642013-07-23 22:01:58 +00001242#if _LIBCPP_DEBUG_LEVEL >= 2
1243 __get_db()->__insert_c(this);
1244#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245}
1246
1247template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1248template <class _InputIterator>
1249unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1250 _InputIterator __first, _InputIterator __last)
1251{
Howard Hinnant39213642013-07-23 22:01:58 +00001252#if _LIBCPP_DEBUG_LEVEL >= 2
1253 __get_db()->__insert_c(this);
1254#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 insert(__first, __last);
1256}
1257
1258template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1259template <class _InputIterator>
1260unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1261 _InputIterator __first, _InputIterator __last, size_type __n,
1262 const hasher& __hf, const key_equal& __eql)
1263 : __table_(__hf, __eql)
1264{
Howard Hinnant39213642013-07-23 22:01:58 +00001265#if _LIBCPP_DEBUG_LEVEL >= 2
1266 __get_db()->__insert_c(this);
1267#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 __table_.rehash(__n);
1269 insert(__first, __last);
1270}
1271
1272template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1273template <class _InputIterator>
1274unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1275 _InputIterator __first, _InputIterator __last, size_type __n,
1276 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1277 : __table_(__hf, __eql, __a)
1278{
Howard Hinnant39213642013-07-23 22:01:58 +00001279#if _LIBCPP_DEBUG_LEVEL >= 2
1280 __get_db()->__insert_c(this);
1281#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282 __table_.rehash(__n);
1283 insert(__first, __last);
1284}
1285
1286template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1287unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1288 const unordered_map& __u)
1289 : __table_(__u.__table_)
1290{
Howard Hinnant39213642013-07-23 22:01:58 +00001291#if _LIBCPP_DEBUG_LEVEL >= 2
1292 __get_db()->__insert_c(this);
1293#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294 __table_.rehash(__u.bucket_count());
1295 insert(__u.begin(), __u.end());
1296}
1297
1298template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1299unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1300 const unordered_map& __u, const allocator_type& __a)
1301 : __table_(__u.__table_, __a)
1302{
Howard Hinnant39213642013-07-23 22:01:58 +00001303#if _LIBCPP_DEBUG_LEVEL >= 2
1304 __get_db()->__insert_c(this);
1305#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306 __table_.rehash(__u.bucket_count());
1307 insert(__u.begin(), __u.end());
1308}
1309
Howard Hinnant73d21a42010-09-04 23:28:19 +00001310#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311
1312template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001313inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1315 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001316 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001317 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318{
Howard Hinnant39213642013-07-23 22:01:58 +00001319#if _LIBCPP_DEBUG_LEVEL >= 2
1320 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001321 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001322#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323}
1324
1325template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1326unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1327 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001328 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001329{
Howard Hinnant39213642013-07-23 22:01:58 +00001330#if _LIBCPP_DEBUG_LEVEL >= 2
1331 __get_db()->__insert_c(this);
1332#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333 if (__a != __u.get_allocator())
1334 {
1335 iterator __i = __u.begin();
1336 while (__u.size() != 0)
1337 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001338 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339 );
1340 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001341#if _LIBCPP_DEBUG_LEVEL >= 2
1342 else
1343 __get_db()->swap(this, &__u);
1344#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345}
1346
Howard Hinnant73d21a42010-09-04 23:28:19 +00001347#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348
Howard Hinnante3e32912011-08-12 21:56:02 +00001349#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1350
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1352unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1353 initializer_list<value_type> __il)
1354{
Howard Hinnant39213642013-07-23 22:01:58 +00001355#if _LIBCPP_DEBUG_LEVEL >= 2
1356 __get_db()->__insert_c(this);
1357#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358 insert(__il.begin(), __il.end());
1359}
1360
1361template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1362unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1363 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1364 const key_equal& __eql)
1365 : __table_(__hf, __eql)
1366{
Howard Hinnant39213642013-07-23 22:01:58 +00001367#if _LIBCPP_DEBUG_LEVEL >= 2
1368 __get_db()->__insert_c(this);
1369#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370 __table_.rehash(__n);
1371 insert(__il.begin(), __il.end());
1372}
1373
1374template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1375unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1376 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1377 const key_equal& __eql, const allocator_type& __a)
1378 : __table_(__hf, __eql, __a)
1379{
Howard Hinnant39213642013-07-23 22:01:58 +00001380#if _LIBCPP_DEBUG_LEVEL >= 2
1381 __get_db()->__insert_c(this);
1382#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 __table_.rehash(__n);
1384 insert(__il.begin(), __il.end());
1385}
1386
Howard Hinnante3e32912011-08-12 21:56:02 +00001387#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1388
Howard Hinnant73d21a42010-09-04 23:28:19 +00001389#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390
1391template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1394unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001395 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001397 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398 return *this;
1399}
1400
Howard Hinnant73d21a42010-09-04 23:28:19 +00001401#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402
Howard Hinnante3e32912011-08-12 21:56:02 +00001403#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1404
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1408unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1409 initializer_list<value_type> __il)
1410{
1411 __table_.__assign_unique(__il.begin(), __il.end());
1412 return *this;
1413}
1414
Howard Hinnante3e32912011-08-12 21:56:02 +00001415#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1416
Howard Hinnant73d21a42010-09-04 23:28:19 +00001417#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418
1419template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001420typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001421unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422{
1423 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001424 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001425 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 __h.get_deleter().__second_constructed = true;
1428 return __h;
1429}
1430
1431template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001432template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001433typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1435{
1436 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001437 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001438 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1439 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440 __h.get_deleter().__first_constructed = true;
1441 __h.get_deleter().__second_constructed = true;
1442 return __h;
1443}
1444
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001445template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001446typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1447unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001448{
1449 __node_allocator& __na = __table_.__node_alloc();
1450 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001451 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001452 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001453 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001454 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001455 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001456}
1457
Howard Hinnant73d21a42010-09-04 23:28:19 +00001458#ifndef _LIBCPP_HAS_NO_VARIADICS
1459
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001461template <class _A0, class _A1, class ..._Args>
1462typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1463unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1464 _A1&& __a1,
1465 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001467 __node_allocator& __na = __table_.__node_alloc();
1468 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1469 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1470 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1471 _VSTD::forward<_Args>(__args)...);
1472 __h.get_deleter().__first_constructed = true;
1473 __h.get_deleter().__second_constructed = true;
1474 return __h;
1475}
1476
1477template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1478template <class... _Args>
1479pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +00001480unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001481{
1482 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1484 if (__r.second)
1485 __h.release();
1486 return __r;
1487}
1488
Howard Hinnant73d21a42010-09-04 23:28:19 +00001489#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001490#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491
1492template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1493typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001494unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495{
1496 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001497 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001498 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001500 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:33 +00001502 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503}
1504
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1506template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508void
1509unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1510 _InputIterator __last)
1511{
1512 for (; __first != __last; ++__first)
1513 __table_.__insert_unique(*__first);
1514}
1515
1516template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1517_Tp&
1518unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1519{
1520 iterator __i = find(__k);
1521 if (__i != end())
1522 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001523 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1525 __h.release();
1526 return __r.first->second;
1527}
1528
Howard Hinnant73d21a42010-09-04 23:28:19 +00001529#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001530
1531template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1532_Tp&
1533unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1534{
1535 iterator __i = find(__k);
1536 if (__i != end())
1537 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001538 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1540 __h.release();
1541 return __r.first->second;
1542}
1543
Howard Hinnant73d21a42010-09-04 23:28:19 +00001544#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545
1546template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1547_Tp&
1548unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1549{
1550 iterator __i = find(__k);
1551#ifndef _LIBCPP_NO_EXCEPTIONS
1552 if (__i == end())
1553 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001554#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555 return __i->second;
1556}
1557
1558template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1559const _Tp&
1560unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1561{
1562 const_iterator __i = find(__k);
1563#ifndef _LIBCPP_NO_EXCEPTIONS
1564 if (__i == end())
1565 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001566#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 return __i->second;
1568}
1569
1570template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001571inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572void
1573swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1574 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001575 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576{
1577 __x.swap(__y);
1578}
1579
1580template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1581bool
1582operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1583 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1584{
1585 if (__x.size() != __y.size())
1586 return false;
1587 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1588 const_iterator;
1589 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1590 __i != __ex; ++__i)
1591 {
1592 const_iterator __j = __y.find(__i->first);
1593 if (__j == __ey || !(*__i == *__j))
1594 return false;
1595 }
1596 return true;
1597}
1598
1599template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601bool
1602operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1603 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1604{
1605 return !(__x == __y);
1606}
1607
1608template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1609 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001610class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611{
1612public:
1613 // types
1614 typedef _Key key_type;
1615 typedef _Tp mapped_type;
1616 typedef _Hash hasher;
1617 typedef _Pred key_equal;
1618 typedef _Alloc allocator_type;
1619 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001620 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 typedef value_type& reference;
1622 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001623 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1624 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625
1626private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001627 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001628 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1629 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001630 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1631 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632
1633 typedef __hash_table<__value_type, __hasher,
1634 __key_equal, __allocator_type> __table;
1635
1636 __table __table_;
1637
1638 typedef typename __table::__node_traits __node_traits;
1639 typedef typename __table::__node_allocator __node_allocator;
1640 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001641 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1642 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643 typedef allocator_traits<allocator_type> __alloc_traits;
1644public:
1645 typedef typename __alloc_traits::pointer pointer;
1646 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier398588c2016-02-08 23:47:13 +00001647 typedef typename __alloc_traits::size_type size_type;
1648 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649
1650 typedef __hash_map_iterator<typename __table::iterator> iterator;
1651 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1652 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1653 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1654
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001656 unordered_multimap()
1657 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001658 {
1659#if _LIBCPP_DEBUG_LEVEL >= 2
1660 __get_db()->__insert_c(this);
1661#endif
1662 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1664 const key_equal& __eql = key_equal());
1665 unordered_multimap(size_type __n, const hasher& __hf,
1666 const key_equal& __eql,
1667 const allocator_type& __a);
1668 template <class _InputIterator>
1669 unordered_multimap(_InputIterator __first, _InputIterator __last);
1670 template <class _InputIterator>
1671 unordered_multimap(_InputIterator __first, _InputIterator __last,
1672 size_type __n, const hasher& __hf = hasher(),
1673 const key_equal& __eql = key_equal());
1674 template <class _InputIterator>
1675 unordered_multimap(_InputIterator __first, _InputIterator __last,
1676 size_type __n, const hasher& __hf,
1677 const key_equal& __eql,
1678 const allocator_type& __a);
1679 explicit unordered_multimap(const allocator_type& __a);
1680 unordered_multimap(const unordered_multimap& __u);
1681 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001682#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001683 unordered_multimap(unordered_multimap&& __u)
1684 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001686#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001687#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688 unordered_multimap(initializer_list<value_type> __il);
1689 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1690 const hasher& __hf = hasher(),
1691 const key_equal& __eql = key_equal());
1692 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1693 const hasher& __hf, const key_equal& __eql,
1694 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001695#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001696#if _LIBCPP_STD_VER > 11
1697 _LIBCPP_INLINE_VISIBILITY
1698 unordered_multimap(size_type __n, const allocator_type& __a)
1699 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1700 _LIBCPP_INLINE_VISIBILITY
1701 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1702 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1703 template <class _InputIterator>
1704 _LIBCPP_INLINE_VISIBILITY
1705 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1706 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1707 template <class _InputIterator>
1708 _LIBCPP_INLINE_VISIBILITY
1709 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1710 const allocator_type& __a)
1711 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1712 _LIBCPP_INLINE_VISIBILITY
1713 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1714 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1715 _LIBCPP_INLINE_VISIBILITY
1716 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1717 const allocator_type& __a)
1718 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1719#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001721 _LIBCPP_INLINE_VISIBILITY
1722 unordered_multimap& operator=(const unordered_multimap& __u)
1723 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001724#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001725 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001726#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001727 if (this != &__u) {
1728 __table_.clear();
1729 __table_.hash_function() = __u.__table_.hash_function();
1730 __table_.key_eq() = __u.__table_.key_eq();
1731 __table_.max_load_factor() = __u.__table_.max_load_factor();
1732 __table_.__copy_assign_alloc(__u.__table_);
1733 insert(__u.begin(), __u.end());
1734 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001735#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001736 return *this;
1737 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001738#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001739 unordered_multimap& operator=(unordered_multimap&& __u)
1740 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001742#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001744#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001747 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001748 {return allocator_type(__table_.__node_alloc());}
1749
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001751 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001753 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001755 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001758 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001760 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001762 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001764 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001766 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001768 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769
Howard Hinnant73d21a42010-09-04 23:28:19 +00001770#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001771#ifndef _LIBCPP_HAS_NO_VARIADICS
1772
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001773 template <class... _Args>
1774 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001776 template <class... _Args>
1777 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001778#endif // _LIBCPP_HAS_NO_VARIADICS
1779#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001782#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001783 template <class _Pp,
1784 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001786 iterator insert(_Pp&& __x)
1787 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001788#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790 iterator insert(const_iterator __p, const value_type& __x)
1791 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001792#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001793 template <class _Pp,
1794 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001796 iterator insert(const_iterator __p, _Pp&& __x)
1797 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001798#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 template <class _InputIterator>
1800 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001801#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803 void insert(initializer_list<value_type> __il)
1804 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001805#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001809 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001810 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814 iterator erase(const_iterator __first, const_iterator __last)
1815 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001817 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001820 void swap(unordered_multimap& __u)
1821 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1822 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825 hasher hash_function() const
1826 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 key_equal key_eq() const
1829 {return __table_.key_eq().key_eq();}
1830
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838 pair<iterator, iterator> equal_range(const key_type& __k)
1839 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1842 {return __table_.__equal_range_multi(__k);}
1843
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001845 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001847 size_type max_bucket_count() const _NOEXCEPT
1848 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851 size_type bucket_size(size_type __n) const
1852 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1855
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1868
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001870 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001872 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 void reserve(size_type __n) {__table_.reserve(__n);}
1879
Howard Hinnant39213642013-07-23 22:01:58 +00001880#if _LIBCPP_DEBUG_LEVEL >= 2
1881
1882 bool __dereferenceable(const const_iterator* __i) const
1883 {return __table_.__dereferenceable(&__i->__i_);}
1884 bool __decrementable(const const_iterator* __i) const
1885 {return __table_.__decrementable(&__i->__i_);}
1886 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1887 {return __table_.__addable(&__i->__i_, __n);}
1888 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1889 {return __table_.__addable(&__i->__i_, __n);}
1890
1891#endif // _LIBCPP_DEBUG_LEVEL >= 2
1892
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001894#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1895 __node_holder __construct_node();
1896 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001897 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001898 __construct_node(_A0&& __a0);
1899#ifndef _LIBCPP_HAS_NO_VARIADICS
1900 template <class _A0, class _A1, class ..._Args>
1901 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1902#endif // _LIBCPP_HAS_NO_VARIADICS
1903#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904};
1905
1906template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1907unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1908 size_type __n, const hasher& __hf, const key_equal& __eql)
1909 : __table_(__hf, __eql)
1910{
Howard Hinnant39213642013-07-23 22:01:58 +00001911#if _LIBCPP_DEBUG_LEVEL >= 2
1912 __get_db()->__insert_c(this);
1913#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914 __table_.rehash(__n);
1915}
1916
1917template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1918unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1919 size_type __n, const hasher& __hf, const key_equal& __eql,
1920 const allocator_type& __a)
1921 : __table_(__hf, __eql, __a)
1922{
Howard Hinnant39213642013-07-23 22:01:58 +00001923#if _LIBCPP_DEBUG_LEVEL >= 2
1924 __get_db()->__insert_c(this);
1925#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926 __table_.rehash(__n);
1927}
1928
1929template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1930template <class _InputIterator>
1931unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1932 _InputIterator __first, _InputIterator __last)
1933{
Howard Hinnant39213642013-07-23 22:01:58 +00001934#if _LIBCPP_DEBUG_LEVEL >= 2
1935 __get_db()->__insert_c(this);
1936#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001937 insert(__first, __last);
1938}
1939
1940template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1941template <class _InputIterator>
1942unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1943 _InputIterator __first, _InputIterator __last, size_type __n,
1944 const hasher& __hf, const key_equal& __eql)
1945 : __table_(__hf, __eql)
1946{
Howard Hinnant39213642013-07-23 22:01:58 +00001947#if _LIBCPP_DEBUG_LEVEL >= 2
1948 __get_db()->__insert_c(this);
1949#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950 __table_.rehash(__n);
1951 insert(__first, __last);
1952}
1953
1954template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1955template <class _InputIterator>
1956unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1957 _InputIterator __first, _InputIterator __last, size_type __n,
1958 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1959 : __table_(__hf, __eql, __a)
1960{
Howard Hinnant39213642013-07-23 22:01:58 +00001961#if _LIBCPP_DEBUG_LEVEL >= 2
1962 __get_db()->__insert_c(this);
1963#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 __table_.rehash(__n);
1965 insert(__first, __last);
1966}
1967
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1971 const allocator_type& __a)
1972 : __table_(__a)
1973{
Howard Hinnant39213642013-07-23 22:01:58 +00001974#if _LIBCPP_DEBUG_LEVEL >= 2
1975 __get_db()->__insert_c(this);
1976#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977}
1978
1979template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1980unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1981 const unordered_multimap& __u)
1982 : __table_(__u.__table_)
1983{
Howard Hinnant39213642013-07-23 22:01:58 +00001984#if _LIBCPP_DEBUG_LEVEL >= 2
1985 __get_db()->__insert_c(this);
1986#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987 __table_.rehash(__u.bucket_count());
1988 insert(__u.begin(), __u.end());
1989}
1990
1991template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1992unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1993 const unordered_multimap& __u, const allocator_type& __a)
1994 : __table_(__u.__table_, __a)
1995{
Howard Hinnant39213642013-07-23 22:01:58 +00001996#if _LIBCPP_DEBUG_LEVEL >= 2
1997 __get_db()->__insert_c(this);
1998#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001999 __table_.rehash(__u.bucket_count());
2000 insert(__u.begin(), __u.end());
2001}
2002
Howard Hinnant73d21a42010-09-04 23:28:19 +00002003#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002004
2005template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2008 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002009 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002010 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011{
Howard Hinnant39213642013-07-23 22:01:58 +00002012#if _LIBCPP_DEBUG_LEVEL >= 2
2013 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002014 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00002015#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016}
2017
2018template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2019unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2020 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002021 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022{
Howard Hinnant39213642013-07-23 22:01:58 +00002023#if _LIBCPP_DEBUG_LEVEL >= 2
2024 __get_db()->__insert_c(this);
2025#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026 if (__a != __u.get_allocator())
2027 {
2028 iterator __i = __u.begin();
2029 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00002030 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00002032 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033 );
Howard Hinnant39213642013-07-23 22:01:58 +00002034 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002035 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002036#if _LIBCPP_DEBUG_LEVEL >= 2
2037 else
2038 __get_db()->swap(this, &__u);
2039#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040}
2041
Howard Hinnant73d21a42010-09-04 23:28:19 +00002042#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043
Howard Hinnante3e32912011-08-12 21:56:02 +00002044#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2045
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2047unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2048 initializer_list<value_type> __il)
2049{
Howard Hinnant39213642013-07-23 22:01:58 +00002050#if _LIBCPP_DEBUG_LEVEL >= 2
2051 __get_db()->__insert_c(this);
2052#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053 insert(__il.begin(), __il.end());
2054}
2055
2056template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2057unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2058 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2059 const key_equal& __eql)
2060 : __table_(__hf, __eql)
2061{
Howard Hinnant39213642013-07-23 22:01:58 +00002062#if _LIBCPP_DEBUG_LEVEL >= 2
2063 __get_db()->__insert_c(this);
2064#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065 __table_.rehash(__n);
2066 insert(__il.begin(), __il.end());
2067}
2068
2069template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2070unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2071 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2072 const key_equal& __eql, const allocator_type& __a)
2073 : __table_(__hf, __eql, __a)
2074{
Howard Hinnant39213642013-07-23 22:01:58 +00002075#if _LIBCPP_DEBUG_LEVEL >= 2
2076 __get_db()->__insert_c(this);
2077#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078 __table_.rehash(__n);
2079 insert(__il.begin(), __il.end());
2080}
2081
Howard Hinnante3e32912011-08-12 21:56:02 +00002082#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2083
Howard Hinnant73d21a42010-09-04 23:28:19 +00002084#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085
2086template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2089unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002090 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002092 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093 return *this;
2094}
2095
Howard Hinnant73d21a42010-09-04 23:28:19 +00002096#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097
Howard Hinnante3e32912011-08-12 21:56:02 +00002098#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2099
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2103unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2104 initializer_list<value_type> __il)
2105{
2106 __table_.__assign_multi(__il.begin(), __il.end());
2107 return *this;
2108}
2109
Howard Hinnante3e32912011-08-12 21:56:02 +00002110#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2111
Howard Hinnant73d21a42010-09-04 23:28:19 +00002112#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113
2114template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002116unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002117{
2118 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002119 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002120 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122 __h.get_deleter().__second_constructed = true;
2123 return __h;
2124}
2125
2126template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002127template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00002128typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
2130{
2131 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002132 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002133 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2134 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135 __h.get_deleter().__first_constructed = true;
2136 __h.get_deleter().__second_constructed = true;
2137 return __h;
2138}
2139
Howard Hinnant73d21a42010-09-04 23:28:19 +00002140#ifndef _LIBCPP_HAS_NO_VARIADICS
2141
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002143template <class _A0, class _A1, class ..._Args>
2144typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
2145unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
2146 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002148 __node_allocator& __na = __table_.__node_alloc();
2149 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2150 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2151 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2152 _VSTD::forward<_Args>(__args)...);
2153 __h.get_deleter().__first_constructed = true;
2154 __h.get_deleter().__second_constructed = true;
2155 return __h;
2156}
2157
2158template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2159template <class... _Args>
2160typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2161unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
2162{
2163 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002164 iterator __r = __table_.__node_insert_multi(__h.get());
2165 __h.release();
2166 return __r;
2167}
2168
2169template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002170template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2172unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002173 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002175 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002176 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2177 __h.release();
2178 return __r;
2179}
2180
Howard Hinnant73d21a42010-09-04 23:28:19 +00002181#endif // _LIBCPP_HAS_NO_VARIADICS
2182#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183
2184template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2185template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187void
2188unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2189 _InputIterator __last)
2190{
2191 for (; __first != __last; ++__first)
2192 __table_.__insert_multi(*__first);
2193}
2194
2195template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197void
2198swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2199 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002200 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201{
2202 __x.swap(__y);
2203}
2204
2205template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2206bool
2207operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2208 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2209{
2210 if (__x.size() != __y.size())
2211 return false;
2212 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2213 const_iterator;
2214 typedef pair<const_iterator, const_iterator> _EqRng;
2215 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2216 {
2217 _EqRng __xeq = __x.equal_range(__i->first);
2218 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002219 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2220 _VSTD::distance(__yeq.first, __yeq.second) ||
2221 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 return false;
2223 __i = __xeq.second;
2224 }
2225 return true;
2226}
2227
2228template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230bool
2231operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2232 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2233{
2234 return !(__x == __y);
2235}
2236
2237_LIBCPP_END_NAMESPACE_STD
2238
2239#endif // _LIBCPP_UNORDERED_MAP