blob: e1a3f641c34db04461316e4875c88dbcac018f6d [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);
126 size_type erase(const key_type& k);
127 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000128 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000130 void swap(unordered_map&)
131 noexcept(
132 (!allocator_type::propagate_on_container_swap::value ||
133 __is_nothrow_swappable<allocator_type>::value) &&
134 __is_nothrow_swappable<hasher>::value &&
135 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136
137 hasher hash_function() const;
138 key_equal key_eq() const;
139
140 iterator find(const key_type& k);
141 const_iterator find(const key_type& k) const;
142 size_type count(const key_type& k) const;
143 pair<iterator, iterator> equal_range(const key_type& k);
144 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
145
146 mapped_type& operator[](const key_type& k);
147 mapped_type& operator[](key_type&& k);
148
149 mapped_type& at(const key_type& k);
150 const mapped_type& at(const key_type& k) const;
151
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000152 size_type bucket_count() const noexcept;
153 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154
155 size_type bucket_size(size_type n) const;
156 size_type bucket(const key_type& k) const;
157
158 local_iterator begin(size_type n);
159 local_iterator end(size_type n);
160 const_local_iterator begin(size_type n) const;
161 const_local_iterator end(size_type n) const;
162 const_local_iterator cbegin(size_type n) const;
163 const_local_iterator cend(size_type n) const;
164
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000165 float load_factor() const noexcept;
166 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 void max_load_factor(float z);
168 void rehash(size_type n);
169 void reserve(size_type n);
170};
171
172template <class Key, class T, class Hash, class Pred, class Alloc>
173 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000174 unordered_map<Key, T, Hash, Pred, Alloc>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176
177template <class Key, class T, class Hash, class Pred, class Alloc>
178 bool
179 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
180 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
181
182template <class Key, class T, class Hash, class Pred, class Alloc>
183 bool
184 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
185 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
186
187template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
188 class Alloc = allocator<pair<const Key, T>>>
189class unordered_multimap
190{
191public:
192 // types
193 typedef Key key_type;
194 typedef T mapped_type;
195 typedef Hash hasher;
196 typedef Pred key_equal;
197 typedef Alloc allocator_type;
198 typedef pair<const key_type, mapped_type> value_type;
199 typedef value_type& reference;
200 typedef const value_type& const_reference;
201 typedef typename allocator_traits<allocator_type>::pointer pointer;
202 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
203 typedef typename allocator_traits<allocator_type>::size_type size_type;
204 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
205
206 typedef /unspecified/ iterator;
207 typedef /unspecified/ const_iterator;
208 typedef /unspecified/ local_iterator;
209 typedef /unspecified/ const_local_iterator;
210
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000211 unordered_multimap()
212 noexcept(
213 is_nothrow_default_constructible<hasher>::value &&
214 is_nothrow_default_constructible<key_equal>::value &&
215 is_nothrow_default_constructible<allocator_type>::value);
216 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 const key_equal& eql = key_equal(),
218 const allocator_type& a = allocator_type());
219 template <class InputIterator>
220 unordered_multimap(InputIterator f, InputIterator l,
221 size_type n = 0, const hasher& hf = hasher(),
222 const key_equal& eql = key_equal(),
223 const allocator_type& a = allocator_type());
224 explicit unordered_multimap(const allocator_type&);
225 unordered_multimap(const unordered_multimap&);
226 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000227 unordered_multimap(unordered_multimap&&)
228 noexcept(
229 is_nothrow_move_constructible<hasher>::value &&
230 is_nothrow_move_constructible<key_equal>::value &&
231 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 unordered_multimap(unordered_multimap&&, const Allocator&);
233 unordered_multimap(initializer_list<value_type>, size_type n = 0,
234 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
235 const allocator_type& a = allocator_type());
Marshall Clow6dff6182013-09-12 03:00:31 +0000236 unordered_multimap(size_type n, const allocator_type& a)
237 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
238 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
239 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
240 template <class InputIterator>
241 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
242 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
243 template <class InputIterator>
244 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
245 const allocator_type& a)
246 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
247 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
248 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
249 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
250 const allocator_type& a)
251 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252 ~unordered_multimap();
253 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000254 unordered_multimap& operator=(unordered_multimap&&)
255 noexcept(
256 allocator_type::propagate_on_container_move_assignment::value &&
257 is_nothrow_move_assignable<allocator_type>::value &&
258 is_nothrow_move_assignable<hasher>::value &&
259 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260 unordered_multimap& operator=(initializer_list<value_type>);
261
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000262 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000264 bool empty() const noexcept;
265 size_type size() const noexcept;
266 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000268 iterator begin() noexcept;
269 iterator end() noexcept;
270 const_iterator begin() const noexcept;
271 const_iterator end() const noexcept;
272 const_iterator cbegin() const noexcept;
273 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274
275 template <class... Args>
276 iterator emplace(Args&&... args);
277 template <class... Args>
278 iterator emplace_hint(const_iterator position, Args&&... args);
279 iterator insert(const value_type& obj);
280 template <class P>
281 iterator insert(P&& obj);
282 iterator insert(const_iterator hint, const value_type& obj);
283 template <class P>
284 iterator insert(const_iterator hint, P&& obj);
285 template <class InputIterator>
286 void insert(InputIterator first, InputIterator last);
287 void insert(initializer_list<value_type>);
288
289 iterator erase(const_iterator position);
290 size_type erase(const key_type& k);
291 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000292 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000294 void swap(unordered_multimap&)
295 noexcept(
296 (!allocator_type::propagate_on_container_swap::value ||
297 __is_nothrow_swappable<allocator_type>::value) &&
298 __is_nothrow_swappable<hasher>::value &&
299 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300
301 hasher hash_function() const;
302 key_equal key_eq() const;
303
304 iterator find(const key_type& k);
305 const_iterator find(const key_type& k) const;
306 size_type count(const key_type& k) const;
307 pair<iterator, iterator> equal_range(const key_type& k);
308 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
309
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000310 size_type bucket_count() const noexcept;
311 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313 size_type bucket_size(size_type n) const;
314 size_type bucket(const key_type& k) const;
315
316 local_iterator begin(size_type n);
317 local_iterator end(size_type n);
318 const_local_iterator begin(size_type n) const;
319 const_local_iterator end(size_type n) const;
320 const_local_iterator cbegin(size_type n) const;
321 const_local_iterator cend(size_type n) const;
322
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000323 float load_factor() const noexcept;
324 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325 void max_load_factor(float z);
326 void rehash(size_type n);
327 void reserve(size_type n);
328};
329
330template <class Key, class T, class Hash, class Pred, class Alloc>
331 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000332 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
333 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334
335template <class Key, class T, class Hash, class Pred, class Alloc>
336 bool
337 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
338 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
339
340template <class Key, class T, class Hash, class Pred, class Alloc>
341 bool
342 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
343 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
344
345} // std
346
347*/
348
349#include <__config>
350#include <__hash_table>
351#include <functional>
352#include <stdexcept>
353
Howard Hinnant08e17472011-10-17 20:05:10 +0000354#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000356#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358_LIBCPP_BEGIN_NAMESPACE_STD
359
Howard Hinnant9b128e02013-07-05 18:06:00 +0000360template <class _Key, class _Cp, class _Hash, bool = is_empty<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000361#if __has_feature(is_final)
362 && !__is_final(_Hash)
363#endif
364 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365class __unordered_map_hasher
366 : private _Hash
367{
368public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000370 __unordered_map_hasher()
371 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
372 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000374 __unordered_map_hasher(const _Hash& __h)
375 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
376 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000378 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000380 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000381 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000382 _LIBCPP_INLINE_VISIBILITY
383 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 {return static_cast<const _Hash&>(*this)(__x);}
385};
386
Howard Hinnant9b128e02013-07-05 18:06:00 +0000387template <class _Key, class _Cp, class _Hash>
388class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389{
390 _Hash __hash_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000391
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000394 __unordered_map_hasher()
395 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
396 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000398 __unordered_map_hasher(const _Hash& __h)
399 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
400 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000402 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000404 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00 +0000405 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24 +0000406 _LIBCPP_INLINE_VISIBILITY
407 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408 {return __hash_(__x);}
409};
410
Howard Hinnant9b128e02013-07-05 18:06:00 +0000411template <class _Key, class _Cp, class _Pred, bool = is_empty<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000412#if __has_feature(is_final)
413 && !__is_final(_Pred)
414#endif
415 >
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
528template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000529class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530{
531 _HashIterator __i_;
532
533 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000534 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
535 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536public:
537 typedef forward_iterator_tag iterator_category;
538 typedef pair<key_type, mapped_type> value_type;
539 typedef typename _HashIterator::difference_type difference_type;
540 typedef value_type& reference;
541 typedef typename __pointer_traits::template
542#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
543 rebind<value_type>
544#else
545 rebind<value_type>::other
546#endif
547 pointer;
548
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000550 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000553 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000556 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000558 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563 __hash_map_iterator operator++(int)
564 {
565 __hash_map_iterator __t(*this);
566 ++(*this);
567 return __t;
568 }
569
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000570 friend _LIBCPP_INLINE_VISIBILITY
571 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000573 friend _LIBCPP_INLINE_VISIBILITY
574 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575 {return __x.__i_ != __y.__i_;}
576
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000577 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
578 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
579 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
580 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
581 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582};
583
584template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000585class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586{
587 _HashIterator __i_;
588
589 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000590 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
591 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592public:
593 typedef forward_iterator_tag iterator_category;
594 typedef pair<key_type, mapped_type> value_type;
595 typedef typename _HashIterator::difference_type difference_type;
596 typedef const value_type& reference;
597 typedef typename __pointer_traits::template
598#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant099084d2011-07-23 16:14:35 +0000599 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600#else
Howard Hinnant099084d2011-07-23 16:14:35 +0000601 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602#endif
603 pointer;
604
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000606 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000609 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000611 __hash_map_const_iterator(
612 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000613 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614 : __i_(__i.__i_) {}
615
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000617 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000619 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624 __hash_map_const_iterator operator++(int)
625 {
626 __hash_map_const_iterator __t(*this);
627 ++(*this);
628 return __t;
629 }
630
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000631 friend _LIBCPP_INLINE_VISIBILITY
632 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000634 friend _LIBCPP_INLINE_VISIBILITY
635 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636 {return __x.__i_ != __y.__i_;}
637
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000638 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
639 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
640 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
641 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642};
643
644template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
645 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000646class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647{
648public:
649 // types
650 typedef _Key key_type;
651 typedef _Tp mapped_type;
652 typedef _Hash hasher;
653 typedef _Pred key_equal;
654 typedef _Alloc allocator_type;
655 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000656 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 typedef value_type& reference;
658 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000659 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
660 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661
662private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000663#if __cplusplus >= 201103L
664 union __value_type
665 {
666 typedef typename unordered_map::value_type value_type;
667 typedef typename unordered_map::__nc_value_type __nc_value_type;
668 value_type __cc;
669 __nc_value_type __nc;
670
671 template <class ..._Args>
672 __value_type(_Args&& ...__args)
673 : __cc(std::forward<_Args>(__args)...) {}
674
675 __value_type(const __value_type& __v)
Howard Hinnantf9d26802013-09-12 00:10:44 +0000676 : __cc(__v.__cc) {}
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000677
678 __value_type(__value_type&& __v)
679 : __nc(std::move(__v.__nc)) {}
680
681 __value_type& operator=(const __value_type& __v)
682 {__nc = __v.__cc; return *this;}
683
684 __value_type& operator=(__value_type&& __v)
685 {__nc = std::move(__v.__nc); return *this;}
686
687 ~__value_type() {__cc.~value_type();}
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000688 };
689#else
690 struct __value_type
691 {
692 typedef typename unordered_map::value_type value_type;
693 value_type __cc;
694
695 __value_type() {}
696
697 template <class _A0>
698 __value_type(const _A0& __a0)
699 : __cc(__a0) {}
700
701 template <class _A0, class _A1>
702 __value_type(const _A0& __a0, const _A1& __a1)
703 : __cc(__a0, __a1) {}
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000704 };
705#endif
Howard Hinnant9b128e02013-07-05 18:06:00 +0000706 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
707 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 typedef typename allocator_traits<allocator_type>::template
709#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
710 rebind_alloc<__value_type>
711#else
712 rebind_alloc<__value_type>::other
713#endif
714 __allocator_type;
715
716 typedef __hash_table<__value_type, __hasher,
717 __key_equal, __allocator_type> __table;
718
719 __table __table_;
720
721 typedef typename __table::__node_pointer __node_pointer;
722 typedef typename __table::__node_const_pointer __node_const_pointer;
723 typedef typename __table::__node_traits __node_traits;
724 typedef typename __table::__node_allocator __node_allocator;
725 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000726 typedef __hash_map_node_destructor<__node_allocator> _Dp;
727 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 typedef allocator_traits<allocator_type> __alloc_traits;
729public:
730 typedef typename __alloc_traits::pointer pointer;
731 typedef typename __alloc_traits::const_pointer const_pointer;
732 typedef typename __alloc_traits::size_type size_type;
733 typedef typename __alloc_traits::difference_type difference_type;
734
735 typedef __hash_map_iterator<typename __table::iterator> iterator;
736 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
737 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
738 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
739
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000741 unordered_map()
742 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000743 {
744#if _LIBCPP_DEBUG_LEVEL >= 2
745 __get_db()->__insert_c(this);
746#endif
747 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
749 const key_equal& __eql = key_equal());
750 unordered_map(size_type __n, const hasher& __hf,
751 const key_equal& __eql,
752 const allocator_type& __a);
753 template <class _InputIterator>
754 unordered_map(_InputIterator __first, _InputIterator __last);
755 template <class _InputIterator>
756 unordered_map(_InputIterator __first, _InputIterator __last,
757 size_type __n, const hasher& __hf = hasher(),
758 const key_equal& __eql = key_equal());
759 template <class _InputIterator>
760 unordered_map(_InputIterator __first, _InputIterator __last,
761 size_type __n, const hasher& __hf,
762 const key_equal& __eql,
763 const allocator_type& __a);
764 explicit unordered_map(const allocator_type& __a);
765 unordered_map(const unordered_map& __u);
766 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000767#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000768 unordered_map(unordered_map&& __u)
769 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000771#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000772#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773 unordered_map(initializer_list<value_type> __il);
774 unordered_map(initializer_list<value_type> __il, size_type __n,
775 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
776 unordered_map(initializer_list<value_type> __il, size_type __n,
777 const hasher& __hf, const key_equal& __eql,
778 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000779#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +0000780#if _LIBCPP_STD_VER > 11
781 _LIBCPP_INLINE_VISIBILITY
782 unordered_map(size_type __n, const allocator_type& __a)
783 : unordered_map(__n, hasher(), key_equal(), __a) {}
784 _LIBCPP_INLINE_VISIBILITY
785 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
786 : unordered_map(__n, __hf, key_equal(), __a) {}
787 template <class _InputIterator>
788 _LIBCPP_INLINE_VISIBILITY
789 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
790 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
791 template <class _InputIterator>
792 _LIBCPP_INLINE_VISIBILITY
793 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
794 const allocator_type& __a)
795 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
796 _LIBCPP_INLINE_VISIBILITY
797 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
798 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
799 _LIBCPP_INLINE_VISIBILITY
800 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
801 const allocator_type& __a)
802 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
803#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000805 _LIBCPP_INLINE_VISIBILITY
806 unordered_map& operator=(const unordered_map& __u)
807 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000808#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000809 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000810#else
811 __table_.clear();
812 __table_.hash_function() = __u.__table_.hash_function();
813 __table_.key_eq() = __u.__table_.key_eq();
814 __table_.max_load_factor() = __u.__table_.max_load_factor();
815 __table_.__copy_assign_alloc(__u.__table_);
816 insert(__u.begin(), __u.end());
817#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000818 return *this;
819 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000820#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000821 unordered_map& operator=(unordered_map&& __u)
822 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000824#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000826#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000829 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 {return allocator_type(__table_.__node_alloc());}
831
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000833 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000835 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000837 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000840 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000842 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000844 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000846 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000848 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000850 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851
Howard Hinnant73d21a42010-09-04 23:28:19 +0000852#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000853#ifndef _LIBCPP_HAS_NO_VARIADICS
854
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000855 template <class... _Args>
856 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000858 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000860#if _LIBCPP_DEBUG_LEVEL >= 2
861 iterator emplace_hint(const_iterator __p, _Args&&... __args)
862 {
863 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
864 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
865 " referring to this unordered_map");
866 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
867 }
868#else
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000869 iterator emplace_hint(const_iterator, _Args&&... __args)
870 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000871#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000872#endif // _LIBCPP_HAS_NO_VARIADICS
873#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 pair<iterator, bool> insert(const value_type& __x)
876 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000877#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000878 template <class _Pp,
879 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000881 pair<iterator, bool> insert(_Pp&& __x)
882 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000883#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000885#if _LIBCPP_DEBUG_LEVEL >= 2
886 iterator insert(const_iterator __p, const value_type& __x)
887 {
888 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
889 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
890 " referring to this unordered_map");
891 return insert(__x).first;
892 }
893#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 iterator insert(const_iterator, const value_type& __x)
895 {return insert(__x).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000896#endif
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 Hinnantf890d9b2013-07-30 21:04:42 +0000901#if _LIBCPP_DEBUG_LEVEL >= 2
902 iterator insert(const_iterator __p, _Pp&& __x)
903 {
904 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
905 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
906 " referring to this unordered_map");
907 return insert(_VSTD::forward<_Pp>(__x)).first;
908 }
909#else
Howard Hinnant99968442011-11-29 18:15:50 +0000910 iterator insert(const_iterator, _Pp&& __x)
911 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnantf890d9b2013-07-30 21:04:42 +0000912#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000913#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 template <class _InputIterator>
915 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000916#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 void insert(initializer_list<value_type> __il)
919 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000920#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000921
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000923 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927 iterator erase(const_iterator __first, const_iterator __last)
928 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000930 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000933 void swap(unordered_map& __u)
934 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
935 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 hasher hash_function() const
939 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941 key_equal key_eq() const
942 {return __table_.key_eq().key_eq();}
943
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 pair<iterator, iterator> equal_range(const key_type& __k)
952 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
955 {return __table_.__equal_range_unique(__k);}
956
957 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000958#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959 mapped_type& operator[](key_type&& __k);
960#endif
961
962 mapped_type& at(const key_type& __k);
963 const mapped_type& at(const key_type& __k) const;
964
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000966 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000968 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000969
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 size_type bucket_size(size_type __n) const
972 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
975
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000979 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
988
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000990 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000992 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000998 void reserve(size_type __n) {__table_.reserve(__n);}
999
Howard Hinnant39213642013-07-23 22:01:58 +00001000#if _LIBCPP_DEBUG_LEVEL >= 2
1001
1002 bool __dereferenceable(const const_iterator* __i) const
1003 {return __table_.__dereferenceable(&__i->__i_);}
1004 bool __decrementable(const const_iterator* __i) const
1005 {return __table_.__decrementable(&__i->__i_);}
1006 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1007 {return __table_.__addable(&__i->__i_, __n);}
1008 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1009 {return __table_.__addable(&__i->__i_, __n);}
1010
1011#endif // _LIBCPP_DEBUG_LEVEL >= 2
1012
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013private:
Howard Hinnant73d21a42010-09-04 23:28:19 +00001014#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001015 __node_holder __construct_node();
1016 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001017 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001018 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001019 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001020#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001021 template <class _A0, class _A1, class ..._Args>
1022 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001023#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001024#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1025 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026};
1027
1028template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1029unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1030 size_type __n, const hasher& __hf, const key_equal& __eql)
1031 : __table_(__hf, __eql)
1032{
Howard Hinnant39213642013-07-23 22:01:58 +00001033#if _LIBCPP_DEBUG_LEVEL >= 2
1034 __get_db()->__insert_c(this);
1035#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 __table_.rehash(__n);
1037}
1038
1039template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1040unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1041 size_type __n, const hasher& __hf, const key_equal& __eql,
1042 const allocator_type& __a)
1043 : __table_(__hf, __eql, __a)
1044{
Howard Hinnant39213642013-07-23 22:01:58 +00001045#if _LIBCPP_DEBUG_LEVEL >= 2
1046 __get_db()->__insert_c(this);
1047#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048 __table_.rehash(__n);
1049}
1050
1051template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1054 const allocator_type& __a)
1055 : __table_(__a)
1056{
Howard Hinnant39213642013-07-23 22:01:58 +00001057#if _LIBCPP_DEBUG_LEVEL >= 2
1058 __get_db()->__insert_c(this);
1059#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060}
1061
1062template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1063template <class _InputIterator>
1064unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1065 _InputIterator __first, _InputIterator __last)
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 insert(__first, __last);
1071}
1072
1073template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1074template <class _InputIterator>
1075unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1076 _InputIterator __first, _InputIterator __last, size_type __n,
1077 const hasher& __hf, const key_equal& __eql)
1078 : __table_(__hf, __eql)
1079{
Howard Hinnant39213642013-07-23 22:01:58 +00001080#if _LIBCPP_DEBUG_LEVEL >= 2
1081 __get_db()->__insert_c(this);
1082#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 __table_.rehash(__n);
1084 insert(__first, __last);
1085}
1086
1087template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1088template <class _InputIterator>
1089unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1090 _InputIterator __first, _InputIterator __last, size_type __n,
1091 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1092 : __table_(__hf, __eql, __a)
1093{
Howard Hinnant39213642013-07-23 22:01:58 +00001094#if _LIBCPP_DEBUG_LEVEL >= 2
1095 __get_db()->__insert_c(this);
1096#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 __table_.rehash(__n);
1098 insert(__first, __last);
1099}
1100
1101template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1102unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1103 const unordered_map& __u)
1104 : __table_(__u.__table_)
1105{
Howard Hinnant39213642013-07-23 22:01:58 +00001106#if _LIBCPP_DEBUG_LEVEL >= 2
1107 __get_db()->__insert_c(this);
1108#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 __table_.rehash(__u.bucket_count());
1110 insert(__u.begin(), __u.end());
1111}
1112
1113template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1114unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1115 const unordered_map& __u, const allocator_type& __a)
1116 : __table_(__u.__table_, __a)
1117{
Howard Hinnant39213642013-07-23 22:01:58 +00001118#if _LIBCPP_DEBUG_LEVEL >= 2
1119 __get_db()->__insert_c(this);
1120#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 __table_.rehash(__u.bucket_count());
1122 insert(__u.begin(), __u.end());
1123}
1124
Howard Hinnant73d21a42010-09-04 23:28:19 +00001125#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126
1127template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1130 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001131 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001132 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133{
Howard Hinnant39213642013-07-23 22:01:58 +00001134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001136 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001137#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138}
1139
1140template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1141unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1142 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001143 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144{
Howard Hinnant39213642013-07-23 22:01:58 +00001145#if _LIBCPP_DEBUG_LEVEL >= 2
1146 __get_db()->__insert_c(this);
1147#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148 if (__a != __u.get_allocator())
1149 {
1150 iterator __i = __u.begin();
1151 while (__u.size() != 0)
1152 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001153 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 );
1155 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001156#if _LIBCPP_DEBUG_LEVEL >= 2
1157 else
1158 __get_db()->swap(this, &__u);
1159#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160}
1161
Howard Hinnant73d21a42010-09-04 23:28:19 +00001162#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163
Howard Hinnante3e32912011-08-12 21:56:02 +00001164#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1165
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1167unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1168 initializer_list<value_type> __il)
1169{
Howard Hinnant39213642013-07-23 22:01:58 +00001170#if _LIBCPP_DEBUG_LEVEL >= 2
1171 __get_db()->__insert_c(this);
1172#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173 insert(__il.begin(), __il.end());
1174}
1175
1176template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1177unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1178 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1179 const key_equal& __eql)
1180 : __table_(__hf, __eql)
1181{
Howard Hinnant39213642013-07-23 22:01:58 +00001182#if _LIBCPP_DEBUG_LEVEL >= 2
1183 __get_db()->__insert_c(this);
1184#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 __table_.rehash(__n);
1186 insert(__il.begin(), __il.end());
1187}
1188
1189template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1190unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1191 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1192 const key_equal& __eql, const allocator_type& __a)
1193 : __table_(__hf, __eql, __a)
1194{
Howard Hinnant39213642013-07-23 22:01:58 +00001195#if _LIBCPP_DEBUG_LEVEL >= 2
1196 __get_db()->__insert_c(this);
1197#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 __table_.rehash(__n);
1199 insert(__il.begin(), __il.end());
1200}
1201
Howard Hinnante3e32912011-08-12 21:56:02 +00001202#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1203
Howard Hinnant73d21a42010-09-04 23:28:19 +00001204#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205
1206template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001207inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1209unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001210 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001212 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 return *this;
1214}
1215
Howard Hinnant73d21a42010-09-04 23:28:19 +00001216#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217
Howard Hinnante3e32912011-08-12 21:56:02 +00001218#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1219
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1223unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1224 initializer_list<value_type> __il)
1225{
1226 __table_.__assign_unique(__il.begin(), __il.end());
1227 return *this;
1228}
1229
Howard Hinnante3e32912011-08-12 21:56:02 +00001230#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1231
Howard Hinnant73d21a42010-09-04 23:28:19 +00001232#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233
1234template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001236unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237{
1238 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001239 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001240 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 __h.get_deleter().__second_constructed = true;
1243 return __h;
1244}
1245
1246template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001247template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001248typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1250{
1251 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001252 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001253 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1254 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 __h.get_deleter().__first_constructed = true;
1256 __h.get_deleter().__second_constructed = true;
1257 return __h;
1258}
1259
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001260template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001261typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1262unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001263{
1264 __node_allocator& __na = __table_.__node_alloc();
1265 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001266 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001267 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001268 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001269 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001270 return __h;
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001271}
1272
Howard Hinnant73d21a42010-09-04 23:28:19 +00001273#ifndef _LIBCPP_HAS_NO_VARIADICS
1274
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001276template <class _A0, class _A1, class ..._Args>
1277typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1278unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1279 _A1&& __a1,
1280 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001282 __node_allocator& __na = __table_.__node_alloc();
1283 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1284 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1285 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1286 _VSTD::forward<_Args>(__args)...);
1287 __h.get_deleter().__first_constructed = true;
1288 __h.get_deleter().__second_constructed = true;
1289 return __h;
1290}
1291
1292template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1293template <class... _Args>
1294pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
1295unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1296{
1297 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1299 if (__r.second)
1300 __h.release();
1301 return __r;
1302}
1303
Howard Hinnant73d21a42010-09-04 23:28:19 +00001304#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001305#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306
1307template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1308typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001309unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310{
1311 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001312 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001313 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001315 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316 __h.get_deleter().__second_constructed = true;
Howard Hinnant9a894d92013-08-22 18:29:50 +00001317 return _VSTD::move(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318}
1319
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1321template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001322inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323void
1324unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1325 _InputIterator __last)
1326{
1327 for (; __first != __last; ++__first)
1328 __table_.__insert_unique(*__first);
1329}
1330
1331template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1332_Tp&
1333unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1334{
1335 iterator __i = find(__k);
1336 if (__i != end())
1337 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001338 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1340 __h.release();
1341 return __r.first->second;
1342}
1343
Howard Hinnant73d21a42010-09-04 23:28:19 +00001344#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
1346template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1347_Tp&
1348unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1349{
1350 iterator __i = find(__k);
1351 if (__i != end())
1352 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001353 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1355 __h.release();
1356 return __r.first->second;
1357}
1358
Howard Hinnant73d21a42010-09-04 23:28:19 +00001359#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360
1361template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1362_Tp&
1363unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1364{
1365 iterator __i = find(__k);
1366#ifndef _LIBCPP_NO_EXCEPTIONS
1367 if (__i == end())
1368 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001369#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370 return __i->second;
1371}
1372
1373template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1374const _Tp&
1375unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1376{
1377 const_iterator __i = find(__k);
1378#ifndef _LIBCPP_NO_EXCEPTIONS
1379 if (__i == end())
1380 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001381#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382 return __i->second;
1383}
1384
1385template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387void
1388swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1389 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001390 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391{
1392 __x.swap(__y);
1393}
1394
1395template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1396bool
1397operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1398 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1399{
1400 if (__x.size() != __y.size())
1401 return false;
1402 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1403 const_iterator;
1404 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1405 __i != __ex; ++__i)
1406 {
1407 const_iterator __j = __y.find(__i->first);
1408 if (__j == __ey || !(*__i == *__j))
1409 return false;
1410 }
1411 return true;
1412}
1413
1414template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416bool
1417operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1418 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1419{
1420 return !(__x == __y);
1421}
1422
1423template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1424 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001425class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426{
1427public:
1428 // types
1429 typedef _Key key_type;
1430 typedef _Tp mapped_type;
1431 typedef _Hash hasher;
1432 typedef _Pred key_equal;
1433 typedef _Alloc allocator_type;
1434 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001435 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436 typedef value_type& reference;
1437 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001438 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1439 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440
1441private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001442#if __cplusplus >= 201103L
1443 union __value_type
1444 {
1445 typedef typename unordered_multimap::value_type value_type;
1446 typedef typename unordered_multimap::__nc_value_type __nc_value_type;
1447 value_type __cc;
1448 __nc_value_type __nc;
1449
1450 template <class ..._Args>
1451 __value_type(_Args&& ...__args)
1452 : __cc(std::forward<_Args>(__args)...) {}
1453
1454 __value_type(const __value_type& __v)
1455 : __cc(std::move(__v.__cc)) {}
1456
1457 __value_type(__value_type&& __v)
1458 : __nc(std::move(__v.__nc)) {}
1459
1460 __value_type& operator=(const __value_type& __v)
1461 {__nc = __v.__cc; return *this;}
1462
1463 __value_type& operator=(__value_type&& __v)
1464 {__nc = std::move(__v.__nc); return *this;}
1465
1466 ~__value_type() {__cc.~value_type();}
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001467 };
1468#else
1469 struct __value_type
1470 {
1471 typedef typename unordered_multimap::value_type value_type;
1472 value_type __cc;
1473
1474 __value_type() {}
1475
1476 template <class _A0>
1477 __value_type(const _A0& __a0)
1478 : __cc(__a0) {}
1479
1480 template <class _A0, class _A1>
1481 __value_type(const _A0& __a0, const _A1& __a1)
1482 : __cc(__a0, __a1) {}
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001483 };
1484#endif
Howard Hinnant9b128e02013-07-05 18:06:00 +00001485 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1486 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 typedef typename allocator_traits<allocator_type>::template
1488#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1489 rebind_alloc<__value_type>
1490#else
1491 rebind_alloc<__value_type>::other
1492#endif
1493 __allocator_type;
1494
1495 typedef __hash_table<__value_type, __hasher,
1496 __key_equal, __allocator_type> __table;
1497
1498 __table __table_;
1499
1500 typedef typename __table::__node_traits __node_traits;
1501 typedef typename __table::__node_allocator __node_allocator;
1502 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001503 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1504 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 typedef allocator_traits<allocator_type> __alloc_traits;
1506public:
1507 typedef typename __alloc_traits::pointer pointer;
1508 typedef typename __alloc_traits::const_pointer const_pointer;
1509 typedef typename __alloc_traits::size_type size_type;
1510 typedef typename __alloc_traits::difference_type difference_type;
1511
1512 typedef __hash_map_iterator<typename __table::iterator> iterator;
1513 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1514 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1515 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1516
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001518 unordered_multimap()
1519 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001520 {
1521#if _LIBCPP_DEBUG_LEVEL >= 2
1522 __get_db()->__insert_c(this);
1523#endif
1524 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1526 const key_equal& __eql = key_equal());
1527 unordered_multimap(size_type __n, const hasher& __hf,
1528 const key_equal& __eql,
1529 const allocator_type& __a);
1530 template <class _InputIterator>
1531 unordered_multimap(_InputIterator __first, _InputIterator __last);
1532 template <class _InputIterator>
1533 unordered_multimap(_InputIterator __first, _InputIterator __last,
1534 size_type __n, const hasher& __hf = hasher(),
1535 const key_equal& __eql = key_equal());
1536 template <class _InputIterator>
1537 unordered_multimap(_InputIterator __first, _InputIterator __last,
1538 size_type __n, const hasher& __hf,
1539 const key_equal& __eql,
1540 const allocator_type& __a);
1541 explicit unordered_multimap(const allocator_type& __a);
1542 unordered_multimap(const unordered_multimap& __u);
1543 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001545 unordered_multimap(unordered_multimap&& __u)
1546 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001548#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001549#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 unordered_multimap(initializer_list<value_type> __il);
1551 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1552 const hasher& __hf = hasher(),
1553 const key_equal& __eql = key_equal());
1554 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1555 const hasher& __hf, const key_equal& __eql,
1556 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001557#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31 +00001558#if _LIBCPP_STD_VER > 11
1559 _LIBCPP_INLINE_VISIBILITY
1560 unordered_multimap(size_type __n, const allocator_type& __a)
1561 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1562 _LIBCPP_INLINE_VISIBILITY
1563 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1564 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1565 template <class _InputIterator>
1566 _LIBCPP_INLINE_VISIBILITY
1567 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1568 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1569 template <class _InputIterator>
1570 _LIBCPP_INLINE_VISIBILITY
1571 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1572 const allocator_type& __a)
1573 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1574 _LIBCPP_INLINE_VISIBILITY
1575 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1576 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1577 _LIBCPP_INLINE_VISIBILITY
1578 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1579 const allocator_type& __a)
1580 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1581#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001583 _LIBCPP_INLINE_VISIBILITY
1584 unordered_multimap& operator=(const unordered_multimap& __u)
1585 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001586#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001587 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001588#else
1589 __table_.clear();
1590 __table_.hash_function() = __u.__table_.hash_function();
1591 __table_.key_eq() = __u.__table_.key_eq();
1592 __table_.max_load_factor() = __u.__table_.max_load_factor();
1593 __table_.__copy_assign_alloc(__u.__table_);
1594 insert(__u.begin(), __u.end());
1595#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001596 return *this;
1597 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001598#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001599 unordered_multimap& operator=(unordered_multimap&& __u)
1600 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001602#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001604#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001607 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 {return allocator_type(__table_.__node_alloc());}
1609
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001611 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001613 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001615 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001618 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001620 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001622 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001624 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001626 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001628 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629
Howard Hinnant73d21a42010-09-04 23:28:19 +00001630#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001631#ifndef _LIBCPP_HAS_NO_VARIADICS
1632
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001633 template <class... _Args>
1634 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001636 template <class... _Args>
1637 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001638#endif // _LIBCPP_HAS_NO_VARIADICS
1639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001641 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001642#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001643 template <class _Pp,
1644 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001646 iterator insert(_Pp&& __x)
1647 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001648#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 iterator insert(const_iterator __p, const value_type& __x)
1651 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001652#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001653 template <class _Pp,
1654 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001656 iterator insert(const_iterator __p, _Pp&& __x)
1657 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001658#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659 template <class _InputIterator>
1660 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001661#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 void insert(initializer_list<value_type> __il)
1664 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001665#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672 iterator erase(const_iterator __first, const_iterator __last)
1673 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001675 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001678 void swap(unordered_multimap& __u)
1679 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1680 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001683 hasher hash_function() const
1684 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686 key_equal key_eq() const
1687 {return __table_.key_eq().key_eq();}
1688
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 pair<iterator, iterator> equal_range(const key_type& __k)
1697 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1700 {return __table_.__equal_range_multi(__k);}
1701
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001703 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001705 size_type max_bucket_count() const _NOEXCEPT
1706 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 size_type bucket_size(size_type __n) const
1710 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1713
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001723 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1726
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001728 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001730 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001732 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736 void reserve(size_type __n) {__table_.reserve(__n);}
1737
Howard Hinnant39213642013-07-23 22:01:58 +00001738#if _LIBCPP_DEBUG_LEVEL >= 2
1739
1740 bool __dereferenceable(const const_iterator* __i) const
1741 {return __table_.__dereferenceable(&__i->__i_);}
1742 bool __decrementable(const const_iterator* __i) const
1743 {return __table_.__decrementable(&__i->__i_);}
1744 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1745 {return __table_.__addable(&__i->__i_, __n);}
1746 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1747 {return __table_.__addable(&__i->__i_, __n);}
1748
1749#endif // _LIBCPP_DEBUG_LEVEL >= 2
1750
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001752#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1753 __node_holder __construct_node();
1754 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001755 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001756 __construct_node(_A0&& __a0);
1757#ifndef _LIBCPP_HAS_NO_VARIADICS
1758 template <class _A0, class _A1, class ..._Args>
1759 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1760#endif // _LIBCPP_HAS_NO_VARIADICS
1761#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762};
1763
1764template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1765unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1766 size_type __n, const hasher& __hf, const key_equal& __eql)
1767 : __table_(__hf, __eql)
1768{
Howard Hinnant39213642013-07-23 22:01:58 +00001769#if _LIBCPP_DEBUG_LEVEL >= 2
1770 __get_db()->__insert_c(this);
1771#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772 __table_.rehash(__n);
1773}
1774
1775template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1776unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1777 size_type __n, const hasher& __hf, const key_equal& __eql,
1778 const allocator_type& __a)
1779 : __table_(__hf, __eql, __a)
1780{
Howard Hinnant39213642013-07-23 22:01:58 +00001781#if _LIBCPP_DEBUG_LEVEL >= 2
1782 __get_db()->__insert_c(this);
1783#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001784 __table_.rehash(__n);
1785}
1786
1787template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1788template <class _InputIterator>
1789unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1790 _InputIterator __first, _InputIterator __last)
1791{
Howard Hinnant39213642013-07-23 22:01:58 +00001792#if _LIBCPP_DEBUG_LEVEL >= 2
1793 __get_db()->__insert_c(this);
1794#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 insert(__first, __last);
1796}
1797
1798template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1799template <class _InputIterator>
1800unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1801 _InputIterator __first, _InputIterator __last, size_type __n,
1802 const hasher& __hf, const key_equal& __eql)
1803 : __table_(__hf, __eql)
1804{
Howard Hinnant39213642013-07-23 22:01:58 +00001805#if _LIBCPP_DEBUG_LEVEL >= 2
1806 __get_db()->__insert_c(this);
1807#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 __table_.rehash(__n);
1809 insert(__first, __last);
1810}
1811
1812template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1813template <class _InputIterator>
1814unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1815 _InputIterator __first, _InputIterator __last, size_type __n,
1816 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1817 : __table_(__hf, __eql, __a)
1818{
Howard Hinnant39213642013-07-23 22:01:58 +00001819#if _LIBCPP_DEBUG_LEVEL >= 2
1820 __get_db()->__insert_c(this);
1821#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 __table_.rehash(__n);
1823 insert(__first, __last);
1824}
1825
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1829 const allocator_type& __a)
1830 : __table_(__a)
1831{
Howard Hinnant39213642013-07-23 22:01:58 +00001832#if _LIBCPP_DEBUG_LEVEL >= 2
1833 __get_db()->__insert_c(this);
1834#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835}
1836
1837template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1838unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1839 const unordered_multimap& __u)
1840 : __table_(__u.__table_)
1841{
Howard Hinnant39213642013-07-23 22:01:58 +00001842#if _LIBCPP_DEBUG_LEVEL >= 2
1843 __get_db()->__insert_c(this);
1844#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845 __table_.rehash(__u.bucket_count());
1846 insert(__u.begin(), __u.end());
1847}
1848
1849template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1850unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1851 const unordered_multimap& __u, const allocator_type& __a)
1852 : __table_(__u.__table_, __a)
1853{
Howard Hinnant39213642013-07-23 22:01:58 +00001854#if _LIBCPP_DEBUG_LEVEL >= 2
1855 __get_db()->__insert_c(this);
1856#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 __table_.rehash(__u.bucket_count());
1858 insert(__u.begin(), __u.end());
1859}
1860
Howard Hinnant73d21a42010-09-04 23:28:19 +00001861#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862
1863template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001864inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1866 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001867 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001868 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869{
Howard Hinnant39213642013-07-23 22:01:58 +00001870#if _LIBCPP_DEBUG_LEVEL >= 2
1871 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001872 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:58 +00001873#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874}
1875
1876template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1877unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1878 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001879 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880{
Howard Hinnant39213642013-07-23 22:01:58 +00001881#if _LIBCPP_DEBUG_LEVEL >= 2
1882 __get_db()->__insert_c(this);
1883#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884 if (__a != __u.get_allocator())
1885 {
1886 iterator __i = __u.begin();
1887 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:58 +00001888 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001890 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891 );
Howard Hinnant39213642013-07-23 22:01:58 +00001892 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893 }
Howard Hinnantf890d9b2013-07-30 21:04:42 +00001894#if _LIBCPP_DEBUG_LEVEL >= 2
1895 else
1896 __get_db()->swap(this, &__u);
1897#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898}
1899
Howard Hinnant73d21a42010-09-04 23:28:19 +00001900#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901
Howard Hinnante3e32912011-08-12 21:56:02 +00001902#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1903
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1905unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1906 initializer_list<value_type> __il)
1907{
Howard Hinnant39213642013-07-23 22:01:58 +00001908#if _LIBCPP_DEBUG_LEVEL >= 2
1909 __get_db()->__insert_c(this);
1910#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911 insert(__il.begin(), __il.end());
1912}
1913
1914template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1915unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1916 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1917 const key_equal& __eql)
1918 : __table_(__hf, __eql)
1919{
Howard Hinnant39213642013-07-23 22:01:58 +00001920#if _LIBCPP_DEBUG_LEVEL >= 2
1921 __get_db()->__insert_c(this);
1922#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001923 __table_.rehash(__n);
1924 insert(__il.begin(), __il.end());
1925}
1926
1927template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1928unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1929 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1930 const key_equal& __eql, const allocator_type& __a)
1931 : __table_(__hf, __eql, __a)
1932{
Howard Hinnant39213642013-07-23 22:01:58 +00001933#if _LIBCPP_DEBUG_LEVEL >= 2
1934 __get_db()->__insert_c(this);
1935#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936 __table_.rehash(__n);
1937 insert(__il.begin(), __il.end());
1938}
1939
Howard Hinnante3e32912011-08-12 21:56:02 +00001940#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1941
Howard Hinnant73d21a42010-09-04 23:28:19 +00001942#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943
1944template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1947unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001948 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001950 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 return *this;
1952}
1953
Howard Hinnant73d21a42010-09-04 23:28:19 +00001954#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955
Howard Hinnante3e32912011-08-12 21:56:02 +00001956#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1957
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1961unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1962 initializer_list<value_type> __il)
1963{
1964 __table_.__assign_multi(__il.begin(), __il.end());
1965 return *this;
1966}
1967
Howard Hinnante3e32912011-08-12 21:56:02 +00001968#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1969
Howard Hinnant73d21a42010-09-04 23:28:19 +00001970#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971
1972template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001973typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001974unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001975{
1976 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001977 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001978 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001979 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980 __h.get_deleter().__second_constructed = true;
1981 return __h;
1982}
1983
1984template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001985template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001986typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001987unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1988{
1989 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001990 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001991 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1992 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993 __h.get_deleter().__first_constructed = true;
1994 __h.get_deleter().__second_constructed = true;
1995 return __h;
1996}
1997
Howard Hinnant73d21a42010-09-04 23:28:19 +00001998#ifndef _LIBCPP_HAS_NO_VARIADICS
1999
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002001template <class _A0, class _A1, class ..._Args>
2002typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
2003unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
2004 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002006 __node_allocator& __na = __table_.__node_alloc();
2007 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
2008 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
2009 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
2010 _VSTD::forward<_Args>(__args)...);
2011 __h.get_deleter().__first_constructed = true;
2012 __h.get_deleter().__second_constructed = true;
2013 return __h;
2014}
2015
2016template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2017template <class... _Args>
2018typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2019unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
2020{
2021 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022 iterator __r = __table_.__node_insert_multi(__h.get());
2023 __h.release();
2024 return __r;
2025}
2026
2027template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002028template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
2030unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002031 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00002033 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002034 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
2035 __h.release();
2036 return __r;
2037}
2038
Howard Hinnant73d21a42010-09-04 23:28:19 +00002039#endif // _LIBCPP_HAS_NO_VARIADICS
2040#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041
2042template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2043template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002044inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045void
2046unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2047 _InputIterator __last)
2048{
2049 for (; __first != __last; ++__first)
2050 __table_.__insert_multi(*__first);
2051}
2052
2053template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055void
2056swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2057 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00002058 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059{
2060 __x.swap(__y);
2061}
2062
2063template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2064bool
2065operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2066 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2067{
2068 if (__x.size() != __y.size())
2069 return false;
2070 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2071 const_iterator;
2072 typedef pair<const_iterator, const_iterator> _EqRng;
2073 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2074 {
2075 _EqRng __xeq = __x.equal_range(__i->first);
2076 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002077 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2078 _VSTD::distance(__yeq.first, __yeq.second) ||
2079 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080 return false;
2081 __i = __xeq.second;
2082 }
2083 return true;
2084}
2085
2086template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00002087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088bool
2089operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2090 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2091{
2092 return !(__x == __y);
2093}
2094
2095_LIBCPP_END_NAMESPACE_STD
2096
2097#endif // _LIBCPP_UNORDERED_MAP