blob: 15d5176f7ce8cdfda69b5bbf21e4d2062d647838 [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
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000364template <class _Key, class _Cp, class _Hash,
365 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000366 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367class __unordered_map_hasher
368 : private _Hash
369{
370public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000372 __unordered_map_hasher()
373 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
374 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000376 __unordered_map_hasher(const _Hash& __h)
377 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
378 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000380 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000382 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000383 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000384 _LIBCPP_INLINE_VISIBILITY
385 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 {return static_cast<const _Hash&>(*this)(__x);}
387};
388
Howard Hinnant9b128e02013-07-05 18:06:00 +0000389template <class _Key, class _Cp, class _Hash>
390class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391{
392 _Hash __hash_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000393
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000396 __unordered_map_hasher()
397 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
398 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000400 __unordered_map_hasher(const _Hash& __h)
401 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
402 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000404 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000406 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000407 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000408 _LIBCPP_INLINE_VISIBILITY
409 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 {return __hash_(__x);}
411};
412
Eric Fiselier3a0e4302015-06-13 07:08:02 +0000413template <class _Key, class _Cp, class _Pred,
414 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000415 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416class __unordered_map_equal
417 : private _Pred
418{
419public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000421 __unordered_map_equal()
422 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
423 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000425 __unordered_map_equal(const _Pred& __p)
426 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
427 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000429 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000431 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000432 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000433 _LIBCPP_INLINE_VISIBILITY
434 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000435 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000437 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000438 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439};
440
Howard Hinnant9b128e02013-07-05 18:06:00 +0000441template <class _Key, class _Cp, class _Pred>
442class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000443{
444 _Pred __pred_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000445
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000448 __unordered_map_equal()
449 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
450 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000452 __unordered_map_equal(const _Pred& __p)
453 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
454 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000456 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000458 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000459 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000460 _LIBCPP_INLINE_VISIBILITY
461 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000462 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000464 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000465 {return __pred_(__x, __y.__cc.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466};
467
468template <class _Alloc>
469class __hash_map_node_destructor
470{
471 typedef _Alloc allocator_type;
472 typedef allocator_traits<allocator_type> __alloc_traits;
473 typedef typename __alloc_traits::value_type::value_type value_type;
474public:
475 typedef typename __alloc_traits::pointer pointer;
476private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000477 typedef typename value_type::value_type::first_type first_type;
478 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479
480 allocator_type& __na_;
481
482 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
483
484public:
485 bool __first_constructed;
486 bool __second_constructed;
487
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000489 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 : __na_(__na),
491 __first_constructed(false),
492 __second_constructed(false)
493 {}
494
Howard Hinnant73d21a42010-09-04 23:28:19 +0000495#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000498 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 : __na_(__x.__na_),
500 __first_constructed(__x.__value_constructed),
501 __second_constructed(__x.__value_constructed)
502 {
503 __x.__value_constructed = false;
504 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000505#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
508 : __na_(__x.__na_),
509 __first_constructed(__x.__value_constructed),
510 __second_constructed(__x.__value_constructed)
511 {
512 const_cast<bool&>(__x.__value_constructed) = false;
513 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000514#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000517 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518 {
519 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000520 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000522 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 if (__p)
524 __alloc_traits::deallocate(__na_, __p, 1);
525 }
526};
527
Howard Hinnantff7546e2013-09-30 19:08:22 +0000528#if __cplusplus >= 201103L
529
530template <class _Key, class _Tp>
531union __hash_value_type
532{
533 typedef _Key key_type;
534 typedef _Tp mapped_type;
535 typedef pair<const key_type, mapped_type> value_type;
536 typedef pair<key_type, mapped_type> __nc_value_type;
537
538 value_type __cc;
539 __nc_value_type __nc;
540
541 template <class ..._Args>
542 _LIBCPP_INLINE_VISIBILITY
543 __hash_value_type(_Args&& ...__args)
544 : __cc(std::forward<_Args>(__args)...) {}
545
546 _LIBCPP_INLINE_VISIBILITY
547 __hash_value_type(const __hash_value_type& __v)
548 : __cc(__v.__cc) {}
549
550 _LIBCPP_INLINE_VISIBILITY
551 __hash_value_type(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000552 : __nc(_VSTD::move(__v.__nc)) {}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000553
554 _LIBCPP_INLINE_VISIBILITY
555 __hash_value_type& operator=(const __hash_value_type& __v)
556 {__nc = __v.__cc; return *this;}
557
558 _LIBCPP_INLINE_VISIBILITY
559 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22 +0000560 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22 +0000561
562 _LIBCPP_INLINE_VISIBILITY
563 ~__hash_value_type() {__cc.~value_type();}
564};
565
566#else
567
568template <class _Key, class _Tp>
569struct __hash_value_type
570{
571 typedef _Key key_type;
572 typedef _Tp mapped_type;
573 typedef pair<const key_type, mapped_type> value_type;
574
575 value_type __cc;
576
577 _LIBCPP_INLINE_VISIBILITY
578 __hash_value_type() {}
579
580 template <class _A0>
581 _LIBCPP_INLINE_VISIBILITY
582 __hash_value_type(const _A0& __a0)
583 : __cc(__a0) {}
584
585 template <class _A0, class _A1>
586 _LIBCPP_INLINE_VISIBILITY
587 __hash_value_type(const _A0& __a0, const _A1& __a1)
588 : __cc(__a0, __a1) {}
589};
590
591#endif
592
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000594class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595{
596 _HashIterator __i_;
597
598 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000599 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
600 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601public:
602 typedef forward_iterator_tag iterator_category;
603 typedef pair<key_type, mapped_type> value_type;
604 typedef typename _HashIterator::difference_type difference_type;
605 typedef value_type& reference;
606 typedef typename __pointer_traits::template
607#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
608 rebind<value_type>
609#else
610 rebind<value_type>::other
611#endif
612 pointer;
613
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000615 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000618 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000621 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000623 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 __hash_map_iterator operator++(int)
629 {
630 __hash_map_iterator __t(*this);
631 ++(*this);
632 return __t;
633 }
634
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000635 friend _LIBCPP_INLINE_VISIBILITY
636 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000638 friend _LIBCPP_INLINE_VISIBILITY
639 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 {return __x.__i_ != __y.__i_;}
641
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000642 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
643 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
644 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
645 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
646 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647};
648
649template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000650class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651{
652 _HashIterator __i_;
653
654 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000655 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
656 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657public:
658 typedef forward_iterator_tag iterator_category;
659 typedef pair<key_type, mapped_type> value_type;
660 typedef typename _HashIterator::difference_type difference_type;
661 typedef const value_type& reference;
662 typedef typename __pointer_traits::template
663#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant099084d2011-07-23 16:14:35 +0000664 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665#else
Howard Hinnant099084d2011-07-23 16:14:35 +0000666 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667#endif
668 pointer;
669
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000671 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000674 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 __hash_map_const_iterator(
677 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000678 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 : __i_(__i.__i_) {}
680
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000682 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000684 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 __hash_map_const_iterator operator++(int)
690 {
691 __hash_map_const_iterator __t(*this);
692 ++(*this);
693 return __t;
694 }
695
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000696 friend _LIBCPP_INLINE_VISIBILITY
697 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000699 friend _LIBCPP_INLINE_VISIBILITY
700 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 {return __x.__i_ != __y.__i_;}
702
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000703 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
704 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
705 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
706 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707};
708
709template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
710 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000711class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712{
713public:
714 // types
715 typedef _Key key_type;
716 typedef _Tp mapped_type;
717 typedef _Hash hasher;
718 typedef _Pred key_equal;
719 typedef _Alloc allocator_type;
720 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000721 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 typedef value_type& reference;
723 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000724 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
725 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726
727private:
Howard Hinnantff7546e2013-09-30 19:08:22 +0000728 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +0000729 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
730 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +0000731 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
732 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733
734 typedef __hash_table<__value_type, __hasher,
735 __key_equal, __allocator_type> __table;
736
737 __table __table_;
738
739 typedef typename __table::__node_pointer __node_pointer;
740 typedef typename __table::__node_const_pointer __node_const_pointer;
741 typedef typename __table::__node_traits __node_traits;
742 typedef typename __table::__node_allocator __node_allocator;
743 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000744 typedef __hash_map_node_destructor<__node_allocator> _Dp;
745 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746 typedef allocator_traits<allocator_type> __alloc_traits;
747public:
748 typedef typename __alloc_traits::pointer pointer;
749 typedef typename __alloc_traits::const_pointer const_pointer;
750 typedef typename __alloc_traits::size_type size_type;
751 typedef typename __alloc_traits::difference_type difference_type;
752
753 typedef __hash_map_iterator<typename __table::iterator> iterator;
754 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
755 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
756 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
757
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000759 unordered_map()
760 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000761 {
762#if _LIBCPP_DEBUG_LEVEL >= 2
763 __get_db()->__insert_c(this);
764#endif
765 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
767 const key_equal& __eql = key_equal());
768 unordered_map(size_type __n, const hasher& __hf,
769 const key_equal& __eql,
770 const allocator_type& __a);
771 template <class _InputIterator>
772 unordered_map(_InputIterator __first, _InputIterator __last);
773 template <class _InputIterator>
774 unordered_map(_InputIterator __first, _InputIterator __last,
775 size_type __n, const hasher& __hf = hasher(),
776 const key_equal& __eql = key_equal());
777 template <class _InputIterator>
778 unordered_map(_InputIterator __first, _InputIterator __last,
779 size_type __n, const hasher& __hf,
780 const key_equal& __eql,
781 const allocator_type& __a);
782 explicit unordered_map(const allocator_type& __a);
783 unordered_map(const unordered_map& __u);
784 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000785#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000786 unordered_map(unordered_map&& __u)
787 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000789#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000790#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791 unordered_map(initializer_list<value_type> __il);
792 unordered_map(initializer_list<value_type> __il, size_type __n,
793 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
794 unordered_map(initializer_list<value_type> __il, size_type __n,
795 const hasher& __hf, const key_equal& __eql,
796 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000797#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000798#if _LIBCPP_STD_VER > 11
799 _LIBCPP_INLINE_VISIBILITY
800 unordered_map(size_type __n, const allocator_type& __a)
801 : unordered_map(__n, hasher(), key_equal(), __a) {}
802 _LIBCPP_INLINE_VISIBILITY
803 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
804 : unordered_map(__n, __hf, key_equal(), __a) {}
805 template <class _InputIterator>
806 _LIBCPP_INLINE_VISIBILITY
807 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
808 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
809 template <class _InputIterator>
810 _LIBCPP_INLINE_VISIBILITY
811 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
812 const allocator_type& __a)
813 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
814 _LIBCPP_INLINE_VISIBILITY
815 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
816 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
817 _LIBCPP_INLINE_VISIBILITY
818 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
819 const allocator_type& __a)
820 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
821#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000823 _LIBCPP_INLINE_VISIBILITY
824 unordered_map& operator=(const unordered_map& __u)
825 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000826#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000827 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000828#else
Marshall Clowebfc50e2014-02-08 04:03:14 +0000829 if (this != &__u) {
830 __table_.clear();
831 __table_.hash_function() = __u.__table_.hash_function();
832 __table_.key_eq() = __u.__table_.key_eq();
833 __table_.max_load_factor() = __u.__table_.max_load_factor();
834 __table_.__copy_assign_alloc(__u.__table_);
835 insert(__u.begin(), __u.end());
836 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000837#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000838 return *this;
839 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000840#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000841 unordered_map& operator=(unordered_map&& __u)
842 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000844#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000846#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000849 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 {return allocator_type(__table_.__node_alloc());}
851
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000853 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000855 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000857 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000860 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000862 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000864 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000866 const_iterator end() const _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 cbegin() 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 cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871
Howard Hinnant73d21a42010-09-04 23:28:19 +0000872#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000873#ifndef _LIBCPP_HAS_NO_VARIADICS
874
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000875 template <class... _Args>
876 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000878 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000880#if _LIBCPP_DEBUG_LEVEL >= 2
881 iterator emplace_hint(const_iterator __p, _Args&&... __args)
882 {
883 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
884 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
885 " referring to this unordered_map");
886 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
887 }
888#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000889 iterator emplace_hint(const_iterator, _Args&&... __args)
890 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000891#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000892#endif // _LIBCPP_HAS_NO_VARIADICS
893#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 pair<iterator, bool> insert(const value_type& __x)
896 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000897#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000898 template <class _Pp,
899 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000901 pair<iterator, bool> insert(_Pp&& __x)
902 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000903#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000905#if _LIBCPP_DEBUG_LEVEL >= 2
906 iterator insert(const_iterator __p, const value_type& __x)
907 {
908 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
909 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
910 " referring to this unordered_map");
911 return insert(__x).first;
912 }
913#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 iterator insert(const_iterator, const value_type& __x)
915 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000916#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000917#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000918 template <class _Pp,
919 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000921#if _LIBCPP_DEBUG_LEVEL >= 2
922 iterator insert(const_iterator __p, _Pp&& __x)
923 {
924 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
925 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
926 " referring to this unordered_map");
927 return insert(_VSTD::forward<_Pp>(__x)).first;
928 }
929#else
Howard Hinnant99968442011-11-29 18:15:50 +0000930 iterator insert(const_iterator, _Pp&& __x)
931 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000932#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000933#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 template <class _InputIterator>
935 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000936#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 void insert(initializer_list<value_type> __il)
939 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000940#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +0000945 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 iterator erase(const_iterator __first, const_iterator __last)
950 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000952 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000955 void swap(unordered_map& __u)
956 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
957 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000960 hasher hash_function() const
961 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 key_equal key_eq() const
964 {return __table_.key_eq().key_eq();}
965
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 pair<iterator, iterator> equal_range(const key_type& __k)
974 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
977 {return __table_.__equal_range_unique(__k);}
978
979 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000980#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 mapped_type& operator[](key_type&& __k);
982#endif
983
984 mapped_type& at(const key_type& __k);
985 const mapped_type& at(const key_type& __k) const;
986
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000988 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000990 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 size_type bucket_size(size_type __n) const
994 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
997
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001001 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 const_local_iterator cbegin(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 cend(size_type __n) const {return __table_.cend(__n);}
1010
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001012 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001014 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 void reserve(size_type __n) {__table_.reserve(__n);}
1021
Howard Hinnant39213642013-07-23 22:01:58 +00001022#if _LIBCPP_DEBUG_LEVEL >= 2
1023
1024 bool __dereferenceable(const const_iterator* __i) const
1025 {return __table_.__dereferenceable(&__i->__i_);}
1026 bool __decrementable(const const_iterator* __i) const
1027 {return __table_.__decrementable(&__i->__i_);}
1028 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1029 {return __table_.__addable(&__i->__i_, __n);}
1030 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1031 {return __table_.__addable(&__i->__i_, __n);}
1032
1033#endif // _LIBCPP_DEBUG_LEVEL >= 2
1034
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001036#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001037 __node_holder __construct_node();
1038 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001039 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001040 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001041 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001042#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001043 template <class _A0, class _A1, class ..._Args>
1044 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001045#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001046#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1047 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048};
1049
1050template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1051unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1052 size_type __n, const hasher& __hf, const key_equal& __eql)
1053 : __table_(__hf, __eql)
1054{
Howard Hinnant39213642013-07-23 22:01:58 +00001055#if _LIBCPP_DEBUG_LEVEL >= 2
1056 __get_db()->__insert_c(this);
1057#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 __table_.rehash(__n);
1059}
1060
1061template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1062unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1063 size_type __n, const hasher& __hf, const key_equal& __eql,
1064 const allocator_type& __a)
1065 : __table_(__hf, __eql, __a)
1066{
Howard Hinnant39213642013-07-23 22:01:58 +00001067#if _LIBCPP_DEBUG_LEVEL >= 2
1068 __get_db()->__insert_c(this);
1069#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070 __table_.rehash(__n);
1071}
1072
1073template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1076 const allocator_type& __a)
1077 : __table_(__a)
1078{
Howard Hinnant39213642013-07-23 22:01:58 +00001079#if _LIBCPP_DEBUG_LEVEL >= 2
1080 __get_db()->__insert_c(this);
1081#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082}
1083
1084template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1085template <class _InputIterator>
1086unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1087 _InputIterator __first, _InputIterator __last)
1088{
Howard Hinnant39213642013-07-23 22:01:58 +00001089#if _LIBCPP_DEBUG_LEVEL >= 2
1090 __get_db()->__insert_c(this);
1091#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 insert(__first, __last);
1093}
1094
1095template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1096template <class _InputIterator>
1097unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1098 _InputIterator __first, _InputIterator __last, size_type __n,
1099 const hasher& __hf, const key_equal& __eql)
1100 : __table_(__hf, __eql)
1101{
Howard Hinnant39213642013-07-23 22:01:58 +00001102#if _LIBCPP_DEBUG_LEVEL >= 2
1103 __get_db()->__insert_c(this);
1104#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 __table_.rehash(__n);
1106 insert(__first, __last);
1107}
1108
1109template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1110template <class _InputIterator>
1111unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1112 _InputIterator __first, _InputIterator __last, size_type __n,
1113 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1114 : __table_(__hf, __eql, __a)
1115{
Howard Hinnant39213642013-07-23 22:01:58 +00001116#if _LIBCPP_DEBUG_LEVEL >= 2
1117 __get_db()->__insert_c(this);
1118#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 __table_.rehash(__n);
1120 insert(__first, __last);
1121}
1122
1123template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1124unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1125 const unordered_map& __u)
1126 : __table_(__u.__table_)
1127{
Howard Hinnant39213642013-07-23 22:01:58 +00001128#if _LIBCPP_DEBUG_LEVEL >= 2
1129 __get_db()->__insert_c(this);
1130#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 __table_.rehash(__u.bucket_count());
1132 insert(__u.begin(), __u.end());
1133}
1134
1135template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1136unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1137 const unordered_map& __u, const allocator_type& __a)
1138 : __table_(__u.__table_, __a)
1139{
Howard Hinnant39213642013-07-23 22:01:58 +00001140#if _LIBCPP_DEBUG_LEVEL >= 2
1141 __get_db()->__insert_c(this);
1142#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 __table_.rehash(__u.bucket_count());
1144 insert(__u.begin(), __u.end());
1145}
1146
Howard Hinnant73d21a42010-09-04 23:28:19 +00001147#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148
1149template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1152 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001153 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001154 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155{
Howard Hinnant39213642013-07-23 22:01:58 +00001156#if _LIBCPP_DEBUG_LEVEL >= 2
1157 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001158 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001159#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160}
1161
1162template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1163unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1164 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001165 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166{
Howard Hinnant39213642013-07-23 22:01:58 +00001167#if _LIBCPP_DEBUG_LEVEL >= 2
1168 __get_db()->__insert_c(this);
1169#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170 if (__a != __u.get_allocator())
1171 {
1172 iterator __i = __u.begin();
1173 while (__u.size() != 0)
1174 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001175 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176 );
1177 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001178#if _LIBCPP_DEBUG_LEVEL >= 2
1179 else
1180 __get_db()->swap(this, &__u);
1181#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182}
1183
Howard Hinnant73d21a42010-09-04 23:28:19 +00001184#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185
Howard Hinnante3e32912011-08-12 21:56:02 +00001186#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1187
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1189unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1190 initializer_list<value_type> __il)
1191{
Howard Hinnant39213642013-07-23 22:01:58 +00001192#if _LIBCPP_DEBUG_LEVEL >= 2
1193 __get_db()->__insert_c(this);
1194#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 insert(__il.begin(), __il.end());
1196}
1197
1198template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1199unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1200 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1201 const key_equal& __eql)
1202 : __table_(__hf, __eql)
1203{
Howard Hinnant39213642013-07-23 22:01:58 +00001204#if _LIBCPP_DEBUG_LEVEL >= 2
1205 __get_db()->__insert_c(this);
1206#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001207 __table_.rehash(__n);
1208 insert(__il.begin(), __il.end());
1209}
1210
1211template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1212unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1213 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1214 const key_equal& __eql, const allocator_type& __a)
1215 : __table_(__hf, __eql, __a)
1216{
Howard Hinnant39213642013-07-23 22:01:58 +00001217#if _LIBCPP_DEBUG_LEVEL >= 2
1218 __get_db()->__insert_c(this);
1219#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220 __table_.rehash(__n);
1221 insert(__il.begin(), __il.end());
1222}
1223
Howard Hinnante3e32912011-08-12 21:56:02 +00001224#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1225
Howard Hinnant73d21a42010-09-04 23:28:19 +00001226#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227
1228template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1231unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001232 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001234 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235 return *this;
1236}
1237
Howard Hinnant73d21a42010-09-04 23:28:19 +00001238#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239
Howard Hinnante3e32912011-08-12 21:56:02 +00001240#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1241
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001243inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1245unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1246 initializer_list<value_type> __il)
1247{
1248 __table_.__assign_unique(__il.begin(), __il.end());
1249 return *this;
1250}
1251
Howard Hinnante3e32912011-08-12 21:56:02 +00001252#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1253
Howard Hinnant73d21a42010-09-04 23:28:19 +00001254#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255
1256template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001258unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259{
1260 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001261 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001262 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264 __h.get_deleter().__second_constructed = true;
1265 return __h;
1266}
1267
1268template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001269template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001270typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1272{
1273 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001274 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001275 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1276 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 __h.get_deleter().__first_constructed = true;
1278 __h.get_deleter().__second_constructed = true;
1279 return __h;
1280}
1281
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001282template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001283typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1284unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001285{
1286 __node_allocator& __na = __table_.__node_alloc();
1287 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001288 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001289 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001290 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001291 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001292 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001293}
1294
Howard Hinnant73d21a42010-09-04 23:28:19 +00001295#ifndef _LIBCPP_HAS_NO_VARIADICS
1296
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001297template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001298template <class _A0, class _A1, class ..._Args>
1299typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1300unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1301 _A1&& __a1,
1302 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001304 __node_allocator& __na = __table_.__node_alloc();
1305 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1306 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1307 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1308 _VSTD::forward<_Args>(__args)...);
1309 __h.get_deleter().__first_constructed = true;
1310 __h.get_deleter().__second_constructed = true;
1311 return __h;
1312}
1313
1314template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1315template <class... _Args>
1316pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
1317unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1318{
1319 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1321 if (__r.second)
1322 __h.release();
1323 return __r;
1324}
1325
Howard Hinnant73d21a42010-09-04 23:28:19 +00001326#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001327#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328
1329template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1330typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001331unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332{
1333 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001334 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001335 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001337 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001339 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340}
1341
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1343template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345void
1346unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1347 _InputIterator __last)
1348{
1349 for (; __first != __last; ++__first)
1350 __table_.__insert_unique(*__first);
1351}
1352
1353template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1354_Tp&
1355unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1356{
1357 iterator __i = find(__k);
1358 if (__i != end())
1359 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001360 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1362 __h.release();
1363 return __r.first->second;
1364}
1365
Howard Hinnant73d21a42010-09-04 23:28:19 +00001366#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367
1368template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1369_Tp&
1370unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1371{
1372 iterator __i = find(__k);
1373 if (__i != end())
1374 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001375 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1377 __h.release();
1378 return __r.first->second;
1379}
1380
Howard Hinnant73d21a42010-09-04 23:28:19 +00001381#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382
1383template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1384_Tp&
1385unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1386{
1387 iterator __i = find(__k);
1388#ifndef _LIBCPP_NO_EXCEPTIONS
1389 if (__i == end())
1390 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001391#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001392 return __i->second;
1393}
1394
1395template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1396const _Tp&
1397unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1398{
1399 const_iterator __i = find(__k);
1400#ifndef _LIBCPP_NO_EXCEPTIONS
1401 if (__i == end())
1402 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001403#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 return __i->second;
1405}
1406
1407template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409void
1410swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1411 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001412 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413{
1414 __x.swap(__y);
1415}
1416
1417template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1418bool
1419operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1420 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1421{
1422 if (__x.size() != __y.size())
1423 return false;
1424 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1425 const_iterator;
1426 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1427 __i != __ex; ++__i)
1428 {
1429 const_iterator __j = __y.find(__i->first);
1430 if (__j == __ey || !(*__i == *__j))
1431 return false;
1432 }
1433 return true;
1434}
1435
1436template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438bool
1439operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1440 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1441{
1442 return !(__x == __y);
1443}
1444
1445template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1446 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001447class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448{
1449public:
1450 // types
1451 typedef _Key key_type;
1452 typedef _Tp mapped_type;
1453 typedef _Hash hasher;
1454 typedef _Pred key_equal;
1455 typedef _Alloc allocator_type;
1456 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001457 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 typedef value_type& reference;
1459 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001460 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1461 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462
1463private:
Howard Hinnantff7546e2013-09-30 19:08:22 +00001464 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00 +00001465 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1466 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38 +00001467 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1468 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469
1470 typedef __hash_table<__value_type, __hasher,
1471 __key_equal, __allocator_type> __table;
1472
1473 __table __table_;
1474
1475 typedef typename __table::__node_traits __node_traits;
1476 typedef typename __table::__node_allocator __node_allocator;
1477 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001478 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1479 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480 typedef allocator_traits<allocator_type> __alloc_traits;
1481public:
1482 typedef typename __alloc_traits::pointer pointer;
1483 typedef typename __alloc_traits::const_pointer const_pointer;
1484 typedef typename __alloc_traits::size_type size_type;
1485 typedef typename __alloc_traits::difference_type difference_type;
1486
1487 typedef __hash_map_iterator<typename __table::iterator> iterator;
1488 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1489 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1490 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1491
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001493 unordered_multimap()
1494 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001495 {
1496#if _LIBCPP_DEBUG_LEVEL >= 2
1497 __get_db()->__insert_c(this);
1498#endif
1499 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1501 const key_equal& __eql = key_equal());
1502 unordered_multimap(size_type __n, const hasher& __hf,
1503 const key_equal& __eql,
1504 const allocator_type& __a);
1505 template <class _InputIterator>
1506 unordered_multimap(_InputIterator __first, _InputIterator __last);
1507 template <class _InputIterator>
1508 unordered_multimap(_InputIterator __first, _InputIterator __last,
1509 size_type __n, const hasher& __hf = hasher(),
1510 const key_equal& __eql = key_equal());
1511 template <class _InputIterator>
1512 unordered_multimap(_InputIterator __first, _InputIterator __last,
1513 size_type __n, const hasher& __hf,
1514 const key_equal& __eql,
1515 const allocator_type& __a);
1516 explicit unordered_multimap(const allocator_type& __a);
1517 unordered_multimap(const unordered_multimap& __u);
1518 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001519#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001520 unordered_multimap(unordered_multimap&& __u)
1521 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001523#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001524#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 unordered_multimap(initializer_list<value_type> __il);
1526 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1527 const hasher& __hf = hasher(),
1528 const key_equal& __eql = key_equal());
1529 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1530 const hasher& __hf, const key_equal& __eql,
1531 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001532#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001533#if _LIBCPP_STD_VER > 11
1534 _LIBCPP_INLINE_VISIBILITY
1535 unordered_multimap(size_type __n, const allocator_type& __a)
1536 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1537 _LIBCPP_INLINE_VISIBILITY
1538 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1539 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1540 template <class _InputIterator>
1541 _LIBCPP_INLINE_VISIBILITY
1542 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1543 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1544 template <class _InputIterator>
1545 _LIBCPP_INLINE_VISIBILITY
1546 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1547 const allocator_type& __a)
1548 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1549 _LIBCPP_INLINE_VISIBILITY
1550 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1551 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1552 _LIBCPP_INLINE_VISIBILITY
1553 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1554 const allocator_type& __a)
1555 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1556#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001558 _LIBCPP_INLINE_VISIBILITY
1559 unordered_multimap& operator=(const unordered_multimap& __u)
1560 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001561#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001562 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001563#else
Marshall Clowebfc50e2014-02-08 04:03:14 +00001564 if (this != &__u) {
1565 __table_.clear();
1566 __table_.hash_function() = __u.__table_.hash_function();
1567 __table_.key_eq() = __u.__table_.key_eq();
1568 __table_.max_load_factor() = __u.__table_.max_load_factor();
1569 __table_.__copy_assign_alloc(__u.__table_);
1570 insert(__u.begin(), __u.end());
1571 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001572#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001573 return *this;
1574 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001575#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001576 unordered_multimap& operator=(unordered_multimap&& __u)
1577 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001579#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001581#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001584 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585 {return allocator_type(__table_.__node_alloc());}
1586
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001588 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001590 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001592 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001595 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001597 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001599 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001601 const_iterator end() const _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 cbegin() 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 cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606
Howard Hinnant73d21a42010-09-04 23:28:19 +00001607#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001608#ifndef _LIBCPP_HAS_NO_VARIADICS
1609
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001610 template <class... _Args>
1611 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001613 template <class... _Args>
1614 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001615#endif // _LIBCPP_HAS_NO_VARIADICS
1616#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001619#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001620 template <class _Pp,
1621 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001623 iterator insert(_Pp&& __x)
1624 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001625#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627 iterator insert(const_iterator __p, const value_type& __x)
1628 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001629#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001630 template <class _Pp,
1631 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001633 iterator insert(const_iterator __p, _Pp&& __x)
1634 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001635#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 template <class _InputIterator>
1637 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001638#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 void insert(initializer_list<value_type> __il)
1641 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001642#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001646 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:00 +00001647 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651 iterator erase(const_iterator __first, const_iterator __last)
1652 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001654 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001657 void swap(unordered_multimap& __u)
1658 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1659 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662 hasher hash_function() const
1663 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665 key_equal key_eq() const
1666 {return __table_.key_eq().key_eq();}
1667
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675 pair<iterator, iterator> equal_range(const key_type& __k)
1676 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1679 {return __table_.__equal_range_multi(__k);}
1680
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001682 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001684 size_type max_bucket_count() const _NOEXCEPT
1685 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688 size_type bucket_size(size_type __n) const
1689 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1692
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 const_local_iterator cbegin(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 cend(size_type __n) const {return __table_.cend(__n);}
1705
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001707 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001709 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001711 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 void reserve(size_type __n) {__table_.reserve(__n);}
1716
Howard Hinnant39213642013-07-23 22:01:58 +00001717#if _LIBCPP_DEBUG_LEVEL >= 2
1718
1719 bool __dereferenceable(const const_iterator* __i) const
1720 {return __table_.__dereferenceable(&__i->__i_);}
1721 bool __decrementable(const const_iterator* __i) const
1722 {return __table_.__decrementable(&__i->__i_);}
1723 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1724 {return __table_.__addable(&__i->__i_, __n);}
1725 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1726 {return __table_.__addable(&__i->__i_, __n);}
1727
1728#endif // _LIBCPP_DEBUG_LEVEL >= 2
1729
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001731#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1732 __node_holder __construct_node();
1733 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001734 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001735 __construct_node(_A0&& __a0);
1736#ifndef _LIBCPP_HAS_NO_VARIADICS
1737 template <class _A0, class _A1, class ..._Args>
1738 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1739#endif // _LIBCPP_HAS_NO_VARIADICS
1740#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741};
1742
1743template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1744unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1745 size_type __n, const hasher& __hf, const key_equal& __eql)
1746 : __table_(__hf, __eql)
1747{
Howard Hinnant39213642013-07-23 22:01:58 +00001748#if _LIBCPP_DEBUG_LEVEL >= 2
1749 __get_db()->__insert_c(this);
1750#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751 __table_.rehash(__n);
1752}
1753
1754template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1755unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1756 size_type __n, const hasher& __hf, const key_equal& __eql,
1757 const allocator_type& __a)
1758 : __table_(__hf, __eql, __a)
1759{
Howard Hinnant39213642013-07-23 22:01:58 +00001760#if _LIBCPP_DEBUG_LEVEL >= 2
1761 __get_db()->__insert_c(this);
1762#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763 __table_.rehash(__n);
1764}
1765
1766template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1767template <class _InputIterator>
1768unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1769 _InputIterator __first, _InputIterator __last)
1770{
Howard Hinnant39213642013-07-23 22:01:58 +00001771#if _LIBCPP_DEBUG_LEVEL >= 2
1772 __get_db()->__insert_c(this);
1773#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 insert(__first, __last);
1775}
1776
1777template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1778template <class _InputIterator>
1779unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1780 _InputIterator __first, _InputIterator __last, size_type __n,
1781 const hasher& __hf, const key_equal& __eql)
1782 : __table_(__hf, __eql)
1783{
Howard Hinnant39213642013-07-23 22:01:58 +00001784#if _LIBCPP_DEBUG_LEVEL >= 2
1785 __get_db()->__insert_c(this);
1786#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787 __table_.rehash(__n);
1788 insert(__first, __last);
1789}
1790
1791template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1792template <class _InputIterator>
1793unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1794 _InputIterator __first, _InputIterator __last, size_type __n,
1795 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1796 : __table_(__hf, __eql, __a)
1797{
Howard Hinnant39213642013-07-23 22:01:58 +00001798#if _LIBCPP_DEBUG_LEVEL >= 2
1799 __get_db()->__insert_c(this);
1800#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801 __table_.rehash(__n);
1802 insert(__first, __last);
1803}
1804
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001806inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1808 const allocator_type& __a)
1809 : __table_(__a)
1810{
Howard Hinnant39213642013-07-23 22:01:58 +00001811#if _LIBCPP_DEBUG_LEVEL >= 2
1812 __get_db()->__insert_c(this);
1813#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814}
1815
1816template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1817unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1818 const unordered_multimap& __u)
1819 : __table_(__u.__table_)
1820{
Howard Hinnant39213642013-07-23 22:01:58 +00001821#if _LIBCPP_DEBUG_LEVEL >= 2
1822 __get_db()->__insert_c(this);
1823#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824 __table_.rehash(__u.bucket_count());
1825 insert(__u.begin(), __u.end());
1826}
1827
1828template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1829unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1830 const unordered_multimap& __u, const allocator_type& __a)
1831 : __table_(__u.__table_, __a)
1832{
Howard Hinnant39213642013-07-23 22:01:58 +00001833#if _LIBCPP_DEBUG_LEVEL >= 2
1834 __get_db()->__insert_c(this);
1835#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 __table_.rehash(__u.bucket_count());
1837 insert(__u.begin(), __u.end());
1838}
1839
Howard Hinnant73d21a42010-09-04 23:28:19 +00001840#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841
1842template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1845 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001846 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001847 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848{
Howard Hinnant39213642013-07-23 22:01:58 +00001849#if _LIBCPP_DEBUG_LEVEL >= 2
1850 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001851 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001852#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853}
1854
1855template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1856unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1857 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001858 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859{
Howard Hinnant39213642013-07-23 22:01:58 +00001860#if _LIBCPP_DEBUG_LEVEL >= 2
1861 __get_db()->__insert_c(this);
1862#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 if (__a != __u.get_allocator())
1864 {
1865 iterator __i = __u.begin();
1866 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00001867 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001869 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870 );
Howard Hinnant39213642013-07-23 22:01:58 +00001871 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001873#if _LIBCPP_DEBUG_LEVEL >= 2
1874 else
1875 __get_db()->swap(this, &__u);
1876#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877}
1878
Howard Hinnant73d21a42010-09-04 23:28:19 +00001879#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880
Howard Hinnante3e32912011-08-12 21:56:02 +00001881#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1882
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1884unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1885 initializer_list<value_type> __il)
1886{
Howard Hinnant39213642013-07-23 22:01:58 +00001887#if _LIBCPP_DEBUG_LEVEL >= 2
1888 __get_db()->__insert_c(this);
1889#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 insert(__il.begin(), __il.end());
1891}
1892
1893template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1894unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1895 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1896 const key_equal& __eql)
1897 : __table_(__hf, __eql)
1898{
Howard Hinnant39213642013-07-23 22:01:58 +00001899#if _LIBCPP_DEBUG_LEVEL >= 2
1900 __get_db()->__insert_c(this);
1901#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902 __table_.rehash(__n);
1903 insert(__il.begin(), __il.end());
1904}
1905
1906template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1907unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1908 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1909 const key_equal& __eql, const allocator_type& __a)
1910 : __table_(__hf, __eql, __a)
1911{
Howard Hinnant39213642013-07-23 22:01:58 +00001912#if _LIBCPP_DEBUG_LEVEL >= 2
1913 __get_db()->__insert_c(this);
1914#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001915 __table_.rehash(__n);
1916 insert(__il.begin(), __il.end());
1917}
1918
Howard Hinnante3e32912011-08-12 21:56:02 +00001919#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1920
Howard Hinnant73d21a42010-09-04 23:28:19 +00001921#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922
1923template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1926unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001927 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001929 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930 return *this;
1931}
1932
Howard Hinnant73d21a42010-09-04 23:28:19 +00001933#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934
Howard Hinnante3e32912011-08-12 21:56:02 +00001935#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1936
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001937template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1940unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1941 initializer_list<value_type> __il)
1942{
1943 __table_.__assign_multi(__il.begin(), __il.end());
1944 return *this;
1945}
1946
Howard Hinnante3e32912011-08-12 21:56:02 +00001947#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1948
Howard Hinnant73d21a42010-09-04 23:28:19 +00001949#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950
1951template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001952typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001953unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954{
1955 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001956 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001957 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959 __h.get_deleter().__second_constructed = true;
1960 return __h;
1961}
1962
1963template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001964template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001965typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1967{
1968 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001969 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001970 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1971 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 __h.get_deleter().__first_constructed = true;
1973 __h.get_deleter().__second_constructed = true;
1974 return __h;
1975}
1976
Howard Hinnant73d21a42010-09-04 23:28:19 +00001977#ifndef _LIBCPP_HAS_NO_VARIADICS
1978
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001980template <class _A0, class _A1, class ..._Args>
1981typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1982unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
1983 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001985 __node_allocator& __na = __table_.__node_alloc();
1986 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1987 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1988 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1989 _VSTD::forward<_Args>(__args)...);
1990 __h.get_deleter().__first_constructed = true;
1991 __h.get_deleter().__second_constructed = true;
1992 return __h;
1993}
1994
1995template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1996template <class... _Args>
1997typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
1998unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1999{
2000 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001 iterator __r = __table_.__node_insert_multi(__h.get());
2002 __h.release();
2003 return __r;
2004}
2005
2006template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002007template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2009unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002010 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002011{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002012 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2014 __h.release();
2015 return __r;
2016}
2017
Howard Hinnant73d21a42010-09-04 23:28:19 +00002018#endif // _LIBCPP_HAS_NO_VARIADICS
2019#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020
2021template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2022template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002023inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024void
2025unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2026 _InputIterator __last)
2027{
2028 for (; __first != __last; ++__first)
2029 __table_.__insert_multi(*__first);
2030}
2031
2032template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002033inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002034void
2035swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2036 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002037 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038{
2039 __x.swap(__y);
2040}
2041
2042template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2043bool
2044operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2045 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2046{
2047 if (__x.size() != __y.size())
2048 return false;
2049 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2050 const_iterator;
2051 typedef pair<const_iterator, const_iterator> _EqRng;
2052 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2053 {
2054 _EqRng __xeq = __x.equal_range(__i->first);
2055 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002056 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2057 _VSTD::distance(__yeq.first, __yeq.second) ||
2058 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059 return false;
2060 __i = __xeq.second;
2061 }
2062 return true;
2063}
2064
2065template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067bool
2068operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2069 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2070{
2071 return !(__x == __y);
2072}
2073
2074_LIBCPP_END_NAMESPACE_STD
2075
2076#endif // _LIBCPP_UNORDERED_MAP