blob: 372868a0df591d3e7b2a02358b5e9417daae392e [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>
Eric Fiselier410ed302016-02-11 21:45:53 +0000372#include <tuple>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373
Eric Fiselierb9536102014-08-10 23:53:08 +0000374#include <__debug>
375
Howard Hinnant08e17472011-10-17 20:05:10 +0000376#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000378#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379
380_LIBCPP_BEGIN_NAMESPACE_STD
381
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000382template <class _Key, class _Cp, class _Hash,
383 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000384 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385class __unordered_map_hasher
386 : private _Hash
387{
388public:
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_;
417public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000419 __unordered_map_hasher()
420 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
421 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000423 __unordered_map_hasher(const _Hash& __h)
424 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
425 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000427 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000429 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000430 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000431 _LIBCPP_INLINE_VISIBILITY
432 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 {return __hash_(__x);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000434 void swap(__unordered_map_hasher&__y)
435 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
436 {
437 using _VSTD::swap;
438 swap(__hash_, __y.__hash_);
439 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440};
441
Marshall Clow7d914d12015-07-13 20:04:56 +0000442template <class _Key, class _Cp, class _Hash, bool __b>
443inline _LIBCPP_INLINE_VISIBILITY
444void
445swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
446 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
447 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
448{
449 __x.swap(__y);
450}
451
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000452template <class _Key, class _Cp, class _Pred,
453 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000454 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455class __unordered_map_equal
456 : private _Pred
457{
458public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000460 __unordered_map_equal()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
462 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000464 __unordered_map_equal(const _Pred& __p)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
466 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000468 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000470 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000471 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000472 _LIBCPP_INLINE_VISIBILITY
473 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000474 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000476 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000477 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000478 void swap(__unordered_map_equal&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
483 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484};
485
Howard Hinnant9b128e02013-07-05 18:06:00 +0000486template <class _Key, class _Cp, class _Pred>
487class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488{
489 _Pred __pred_;
490public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000492 __unordered_map_equal()
493 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
494 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000496 __unordered_map_equal(const _Pred& __p)
497 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
498 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000500 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000502 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000503 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000504 _LIBCPP_INLINE_VISIBILITY
505 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000506 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000508 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000509 {return __pred_(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56 +0000510 void swap(__unordered_map_equal&__y)
511 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
512 {
513 using _VSTD::swap;
514 swap(__pred_, __y.__pred_);
515 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516};
517
Marshall Clow7d914d12015-07-13 20:04:56 +0000518template <class _Key, class _Cp, class _Pred, bool __b>
519inline _LIBCPP_INLINE_VISIBILITY
520void
521swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
522 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
523 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
524{
525 __x.swap(__y);
526}
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528template <class _Alloc>
529class __hash_map_node_destructor
530{
531 typedef _Alloc allocator_type;
532 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000533
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534public:
Eric Fiselier774c7c52016-02-10 20:46:23 +0000535
536 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537private:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538
539 allocator_type& __na_;
540
541 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
542
543public:
544 bool __first_constructed;
545 bool __second_constructed;
546
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000548 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 : __na_(__na),
550 __first_constructed(false),
551 __second_constructed(false)
552 {}
553
Howard Hinnant73d21a42010-09-04 23:28:19 +0000554#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000557 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558 : __na_(__x.__na_),
559 __first_constructed(__x.__value_constructed),
560 __second_constructed(__x.__value_constructed)
561 {
562 __x.__value_constructed = false;
563 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000564#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
567 : __na_(__x.__na_),
568 __first_constructed(__x.__value_constructed),
569 __second_constructed(__x.__value_constructed)
570 {
571 const_cast<bool&>(__x.__value_constructed) = false;
572 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000573#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000576 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577 {
578 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000579 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000581 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582 if (__p)
583 __alloc_traits::deallocate(__na_, __p, 1);
584 }
585};
586
Eric Fiselier2960ae22016-02-11 11:59:44 +0000587#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantff7546e2013-09-30 19:08:22 +0000588template <class _Key, class _Tp>
589union __hash_value_type
590{
591 typedef _Key key_type;
592 typedef _Tp mapped_type;
593 typedef pair<const key_type, mapped_type> value_type;
594 typedef pair<key_type, mapped_type> __nc_value_type;
595
596 value_type __cc;
597 __nc_value_type __nc;
598
Howard Hinnantff7546e2013-09-30 19:08:22 +0000599 _LIBCPP_INLINE_VISIBILITY
600 __hash_value_type& operator=(const __hash_value_type& __v)
601 {__nc = __v.__cc; return *this;}
602
603 _LIBCPP_INLINE_VISIBILITY
604 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000605 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000606
Eric Fiselier2960ae22016-02-11 11:59:44 +0000607 template <class _ValueTp,
608 class = typename enable_if<
609 __is_same_uncvref<_ValueTp, value_type>::value
610 >::type
611 >
Howard Hinnantff7546e2013-09-30 19:08:22 +0000612 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2960ae22016-02-11 11:59:44 +0000613 __hash_value_type& operator=(_ValueTp&& __v) {
614 __nc = _VSTD::forward<_ValueTp>(__v); return *this;
615 }
616
617private:
618 __hash_value_type(const __hash_value_type& __v) = delete;
619 __hash_value_type(__hash_value_type&& __v) = delete;
620 template <class ..._Args>
621 explicit __hash_value_type(_Args&& ...__args) = delete;
622
623 ~__hash_value_type() = delete;
Howard Hinnantff7546e2013-09-30 19:08:22 +0000624};
625
626#else
627
628template <class _Key, class _Tp>
629struct __hash_value_type
630{
631 typedef _Key key_type;
632 typedef _Tp mapped_type;
633 typedef pair<const key_type, mapped_type> value_type;
634
635 value_type __cc;
636
Eric Fiselier2960ae22016-02-11 11:59:44 +0000637private:
638 ~__hash_value_type();
Howard Hinnantff7546e2013-09-30 19:08:22 +0000639};
640
641#endif
642
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000644class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645{
646 _HashIterator __i_;
647
Eric Fiselier774c7c52016-02-10 20:46:23 +0000648 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
649
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650public:
651 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000652 typedef typename _NodeTypes::__map_value_type value_type;
653 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 typedef value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000655 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000658 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000661 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000664 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000666 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 __hash_map_iterator operator++(int)
672 {
673 __hash_map_iterator __t(*this);
674 ++(*this);
675 return __t;
676 }
677
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000678 friend _LIBCPP_INLINE_VISIBILITY
679 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000681 friend _LIBCPP_INLINE_VISIBILITY
682 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 {return __x.__i_ != __y.__i_;}
684
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000685 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
686 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
687 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
688 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
689 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690};
691
692template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000693class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694{
695 _HashIterator __i_;
696
Eric Fiselier774c7c52016-02-10 20:46:23 +0000697 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
698
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699public:
700 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000701 typedef typename _NodeTypes::__map_value_type value_type;
702 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 typedef const value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000704 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000707 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000710 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 __hash_map_const_iterator(
713 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000714 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 : __i_(__i.__i_) {}
716
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000718 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000720 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 __hash_map_const_iterator operator++(int)
726 {
727 __hash_map_const_iterator __t(*this);
728 ++(*this);
729 return __t;
730 }
731
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000732 friend _LIBCPP_INLINE_VISIBILITY
733 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000735 friend _LIBCPP_INLINE_VISIBILITY
736 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 {return __x.__i_ != __y.__i_;}
738
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000739 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
740 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
741 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
742 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743};
744
745template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
746 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000747class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748{
749public:
750 // types
751 typedef _Key key_type;
752 typedef _Tp mapped_type;
753 typedef _Hash hasher;
754 typedef _Pred key_equal;
755 typedef _Alloc allocator_type;
756 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000757 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758 typedef value_type& reference;
759 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000760 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
761 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762
763private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000764 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000765 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
766 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000767 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
768 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769
770 typedef __hash_table<__value_type, __hasher,
771 __key_equal, __allocator_type> __table;
772
773 __table __table_;
774
Eric Fiselier2960ae22016-02-11 11:59:44 +0000775 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 typedef typename __table::__node_pointer __node_pointer;
777 typedef typename __table::__node_const_pointer __node_const_pointer;
778 typedef typename __table::__node_traits __node_traits;
779 typedef typename __table::__node_allocator __node_allocator;
780 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000781 typedef __hash_map_node_destructor<__node_allocator> _Dp;
782 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier2960ae22016-02-11 11:59:44 +0000784
785 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
786 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787public:
788 typedef typename __alloc_traits::pointer pointer;
789 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +0000790 typedef typename __table::size_type size_type;
791 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792
793 typedef __hash_map_iterator<typename __table::iterator> iterator;
794 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
795 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
796 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
797
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000799 unordered_map()
800 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000801 {
802#if _LIBCPP_DEBUG_LEVEL >= 2
803 __get_db()->__insert_c(this);
804#endif
805 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
807 const key_equal& __eql = key_equal());
808 unordered_map(size_type __n, const hasher& __hf,
809 const key_equal& __eql,
810 const allocator_type& __a);
811 template <class _InputIterator>
812 unordered_map(_InputIterator __first, _InputIterator __last);
813 template <class _InputIterator>
814 unordered_map(_InputIterator __first, _InputIterator __last,
815 size_type __n, const hasher& __hf = hasher(),
816 const key_equal& __eql = key_equal());
817 template <class _InputIterator>
818 unordered_map(_InputIterator __first, _InputIterator __last,
819 size_type __n, const hasher& __hf,
820 const key_equal& __eql,
821 const allocator_type& __a);
822 explicit unordered_map(const allocator_type& __a);
823 unordered_map(const unordered_map& __u);
824 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000825#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000826 unordered_map(unordered_map&& __u)
827 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000829#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000830#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831 unordered_map(initializer_list<value_type> __il);
832 unordered_map(initializer_list<value_type> __il, size_type __n,
833 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
834 unordered_map(initializer_list<value_type> __il, size_type __n,
835 const hasher& __hf, const key_equal& __eql,
836 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000837#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000838#if _LIBCPP_STD_VER > 11
839 _LIBCPP_INLINE_VISIBILITY
840 unordered_map(size_type __n, const allocator_type& __a)
841 : unordered_map(__n, hasher(), key_equal(), __a) {}
842 _LIBCPP_INLINE_VISIBILITY
843 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
844 : unordered_map(__n, __hf, key_equal(), __a) {}
845 template <class _InputIterator>
846 _LIBCPP_INLINE_VISIBILITY
847 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
848 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
849 template <class _InputIterator>
850 _LIBCPP_INLINE_VISIBILITY
851 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
852 const allocator_type& __a)
853 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
854 _LIBCPP_INLINE_VISIBILITY
855 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
856 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
857 _LIBCPP_INLINE_VISIBILITY
858 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
859 const allocator_type& __a)
860 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
861#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000863 _LIBCPP_INLINE_VISIBILITY
864 unordered_map& operator=(const unordered_map& __u)
865 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000866#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000867 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000868#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000869 if (this != &__u) {
870 __table_.clear();
871 __table_.hash_function() = __u.__table_.hash_function();
872 __table_.key_eq() = __u.__table_.key_eq();
873 __table_.max_load_factor() = __u.__table_.max_load_factor();
874 __table_.__copy_assign_alloc(__u.__table_);
875 insert(__u.begin(), __u.end());
876 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000877#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000878 return *this;
879 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000880#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000881 unordered_map& operator=(unordered_map&& __u)
882 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000884#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000886#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000889 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 {return allocator_type(__table_.__node_alloc());}
891
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000893 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000895 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000897 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000900 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000902 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000904 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000906 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000908 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000910 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911
Eric Fiselier2960ae22016-02-11 11:59:44 +0000912#ifndef _LIBCPP_CXX03_LANG
913 template <class... _Args>
914 _LIBCPP_INLINE_VISIBILITY
915 pair<iterator, bool> emplace(_Args&&... __args) {
916 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
917 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000918
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000919 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:44 +0000920 _LIBCPP_INLINE_VISIBILITY
921 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000922#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier2960ae22016-02-11 11:59:44 +0000923 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
924 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
925 " referring to this unordered_map");
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000926#endif
Eric Fiselier2960ae22016-02-11 11:59:44 +0000927 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
928 }
929
930#endif // _LIBCPP_CXX03_LANG
931
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 pair<iterator, bool> insert(const value_type& __x)
934 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000935#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000936 template <class _Pp,
937 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000939 pair<iterator, bool> insert(_Pp&& __x)
940 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000941#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000943#if _LIBCPP_DEBUG_LEVEL >= 2
944 iterator insert(const_iterator __p, const value_type& __x)
945 {
946 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
947 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
948 " referring to this unordered_map");
949 return insert(__x).first;
950 }
951#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952 iterator insert(const_iterator, const value_type& __x)
953 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000954#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000955#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000956 template <class _Pp,
957 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000959#if _LIBCPP_DEBUG_LEVEL >= 2
960 iterator insert(const_iterator __p, _Pp&& __x)
961 {
962 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
963 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
964 " referring to this unordered_map");
965 return insert(_VSTD::forward<_Pp>(__x)).first;
966 }
967#else
Howard Hinnant99968442011-11-29 18:15:50 +0000968 iterator insert(const_iterator, _Pp&& __x)
969 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000970#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000971#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 template <class _InputIterator>
973 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000974#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 void insert(initializer_list<value_type> __il)
977 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000978#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000979
Marshall Clow0ce05a92015-07-07 05:45:35 +0000980#if _LIBCPP_STD_VER > 14
981#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
982#ifndef _LIBCPP_HAS_NO_VARIADICS
983 template <class... _Args>
984 _LIBCPP_INLINE_VISIBILITY
985 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
986 {
987 iterator __p = __table_.find(__k);
988 if ( __p != end())
989 return _VSTD::make_pair(__p, false);
990 else
991 return _VSTD::make_pair(
992 emplace_hint(__p,
993 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
994 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
995 true);
996 }
997
998 template <class... _Args>
999 _LIBCPP_INLINE_VISIBILITY
1000 pair<iterator, bool> try_emplace(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(_VSTD::move(__k)),
1009 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)),
1010 true);
1011 }
1012
1013 template <class... _Args>
1014 _LIBCPP_INLINE_VISIBILITY
1015 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1016 {
1017 iterator __p = __table_.find(__k);
1018 if ( __p != end())
1019 return __p;
1020 else
1021 return emplace_hint(__h,
1022 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k),
1023 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1024 }
1025
1026 template <class... _Args>
1027 _LIBCPP_INLINE_VISIBILITY
1028 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1029 {
1030 iterator __p = __table_.find(__k);
1031 if ( __p != end())
1032 return __p;
1033 else
1034 return emplace_hint(__h,
1035 _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1036 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1037 }
1038
1039 template <class _Vp>
1040 _LIBCPP_INLINE_VISIBILITY
1041 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1042 {
1043 iterator __p = __table_.find(__k);
1044 if ( __p != end())
1045 {
1046 __p->second = _VSTD::move(__v);
1047 return _VSTD::make_pair(__p, false);
1048 }
1049 return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
1050 }
1051
1052 template <class _Vp>
1053 _LIBCPP_INLINE_VISIBILITY
1054 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1055 {
1056 iterator __p = __table_.find(__k);
1057 if ( __p != end())
1058 {
1059 __p->second = _VSTD::move(__v);
1060 return _VSTD::make_pair(__p, false);
1061 }
1062 return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true);
1063 }
1064
1065 template <class _Vp>
1066 _LIBCPP_INLINE_VISIBILITY
1067 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1068 {
1069 iterator __p = __table_.find(__k);
1070 if ( __p != end())
1071 {
1072 __p->second = _VSTD::move(__v);
1073 return __p;
1074 }
1075 return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
1076 }
1077
1078 template <class _Vp>
1079 _LIBCPP_INLINE_VISIBILITY
1080 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1081 {
1082 iterator __p = __table_.find(__k);
1083 if ( __p != end())
1084 {
1085 __p->second = _VSTD::move(__v);
1086 return __p;
1087 }
1088 return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v));
1089 }
1090#endif
1091#endif
1092#endif
1093
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001096 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001097 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 iterator erase(const_iterator __first, const_iterator __last)
1102 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001104 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001107 void swap(unordered_map& __u)
1108 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1109 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001110
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 hasher hash_function() const
1113 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115 key_equal key_eq() const
1116 {return __table_.key_eq().key_eq();}
1117
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 pair<iterator, iterator> equal_range(const key_type& __k)
1126 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1129 {return __table_.__equal_range_unique(__k);}
1130
1131 mapped_type& operator[](const key_type& __k);
Eric Fiselier410ed302016-02-11 21:45:53 +00001132#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 mapped_type& operator[](key_type&& __k);
1134#endif
1135
1136 mapped_type& at(const key_type& __k);
1137 const mapped_type& at(const key_type& __k) const;
1138
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001140 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001142 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145 size_type bucket_size(size_type __n) const
1146 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1149
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1162
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001164 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001166 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 void reserve(size_type __n) {__table_.reserve(__n);}
1173
Howard Hinnant39213642013-07-23 22:01:58 +00001174#if _LIBCPP_DEBUG_LEVEL >= 2
1175
1176 bool __dereferenceable(const const_iterator* __i) const
1177 {return __table_.__dereferenceable(&__i->__i_);}
1178 bool __decrementable(const const_iterator* __i) const
1179 {return __table_.__decrementable(&__i->__i_);}
1180 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1181 {return __table_.__addable(&__i->__i_, __n);}
1182 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1183 {return __table_.__addable(&__i->__i_, __n);}
1184
1185#endif // _LIBCPP_DEBUG_LEVEL >= 2
1186
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187private:
Eric Fiselier410ed302016-02-11 21:45:53 +00001188
1189#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001190 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier410ed302016-02-11 21:45:53 +00001191#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001192};
1193
1194template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1195unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1196 size_type __n, const hasher& __hf, const key_equal& __eql)
1197 : __table_(__hf, __eql)
1198{
Howard Hinnant39213642013-07-23 22:01:58 +00001199#if _LIBCPP_DEBUG_LEVEL >= 2
1200 __get_db()->__insert_c(this);
1201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202 __table_.rehash(__n);
1203}
1204
1205template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1206unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1207 size_type __n, const hasher& __hf, const key_equal& __eql,
1208 const allocator_type& __a)
1209 : __table_(__hf, __eql, __a)
1210{
Howard Hinnant39213642013-07-23 22:01:58 +00001211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214 __table_.rehash(__n);
1215}
1216
1217template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1220 const allocator_type& __a)
1221 : __table_(__a)
1222{
Howard Hinnant39213642013-07-23 22:01:58 +00001223#if _LIBCPP_DEBUG_LEVEL >= 2
1224 __get_db()->__insert_c(this);
1225#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226}
1227
1228template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1229template <class _InputIterator>
1230unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1231 _InputIterator __first, _InputIterator __last)
1232{
Howard Hinnant39213642013-07-23 22:01:58 +00001233#if _LIBCPP_DEBUG_LEVEL >= 2
1234 __get_db()->__insert_c(this);
1235#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236 insert(__first, __last);
1237}
1238
1239template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1240template <class _InputIterator>
1241unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1242 _InputIterator __first, _InputIterator __last, size_type __n,
1243 const hasher& __hf, const key_equal& __eql)
1244 : __table_(__hf, __eql)
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 __table_.rehash(__n);
1250 insert(__first, __last);
1251}
1252
1253template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1254template <class _InputIterator>
1255unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1256 _InputIterator __first, _InputIterator __last, size_type __n,
1257 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1258 : __table_(__hf, __eql, __a)
1259{
Howard Hinnant39213642013-07-23 22:01:58 +00001260#if _LIBCPP_DEBUG_LEVEL >= 2
1261 __get_db()->__insert_c(this);
1262#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 __table_.rehash(__n);
1264 insert(__first, __last);
1265}
1266
1267template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1268unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1269 const unordered_map& __u)
1270 : __table_(__u.__table_)
1271{
Howard Hinnant39213642013-07-23 22:01:58 +00001272#if _LIBCPP_DEBUG_LEVEL >= 2
1273 __get_db()->__insert_c(this);
1274#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275 __table_.rehash(__u.bucket_count());
1276 insert(__u.begin(), __u.end());
1277}
1278
1279template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1280unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1281 const unordered_map& __u, const allocator_type& __a)
1282 : __table_(__u.__table_, __a)
1283{
Howard Hinnant39213642013-07-23 22:01:58 +00001284#if _LIBCPP_DEBUG_LEVEL >= 2
1285 __get_db()->__insert_c(this);
1286#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 __table_.rehash(__u.bucket_count());
1288 insert(__u.begin(), __u.end());
1289}
1290
Howard Hinnant73d21a42010-09-04 23:28:19 +00001291#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292
1293template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001294inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1296 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001297 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001298 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299{
Howard Hinnant39213642013-07-23 22:01:58 +00001300#if _LIBCPP_DEBUG_LEVEL >= 2
1301 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001302 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001303#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304}
1305
1306template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1307unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1308 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001309 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310{
Howard Hinnant39213642013-07-23 22:01:58 +00001311#if _LIBCPP_DEBUG_LEVEL >= 2
1312 __get_db()->__insert_c(this);
1313#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314 if (__a != __u.get_allocator())
1315 {
1316 iterator __i = __u.begin();
Eric Fiselier2960ae22016-02-11 11:59:44 +00001317 while (__u.size() != 0) {
1318 __table_.__emplace_unique(_VSTD::move(
1319 __u.__table_.remove((__i++).__i_)->__value_.__nc));
1320 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001322#if _LIBCPP_DEBUG_LEVEL >= 2
1323 else
1324 __get_db()->swap(this, &__u);
1325#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001326}
1327
Howard Hinnant73d21a42010-09-04 23:28:19 +00001328#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001329
Howard Hinnante3e32912011-08-12 21:56:02 +00001330#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1331
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1333unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1334 initializer_list<value_type> __il)
1335{
Howard Hinnant39213642013-07-23 22:01:58 +00001336#if _LIBCPP_DEBUG_LEVEL >= 2
1337 __get_db()->__insert_c(this);
1338#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339 insert(__il.begin(), __il.end());
1340}
1341
1342template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1343unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1344 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1345 const key_equal& __eql)
1346 : __table_(__hf, __eql)
1347{
Howard Hinnant39213642013-07-23 22:01:58 +00001348#if _LIBCPP_DEBUG_LEVEL >= 2
1349 __get_db()->__insert_c(this);
1350#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351 __table_.rehash(__n);
1352 insert(__il.begin(), __il.end());
1353}
1354
1355template <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, size_type __n, const hasher& __hf,
1358 const key_equal& __eql, const allocator_type& __a)
1359 : __table_(__hf, __eql, __a)
1360{
Howard Hinnant39213642013-07-23 22:01:58 +00001361#if _LIBCPP_DEBUG_LEVEL >= 2
1362 __get_db()->__insert_c(this);
1363#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364 __table_.rehash(__n);
1365 insert(__il.begin(), __il.end());
1366}
1367
Howard Hinnante3e32912011-08-12 21:56:02 +00001368#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1369
Howard Hinnant73d21a42010-09-04 23:28:19 +00001370#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371
1372template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1375unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001376 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001378 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 return *this;
1380}
1381
Howard Hinnant73d21a42010-09-04 23:28:19 +00001382#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383
Howard Hinnante3e32912011-08-12 21:56:02 +00001384#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1385
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1389unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1390 initializer_list<value_type> __il)
1391{
1392 __table_.__assign_unique(__il.begin(), __il.end());
1393 return *this;
1394}
1395
Howard Hinnante3e32912011-08-12 21:56:02 +00001396#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1397
Eric Fiselier410ed302016-02-11 21:45:53 +00001398#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1400typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001401unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402{
1403 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001404 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001405 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001407 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:33 +00001409 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410}
Eric Fiselier410ed302016-02-11 21:45:53 +00001411#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1414template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416void
1417unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1418 _InputIterator __last)
1419{
1420 for (; __first != __last; ++__first)
1421 __table_.__insert_unique(*__first);
1422}
1423
Eric Fiselier410ed302016-02-11 21:45:53 +00001424#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1426_Tp&
1427unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1428{
1429 iterator __i = find(__k);
1430 if (__i != end())
1431 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001432 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1434 __h.release();
1435 return __r.first->second;
1436}
Eric Fiselier410ed302016-02-11 21:45:53 +00001437#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
Eric Fiselier410ed302016-02-11 21:45:53 +00001439template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1440_Tp&
1441unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1442{
1443 return __table_.__emplace_unique_key_args(__k,
1444 std::piecewise_construct, std::forward_as_tuple(__k),
1445 std::forward_as_tuple()).first->__cc.second;
1446}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447
1448template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1449_Tp&
1450unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1451{
Eric Fiselier410ed302016-02-11 21:45:53 +00001452 return __table_.__emplace_unique_key_args(__k,
1453 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1454 std::forward_as_tuple()).first->__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455}
1456
Eric Fiselier410ed302016-02-11 21:45:53 +00001457#endif // !_LIBCPP_CXX03_MODE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458
1459template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1460_Tp&
1461unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1462{
1463 iterator __i = find(__k);
1464#ifndef _LIBCPP_NO_EXCEPTIONS
1465 if (__i == end())
1466 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001467#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468 return __i->second;
1469}
1470
1471template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1472const _Tp&
1473unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1474{
1475 const_iterator __i = find(__k);
1476#ifndef _LIBCPP_NO_EXCEPTIONS
1477 if (__i == end())
1478 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001479#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480 return __i->second;
1481}
1482
1483template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485void
1486swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1487 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001488 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489{
1490 __x.swap(__y);
1491}
1492
1493template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1494bool
1495operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1496 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1497{
1498 if (__x.size() != __y.size())
1499 return false;
1500 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1501 const_iterator;
1502 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1503 __i != __ex; ++__i)
1504 {
1505 const_iterator __j = __y.find(__i->first);
1506 if (__j == __ey || !(*__i == *__j))
1507 return false;
1508 }
1509 return true;
1510}
1511
1512template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514bool
1515operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1516 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1517{
1518 return !(__x == __y);
1519}
1520
1521template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1522 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001523class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524{
1525public:
1526 // types
1527 typedef _Key key_type;
1528 typedef _Tp mapped_type;
1529 typedef _Hash hasher;
1530 typedef _Pred key_equal;
1531 typedef _Alloc allocator_type;
1532 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001533 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 typedef value_type& reference;
1535 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001536 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1537 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538
1539private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001540 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001541 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1542 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001543 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1544 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545
1546 typedef __hash_table<__value_type, __hasher,
1547 __key_equal, __allocator_type> __table;
1548
1549 __table __table_;
1550
Eric Fiselier2960ae22016-02-11 11:59:44 +00001551 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 typedef typename __table::__node_traits __node_traits;
1553 typedef typename __table::__node_allocator __node_allocator;
1554 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001555 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1556 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001558 static_assert((is_same<typename __node_traits::size_type,
1559 typename __alloc_traits::size_type>::value),
1560 "Allocator uses different size_type for different types");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561public:
1562 typedef typename __alloc_traits::pointer pointer;
1563 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23 +00001564 typedef typename __table::size_type size_type;
1565 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566
1567 typedef __hash_map_iterator<typename __table::iterator> iterator;
1568 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1569 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1570 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1571
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001573 unordered_multimap()
1574 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001575 {
1576#if _LIBCPP_DEBUG_LEVEL >= 2
1577 __get_db()->__insert_c(this);
1578#endif
1579 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1581 const key_equal& __eql = key_equal());
1582 unordered_multimap(size_type __n, const hasher& __hf,
1583 const key_equal& __eql,
1584 const allocator_type& __a);
1585 template <class _InputIterator>
1586 unordered_multimap(_InputIterator __first, _InputIterator __last);
1587 template <class _InputIterator>
1588 unordered_multimap(_InputIterator __first, _InputIterator __last,
1589 size_type __n, const hasher& __hf = hasher(),
1590 const key_equal& __eql = key_equal());
1591 template <class _InputIterator>
1592 unordered_multimap(_InputIterator __first, _InputIterator __last,
1593 size_type __n, const hasher& __hf,
1594 const key_equal& __eql,
1595 const allocator_type& __a);
1596 explicit unordered_multimap(const allocator_type& __a);
1597 unordered_multimap(const unordered_multimap& __u);
1598 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001599#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001600 unordered_multimap(unordered_multimap&& __u)
1601 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001603#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001604#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 unordered_multimap(initializer_list<value_type> __il);
1606 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1607 const hasher& __hf = hasher(),
1608 const key_equal& __eql = key_equal());
1609 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1610 const hasher& __hf, const key_equal& __eql,
1611 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001612#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001613#if _LIBCPP_STD_VER > 11
1614 _LIBCPP_INLINE_VISIBILITY
1615 unordered_multimap(size_type __n, const allocator_type& __a)
1616 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1617 _LIBCPP_INLINE_VISIBILITY
1618 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1619 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1620 template <class _InputIterator>
1621 _LIBCPP_INLINE_VISIBILITY
1622 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1623 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1624 template <class _InputIterator>
1625 _LIBCPP_INLINE_VISIBILITY
1626 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1627 const allocator_type& __a)
1628 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1629 _LIBCPP_INLINE_VISIBILITY
1630 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1631 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1632 _LIBCPP_INLINE_VISIBILITY
1633 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1634 const allocator_type& __a)
1635 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1636#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001638 _LIBCPP_INLINE_VISIBILITY
1639 unordered_multimap& operator=(const unordered_multimap& __u)
1640 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001641#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001642 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001643#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001644 if (this != &__u) {
1645 __table_.clear();
1646 __table_.hash_function() = __u.__table_.hash_function();
1647 __table_.key_eq() = __u.__table_.key_eq();
1648 __table_.max_load_factor() = __u.__table_.max_load_factor();
1649 __table_.__copy_assign_alloc(__u.__table_);
1650 insert(__u.begin(), __u.end());
1651 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001652#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001653 return *this;
1654 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001655#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001656 unordered_multimap& operator=(unordered_multimap&& __u)
1657 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001659#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001661#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001664 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665 {return allocator_type(__table_.__node_alloc());}
1666
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001668 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001670 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001672 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001675 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001677 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001679 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001681 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001683 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001685 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686
Eric Fiselier2960ae22016-02-11 11:59:44 +00001687#ifndef _LIBCPP_CXX03_LANG
1688 template <class... _Args>
1689 iterator emplace(_Args&&... __args) {
1690 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1691 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001692
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001693 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:44 +00001694 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1695 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1696 }
1697#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001701#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001702 template <class _Pp,
1703 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001705 iterator insert(_Pp&& __x)
1706 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001707#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 iterator insert(const_iterator __p, const value_type& __x)
1710 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001711#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001712 template <class _Pp,
1713 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001715 iterator insert(const_iterator __p, _Pp&& __x)
1716 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001717#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 template <class _InputIterator>
1719 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001720#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 void insert(initializer_list<value_type> __il)
1723 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001724#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001728 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001729 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 iterator erase(const_iterator __first, const_iterator __last)
1734 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001736 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001739 void swap(unordered_multimap& __u)
1740 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1741 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 hasher hash_function() const
1745 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747 key_equal key_eq() const
1748 {return __table_.key_eq().key_eq();}
1749
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757 pair<iterator, iterator> equal_range(const key_type& __k)
1758 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1761 {return __table_.__equal_range_multi(__k);}
1762
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001764 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001766 size_type max_bucket_count() const _NOEXCEPT
1767 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001768
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001770 size_type bucket_size(size_type __n) const
1771 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1774
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001780 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001784 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1787
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001789 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001791 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 void reserve(size_type __n) {__table_.reserve(__n);}
1798
Howard Hinnant39213642013-07-23 22:01:58 +00001799#if _LIBCPP_DEBUG_LEVEL >= 2
1800
1801 bool __dereferenceable(const const_iterator* __i) const
1802 {return __table_.__dereferenceable(&__i->__i_);}
1803 bool __decrementable(const const_iterator* __i) const
1804 {return __table_.__decrementable(&__i->__i_);}
1805 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1806 {return __table_.__addable(&__i->__i_, __n);}
1807 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1808 {return __table_.__addable(&__i->__i_, __n);}
1809
1810#endif // _LIBCPP_DEBUG_LEVEL >= 2
1811
Eric Fiselier2960ae22016-02-11 11:59:44 +00001812
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813};
1814
1815template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1816unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1817 size_type __n, const hasher& __hf, const key_equal& __eql)
1818 : __table_(__hf, __eql)
1819{
Howard Hinnant39213642013-07-23 22:01:58 +00001820#if _LIBCPP_DEBUG_LEVEL >= 2
1821 __get_db()->__insert_c(this);
1822#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 __table_.rehash(__n);
1824}
1825
1826template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1827unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1828 size_type __n, const hasher& __hf, const key_equal& __eql,
1829 const allocator_type& __a)
1830 : __table_(__hf, __eql, __a)
1831{
Howard Hinnant39213642013-07-23 22:01:58 +00001832#if _LIBCPP_DEBUG_LEVEL >= 2
1833 __get_db()->__insert_c(this);
1834#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835 __table_.rehash(__n);
1836}
1837
1838template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1839template <class _InputIterator>
1840unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1841 _InputIterator __first, _InputIterator __last)
1842{
Howard Hinnant39213642013-07-23 22:01:58 +00001843#if _LIBCPP_DEBUG_LEVEL >= 2
1844 __get_db()->__insert_c(this);
1845#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846 insert(__first, __last);
1847}
1848
1849template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1850template <class _InputIterator>
1851unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1852 _InputIterator __first, _InputIterator __last, size_type __n,
1853 const hasher& __hf, const key_equal& __eql)
1854 : __table_(__hf, __eql)
1855{
Howard Hinnant39213642013-07-23 22:01:58 +00001856#if _LIBCPP_DEBUG_LEVEL >= 2
1857 __get_db()->__insert_c(this);
1858#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 __table_.rehash(__n);
1860 insert(__first, __last);
1861}
1862
1863template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1864template <class _InputIterator>
1865unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1866 _InputIterator __first, _InputIterator __last, size_type __n,
1867 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1868 : __table_(__hf, __eql, __a)
1869{
Howard Hinnant39213642013-07-23 22:01:58 +00001870#if _LIBCPP_DEBUG_LEVEL >= 2
1871 __get_db()->__insert_c(this);
1872#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 __table_.rehash(__n);
1874 insert(__first, __last);
1875}
1876
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001879unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1880 const allocator_type& __a)
1881 : __table_(__a)
1882{
Howard Hinnant39213642013-07-23 22:01:58 +00001883#if _LIBCPP_DEBUG_LEVEL >= 2
1884 __get_db()->__insert_c(this);
1885#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886}
1887
1888template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1889unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1890 const unordered_multimap& __u)
1891 : __table_(__u.__table_)
1892{
Howard Hinnant39213642013-07-23 22:01:58 +00001893#if _LIBCPP_DEBUG_LEVEL >= 2
1894 __get_db()->__insert_c(this);
1895#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896 __table_.rehash(__u.bucket_count());
1897 insert(__u.begin(), __u.end());
1898}
1899
1900template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1901unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1902 const unordered_multimap& __u, const allocator_type& __a)
1903 : __table_(__u.__table_, __a)
1904{
Howard Hinnant39213642013-07-23 22:01:58 +00001905#if _LIBCPP_DEBUG_LEVEL >= 2
1906 __get_db()->__insert_c(this);
1907#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908 __table_.rehash(__u.bucket_count());
1909 insert(__u.begin(), __u.end());
1910}
1911
Howard Hinnant73d21a42010-09-04 23:28:19 +00001912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913
1914template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1917 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001918 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001919 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920{
Howard Hinnant39213642013-07-23 22:01:58 +00001921#if _LIBCPP_DEBUG_LEVEL >= 2
1922 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001923 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001924#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925}
1926
1927template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1928unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1929 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001930 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931{
Howard Hinnant39213642013-07-23 22:01:58 +00001932#if _LIBCPP_DEBUG_LEVEL >= 2
1933 __get_db()->__insert_c(this);
1934#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 if (__a != __u.get_allocator())
1936 {
1937 iterator __i = __u.begin();
1938 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00001939 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940 __table_.__insert_multi(
Eric Fiselier2960ae22016-02-11 11:59:44 +00001941 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942 );
Howard Hinnant39213642013-07-23 22:01:58 +00001943 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001945#if _LIBCPP_DEBUG_LEVEL >= 2
1946 else
1947 __get_db()->swap(this, &__u);
1948#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949}
1950
Howard Hinnant73d21a42010-09-04 23:28:19 +00001951#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001952
Howard Hinnante3e32912011-08-12 21:56:02 +00001953#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1954
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1956unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1957 initializer_list<value_type> __il)
1958{
Howard Hinnant39213642013-07-23 22:01:58 +00001959#if _LIBCPP_DEBUG_LEVEL >= 2
1960 __get_db()->__insert_c(this);
1961#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 insert(__il.begin(), __il.end());
1963}
1964
1965template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1966unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1967 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1968 const key_equal& __eql)
1969 : __table_(__hf, __eql)
1970{
Howard Hinnant39213642013-07-23 22:01:58 +00001971#if _LIBCPP_DEBUG_LEVEL >= 2
1972 __get_db()->__insert_c(this);
1973#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974 __table_.rehash(__n);
1975 insert(__il.begin(), __il.end());
1976}
1977
1978template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1979unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1980 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1981 const key_equal& __eql, const allocator_type& __a)
1982 : __table_(__hf, __eql, __a)
1983{
Howard Hinnant39213642013-07-23 22:01:58 +00001984#if _LIBCPP_DEBUG_LEVEL >= 2
1985 __get_db()->__insert_c(this);
1986#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987 __table_.rehash(__n);
1988 insert(__il.begin(), __il.end());
1989}
1990
Howard Hinnante3e32912011-08-12 21:56:02 +00001991#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1992
Howard Hinnant73d21a42010-09-04 23:28:19 +00001993#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994
1995template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001996inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1998unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001999 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002001 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002 return *this;
2003}
2004
Howard Hinnant73d21a42010-09-04 23:28:19 +00002005#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006
Howard Hinnante3e32912011-08-12 21:56:02 +00002007#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2008
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2012unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2013 initializer_list<value_type> __il)
2014{
2015 __table_.__assign_multi(__il.begin(), __il.end());
2016 return *this;
2017}
2018
Howard Hinnante3e32912011-08-12 21:56:02 +00002019#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022
2023template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2024template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026void
2027unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2028 _InputIterator __last)
2029{
2030 for (; __first != __last; ++__first)
2031 __table_.__insert_multi(*__first);
2032}
2033
2034template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002035inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036void
2037swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2038 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002039 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040{
2041 __x.swap(__y);
2042}
2043
2044template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2045bool
2046operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2047 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2048{
2049 if (__x.size() != __y.size())
2050 return false;
2051 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2052 const_iterator;
2053 typedef pair<const_iterator, const_iterator> _EqRng;
2054 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2055 {
2056 _EqRng __xeq = __x.equal_range(__i->first);
2057 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002058 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2059 _VSTD::distance(__yeq.first, __yeq.second) ||
2060 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061 return false;
2062 __i = __xeq.second;
2063 }
2064 return true;
2065}
2066
2067template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002068inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069bool
2070operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2071 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2072{
2073 return !(__x == __y);
2074}
2075
2076_LIBCPP_END_NAMESPACE_STD
2077
2078#endif // _LIBCPP_UNORDERED_MAP