blob: a05c2b5ef8547f81cdfa12f297a11208ea16c3ad [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{
Eric Fiselier774c7c52016-02-10 20:46:23 +0000387 typedef typename __key_value_types<_Cp>::__map_value_type _PairT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000390 __unordered_map_hasher()
391 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
392 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000394 __unordered_map_hasher(const _Hash& __h)
395 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
396 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000398 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000400 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000401 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000402 _LIBCPP_INLINE_VISIBILITY
403 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000405 void swap(__unordered_map_hasher&__y)
406 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
407 {
408 using _VSTD::swap;
409 swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y));
410 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411};
412
Howard Hinnant9b128e02013-07-05 18:06:00 +0000413template <class _Key, class _Cp, class _Hash>
414class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415{
416 _Hash __hash_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000417
Eric Fiselier774c7c52016-02-10 20:46:23 +0000418 typedef typename __key_value_types<_Cp>::__map_value_type _PairT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000421 __unordered_map_hasher()
422 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
423 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000425 __unordered_map_hasher(const _Hash& __h)
426 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
427 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000429 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000431 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000432 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000433 _LIBCPP_INLINE_VISIBILITY
434 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 {return __hash_(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000436 void swap(__unordered_map_hasher&__y)
437 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
438 {
439 using _VSTD::swap;
440 swap(__hash_, __y.__hash_);
441 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442};
443
Marshall Clow7d914d12015-07-13 20:04:56 +0000444template <class _Key, class _Cp, class _Hash, bool __b>
445inline _LIBCPP_INLINE_VISIBILITY
446void
447swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
448 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
449 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
450{
451 __x.swap(__y);
452}
453
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000454template <class _Key, class _Cp, class _Pred,
455 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000456 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457class __unordered_map_equal
458 : private _Pred
459{
Eric Fiselier774c7c52016-02-10 20:46:23 +0000460 typedef typename __key_value_types<_Cp>::__map_value_type _PairT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000463 __unordered_map_equal()
464 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
465 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000467 __unordered_map_equal(const _Pred& __p)
468 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
469 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000471 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000473 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000474 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000475 _LIBCPP_INLINE_VISIBILITY
476 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000477 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000479 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000480 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000481 void swap(__unordered_map_equal&__y)
482 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
483 {
484 using _VSTD::swap;
485 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
486 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487};
488
Howard Hinnant9b128e02013-07-05 18:06:00 +0000489template <class _Key, class _Cp, class _Pred>
490class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491{
492 _Pred __pred_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000493
Eric Fiselier774c7c52016-02-10 20:46:23 +0000494 typedef typename __key_value_types<_Cp>::__map_value_type _PairT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000497 __unordered_map_equal()
498 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
499 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000501 __unordered_map_equal(const _Pred& __p)
502 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
503 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000505 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000507 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000508 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000509 _LIBCPP_INLINE_VISIBILITY
510 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000511 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000513 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000514 {return __pred_(__x, __y.__cc.first);}
Eric Fiselier774c7c52016-02-10 20:46:23 +0000515 _LIBCPP_INLINE_VISIBILITY
516 bool operator()(const _Key& __x, const _PairT& __y) const
517 {return __pred_(__x, __y.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000518 void swap(__unordered_map_equal&__y)
519 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
520 {
521 using _VSTD::swap;
522 swap(__pred_, __y.__pred_);
523 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524};
525
Marshall Clow7d914d12015-07-13 20:04:56 +0000526template <class _Key, class _Cp, class _Pred, bool __b>
527inline _LIBCPP_INLINE_VISIBILITY
528void
529swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
530 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
531 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
532{
533 __x.swap(__y);
534}
535
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536template <class _Alloc>
537class __hash_map_node_destructor
538{
539 typedef _Alloc allocator_type;
540 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000541
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542public:
Eric Fiselier774c7c52016-02-10 20:46:23 +0000543
544 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546
547 allocator_type& __na_;
548
549 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
550
551public:
552 bool __first_constructed;
553 bool __second_constructed;
554
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000556 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557 : __na_(__na),
558 __first_constructed(false),
559 __second_constructed(false)
560 {}
561
Howard Hinnant73d21a42010-09-04 23:28:19 +0000562#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000565 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 : __na_(__x.__na_),
567 __first_constructed(__x.__value_constructed),
568 __second_constructed(__x.__value_constructed)
569 {
570 __x.__value_constructed = false;
571 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000572#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
575 : __na_(__x.__na_),
576 __first_constructed(__x.__value_constructed),
577 __second_constructed(__x.__value_constructed)
578 {
579 const_cast<bool&>(__x.__value_constructed) = false;
580 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000581#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000584 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585 {
586 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000587 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000589 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590 if (__p)
591 __alloc_traits::deallocate(__na_, __p, 1);
592 }
593};
594
Howard Hinnantff7546e2013-09-30 19:08:22 +0000595#if __cplusplus >= 201103L
596
597template <class _Key, class _Tp>
598union __hash_value_type
599{
600 typedef _Key key_type;
601 typedef _Tp mapped_type;
602 typedef pair<const key_type, mapped_type> value_type;
603 typedef pair<key_type, mapped_type> __nc_value_type;
604
605 value_type __cc;
606 __nc_value_type __nc;
607
608 template <class ..._Args>
609 _LIBCPP_INLINE_VISIBILITY
610 __hash_value_type(_Args&& ...__args)
611 : __cc(std::forward<_Args>(__args)...) {}
612
613 _LIBCPP_INLINE_VISIBILITY
614 __hash_value_type(const __hash_value_type& __v)
615 : __cc(__v.__cc) {}
616
617 _LIBCPP_INLINE_VISIBILITY
618 __hash_value_type(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000619 : __nc(_VSTD::move(__v.__nc)) {}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000620
621 _LIBCPP_INLINE_VISIBILITY
622 __hash_value_type& operator=(const __hash_value_type& __v)
623 {__nc = __v.__cc; return *this;}
624
625 _LIBCPP_INLINE_VISIBILITY
626 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000627 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000628
629 _LIBCPP_INLINE_VISIBILITY
630 ~__hash_value_type() {__cc.~value_type();}
631};
632
633#else
634
635template <class _Key, class _Tp>
636struct __hash_value_type
637{
638 typedef _Key key_type;
639 typedef _Tp mapped_type;
640 typedef pair<const key_type, mapped_type> value_type;
641
642 value_type __cc;
643
644 _LIBCPP_INLINE_VISIBILITY
645 __hash_value_type() {}
646
647 template <class _A0>
648 _LIBCPP_INLINE_VISIBILITY
649 __hash_value_type(const _A0& __a0)
650 : __cc(__a0) {}
651
652 template <class _A0, class _A1>
653 _LIBCPP_INLINE_VISIBILITY
654 __hash_value_type(const _A0& __a0, const _A1& __a1)
655 : __cc(__a0, __a1) {}
656};
657
658#endif
659
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000661class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662{
663 _HashIterator __i_;
664
Eric Fiselier774c7c52016-02-10 20:46:23 +0000665 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
666
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667public:
668 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000669 typedef typename _NodeTypes::__map_value_type value_type;
670 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 typedef value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000672 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000675 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000678 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000681 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000683 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 __hash_map_iterator operator++(int)
689 {
690 __hash_map_iterator __t(*this);
691 ++(*this);
692 return __t;
693 }
694
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000695 friend _LIBCPP_INLINE_VISIBILITY
696 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000698 friend _LIBCPP_INLINE_VISIBILITY
699 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 {return __x.__i_ != __y.__i_;}
701
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000702 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
703 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
704 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
705 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
706 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707};
708
709template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000710class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711{
712 _HashIterator __i_;
713
Eric Fiselier774c7c52016-02-10 20:46:23 +0000714 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
715
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716public:
717 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000718 typedef typename _NodeTypes::__map_value_type value_type;
719 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720 typedef const value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000721 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000724 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000727 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 __hash_map_const_iterator(
730 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000731 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 : __i_(__i.__i_) {}
733
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000735 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000737 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 __hash_map_const_iterator operator++(int)
743 {
744 __hash_map_const_iterator __t(*this);
745 ++(*this);
746 return __t;
747 }
748
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000749 friend _LIBCPP_INLINE_VISIBILITY
750 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000752 friend _LIBCPP_INLINE_VISIBILITY
753 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 {return __x.__i_ != __y.__i_;}
755
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000756 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
757 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
758 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
759 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760};
761
762template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
763 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000764class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765{
766public:
767 // types
768 typedef _Key key_type;
769 typedef _Tp mapped_type;
770 typedef _Hash hasher;
771 typedef _Pred key_equal;
772 typedef _Alloc allocator_type;
773 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000774 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 typedef value_type& reference;
776 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000777 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
778 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779
780private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000781 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000782 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
783 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000784 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
785 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786
787 typedef __hash_table<__value_type, __hasher,
788 __key_equal, __allocator_type> __table;
789
790 __table __table_;
791
792 typedef typename __table::__node_pointer __node_pointer;
793 typedef typename __table::__node_const_pointer __node_const_pointer;
794 typedef typename __table::__node_traits __node_traits;
795 typedef typename __table::__node_allocator __node_allocator;
796 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000797 typedef __hash_map_node_destructor<__node_allocator> _Dp;
798 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 typedef allocator_traits<allocator_type> __alloc_traits;
800public:
801 typedef typename __alloc_traits::pointer pointer;
802 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000803 typedef typename __table::size_type size_type;
804 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805
806 typedef __hash_map_iterator<typename __table::iterator> iterator;
807 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
808 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
809 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
810
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000812 unordered_map()
813 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000814 {
815#if _LIBCPP_DEBUG_LEVEL >= 2
816 __get_db()->__insert_c(this);
817#endif
818 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
820 const key_equal& __eql = key_equal());
821 unordered_map(size_type __n, const hasher& __hf,
822 const key_equal& __eql,
823 const allocator_type& __a);
824 template <class _InputIterator>
825 unordered_map(_InputIterator __first, _InputIterator __last);
826 template <class _InputIterator>
827 unordered_map(_InputIterator __first, _InputIterator __last,
828 size_type __n, const hasher& __hf = hasher(),
829 const key_equal& __eql = key_equal());
830 template <class _InputIterator>
831 unordered_map(_InputIterator __first, _InputIterator __last,
832 size_type __n, const hasher& __hf,
833 const key_equal& __eql,
834 const allocator_type& __a);
835 explicit unordered_map(const allocator_type& __a);
836 unordered_map(const unordered_map& __u);
837 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000838#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000839 unordered_map(unordered_map&& __u)
840 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000842#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000843#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844 unordered_map(initializer_list<value_type> __il);
845 unordered_map(initializer_list<value_type> __il, size_type __n,
846 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
847 unordered_map(initializer_list<value_type> __il, size_type __n,
848 const hasher& __hf, const key_equal& __eql,
849 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000850#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000851#if _LIBCPP_STD_VER > 11
852 _LIBCPP_INLINE_VISIBILITY
853 unordered_map(size_type __n, const allocator_type& __a)
854 : unordered_map(__n, hasher(), key_equal(), __a) {}
855 _LIBCPP_INLINE_VISIBILITY
856 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
857 : unordered_map(__n, __hf, key_equal(), __a) {}
858 template <class _InputIterator>
859 _LIBCPP_INLINE_VISIBILITY
860 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
861 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
862 template <class _InputIterator>
863 _LIBCPP_INLINE_VISIBILITY
864 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
865 const allocator_type& __a)
866 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
867 _LIBCPP_INLINE_VISIBILITY
868 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
869 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
870 _LIBCPP_INLINE_VISIBILITY
871 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
872 const allocator_type& __a)
873 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
874#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000876 _LIBCPP_INLINE_VISIBILITY
877 unordered_map& operator=(const unordered_map& __u)
878 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000879#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000880 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000881#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000882 if (this != &__u) {
883 __table_.clear();
884 __table_.hash_function() = __u.__table_.hash_function();
885 __table_.key_eq() = __u.__table_.key_eq();
886 __table_.max_load_factor() = __u.__table_.max_load_factor();
887 __table_.__copy_assign_alloc(__u.__table_);
888 insert(__u.begin(), __u.end());
889 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000890#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000891 return *this;
892 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000893#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000894 unordered_map& operator=(unordered_map&& __u)
895 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000897#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000899#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000902 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 {return allocator_type(__table_.__node_alloc());}
904
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000906 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000908 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000910 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000913 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000915 iterator end() _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 begin() 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 end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000921 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000923 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924
Howard Hinnant73d21a42010-09-04 23:28:19 +0000925#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000926#ifndef _LIBCPP_HAS_NO_VARIADICS
927
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000928 template <class... _Args>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000929 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000931 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000933#if _LIBCPP_DEBUG_LEVEL >= 2
934 iterator emplace_hint(const_iterator __p, _Args&&... __args)
935 {
936 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
937 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
938 " referring to this unordered_map");
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +0000939 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000940 }
941#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000942 iterator emplace_hint(const_iterator, _Args&&... __args)
943 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000944#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000945#endif // _LIBCPP_HAS_NO_VARIADICS
946#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948 pair<iterator, bool> insert(const value_type& __x)
949 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000950#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000951 template <class _Pp,
952 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000954 pair<iterator, bool> insert(_Pp&& __x)
955 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000956#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000958#if _LIBCPP_DEBUG_LEVEL >= 2
959 iterator insert(const_iterator __p, const value_type& __x)
960 {
961 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
962 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
963 " referring to this unordered_map");
964 return insert(__x).first;
965 }
966#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 iterator insert(const_iterator, const value_type& __x)
968 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000969#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000970#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000971 template <class _Pp,
972 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000974#if _LIBCPP_DEBUG_LEVEL >= 2
975 iterator insert(const_iterator __p, _Pp&& __x)
976 {
977 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
978 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
979 " referring to this unordered_map");
980 return insert(_VSTD::forward<_Pp>(__x)).first;
981 }
982#else
Howard Hinnant99968442011-11-29 18:15:50 +0000983 iterator insert(const_iterator, _Pp&& __x)
984 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000985#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000986#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 template <class _InputIterator>
988 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000989#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 void insert(initializer_list<value_type> __il)
992 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000993#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994
Marshall Clow0ce05a92015-07-07 05:45:35 +0000995#if _LIBCPP_STD_VER > 14
996#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
997#ifndef _LIBCPP_HAS_NO_VARIADICS
998 template <class... _Args>
999 _LIBCPP_INLINE_VISIBILITY
1000 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1001 {
1002 iterator __p = __table_.find(__k);
1003 if ( __p != end())
1004 return _VSTD::make_pair(__p, false);
1005 else
1006 return _VSTD::make_pair(
1007 emplace_hint(__p,
1008 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1009 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1010 true);
1011 }
1012
1013 template <class... _Args>
1014 _LIBCPP_INLINE_VISIBILITY
1015 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1016 {
1017 iterator __p = __table_.find(__k);
1018 if ( __p != end())
1019 return _VSTD::make_pair(__p, false);
1020 else
1021 return _VSTD::make_pair(
1022 emplace_hint(__p,
1023 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1024 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1025 true);
1026 }
1027
1028 template <class... _Args>
1029 _LIBCPP_INLINE_VISIBILITY
1030 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1031 {
1032 iterator __p = __table_.find(__k);
1033 if ( __p != end())
1034 return __p;
1035 else
1036 return emplace_hint(__h,
1037 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1038 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1039 }
1040
1041 template <class... _Args>
1042 _LIBCPP_INLINE_VISIBILITY
1043 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1044 {
1045 iterator __p = __table_.find(__k);
1046 if ( __p != end())
1047 return __p;
1048 else
1049 return emplace_hint(__h,
1050 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1051 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1052 }
1053
1054 template <class _Vp>
1055 _LIBCPP_INLINE_VISIBILITY
1056 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1057 {
1058 iterator __p = __table_.find(__k);
1059 if ( __p != end())
1060 {
1061 __p->second = _VSTD::move(__v);
1062 return _VSTD::make_pair(__p, false);
1063 }
1064 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1065 }
1066
1067 template <class _Vp>
1068 _LIBCPP_INLINE_VISIBILITY
1069 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1070 {
1071 iterator __p = __table_.find(__k);
1072 if ( __p != end())
1073 {
1074 __p->second = _VSTD::move(__v);
1075 return _VSTD::make_pair(__p, false);
1076 }
1077 return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
1078 }
1079
1080 template <class _Vp>
1081 _LIBCPP_INLINE_VISIBILITY
1082 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1083 {
1084 iterator __p = __table_.find(__k);
1085 if ( __p != end())
1086 {
1087 __p->second = _VSTD::move(__v);
1088 return __p;
1089 }
1090 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1091 }
1092
1093 template <class _Vp>
1094 _LIBCPP_INLINE_VISIBILITY
1095 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1096 {
1097 iterator __p = __table_.find(__k);
1098 if ( __p != end())
1099 {
1100 __p->second = _VSTD::move(__v);
1101 return __p;
1102 }
1103 return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
1104 }
1105#endif
1106#endif
1107#endif
1108
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001111 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001112 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001116 iterator erase(const_iterator __first, const_iterator __last)
1117 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001119 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001122 void swap(unordered_map& __u)
1123 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1124 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 hasher hash_function() const
1128 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 key_equal key_eq() const
1131 {return __table_.key_eq().key_eq();}
1132
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140 pair<iterator, iterator> equal_range(const key_type& __k)
1141 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1144 {return __table_.__equal_range_unique(__k);}
1145
1146 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001147#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 mapped_type& operator[](key_type&& __k);
1149#endif
1150
1151 mapped_type& at(const key_type& __k);
1152 const mapped_type& at(const key_type& __k) const;
1153
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001155 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001157 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 size_type bucket_size(size_type __n) const
1161 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1164
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 const_local_iterator begin(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 end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1177
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001179 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001181 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187 void reserve(size_type __n) {__table_.reserve(__n);}
1188
Howard Hinnant39213642013-07-23 22:01:58 +00001189#if _LIBCPP_DEBUG_LEVEL >= 2
1190
1191 bool __dereferenceable(const const_iterator* __i) const
1192 {return __table_.__dereferenceable(&__i->__i_);}
1193 bool __decrementable(const const_iterator* __i) const
1194 {return __table_.__decrementable(&__i->__i_);}
1195 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1196 {return __table_.__addable(&__i->__i_, __n);}
1197 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1198 {return __table_.__addable(&__i->__i_, __n);}
1199
1200#endif // _LIBCPP_DEBUG_LEVEL >= 2
1201
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001203#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001204 __node_holder __construct_node();
1205 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001206 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001207 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001208 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001209#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001210 template <class _A0, class _A1, class ..._Args>
1211 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001212#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001213#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1214 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215};
1216
1217template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1218unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1219 size_type __n, const hasher& __hf, const key_equal& __eql)
1220 : __table_(__hf, __eql)
1221{
Howard Hinnant39213642013-07-23 22:01:58 +00001222#if _LIBCPP_DEBUG_LEVEL >= 2
1223 __get_db()->__insert_c(this);
1224#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225 __table_.rehash(__n);
1226}
1227
1228template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1229unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1230 size_type __n, const hasher& __hf, const key_equal& __eql,
1231 const allocator_type& __a)
1232 : __table_(__hf, __eql, __a)
1233{
Howard Hinnant39213642013-07-23 22:01:58 +00001234#if _LIBCPP_DEBUG_LEVEL >= 2
1235 __get_db()->__insert_c(this);
1236#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237 __table_.rehash(__n);
1238}
1239
1240template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1243 const allocator_type& __a)
1244 : __table_(__a)
1245{
Howard Hinnant39213642013-07-23 22:01:58 +00001246#if _LIBCPP_DEBUG_LEVEL >= 2
1247 __get_db()->__insert_c(this);
1248#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249}
1250
1251template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1252template <class _InputIterator>
1253unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1254 _InputIterator __first, _InputIterator __last)
1255{
Howard Hinnant39213642013-07-23 22:01:58 +00001256#if _LIBCPP_DEBUG_LEVEL >= 2
1257 __get_db()->__insert_c(this);
1258#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259 insert(__first, __last);
1260}
1261
1262template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1263template <class _InputIterator>
1264unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1265 _InputIterator __first, _InputIterator __last, size_type __n,
1266 const hasher& __hf, const key_equal& __eql)
1267 : __table_(__hf, __eql)
1268{
Howard Hinnant39213642013-07-23 22:01:58 +00001269#if _LIBCPP_DEBUG_LEVEL >= 2
1270 __get_db()->__insert_c(this);
1271#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272 __table_.rehash(__n);
1273 insert(__first, __last);
1274}
1275
1276template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1277template <class _InputIterator>
1278unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1279 _InputIterator __first, _InputIterator __last, size_type __n,
1280 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1281 : __table_(__hf, __eql, __a)
1282{
Howard Hinnant39213642013-07-23 22:01:58 +00001283#if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
1285#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 __table_.rehash(__n);
1287 insert(__first, __last);
1288}
1289
1290template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1291unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1292 const unordered_map& __u)
1293 : __table_(__u.__table_)
1294{
Howard Hinnant39213642013-07-23 22:01:58 +00001295#if _LIBCPP_DEBUG_LEVEL >= 2
1296 __get_db()->__insert_c(this);
1297#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298 __table_.rehash(__u.bucket_count());
1299 insert(__u.begin(), __u.end());
1300}
1301
1302template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1303unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1304 const unordered_map& __u, const allocator_type& __a)
1305 : __table_(__u.__table_, __a)
1306{
Howard Hinnant39213642013-07-23 22:01:58 +00001307#if _LIBCPP_DEBUG_LEVEL >= 2
1308 __get_db()->__insert_c(this);
1309#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310 __table_.rehash(__u.bucket_count());
1311 insert(__u.begin(), __u.end());
1312}
1313
Howard Hinnant73d21a42010-09-04 23:28:19 +00001314#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315
1316template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001317inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1319 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001320 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001321 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001322{
Howard Hinnant39213642013-07-23 22:01:58 +00001323#if _LIBCPP_DEBUG_LEVEL >= 2
1324 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001325 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001326#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327}
1328
1329template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1330unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1331 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001332 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333{
Howard Hinnant39213642013-07-23 22:01:58 +00001334#if _LIBCPP_DEBUG_LEVEL >= 2
1335 __get_db()->__insert_c(this);
1336#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337 if (__a != __u.get_allocator())
1338 {
1339 iterator __i = __u.begin();
1340 while (__u.size() != 0)
1341 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001342 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343 );
1344 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001345#if _LIBCPP_DEBUG_LEVEL >= 2
1346 else
1347 __get_db()->swap(this, &__u);
1348#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349}
1350
Howard Hinnant73d21a42010-09-04 23:28:19 +00001351#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352
Howard Hinnante3e32912011-08-12 21:56:02 +00001353#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1354
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1356unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1357 initializer_list<value_type> __il)
1358{
Howard Hinnant39213642013-07-23 22:01:58 +00001359#if _LIBCPP_DEBUG_LEVEL >= 2
1360 __get_db()->__insert_c(this);
1361#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362 insert(__il.begin(), __il.end());
1363}
1364
1365template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1366unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1367 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1368 const key_equal& __eql)
1369 : __table_(__hf, __eql)
1370{
Howard Hinnant39213642013-07-23 22:01:58 +00001371#if _LIBCPP_DEBUG_LEVEL >= 2
1372 __get_db()->__insert_c(this);
1373#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 __table_.rehash(__n);
1375 insert(__il.begin(), __il.end());
1376}
1377
1378template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1379unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1380 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1381 const key_equal& __eql, const allocator_type& __a)
1382 : __table_(__hf, __eql, __a)
1383{
Howard Hinnant39213642013-07-23 22:01:58 +00001384#if _LIBCPP_DEBUG_LEVEL >= 2
1385 __get_db()->__insert_c(this);
1386#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 __table_.rehash(__n);
1388 insert(__il.begin(), __il.end());
1389}
1390
Howard Hinnante3e32912011-08-12 21:56:02 +00001391#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1392
Howard Hinnant73d21a42010-09-04 23:28:19 +00001393#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394
1395template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001396inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1398unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001399 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001401 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402 return *this;
1403}
1404
Howard Hinnant73d21a42010-09-04 23:28:19 +00001405#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406
Howard Hinnante3e32912011-08-12 21:56:02 +00001407#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1408
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001410inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1412unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1413 initializer_list<value_type> __il)
1414{
1415 __table_.__assign_unique(__il.begin(), __il.end());
1416 return *this;
1417}
1418
Howard Hinnante3e32912011-08-12 21:56:02 +00001419#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1420
Howard Hinnant73d21a42010-09-04 23:28:19 +00001421#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422
1423template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001425unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426{
1427 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001428 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001429 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431 __h.get_deleter().__second_constructed = true;
1432 return __h;
1433}
1434
1435template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001436template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001437typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1439{
1440 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001441 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001442 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1443 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 __h.get_deleter().__first_constructed = true;
1445 __h.get_deleter().__second_constructed = true;
1446 return __h;
1447}
1448
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001449template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001450typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1451unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001452{
1453 __node_allocator& __na = __table_.__node_alloc();
1454 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001455 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001456 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001457 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001458 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001459 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001460}
1461
Howard Hinnant73d21a42010-09-04 23:28:19 +00001462#ifndef _LIBCPP_HAS_NO_VARIADICS
1463
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001465template <class _A0, class _A1, class ..._Args>
1466typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1467unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1468 _A1&& __a1,
1469 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001471 __node_allocator& __na = __table_.__node_alloc();
1472 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1473 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1474 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1475 _VSTD::forward<_Args>(__args)...);
1476 __h.get_deleter().__first_constructed = true;
1477 __h.get_deleter().__second_constructed = true;
1478 return __h;
1479}
1480
1481template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1482template <class... _Args>
1483pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
Duncan P. N. Exon Smith005e38f2016-01-23 15:12:47 +00001484unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001485{
1486 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1488 if (__r.second)
1489 __h.release();
1490 return __r;
1491}
1492
Howard Hinnant73d21a42010-09-04 23:28:19 +00001493#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001494#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495
1496template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1497typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001498unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499{
1500 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001501 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001502 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001504 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:33 +00001506 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507}
1508
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1510template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512void
1513unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1514 _InputIterator __last)
1515{
1516 for (; __first != __last; ++__first)
1517 __table_.__insert_unique(*__first);
1518}
1519
1520template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1521_Tp&
1522unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1523{
1524 iterator __i = find(__k);
1525 if (__i != end())
1526 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001527 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1529 __h.release();
1530 return __r.first->second;
1531}
1532
Howard Hinnant73d21a42010-09-04 23:28:19 +00001533#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534
1535template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1536_Tp&
1537unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1538{
1539 iterator __i = find(__k);
1540 if (__i != end())
1541 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001542 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1544 __h.release();
1545 return __r.first->second;
1546}
1547
Howard Hinnant73d21a42010-09-04 23:28:19 +00001548#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549
1550template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1551_Tp&
1552unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1553{
1554 iterator __i = find(__k);
1555#ifndef _LIBCPP_NO_EXCEPTIONS
1556 if (__i == end())
1557 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001558#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 return __i->second;
1560}
1561
1562template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1563const _Tp&
1564unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1565{
1566 const_iterator __i = find(__k);
1567#ifndef _LIBCPP_NO_EXCEPTIONS
1568 if (__i == end())
1569 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001570#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571 return __i->second;
1572}
1573
1574template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576void
1577swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1578 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001579 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580{
1581 __x.swap(__y);
1582}
1583
1584template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1585bool
1586operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1587 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1588{
1589 if (__x.size() != __y.size())
1590 return false;
1591 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1592 const_iterator;
1593 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1594 __i != __ex; ++__i)
1595 {
1596 const_iterator __j = __y.find(__i->first);
1597 if (__j == __ey || !(*__i == *__j))
1598 return false;
1599 }
1600 return true;
1601}
1602
1603template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605bool
1606operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1607 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1608{
1609 return !(__x == __y);
1610}
1611
1612template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1613 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001614class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615{
1616public:
1617 // types
1618 typedef _Key key_type;
1619 typedef _Tp mapped_type;
1620 typedef _Hash hasher;
1621 typedef _Pred key_equal;
1622 typedef _Alloc allocator_type;
1623 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001624 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 typedef value_type& reference;
1626 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001627 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1628 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629
1630private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001631 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001632 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1633 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001634 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1635 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636
1637 typedef __hash_table<__value_type, __hasher,
1638 __key_equal, __allocator_type> __table;
1639
1640 __table __table_;
1641
1642 typedef typename __table::__node_traits __node_traits;
1643 typedef typename __table::__node_allocator __node_allocator;
1644 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001645 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1646 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001648 static_assert((is_same<typename __node_traits::size_type,
1649 typename __alloc_traits::size_type>::value),
1650 "Allocator uses different size_type for different types");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651public:
1652 typedef typename __alloc_traits::pointer pointer;
1653 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001654 typedef typename __table::size_type size_type;
1655 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001656
1657 typedef __hash_map_iterator<typename __table::iterator> iterator;
1658 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1659 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1660 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1661
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001663 unordered_multimap()
1664 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001665 {
1666#if _LIBCPP_DEBUG_LEVEL >= 2
1667 __get_db()->__insert_c(this);
1668#endif
1669 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1671 const key_equal& __eql = key_equal());
1672 unordered_multimap(size_type __n, const hasher& __hf,
1673 const key_equal& __eql,
1674 const allocator_type& __a);
1675 template <class _InputIterator>
1676 unordered_multimap(_InputIterator __first, _InputIterator __last);
1677 template <class _InputIterator>
1678 unordered_multimap(_InputIterator __first, _InputIterator __last,
1679 size_type __n, const hasher& __hf = hasher(),
1680 const key_equal& __eql = key_equal());
1681 template <class _InputIterator>
1682 unordered_multimap(_InputIterator __first, _InputIterator __last,
1683 size_type __n, const hasher& __hf,
1684 const key_equal& __eql,
1685 const allocator_type& __a);
1686 explicit unordered_multimap(const allocator_type& __a);
1687 unordered_multimap(const unordered_multimap& __u);
1688 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001689#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001690 unordered_multimap(unordered_multimap&& __u)
1691 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001693#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001694#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 unordered_multimap(initializer_list<value_type> __il);
1696 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1697 const hasher& __hf = hasher(),
1698 const key_equal& __eql = key_equal());
1699 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1700 const hasher& __hf, const key_equal& __eql,
1701 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001702#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001703#if _LIBCPP_STD_VER > 11
1704 _LIBCPP_INLINE_VISIBILITY
1705 unordered_multimap(size_type __n, const allocator_type& __a)
1706 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1707 _LIBCPP_INLINE_VISIBILITY
1708 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1709 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1710 template <class _InputIterator>
1711 _LIBCPP_INLINE_VISIBILITY
1712 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1713 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1714 template <class _InputIterator>
1715 _LIBCPP_INLINE_VISIBILITY
1716 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1717 const allocator_type& __a)
1718 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1719 _LIBCPP_INLINE_VISIBILITY
1720 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1721 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1722 _LIBCPP_INLINE_VISIBILITY
1723 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1724 const allocator_type& __a)
1725 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1726#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001728 _LIBCPP_INLINE_VISIBILITY
1729 unordered_multimap& operator=(const unordered_multimap& __u)
1730 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001731#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001732 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001733#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001734 if (this != &__u) {
1735 __table_.clear();
1736 __table_.hash_function() = __u.__table_.hash_function();
1737 __table_.key_eq() = __u.__table_.key_eq();
1738 __table_.max_load_factor() = __u.__table_.max_load_factor();
1739 __table_.__copy_assign_alloc(__u.__table_);
1740 insert(__u.begin(), __u.end());
1741 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001742#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001743 return *this;
1744 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001745#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001746 unordered_multimap& operator=(unordered_multimap&& __u)
1747 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001748#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001749#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001751#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001754 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 {return allocator_type(__table_.__node_alloc());}
1756
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001758 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001760 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001762 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001765 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001767 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001769 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001771 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001773 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001775 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776
Howard Hinnant73d21a42010-09-04 23:28:19 +00001777#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001778#ifndef _LIBCPP_HAS_NO_VARIADICS
1779
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001780 template <class... _Args>
1781 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001783 template <class... _Args>
1784 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001785#endif // _LIBCPP_HAS_NO_VARIADICS
1786#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001789#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001790 template <class _Pp,
1791 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001793 iterator insert(_Pp&& __x)
1794 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001795#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 iterator insert(const_iterator __p, const value_type& __x)
1798 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001799#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001800 template <class _Pp,
1801 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001803 iterator insert(const_iterator __p, _Pp&& __x)
1804 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001805#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 template <class _InputIterator>
1807 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001808#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 void insert(initializer_list<value_type> __il)
1811 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001812#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001816 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001817 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 iterator erase(const_iterator __first, const_iterator __last)
1822 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001824 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001827 void swap(unordered_multimap& __u)
1828 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1829 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 hasher hash_function() const
1833 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835 key_equal key_eq() const
1836 {return __table_.key_eq().key_eq();}
1837
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845 pair<iterator, iterator> equal_range(const key_type& __k)
1846 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1849 {return __table_.__equal_range_multi(__k);}
1850
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001852 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001854 size_type max_bucket_count() const _NOEXCEPT
1855 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858 size_type bucket_size(size_type __n) const
1859 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1862
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1875
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001877 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001879 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001881 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885 void reserve(size_type __n) {__table_.reserve(__n);}
1886
Howard Hinnant39213642013-07-23 22:01:58 +00001887#if _LIBCPP_DEBUG_LEVEL >= 2
1888
1889 bool __dereferenceable(const const_iterator* __i) const
1890 {return __table_.__dereferenceable(&__i->__i_);}
1891 bool __decrementable(const const_iterator* __i) const
1892 {return __table_.__decrementable(&__i->__i_);}
1893 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1894 {return __table_.__addable(&__i->__i_, __n);}
1895 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1896 {return __table_.__addable(&__i->__i_, __n);}
1897
1898#endif // _LIBCPP_DEBUG_LEVEL >= 2
1899
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001901#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1902 __node_holder __construct_node();
1903 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001904 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001905 __construct_node(_A0&& __a0);
1906#ifndef _LIBCPP_HAS_NO_VARIADICS
1907 template <class _A0, class _A1, class ..._Args>
1908 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1909#endif // _LIBCPP_HAS_NO_VARIADICS
1910#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911};
1912
1913template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1914unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1915 size_type __n, const hasher& __hf, const key_equal& __eql)
1916 : __table_(__hf, __eql)
1917{
Howard Hinnant39213642013-07-23 22:01:58 +00001918#if _LIBCPP_DEBUG_LEVEL >= 2
1919 __get_db()->__insert_c(this);
1920#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921 __table_.rehash(__n);
1922}
1923
1924template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1925unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1926 size_type __n, const hasher& __hf, const key_equal& __eql,
1927 const allocator_type& __a)
1928 : __table_(__hf, __eql, __a)
1929{
Howard Hinnant39213642013-07-23 22:01:58 +00001930#if _LIBCPP_DEBUG_LEVEL >= 2
1931 __get_db()->__insert_c(this);
1932#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 __table_.rehash(__n);
1934}
1935
1936template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1937template <class _InputIterator>
1938unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1939 _InputIterator __first, _InputIterator __last)
1940{
Howard Hinnant39213642013-07-23 22:01:58 +00001941#if _LIBCPP_DEBUG_LEVEL >= 2
1942 __get_db()->__insert_c(this);
1943#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 insert(__first, __last);
1945}
1946
1947template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1948template <class _InputIterator>
1949unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1950 _InputIterator __first, _InputIterator __last, size_type __n,
1951 const hasher& __hf, const key_equal& __eql)
1952 : __table_(__hf, __eql)
1953{
Howard Hinnant39213642013-07-23 22:01:58 +00001954#if _LIBCPP_DEBUG_LEVEL >= 2
1955 __get_db()->__insert_c(this);
1956#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001957 __table_.rehash(__n);
1958 insert(__first, __last);
1959}
1960
1961template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1962template <class _InputIterator>
1963unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1964 _InputIterator __first, _InputIterator __last, size_type __n,
1965 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1966 : __table_(__hf, __eql, __a)
1967{
Howard Hinnant39213642013-07-23 22:01:58 +00001968#if _LIBCPP_DEBUG_LEVEL >= 2
1969 __get_db()->__insert_c(this);
1970#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971 __table_.rehash(__n);
1972 insert(__first, __last);
1973}
1974
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001975template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1978 const allocator_type& __a)
1979 : __table_(__a)
1980{
Howard Hinnant39213642013-07-23 22:01:58 +00001981#if _LIBCPP_DEBUG_LEVEL >= 2
1982 __get_db()->__insert_c(this);
1983#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984}
1985
1986template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1987unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1988 const unordered_multimap& __u)
1989 : __table_(__u.__table_)
1990{
Howard Hinnant39213642013-07-23 22:01:58 +00001991#if _LIBCPP_DEBUG_LEVEL >= 2
1992 __get_db()->__insert_c(this);
1993#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 __table_.rehash(__u.bucket_count());
1995 insert(__u.begin(), __u.end());
1996}
1997
1998template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1999unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2000 const unordered_multimap& __u, const allocator_type& __a)
2001 : __table_(__u.__table_, __a)
2002{
Howard Hinnant39213642013-07-23 22:01:58 +00002003#if _LIBCPP_DEBUG_LEVEL >= 2
2004 __get_db()->__insert_c(this);
2005#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006 __table_.rehash(__u.bucket_count());
2007 insert(__u.begin(), __u.end());
2008}
2009
Howard Hinnant73d21a42010-09-04 23:28:19 +00002010#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011
2012template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002013inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2015 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002016 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002017 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002018{
Howard Hinnant39213642013-07-23 22:01:58 +00002019#if _LIBCPP_DEBUG_LEVEL >= 2
2020 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002021 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00002022#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023}
2024
2025template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2026unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2027 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002028 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029{
Howard Hinnant39213642013-07-23 22:01:58 +00002030#if _LIBCPP_DEBUG_LEVEL >= 2
2031 __get_db()->__insert_c(this);
2032#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033 if (__a != __u.get_allocator())
2034 {
2035 iterator __i = __u.begin();
2036 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00002037 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00002039 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040 );
Howard Hinnant39213642013-07-23 22:01:58 +00002041 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002042 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00002043#if _LIBCPP_DEBUG_LEVEL >= 2
2044 else
2045 __get_db()->swap(this, &__u);
2046#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047}
2048
Howard Hinnant73d21a42010-09-04 23:28:19 +00002049#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050
Howard Hinnante3e32912011-08-12 21:56:02 +00002051#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2052
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2054unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2055 initializer_list<value_type> __il)
2056{
Howard Hinnant39213642013-07-23 22:01:58 +00002057#if _LIBCPP_DEBUG_LEVEL >= 2
2058 __get_db()->__insert_c(this);
2059#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060 insert(__il.begin(), __il.end());
2061}
2062
2063template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2064unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2065 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2066 const key_equal& __eql)
2067 : __table_(__hf, __eql)
2068{
Howard Hinnant39213642013-07-23 22:01:58 +00002069#if _LIBCPP_DEBUG_LEVEL >= 2
2070 __get_db()->__insert_c(this);
2071#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 __table_.rehash(__n);
2073 insert(__il.begin(), __il.end());
2074}
2075
2076template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2077unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2078 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2079 const key_equal& __eql, const allocator_type& __a)
2080 : __table_(__hf, __eql, __a)
2081{
Howard Hinnant39213642013-07-23 22:01:58 +00002082#if _LIBCPP_DEBUG_LEVEL >= 2
2083 __get_db()->__insert_c(this);
2084#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 __table_.rehash(__n);
2086 insert(__il.begin(), __il.end());
2087}
2088
Howard Hinnante3e32912011-08-12 21:56:02 +00002089#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2090
Howard Hinnant73d21a42010-09-04 23:28:19 +00002091#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002092
2093template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002094inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2096unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002097 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002099 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 return *this;
2101}
2102
Howard Hinnant73d21a42010-09-04 23:28:19 +00002103#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002104
Howard Hinnante3e32912011-08-12 21:56:02 +00002105#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2106
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2110unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2111 initializer_list<value_type> __il)
2112{
2113 __table_.__assign_multi(__il.begin(), __il.end());
2114 return *this;
2115}
2116
Howard Hinnante3e32912011-08-12 21:56:02 +00002117#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2118
Howard Hinnant73d21a42010-09-04 23:28:19 +00002119#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120
2121template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002122typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002123unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002124{
2125 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002126 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002127 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002128 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129 __h.get_deleter().__second_constructed = true;
2130 return __h;
2131}
2132
2133template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002134template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00002135typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
2137{
2138 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00002139 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00002140 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2141 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142 __h.get_deleter().__first_constructed = true;
2143 __h.get_deleter().__second_constructed = true;
2144 return __h;
2145}
2146
Howard Hinnant73d21a42010-09-04 23:28:19 +00002147#ifndef _LIBCPP_HAS_NO_VARIADICS
2148
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002150template <class _A0, class _A1, class ..._Args>
2151typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
2152unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
2153 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002155 __node_allocator& __na = __table_.__node_alloc();
2156 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2157 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2158 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2159 _VSTD::forward<_Args>(__args)...);
2160 __h.get_deleter().__first_constructed = true;
2161 __h.get_deleter().__second_constructed = true;
2162 return __h;
2163}
2164
2165template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2166template <class... _Args>
2167typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2168unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
2169{
2170 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171 iterator __r = __table_.__node_insert_multi(__h.get());
2172 __h.release();
2173 return __r;
2174}
2175
2176template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002177template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002178typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2179unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002180 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002182 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2184 __h.release();
2185 return __r;
2186}
2187
Howard Hinnant73d21a42010-09-04 23:28:19 +00002188#endif // _LIBCPP_HAS_NO_VARIADICS
2189#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190
2191template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2192template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002193inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194void
2195unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2196 _InputIterator __last)
2197{
2198 for (; __first != __last; ++__first)
2199 __table_.__insert_multi(*__first);
2200}
2201
2202template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002203inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204void
2205swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2206 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002207 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208{
2209 __x.swap(__y);
2210}
2211
2212template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2213bool
2214operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2215 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2216{
2217 if (__x.size() != __y.size())
2218 return false;
2219 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2220 const_iterator;
2221 typedef pair<const_iterator, const_iterator> _EqRng;
2222 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2223 {
2224 _EqRng __xeq = __x.equal_range(__i->first);
2225 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002226 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2227 _VSTD::distance(__yeq.first, __yeq.second) ||
2228 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229 return false;
2230 __i = __xeq.second;
2231 }
2232 return true;
2233}
2234
2235template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237bool
2238operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2239 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2240{
2241 return !(__x == __y);
2242}
2243
2244_LIBCPP_END_NAMESPACE_STD
2245
2246#endif // _LIBCPP_UNORDERED_MAP