blob: 6cd82f5c9f52850dc94d2fa15178c0dadc86a0af [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
125 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000126 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000127 size_type erase(const key_type& k);
128 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000129 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000131 void swap(unordered_map&)
132 noexcept(
133 (!allocator_type::propagate_on_container_swap::value ||
134 __is_nothrow_swappable<allocator_type>::value) &&
135 __is_nothrow_swappable<hasher>::value &&
136 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137
138 hasher hash_function() const;
139 key_equal key_eq() const;
140
141 iterator find(const key_type& k);
142 const_iterator find(const key_type& k) const;
143 size_type count(const key_type& k) const;
144 pair<iterator, iterator> equal_range(const key_type& k);
145 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
146
147 mapped_type& operator[](const key_type& k);
148 mapped_type& operator[](key_type&& k);
149
150 mapped_type& at(const key_type& k);
151 const mapped_type& at(const key_type& k) const;
152
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000153 size_type bucket_count() const noexcept;
154 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155
156 size_type bucket_size(size_type n) const;
157 size_type bucket(const key_type& k) const;
158
159 local_iterator begin(size_type n);
160 local_iterator end(size_type n);
161 const_local_iterator begin(size_type n) const;
162 const_local_iterator end(size_type n) const;
163 const_local_iterator cbegin(size_type n) const;
164 const_local_iterator cend(size_type n) const;
165
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000166 float load_factor() const noexcept;
167 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000168 void max_load_factor(float z);
169 void rehash(size_type n);
170 void reserve(size_type n);
171};
172
173template <class Key, class T, class Hash, class Pred, class Alloc>
174 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000175 unordered_map<Key, T, Hash, Pred, Alloc>& y)
176 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177
178template <class Key, class T, class Hash, class Pred, class Alloc>
179 bool
180 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
181 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
182
183template <class Key, class T, class Hash, class Pred, class Alloc>
184 bool
185 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
186 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
187
188template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
189 class Alloc = allocator<pair<const Key, T>>>
190class unordered_multimap
191{
192public:
193 // types
194 typedef Key key_type;
195 typedef T mapped_type;
196 typedef Hash hasher;
197 typedef Pred key_equal;
198 typedef Alloc allocator_type;
199 typedef pair<const key_type, mapped_type> value_type;
200 typedef value_type& reference;
201 typedef const value_type& const_reference;
202 typedef typename allocator_traits<allocator_type>::pointer pointer;
203 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
204 typedef typename allocator_traits<allocator_type>::size_type size_type;
205 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
206
207 typedef /unspecified/ iterator;
208 typedef /unspecified/ const_iterator;
209 typedef /unspecified/ local_iterator;
210 typedef /unspecified/ const_local_iterator;
211
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000212 unordered_multimap()
213 noexcept(
214 is_nothrow_default_constructible<hasher>::value &&
215 is_nothrow_default_constructible<key_equal>::value &&
216 is_nothrow_default_constructible<allocator_type>::value);
217 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 const key_equal& eql = key_equal(),
219 const allocator_type& a = allocator_type());
220 template <class InputIterator>
221 unordered_multimap(InputIterator f, InputIterator l,
222 size_type n = 0, const hasher& hf = hasher(),
223 const key_equal& eql = key_equal(),
224 const allocator_type& a = allocator_type());
225 explicit unordered_multimap(const allocator_type&);
226 unordered_multimap(const unordered_multimap&);
227 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000228 unordered_multimap(unordered_multimap&&)
229 noexcept(
230 is_nothrow_move_constructible<hasher>::value &&
231 is_nothrow_move_constructible<key_equal>::value &&
232 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233 unordered_multimap(unordered_multimap&&, const Allocator&);
234 unordered_multimap(initializer_list<value_type>, size_type n = 0,
235 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
Marshall Clow6dff6182013-09-12 03:00:31 +0000237 unordered_multimap(size_type n, const allocator_type& a)
238 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
239 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
240 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
241 template <class InputIterator>
242 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
243 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
244 template <class InputIterator>
245 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
246 const allocator_type& a)
247 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
248 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
249 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
250 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
251 const allocator_type& a)
252 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253 ~unordered_multimap();
254 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000255 unordered_multimap& operator=(unordered_multimap&&)
256 noexcept(
257 allocator_type::propagate_on_container_move_assignment::value &&
258 is_nothrow_move_assignable<allocator_type>::value &&
259 is_nothrow_move_assignable<hasher>::value &&
260 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261 unordered_multimap& operator=(initializer_list<value_type>);
262
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000263 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000265 bool empty() const noexcept;
266 size_type size() const noexcept;
267 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000269 iterator begin() noexcept;
270 iterator end() noexcept;
271 const_iterator begin() const noexcept;
272 const_iterator end() const noexcept;
273 const_iterator cbegin() const noexcept;
274 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275
276 template <class... Args>
277 iterator emplace(Args&&... args);
278 template <class... Args>
279 iterator emplace_hint(const_iterator position, Args&&... args);
280 iterator insert(const value_type& obj);
281 template <class P>
282 iterator insert(P&& obj);
283 iterator insert(const_iterator hint, const value_type& obj);
284 template <class P>
285 iterator insert(const_iterator hint, P&& obj);
286 template <class InputIterator>
287 void insert(InputIterator first, InputIterator last);
288 void insert(initializer_list<value_type>);
289
290 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000291 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000292 size_type erase(const key_type& k);
293 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000294 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000295
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000296 void swap(unordered_multimap&)
297 noexcept(
298 (!allocator_type::propagate_on_container_swap::value ||
299 __is_nothrow_swappable<allocator_type>::value) &&
300 __is_nothrow_swappable<hasher>::value &&
301 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
303 hasher hash_function() const;
304 key_equal key_eq() const;
305
306 iterator find(const key_type& k);
307 const_iterator find(const key_type& k) const;
308 size_type count(const key_type& k) const;
309 pair<iterator, iterator> equal_range(const key_type& k);
310 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
311
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000312 size_type bucket_count() const noexcept;
313 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314
315 size_type bucket_size(size_type n) const;
316 size_type bucket(const key_type& k) const;
317
318 local_iterator begin(size_type n);
319 local_iterator end(size_type n);
320 const_local_iterator begin(size_type n) const;
321 const_local_iterator end(size_type n) const;
322 const_local_iterator cbegin(size_type n) const;
323 const_local_iterator cend(size_type n) const;
324
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000325 float load_factor() const noexcept;
326 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 void max_load_factor(float z);
328 void rehash(size_type n);
329 void reserve(size_type n);
330};
331
332template <class Key, class T, class Hash, class Pred, class Alloc>
333 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000334 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
335 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336
337template <class Key, class T, class Hash, class Pred, class Alloc>
338 bool
339 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
340 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
341
342template <class Key, class T, class Hash, class Pred, class Alloc>
343 bool
344 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
345 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
346
347} // std
348
349*/
350
351#include <__config>
352#include <__hash_table>
353#include <functional>
354#include <stdexcept>
355
Eric Fiselierb9536102014-08-10 23:53:08 +0000356#include <__debug>
357
Howard Hinnant08e17472011-10-17 20:05:10 +0000358#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000360#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362_LIBCPP_BEGIN_NAMESPACE_STD
363
Howard Hinnant9b128e02013-07-05 18:06:00 +0000364template <class _Key, class _Cp, class _Hash, bool = is_empty<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000365#if __has_feature(is_final)
366 && !__is_final(_Hash)
367#endif
368 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369class __unordered_map_hasher
370 : private _Hash
371{
372public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000374 __unordered_map_hasher()
375 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
376 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000378 __unordered_map_hasher(const _Hash& __h)
379 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
380 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000382 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000384 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000385 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000386 _LIBCPP_INLINE_VISIBILITY
387 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 {return static_cast<const _Hash&>(*this)(__x);}
389};
390
Howard Hinnant9b128e02013-07-05 18:06:00 +0000391template <class _Key, class _Cp, class _Hash>
392class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393{
394 _Hash __hash_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000395
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000398 __unordered_map_hasher()
399 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
400 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000402 __unordered_map_hasher(const _Hash& __h)
403 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
404 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000406 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000408 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000409 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000410 _LIBCPP_INLINE_VISIBILITY
411 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 {return __hash_(__x);}
413};
414
Howard Hinnant9b128e02013-07-05 18:06:00 +0000415template <class _Key, class _Cp, class _Pred, bool = is_empty<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000416#if __has_feature(is_final)
417 && !__is_final(_Pred)
418#endif
419 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420class __unordered_map_equal
421 : private _Pred
422{
423public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000425 __unordered_map_equal()
426 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
427 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000429 __unordered_map_equal(const _Pred& __p)
430 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
431 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000433 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000435 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000436 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000437 _LIBCPP_INLINE_VISIBILITY
438 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000439 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000441 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000442 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443};
444
Howard Hinnant9b128e02013-07-05 18:06:00 +0000445template <class _Key, class _Cp, class _Pred>
446class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447{
448 _Pred __pred_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000449
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000452 __unordered_map_equal()
453 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
454 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000456 __unordered_map_equal(const _Pred& __p)
457 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
458 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000460 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000462 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000463 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000464 _LIBCPP_INLINE_VISIBILITY
465 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000466 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000468 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000469 {return __pred_(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470};
471
472template <class _Alloc>
473class __hash_map_node_destructor
474{
475 typedef _Alloc allocator_type;
476 typedef allocator_traits<allocator_type> __alloc_traits;
477 typedef typename __alloc_traits::value_type::value_type value_type;
478public:
479 typedef typename __alloc_traits::pointer pointer;
480private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000481 typedef typename value_type::value_type::first_type first_type;
482 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483
484 allocator_type& __na_;
485
486 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
487
488public:
489 bool __first_constructed;
490 bool __second_constructed;
491
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000493 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 : __na_(__na),
495 __first_constructed(false),
496 __second_constructed(false)
497 {}
498
Howard Hinnant73d21a42010-09-04 23:28:19 +0000499#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000502 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503 : __na_(__x.__na_),
504 __first_constructed(__x.__value_constructed),
505 __second_constructed(__x.__value_constructed)
506 {
507 __x.__value_constructed = false;
508 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000509#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
512 : __na_(__x.__na_),
513 __first_constructed(__x.__value_constructed),
514 __second_constructed(__x.__value_constructed)
515 {
516 const_cast<bool&>(__x.__value_constructed) = false;
517 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000518#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000521 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522 {
523 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000524 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000526 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 if (__p)
528 __alloc_traits::deallocate(__na_, __p, 1);
529 }
530};
531
Howard Hinnantff7546e2013-09-30 19:08:22 +0000532#if __cplusplus >= 201103L
533
534template <class _Key, class _Tp>
535union __hash_value_type
536{
537 typedef _Key key_type;
538 typedef _Tp mapped_type;
539 typedef pair<const key_type, mapped_type> value_type;
540 typedef pair<key_type, mapped_type> __nc_value_type;
541
542 value_type __cc;
543 __nc_value_type __nc;
544
545 template <class ..._Args>
546 _LIBCPP_INLINE_VISIBILITY
547 __hash_value_type(_Args&& ...__args)
548 : __cc(std::forward<_Args>(__args)...) {}
549
550 _LIBCPP_INLINE_VISIBILITY
551 __hash_value_type(const __hash_value_type& __v)
552 : __cc(__v.__cc) {}
553
554 _LIBCPP_INLINE_VISIBILITY
555 __hash_value_type(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000556 : __nc(_VSTD::move(__v.__nc)) {}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000557
558 _LIBCPP_INLINE_VISIBILITY
559 __hash_value_type& operator=(const __hash_value_type& __v)
560 {__nc = __v.__cc; return *this;}
561
562 _LIBCPP_INLINE_VISIBILITY
563 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000564 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000565
566 _LIBCPP_INLINE_VISIBILITY
567 ~__hash_value_type() {__cc.~value_type();}
568};
569
570#else
571
572template <class _Key, class _Tp>
573struct __hash_value_type
574{
575 typedef _Key key_type;
576 typedef _Tp mapped_type;
577 typedef pair<const key_type, mapped_type> value_type;
578
579 value_type __cc;
580
581 _LIBCPP_INLINE_VISIBILITY
582 __hash_value_type() {}
583
584 template <class _A0>
585 _LIBCPP_INLINE_VISIBILITY
586 __hash_value_type(const _A0& __a0)
587 : __cc(__a0) {}
588
589 template <class _A0, class _A1>
590 _LIBCPP_INLINE_VISIBILITY
591 __hash_value_type(const _A0& __a0, const _A1& __a1)
592 : __cc(__a0, __a1) {}
593};
594
595#endif
596
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000598class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599{
600 _HashIterator __i_;
601
602 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000603 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
604 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605public:
606 typedef forward_iterator_tag iterator_category;
607 typedef pair<key_type, mapped_type> value_type;
608 typedef typename _HashIterator::difference_type difference_type;
609 typedef value_type& reference;
610 typedef typename __pointer_traits::template
611#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
612 rebind<value_type>
613#else
614 rebind<value_type>::other
615#endif
616 pointer;
617
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000619 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000622 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000625 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000627 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 __hash_map_iterator operator++(int)
633 {
634 __hash_map_iterator __t(*this);
635 ++(*this);
636 return __t;
637 }
638
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000639 friend _LIBCPP_INLINE_VISIBILITY
640 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000642 friend _LIBCPP_INLINE_VISIBILITY
643 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 {return __x.__i_ != __y.__i_;}
645
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000646 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
647 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
648 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
649 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
650 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651};
652
653template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000654class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655{
656 _HashIterator __i_;
657
658 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000659 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
660 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661public:
662 typedef forward_iterator_tag iterator_category;
663 typedef pair<key_type, mapped_type> value_type;
664 typedef typename _HashIterator::difference_type difference_type;
665 typedef const value_type& reference;
666 typedef typename __pointer_traits::template
667#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant099084d2011-07-23 16:14:35 +0000668 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669#else
Howard Hinnant099084d2011-07-23 16:14:35 +0000670 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671#endif
672 pointer;
673
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000675 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000678 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 __hash_map_const_iterator(
681 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000682 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 : __i_(__i.__i_) {}
684
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000686 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000688 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 __hash_map_const_iterator operator++(int)
694 {
695 __hash_map_const_iterator __t(*this);
696 ++(*this);
697 return __t;
698 }
699
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000700 friend _LIBCPP_INLINE_VISIBILITY
701 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 friend _LIBCPP_INLINE_VISIBILITY
704 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return __x.__i_ != __y.__i_;}
706
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000707 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
708 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
709 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
710 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711};
712
713template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
714 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000715class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716{
717public:
718 // types
719 typedef _Key key_type;
720 typedef _Tp mapped_type;
721 typedef _Hash hasher;
722 typedef _Pred key_equal;
723 typedef _Alloc allocator_type;
724 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000725 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726 typedef value_type& reference;
727 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000728 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
729 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730
731private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000732 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000733 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
734 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000735 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
736 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737
738 typedef __hash_table<__value_type, __hasher,
739 __key_equal, __allocator_type> __table;
740
741 __table __table_;
742
743 typedef typename __table::__node_pointer __node_pointer;
744 typedef typename __table::__node_const_pointer __node_const_pointer;
745 typedef typename __table::__node_traits __node_traits;
746 typedef typename __table::__node_allocator __node_allocator;
747 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000748 typedef __hash_map_node_destructor<__node_allocator> _Dp;
749 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 typedef allocator_traits<allocator_type> __alloc_traits;
751public:
752 typedef typename __alloc_traits::pointer pointer;
753 typedef typename __alloc_traits::const_pointer const_pointer;
754 typedef typename __alloc_traits::size_type size_type;
755 typedef typename __alloc_traits::difference_type difference_type;
756
757 typedef __hash_map_iterator<typename __table::iterator> iterator;
758 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
759 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
760 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
761
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000763 unordered_map()
764 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000765 {
766#if _LIBCPP_DEBUG_LEVEL >= 2
767 __get_db()->__insert_c(this);
768#endif
769 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
771 const key_equal& __eql = key_equal());
772 unordered_map(size_type __n, const hasher& __hf,
773 const key_equal& __eql,
774 const allocator_type& __a);
775 template <class _InputIterator>
776 unordered_map(_InputIterator __first, _InputIterator __last);
777 template <class _InputIterator>
778 unordered_map(_InputIterator __first, _InputIterator __last,
779 size_type __n, const hasher& __hf = hasher(),
780 const key_equal& __eql = key_equal());
781 template <class _InputIterator>
782 unordered_map(_InputIterator __first, _InputIterator __last,
783 size_type __n, const hasher& __hf,
784 const key_equal& __eql,
785 const allocator_type& __a);
786 explicit unordered_map(const allocator_type& __a);
787 unordered_map(const unordered_map& __u);
788 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000789#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000790 unordered_map(unordered_map&& __u)
791 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000793#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000794#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 unordered_map(initializer_list<value_type> __il);
796 unordered_map(initializer_list<value_type> __il, size_type __n,
797 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
798 unordered_map(initializer_list<value_type> __il, size_type __n,
799 const hasher& __hf, const key_equal& __eql,
800 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000801#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000802#if _LIBCPP_STD_VER > 11
803 _LIBCPP_INLINE_VISIBILITY
804 unordered_map(size_type __n, const allocator_type& __a)
805 : unordered_map(__n, hasher(), key_equal(), __a) {}
806 _LIBCPP_INLINE_VISIBILITY
807 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
808 : unordered_map(__n, __hf, key_equal(), __a) {}
809 template <class _InputIterator>
810 _LIBCPP_INLINE_VISIBILITY
811 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
812 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
813 template <class _InputIterator>
814 _LIBCPP_INLINE_VISIBILITY
815 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
816 const allocator_type& __a)
817 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
818 _LIBCPP_INLINE_VISIBILITY
819 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
820 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
821 _LIBCPP_INLINE_VISIBILITY
822 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
823 const allocator_type& __a)
824 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
825#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000827 _LIBCPP_INLINE_VISIBILITY
828 unordered_map& operator=(const unordered_map& __u)
829 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000830#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000831 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000832#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000833 if (this != &__u) {
834 __table_.clear();
835 __table_.hash_function() = __u.__table_.hash_function();
836 __table_.key_eq() = __u.__table_.key_eq();
837 __table_.max_load_factor() = __u.__table_.max_load_factor();
838 __table_.__copy_assign_alloc(__u.__table_);
839 insert(__u.begin(), __u.end());
840 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000841#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000842 return *this;
843 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000844#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000845 unordered_map& operator=(unordered_map&& __u)
846 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000848#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000850#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000853 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 {return allocator_type(__table_.__node_alloc());}
855
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000857 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000859 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000861 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000864 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000866 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000868 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000870 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000872 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000874 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875
Howard Hinnant73d21a42010-09-04 23:28:19 +0000876#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000877#ifndef _LIBCPP_HAS_NO_VARIADICS
878
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000879 template <class... _Args>
880 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000882 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000884#if _LIBCPP_DEBUG_LEVEL >= 2
885 iterator emplace_hint(const_iterator __p, _Args&&... __args)
886 {
887 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
888 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
889 " referring to this unordered_map");
890 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
891 }
892#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000893 iterator emplace_hint(const_iterator, _Args&&... __args)
894 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000895#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000896#endif // _LIBCPP_HAS_NO_VARIADICS
897#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 pair<iterator, bool> insert(const value_type& __x)
900 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000901#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000902 template <class _Pp,
903 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000905 pair<iterator, bool> insert(_Pp&& __x)
906 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000907#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000909#if _LIBCPP_DEBUG_LEVEL >= 2
910 iterator insert(const_iterator __p, const value_type& __x)
911 {
912 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
913 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
914 " referring to this unordered_map");
915 return insert(__x).first;
916 }
917#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 iterator insert(const_iterator, const value_type& __x)
919 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000920#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000921#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000922 template <class _Pp,
923 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000925#if _LIBCPP_DEBUG_LEVEL >= 2
926 iterator insert(const_iterator __p, _Pp&& __x)
927 {
928 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
929 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
930 " referring to this unordered_map");
931 return insert(_VSTD::forward<_Pp>(__x)).first;
932 }
933#else
Howard Hinnant99968442011-11-29 18:15:50 +0000934 iterator insert(const_iterator, _Pp&& __x)
935 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000936#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000937#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 template <class _InputIterator>
939 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000940#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 void insert(initializer_list<value_type> __il)
943 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000944#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000948 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +0000949 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 iterator erase(const_iterator __first, const_iterator __last)
954 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000956 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000959 void swap(unordered_map& __u)
960 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
961 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000962
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964 hasher hash_function() const
965 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 key_equal key_eq() const
968 {return __table_.key_eq().key_eq();}
969
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 pair<iterator, iterator> equal_range(const key_type& __k)
978 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
981 {return __table_.__equal_range_unique(__k);}
982
983 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000984#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 mapped_type& operator[](key_type&& __k);
986#endif
987
988 mapped_type& at(const key_type& __k);
989 const mapped_type& at(const key_type& __k) const;
990
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000992 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000994 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 size_type bucket_size(size_type __n) const
998 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1001
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001009 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1014
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001016 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001018 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 void reserve(size_type __n) {__table_.reserve(__n);}
1025
Howard Hinnant39213642013-07-23 22:01:58 +00001026#if _LIBCPP_DEBUG_LEVEL >= 2
1027
1028 bool __dereferenceable(const const_iterator* __i) const
1029 {return __table_.__dereferenceable(&__i->__i_);}
1030 bool __decrementable(const const_iterator* __i) const
1031 {return __table_.__decrementable(&__i->__i_);}
1032 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1033 {return __table_.__addable(&__i->__i_, __n);}
1034 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1035 {return __table_.__addable(&__i->__i_, __n);}
1036
1037#endif // _LIBCPP_DEBUG_LEVEL >= 2
1038
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001040#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001041 __node_holder __construct_node();
1042 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001043 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001044 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001045 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001046#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001047 template <class _A0, class _A1, class ..._Args>
1048 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001049#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001050#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1051 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052};
1053
1054template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1055unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1056 size_type __n, const hasher& __hf, const key_equal& __eql)
1057 : __table_(__hf, __eql)
1058{
Howard Hinnant39213642013-07-23 22:01:58 +00001059#if _LIBCPP_DEBUG_LEVEL >= 2
1060 __get_db()->__insert_c(this);
1061#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062 __table_.rehash(__n);
1063}
1064
1065template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1066unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1067 size_type __n, const hasher& __hf, const key_equal& __eql,
1068 const allocator_type& __a)
1069 : __table_(__hf, __eql, __a)
1070{
Howard Hinnant39213642013-07-23 22:01:58 +00001071#if _LIBCPP_DEBUG_LEVEL >= 2
1072 __get_db()->__insert_c(this);
1073#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074 __table_.rehash(__n);
1075}
1076
1077template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1080 const allocator_type& __a)
1081 : __table_(__a)
1082{
Howard Hinnant39213642013-07-23 22:01:58 +00001083#if _LIBCPP_DEBUG_LEVEL >= 2
1084 __get_db()->__insert_c(this);
1085#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086}
1087
1088template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1089template <class _InputIterator>
1090unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1091 _InputIterator __first, _InputIterator __last)
1092{
Howard Hinnant39213642013-07-23 22:01:58 +00001093#if _LIBCPP_DEBUG_LEVEL >= 2
1094 __get_db()->__insert_c(this);
1095#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096 insert(__first, __last);
1097}
1098
1099template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1100template <class _InputIterator>
1101unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1102 _InputIterator __first, _InputIterator __last, size_type __n,
1103 const hasher& __hf, const key_equal& __eql)
1104 : __table_(__hf, __eql)
1105{
Howard Hinnant39213642013-07-23 22:01:58 +00001106#if _LIBCPP_DEBUG_LEVEL >= 2
1107 __get_db()->__insert_c(this);
1108#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 __table_.rehash(__n);
1110 insert(__first, __last);
1111}
1112
1113template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1114template <class _InputIterator>
1115unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1116 _InputIterator __first, _InputIterator __last, size_type __n,
1117 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1118 : __table_(__hf, __eql, __a)
1119{
Howard Hinnant39213642013-07-23 22:01:58 +00001120#if _LIBCPP_DEBUG_LEVEL >= 2
1121 __get_db()->__insert_c(this);
1122#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123 __table_.rehash(__n);
1124 insert(__first, __last);
1125}
1126
1127template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1128unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1129 const unordered_map& __u)
1130 : __table_(__u.__table_)
1131{
Howard Hinnant39213642013-07-23 22:01:58 +00001132#if _LIBCPP_DEBUG_LEVEL >= 2
1133 __get_db()->__insert_c(this);
1134#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 __table_.rehash(__u.bucket_count());
1136 insert(__u.begin(), __u.end());
1137}
1138
1139template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1140unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1141 const unordered_map& __u, const allocator_type& __a)
1142 : __table_(__u.__table_, __a)
1143{
Howard Hinnant39213642013-07-23 22:01:58 +00001144#if _LIBCPP_DEBUG_LEVEL >= 2
1145 __get_db()->__insert_c(this);
1146#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 __table_.rehash(__u.bucket_count());
1148 insert(__u.begin(), __u.end());
1149}
1150
Howard Hinnant73d21a42010-09-04 23:28:19 +00001151#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152
1153template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001154inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1156 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001157 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001158 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159{
Howard Hinnant39213642013-07-23 22:01:58 +00001160#if _LIBCPP_DEBUG_LEVEL >= 2
1161 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001162 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001163#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164}
1165
1166template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1167unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1168 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001169 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170{
Howard Hinnant39213642013-07-23 22:01:58 +00001171#if _LIBCPP_DEBUG_LEVEL >= 2
1172 __get_db()->__insert_c(this);
1173#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 if (__a != __u.get_allocator())
1175 {
1176 iterator __i = __u.begin();
1177 while (__u.size() != 0)
1178 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001179 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180 );
1181 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001182#if _LIBCPP_DEBUG_LEVEL >= 2
1183 else
1184 __get_db()->swap(this, &__u);
1185#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186}
1187
Howard Hinnant73d21a42010-09-04 23:28:19 +00001188#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189
Howard Hinnante3e32912011-08-12 21:56:02 +00001190#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1191
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001192template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1193unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1194 initializer_list<value_type> __il)
1195{
Howard Hinnant39213642013-07-23 22:01:58 +00001196#if _LIBCPP_DEBUG_LEVEL >= 2
1197 __get_db()->__insert_c(this);
1198#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 insert(__il.begin(), __il.end());
1200}
1201
1202template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1203unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1204 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1205 const key_equal& __eql)
1206 : __table_(__hf, __eql)
1207{
Howard Hinnant39213642013-07-23 22:01:58 +00001208#if _LIBCPP_DEBUG_LEVEL >= 2
1209 __get_db()->__insert_c(this);
1210#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211 __table_.rehash(__n);
1212 insert(__il.begin(), __il.end());
1213}
1214
1215template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1216unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1217 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1218 const key_equal& __eql, const allocator_type& __a)
1219 : __table_(__hf, __eql, __a)
1220{
Howard Hinnant39213642013-07-23 22:01:58 +00001221#if _LIBCPP_DEBUG_LEVEL >= 2
1222 __get_db()->__insert_c(this);
1223#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224 __table_.rehash(__n);
1225 insert(__il.begin(), __il.end());
1226}
1227
Howard Hinnante3e32912011-08-12 21:56:02 +00001228#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1229
Howard Hinnant73d21a42010-09-04 23:28:19 +00001230#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231
1232template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001233inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1235unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001236 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001238 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239 return *this;
1240}
1241
Howard Hinnant73d21a42010-09-04 23:28:19 +00001242#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243
Howard Hinnante3e32912011-08-12 21:56:02 +00001244#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1245
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1249unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1250 initializer_list<value_type> __il)
1251{
1252 __table_.__assign_unique(__il.begin(), __il.end());
1253 return *this;
1254}
1255
Howard Hinnante3e32912011-08-12 21:56:02 +00001256#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1257
Howard Hinnant73d21a42010-09-04 23:28:19 +00001258#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259
1260template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001262unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263{
1264 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001265 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001266 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 __h.get_deleter().__second_constructed = true;
1269 return __h;
1270}
1271
1272template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001273template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001274typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1276{
1277 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001278 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001279 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1280 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281 __h.get_deleter().__first_constructed = true;
1282 __h.get_deleter().__second_constructed = true;
1283 return __h;
1284}
1285
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001286template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001287typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1288unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001289{
1290 __node_allocator& __na = __table_.__node_alloc();
1291 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001292 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001293 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001294 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001295 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001296 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001297}
1298
Howard Hinnant73d21a42010-09-04 23:28:19 +00001299#ifndef _LIBCPP_HAS_NO_VARIADICS
1300
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001302template <class _A0, class _A1, class ..._Args>
1303typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1304unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1305 _A1&& __a1,
1306 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001308 __node_allocator& __na = __table_.__node_alloc();
1309 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1310 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1311 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1312 _VSTD::forward<_Args>(__args)...);
1313 __h.get_deleter().__first_constructed = true;
1314 __h.get_deleter().__second_constructed = true;
1315 return __h;
1316}
1317
1318template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1319template <class... _Args>
1320pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
1321unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1322{
1323 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1325 if (__r.second)
1326 __h.release();
1327 return __r;
1328}
1329
Howard Hinnant73d21a42010-09-04 23:28:19 +00001330#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001331#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332
1333template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1334typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001335unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336{
1337 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001338 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001339 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001341 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001343 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001344}
1345
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001346template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1347template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349void
1350unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1351 _InputIterator __last)
1352{
1353 for (; __first != __last; ++__first)
1354 __table_.__insert_unique(*__first);
1355}
1356
1357template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1358_Tp&
1359unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1360{
1361 iterator __i = find(__k);
1362 if (__i != end())
1363 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001364 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1366 __h.release();
1367 return __r.first->second;
1368}
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>
1373_Tp&
1374unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1375{
1376 iterator __i = find(__k);
1377 if (__i != end())
1378 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001379 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1381 __h.release();
1382 return __r.first->second;
1383}
1384
Howard Hinnant73d21a42010-09-04 23:28:19 +00001385#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386
1387template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1388_Tp&
1389unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1390{
1391 iterator __i = find(__k);
1392#ifndef _LIBCPP_NO_EXCEPTIONS
1393 if (__i == end())
1394 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001395#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396 return __i->second;
1397}
1398
1399template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1400const _Tp&
1401unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1402{
1403 const_iterator __i = find(__k);
1404#ifndef _LIBCPP_NO_EXCEPTIONS
1405 if (__i == end())
1406 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001407#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 return __i->second;
1409}
1410
1411template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001412inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413void
1414swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1415 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001416 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417{
1418 __x.swap(__y);
1419}
1420
1421template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1422bool
1423operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1424 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1425{
1426 if (__x.size() != __y.size())
1427 return false;
1428 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1429 const_iterator;
1430 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1431 __i != __ex; ++__i)
1432 {
1433 const_iterator __j = __y.find(__i->first);
1434 if (__j == __ey || !(*__i == *__j))
1435 return false;
1436 }
1437 return true;
1438}
1439
1440template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442bool
1443operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1444 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1445{
1446 return !(__x == __y);
1447}
1448
1449template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1450 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001451class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452{
1453public:
1454 // types
1455 typedef _Key key_type;
1456 typedef _Tp mapped_type;
1457 typedef _Hash hasher;
1458 typedef _Pred key_equal;
1459 typedef _Alloc allocator_type;
1460 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001461 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462 typedef value_type& reference;
1463 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001464 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1465 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466
1467private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001468 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001469 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1470 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001471 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1472 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473
1474 typedef __hash_table<__value_type, __hasher,
1475 __key_equal, __allocator_type> __table;
1476
1477 __table __table_;
1478
1479 typedef typename __table::__node_traits __node_traits;
1480 typedef typename __table::__node_allocator __node_allocator;
1481 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001482 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1483 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484 typedef allocator_traits<allocator_type> __alloc_traits;
1485public:
1486 typedef typename __alloc_traits::pointer pointer;
1487 typedef typename __alloc_traits::const_pointer const_pointer;
1488 typedef typename __alloc_traits::size_type size_type;
1489 typedef typename __alloc_traits::difference_type difference_type;
1490
1491 typedef __hash_map_iterator<typename __table::iterator> iterator;
1492 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1493 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1494 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1495
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001497 unordered_multimap()
1498 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001499 {
1500#if _LIBCPP_DEBUG_LEVEL >= 2
1501 __get_db()->__insert_c(this);
1502#endif
1503 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1505 const key_equal& __eql = key_equal());
1506 unordered_multimap(size_type __n, const hasher& __hf,
1507 const key_equal& __eql,
1508 const allocator_type& __a);
1509 template <class _InputIterator>
1510 unordered_multimap(_InputIterator __first, _InputIterator __last);
1511 template <class _InputIterator>
1512 unordered_multimap(_InputIterator __first, _InputIterator __last,
1513 size_type __n, const hasher& __hf = hasher(),
1514 const key_equal& __eql = key_equal());
1515 template <class _InputIterator>
1516 unordered_multimap(_InputIterator __first, _InputIterator __last,
1517 size_type __n, const hasher& __hf,
1518 const key_equal& __eql,
1519 const allocator_type& __a);
1520 explicit unordered_multimap(const allocator_type& __a);
1521 unordered_multimap(const unordered_multimap& __u);
1522 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001523#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001524 unordered_multimap(unordered_multimap&& __u)
1525 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001527#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001528#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 unordered_multimap(initializer_list<value_type> __il);
1530 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1531 const hasher& __hf = hasher(),
1532 const key_equal& __eql = key_equal());
1533 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1534 const hasher& __hf, const key_equal& __eql,
1535 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001536#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001537#if _LIBCPP_STD_VER > 11
1538 _LIBCPP_INLINE_VISIBILITY
1539 unordered_multimap(size_type __n, const allocator_type& __a)
1540 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1541 _LIBCPP_INLINE_VISIBILITY
1542 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1543 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1544 template <class _InputIterator>
1545 _LIBCPP_INLINE_VISIBILITY
1546 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1547 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1548 template <class _InputIterator>
1549 _LIBCPP_INLINE_VISIBILITY
1550 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1551 const allocator_type& __a)
1552 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1553 _LIBCPP_INLINE_VISIBILITY
1554 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1555 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1556 _LIBCPP_INLINE_VISIBILITY
1557 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1558 const allocator_type& __a)
1559 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1560#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001561 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001562 _LIBCPP_INLINE_VISIBILITY
1563 unordered_multimap& operator=(const unordered_multimap& __u)
1564 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001565#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001566 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001567#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001568 if (this != &__u) {
1569 __table_.clear();
1570 __table_.hash_function() = __u.__table_.hash_function();
1571 __table_.key_eq() = __u.__table_.key_eq();
1572 __table_.max_load_factor() = __u.__table_.max_load_factor();
1573 __table_.__copy_assign_alloc(__u.__table_);
1574 insert(__u.begin(), __u.end());
1575 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001576#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001577 return *this;
1578 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001579#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001580 unordered_multimap& operator=(unordered_multimap&& __u)
1581 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001583#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001584 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001585#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001588 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 {return allocator_type(__table_.__node_alloc());}
1590
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001592 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001594 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001596 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001599 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001601 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001603 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001605 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001607 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001609 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001610
Howard Hinnant73d21a42010-09-04 23:28:19 +00001611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001612#ifndef _LIBCPP_HAS_NO_VARIADICS
1613
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001614 template <class... _Args>
1615 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001617 template <class... _Args>
1618 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001619#endif // _LIBCPP_HAS_NO_VARIADICS
1620#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001623#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001624 template <class _Pp,
1625 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001627 iterator insert(_Pp&& __x)
1628 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001629#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631 iterator insert(const_iterator __p, const value_type& __x)
1632 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001633#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001634 template <class _Pp,
1635 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001637 iterator insert(const_iterator __p, _Pp&& __x)
1638 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 template <class _InputIterator>
1641 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001642#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 void insert(initializer_list<value_type> __il)
1645 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001646#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001650 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001651 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 iterator erase(const_iterator __first, const_iterator __last)
1656 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001658 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001661 void swap(unordered_multimap& __u)
1662 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1663 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666 hasher hash_function() const
1667 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 key_equal key_eq() const
1670 {return __table_.key_eq().key_eq();}
1671
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001677 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679 pair<iterator, iterator> equal_range(const key_type& __k)
1680 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1683 {return __table_.__equal_range_multi(__k);}
1684
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001686 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001688 size_type max_bucket_count() const _NOEXCEPT
1689 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 size_type bucket_size(size_type __n) const
1693 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1696
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1709
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001711 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001713 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719 void reserve(size_type __n) {__table_.reserve(__n);}
1720
Howard Hinnant39213642013-07-23 22:01:58 +00001721#if _LIBCPP_DEBUG_LEVEL >= 2
1722
1723 bool __dereferenceable(const const_iterator* __i) const
1724 {return __table_.__dereferenceable(&__i->__i_);}
1725 bool __decrementable(const const_iterator* __i) const
1726 {return __table_.__decrementable(&__i->__i_);}
1727 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1728 {return __table_.__addable(&__i->__i_, __n);}
1729 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1730 {return __table_.__addable(&__i->__i_, __n);}
1731
1732#endif // _LIBCPP_DEBUG_LEVEL >= 2
1733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001735#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1736 __node_holder __construct_node();
1737 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001738 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001739 __construct_node(_A0&& __a0);
1740#ifndef _LIBCPP_HAS_NO_VARIADICS
1741 template <class _A0, class _A1, class ..._Args>
1742 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1743#endif // _LIBCPP_HAS_NO_VARIADICS
1744#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745};
1746
1747template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1748unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1749 size_type __n, const hasher& __hf, const key_equal& __eql)
1750 : __table_(__hf, __eql)
1751{
Howard Hinnant39213642013-07-23 22:01:58 +00001752#if _LIBCPP_DEBUG_LEVEL >= 2
1753 __get_db()->__insert_c(this);
1754#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 __table_.rehash(__n);
1756}
1757
1758template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1759unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1760 size_type __n, const hasher& __hf, const key_equal& __eql,
1761 const allocator_type& __a)
1762 : __table_(__hf, __eql, __a)
1763{
Howard Hinnant39213642013-07-23 22:01:58 +00001764#if _LIBCPP_DEBUG_LEVEL >= 2
1765 __get_db()->__insert_c(this);
1766#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767 __table_.rehash(__n);
1768}
1769
1770template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1771template <class _InputIterator>
1772unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1773 _InputIterator __first, _InputIterator __last)
1774{
Howard Hinnant39213642013-07-23 22:01:58 +00001775#if _LIBCPP_DEBUG_LEVEL >= 2
1776 __get_db()->__insert_c(this);
1777#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778 insert(__first, __last);
1779}
1780
1781template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1782template <class _InputIterator>
1783unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1784 _InputIterator __first, _InputIterator __last, size_type __n,
1785 const hasher& __hf, const key_equal& __eql)
1786 : __table_(__hf, __eql)
1787{
Howard Hinnant39213642013-07-23 22:01:58 +00001788#if _LIBCPP_DEBUG_LEVEL >= 2
1789 __get_db()->__insert_c(this);
1790#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791 __table_.rehash(__n);
1792 insert(__first, __last);
1793}
1794
1795template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1796template <class _InputIterator>
1797unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1798 _InputIterator __first, _InputIterator __last, size_type __n,
1799 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1800 : __table_(__hf, __eql, __a)
1801{
Howard Hinnant39213642013-07-23 22:01:58 +00001802#if _LIBCPP_DEBUG_LEVEL >= 2
1803 __get_db()->__insert_c(this);
1804#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805 __table_.rehash(__n);
1806 insert(__first, __last);
1807}
1808
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001810inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1812 const allocator_type& __a)
1813 : __table_(__a)
1814{
Howard Hinnant39213642013-07-23 22:01:58 +00001815#if _LIBCPP_DEBUG_LEVEL >= 2
1816 __get_db()->__insert_c(this);
1817#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818}
1819
1820template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1821unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1822 const unordered_multimap& __u)
1823 : __table_(__u.__table_)
1824{
Howard Hinnant39213642013-07-23 22:01:58 +00001825#if _LIBCPP_DEBUG_LEVEL >= 2
1826 __get_db()->__insert_c(this);
1827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 __table_.rehash(__u.bucket_count());
1829 insert(__u.begin(), __u.end());
1830}
1831
1832template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1833unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1834 const unordered_multimap& __u, const allocator_type& __a)
1835 : __table_(__u.__table_, __a)
1836{
Howard Hinnant39213642013-07-23 22:01:58 +00001837#if _LIBCPP_DEBUG_LEVEL >= 2
1838 __get_db()->__insert_c(this);
1839#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001840 __table_.rehash(__u.bucket_count());
1841 insert(__u.begin(), __u.end());
1842}
1843
Howard Hinnant73d21a42010-09-04 23:28:19 +00001844#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845
1846template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001847inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1849 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001850 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001851 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852{
Howard Hinnant39213642013-07-23 22:01:58 +00001853#if _LIBCPP_DEBUG_LEVEL >= 2
1854 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001855 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001856#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857}
1858
1859template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1860unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1861 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001862 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863{
Howard Hinnant39213642013-07-23 22:01:58 +00001864#if _LIBCPP_DEBUG_LEVEL >= 2
1865 __get_db()->__insert_c(this);
1866#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 if (__a != __u.get_allocator())
1868 {
1869 iterator __i = __u.begin();
1870 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00001871 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001873 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 );
Howard Hinnant39213642013-07-23 22:01:58 +00001875 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001877#if _LIBCPP_DEBUG_LEVEL >= 2
1878 else
1879 __get_db()->swap(this, &__u);
1880#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001881}
1882
Howard Hinnant73d21a42010-09-04 23:28:19 +00001883#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884
Howard Hinnante3e32912011-08-12 21:56:02 +00001885#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1886
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1888unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1889 initializer_list<value_type> __il)
1890{
Howard Hinnant39213642013-07-23 22:01:58 +00001891#if _LIBCPP_DEBUG_LEVEL >= 2
1892 __get_db()->__insert_c(this);
1893#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894 insert(__il.begin(), __il.end());
1895}
1896
1897template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1898unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1899 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1900 const key_equal& __eql)
1901 : __table_(__hf, __eql)
1902{
Howard Hinnant39213642013-07-23 22:01:58 +00001903#if _LIBCPP_DEBUG_LEVEL >= 2
1904 __get_db()->__insert_c(this);
1905#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906 __table_.rehash(__n);
1907 insert(__il.begin(), __il.end());
1908}
1909
1910template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1911unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1912 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1913 const key_equal& __eql, const allocator_type& __a)
1914 : __table_(__hf, __eql, __a)
1915{
Howard Hinnant39213642013-07-23 22:01:58 +00001916#if _LIBCPP_DEBUG_LEVEL >= 2
1917 __get_db()->__insert_c(this);
1918#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001919 __table_.rehash(__n);
1920 insert(__il.begin(), __il.end());
1921}
1922
Howard Hinnante3e32912011-08-12 21:56:02 +00001923#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1924
Howard Hinnant73d21a42010-09-04 23:28:19 +00001925#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926
1927template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001928inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1930unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001931 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001932{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001933 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934 return *this;
1935}
1936
Howard Hinnant73d21a42010-09-04 23:28:19 +00001937#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938
Howard Hinnante3e32912011-08-12 21:56:02 +00001939#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1940
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1944unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1945 initializer_list<value_type> __il)
1946{
1947 __table_.__assign_multi(__il.begin(), __il.end());
1948 return *this;
1949}
1950
Howard Hinnante3e32912011-08-12 21:56:02 +00001951#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1952
Howard Hinnant73d21a42010-09-04 23:28:19 +00001953#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954
1955template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001957unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958{
1959 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001960 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001961 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963 __h.get_deleter().__second_constructed = true;
1964 return __h;
1965}
1966
1967template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001968template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001969typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1971{
1972 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001973 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001974 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1975 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976 __h.get_deleter().__first_constructed = true;
1977 __h.get_deleter().__second_constructed = true;
1978 return __h;
1979}
1980
Howard Hinnant73d21a42010-09-04 23:28:19 +00001981#ifndef _LIBCPP_HAS_NO_VARIADICS
1982
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001983template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001984template <class _A0, class _A1, class ..._Args>
1985typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1986unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
1987 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001989 __node_allocator& __na = __table_.__node_alloc();
1990 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1991 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1992 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1993 _VSTD::forward<_Args>(__args)...);
1994 __h.get_deleter().__first_constructed = true;
1995 __h.get_deleter().__second_constructed = true;
1996 return __h;
1997}
1998
1999template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2000template <class... _Args>
2001typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2002unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
2003{
2004 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005 iterator __r = __table_.__node_insert_multi(__h.get());
2006 __h.release();
2007 return __r;
2008}
2009
2010template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002011template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2013unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002014 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002016 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2018 __h.release();
2019 return __r;
2020}
2021
Howard Hinnant73d21a42010-09-04 23:28:19 +00002022#endif // _LIBCPP_HAS_NO_VARIADICS
2023#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024
2025template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2026template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002027inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002028void
2029unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2030 _InputIterator __last)
2031{
2032 for (; __first != __last; ++__first)
2033 __table_.__insert_multi(*__first);
2034}
2035
2036template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002037inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038void
2039swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2040 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002041 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002042{
2043 __x.swap(__y);
2044}
2045
2046template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2047bool
2048operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2049 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2050{
2051 if (__x.size() != __y.size())
2052 return false;
2053 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2054 const_iterator;
2055 typedef pair<const_iterator, const_iterator> _EqRng;
2056 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2057 {
2058 _EqRng __xeq = __x.equal_range(__i->first);
2059 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002060 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2061 _VSTD::distance(__yeq.first, __yeq.second) ||
2062 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 return false;
2064 __i = __xeq.second;
2065 }
2066 return true;
2067}
2068
2069template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071bool
2072operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2073 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2074{
2075 return !(__x == __y);
2076}
2077
2078_LIBCPP_END_NAMESPACE_STD
2079
2080#endif // _LIBCPP_UNORDERED_MAP