blob: 55469894955c72ad742fd2c05e321828b000ecbb [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:2447 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:1653 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:2463 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:1668 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:3172 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:1688 ~unordered_map();
89 unordered_map& operator=(const unordered_map&);
Howard Hinnant5f2f14c2011-06-04 18:54:2490 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:1696 unordered_map& operator=(initializer_list<value_type>);
97
Howard Hinnant5f2f14c2011-06-04 18:54:2498 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1699
Howard Hinnant5f2f14c2011-06-04 18:54:24100 bool empty() const noexcept;
101 size_type size() const noexcept;
102 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16103
Howard Hinnant5f2f14c2011-06-04 18:54:24104 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:16110
111 template <class... Args>
112 pair<iterator, bool> emplace(Args&&... args);
113 template <class... Args>
114 iterator emplace_hint(const_iterator position, Args&&... args);
115 pair<iterator, bool> insert(const value_type& obj);
116 template <class P>
117 pair<iterator, bool> insert(P&& obj);
118 iterator insert(const_iterator hint, const value_type& obj);
119 template <class P>
120 iterator insert(const_iterator hint, P&& obj);
121 template <class InputIterator>
122 void insert(InputIterator first, InputIterator last);
123 void insert(initializer_list<value_type>);
124
Marshall Clow0ce05a92015-07-07 05:45:35125 template <class... Args>
126 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
127 template <class... Args>
128 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
129 template <class... Args>
130 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
131 template <class... Args>
132 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
133 template <class M>
134 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
135 template <class M>
136 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
137 template <class M>
138 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
139 template <class M>
140 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
141
Howard Hinnantbc8d3f92010-05-11 19:42:16142 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00143 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16144 size_type erase(const key_type& k);
145 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24146 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16147
Howard Hinnant5f2f14c2011-06-04 18:54:24148 void swap(unordered_map&)
149 noexcept(
150 (!allocator_type::propagate_on_container_swap::value ||
151 __is_nothrow_swappable<allocator_type>::value) &&
152 __is_nothrow_swappable<hasher>::value &&
153 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16154
155 hasher hash_function() const;
156 key_equal key_eq() const;
157
158 iterator find(const key_type& k);
159 const_iterator find(const key_type& k) const;
160 size_type count(const key_type& k) const;
161 pair<iterator, iterator> equal_range(const key_type& k);
162 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
163
164 mapped_type& operator[](const key_type& k);
165 mapped_type& operator[](key_type&& k);
166
167 mapped_type& at(const key_type& k);
168 const mapped_type& at(const key_type& k) const;
169
Howard Hinnant5f2f14c2011-06-04 18:54:24170 size_type bucket_count() const noexcept;
171 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16172
173 size_type bucket_size(size_type n) const;
174 size_type bucket(const key_type& k) const;
175
176 local_iterator begin(size_type n);
177 local_iterator end(size_type n);
178 const_local_iterator begin(size_type n) const;
179 const_local_iterator end(size_type n) const;
180 const_local_iterator cbegin(size_type n) const;
181 const_local_iterator cend(size_type n) const;
182
Howard Hinnant5f2f14c2011-06-04 18:54:24183 float load_factor() const noexcept;
184 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16185 void max_load_factor(float z);
186 void rehash(size_type n);
187 void reserve(size_type n);
188};
189
190template <class Key, class T, class Hash, class Pred, class Alloc>
191 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24192 unordered_map<Key, T, Hash, Pred, Alloc>& y)
193 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16194
195template <class Key, class T, class Hash, class Pred, class Alloc>
196 bool
197 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
198 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
199
200template <class Key, class T, class Hash, class Pred, class Alloc>
201 bool
202 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
203 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
204
205template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
206 class Alloc = allocator<pair<const Key, T>>>
207class unordered_multimap
208{
209public:
210 // types
211 typedef Key key_type;
212 typedef T mapped_type;
213 typedef Hash hasher;
214 typedef Pred key_equal;
215 typedef Alloc allocator_type;
216 typedef pair<const key_type, mapped_type> value_type;
217 typedef value_type& reference;
218 typedef const value_type& const_reference;
219 typedef typename allocator_traits<allocator_type>::pointer pointer;
220 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
221 typedef typename allocator_traits<allocator_type>::size_type size_type;
222 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
223
224 typedef /unspecified/ iterator;
225 typedef /unspecified/ const_iterator;
226 typedef /unspecified/ local_iterator;
227 typedef /unspecified/ const_local_iterator;
228
Howard Hinnant5f2f14c2011-06-04 18:54:24229 unordered_multimap()
230 noexcept(
231 is_nothrow_default_constructible<hasher>::value &&
232 is_nothrow_default_constructible<key_equal>::value &&
233 is_nothrow_default_constructible<allocator_type>::value);
234 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16235 const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
237 template <class InputIterator>
238 unordered_multimap(InputIterator f, InputIterator l,
239 size_type n = 0, const hasher& hf = hasher(),
240 const key_equal& eql = key_equal(),
241 const allocator_type& a = allocator_type());
242 explicit unordered_multimap(const allocator_type&);
243 unordered_multimap(const unordered_multimap&);
244 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24245 unordered_multimap(unordered_multimap&&)
246 noexcept(
247 is_nothrow_move_constructible<hasher>::value &&
248 is_nothrow_move_constructible<key_equal>::value &&
249 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16250 unordered_multimap(unordered_multimap&&, const Allocator&);
251 unordered_multimap(initializer_list<value_type>, size_type n = 0,
252 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
253 const allocator_type& a = allocator_type());
Marshall Clow6dff6182013-09-12 03:00:31254 unordered_multimap(size_type n, const allocator_type& a)
255 : unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
256 unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
257 : unordered_multimap(n, hf, key_equal(), a) {} // C++14
258 template <class InputIterator>
259 unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
260 : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
261 template <class InputIterator>
262 unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
263 const allocator_type& a)
264 : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
265 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
266 : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
267 unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
268 const allocator_type& a)
269 : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16270 ~unordered_multimap();
271 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant5f2f14c2011-06-04 18:54:24272 unordered_multimap& operator=(unordered_multimap&&)
273 noexcept(
274 allocator_type::propagate_on_container_move_assignment::value &&
275 is_nothrow_move_assignable<allocator_type>::value &&
276 is_nothrow_move_assignable<hasher>::value &&
277 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16278 unordered_multimap& operator=(initializer_list<value_type>);
279
Howard Hinnant5f2f14c2011-06-04 18:54:24280 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16281
Howard Hinnant5f2f14c2011-06-04 18:54:24282 bool empty() const noexcept;
283 size_type size() const noexcept;
284 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16285
Howard Hinnant5f2f14c2011-06-04 18:54:24286 iterator begin() noexcept;
287 iterator end() noexcept;
288 const_iterator begin() const noexcept;
289 const_iterator end() const noexcept;
290 const_iterator cbegin() const noexcept;
291 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16292
293 template <class... Args>
294 iterator emplace(Args&&... args);
295 template <class... Args>
296 iterator emplace_hint(const_iterator position, Args&&... args);
297 iterator insert(const value_type& obj);
298 template <class P>
299 iterator insert(P&& obj);
300 iterator insert(const_iterator hint, const value_type& obj);
301 template <class P>
302 iterator insert(const_iterator hint, P&& obj);
303 template <class InputIterator>
304 void insert(InputIterator first, InputIterator last);
305 void insert(initializer_list<value_type>);
306
307 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00308 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16309 size_type erase(const key_type& k);
310 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24311 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16312
Howard Hinnant5f2f14c2011-06-04 18:54:24313 void swap(unordered_multimap&)
314 noexcept(
315 (!allocator_type::propagate_on_container_swap::value ||
316 __is_nothrow_swappable<allocator_type>::value) &&
317 __is_nothrow_swappable<hasher>::value &&
318 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16319
320 hasher hash_function() const;
321 key_equal key_eq() const;
322
323 iterator find(const key_type& k);
324 const_iterator find(const key_type& k) const;
325 size_type count(const key_type& k) const;
326 pair<iterator, iterator> equal_range(const key_type& k);
327 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
328
Howard Hinnant5f2f14c2011-06-04 18:54:24329 size_type bucket_count() const noexcept;
330 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16331
332 size_type bucket_size(size_type n) const;
333 size_type bucket(const key_type& k) const;
334
335 local_iterator begin(size_type n);
336 local_iterator end(size_type n);
337 const_local_iterator begin(size_type n) const;
338 const_local_iterator end(size_type n) const;
339 const_local_iterator cbegin(size_type n) const;
340 const_local_iterator cend(size_type n) const;
341
Howard Hinnant5f2f14c2011-06-04 18:54:24342 float load_factor() const noexcept;
343 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16344 void max_load_factor(float z);
345 void rehash(size_type n);
346 void reserve(size_type n);
347};
348
349template <class Key, class T, class Hash, class Pred, class Alloc>
350 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24351 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
352 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16353
354template <class Key, class T, class Hash, class Pred, class Alloc>
355 bool
356 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
357 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
358
359template <class Key, class T, class Hash, class Pred, class Alloc>
360 bool
361 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
362 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
363
364} // std
365
366*/
367
368#include <__config>
369#include <__hash_table>
370#include <functional>
371#include <stdexcept>
Eric Fiselier410ed302016-02-11 21:45:53372#include <tuple>
Howard Hinnantbc8d3f92010-05-11 19:42:16373
Eric Fiselierb9536102014-08-10 23:53:08374#include <__debug>
375
Howard Hinnant08e17472011-10-17 20:05:10376#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16377#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10378#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16379
380_LIBCPP_BEGIN_NAMESPACE_STD
381
Eric Fiselier3a0e4302015-06-13 07:08:02382template <class _Key, class _Cp, class _Hash,
383 bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33384 >
Howard Hinnantbc8d3f92010-05-11 19:42:16385class __unordered_map_hasher
386 : private _Hash
387{
Howard Hinnantbc8d3f92010-05-11 19:42:16388public:
Howard Hinnantee6ccd02010-09-23 18:58:28389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24390 __unordered_map_hasher()
391 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
392 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24394 __unordered_map_hasher(const _Hash& __h)
395 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
396 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24398 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24400 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00401 {return static_cast<const _Hash&>(*this)(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24402 _LIBCPP_INLINE_VISIBILITY
403 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16404 {return static_cast<const _Hash&>(*this)(__x);}
Marshall Clow7d914d12015-07-13 20:04:56405 void swap(__unordered_map_hasher&__y)
406 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
407 {
408 using _VSTD::swap;
409 swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y));
410 }
Howard Hinnantbc8d3f92010-05-11 19:42:16411};
412
Howard Hinnant9b128e02013-07-05 18:06:00413template <class _Key, class _Cp, class _Hash>
414class __unordered_map_hasher<_Key, _Cp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16415{
416 _Hash __hash_;
Howard Hinnantbc8d3f92010-05-11 19:42:16417public:
Howard Hinnantee6ccd02010-09-23 18:58:28418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24419 __unordered_map_hasher()
420 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
421 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24423 __unordered_map_hasher(const _Hash& __h)
424 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
425 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24427 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24429 size_t operator()(const _Cp& __x) const
Howard Hinnant9b128e02013-07-05 18:06:00430 {return __hash_(__x.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24431 _LIBCPP_INLINE_VISIBILITY
432 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16433 {return __hash_(__x);}
Marshall Clow7d914d12015-07-13 20:04:56434 void swap(__unordered_map_hasher&__y)
435 _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
436 {
437 using _VSTD::swap;
438 swap(__hash_, __y.__hash_);
439 }
Howard Hinnantbc8d3f92010-05-11 19:42:16440};
441
Marshall Clow7d914d12015-07-13 20:04:56442template <class _Key, class _Cp, class _Hash, bool __b>
443inline _LIBCPP_INLINE_VISIBILITY
444void
445swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
446 __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
447 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
448{
449 __x.swap(__y);
450}
451
Eric Fiselier3a0e4302015-06-13 07:08:02452template <class _Key, class _Cp, class _Pred,
453 bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33454 >
Howard Hinnantbc8d3f92010-05-11 19:42:16455class __unordered_map_equal
456 : private _Pred
457{
Howard Hinnantbc8d3f92010-05-11 19:42:16458public:
Howard Hinnantee6ccd02010-09-23 18:58:28459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24460 __unordered_map_equal()
461 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
462 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24464 __unordered_map_equal(const _Pred& __p)
465 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
466 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24468 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24470 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00471 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24472 _LIBCPP_INLINE_VISIBILITY
473 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00474 {return static_cast<const _Pred&>(*this)(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24476 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00477 {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56478 void swap(__unordered_map_equal&__y)
479 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
480 {
481 using _VSTD::swap;
482 swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y));
483 }
Howard Hinnantbc8d3f92010-05-11 19:42:16484};
485
Howard Hinnant9b128e02013-07-05 18:06:00486template <class _Key, class _Cp, class _Pred>
487class __unordered_map_equal<_Key, _Cp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16488{
489 _Pred __pred_;
Howard Hinnantbc8d3f92010-05-11 19:42:16490public:
Howard Hinnantee6ccd02010-09-23 18:58:28491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24492 __unordered_map_equal()
493 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
494 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24496 __unordered_map_equal(const _Pred& __p)
497 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
498 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24500 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24502 bool operator()(const _Cp& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00503 {return __pred_(__x.__cc.first, __y.__cc.first);}
Howard Hinnantf8880d02011-12-12 17:26:24504 _LIBCPP_INLINE_VISIBILITY
505 bool operator()(const _Cp& __x, const _Key& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00506 {return __pred_(__x.__cc.first, __y);}
Howard Hinnantf8880d02011-12-12 17:26:24507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24508 bool operator()(const _Key& __x, const _Cp& __y) const
Howard Hinnant9b128e02013-07-05 18:06:00509 {return __pred_(__x, __y.__cc.first);}
Marshall Clow7d914d12015-07-13 20:04:56510 void swap(__unordered_map_equal&__y)
511 _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
512 {
513 using _VSTD::swap;
514 swap(__pred_, __y.__pred_);
515 }
Howard Hinnantbc8d3f92010-05-11 19:42:16516};
517
Marshall Clow7d914d12015-07-13 20:04:56518template <class _Key, class _Cp, class _Pred, bool __b>
519inline _LIBCPP_INLINE_VISIBILITY
520void
521swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
522 __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
523 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
524{
525 __x.swap(__y);
526}
527
Howard Hinnantbc8d3f92010-05-11 19:42:16528template <class _Alloc>
529class __hash_map_node_destructor
530{
531 typedef _Alloc allocator_type;
532 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:23533
Howard Hinnantbc8d3f92010-05-11 19:42:16534public:
Eric Fiselier774c7c52016-02-10 20:46:23535
536 typedef typename __alloc_traits::pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16537private:
Howard Hinnantbc8d3f92010-05-11 19:42:16538
539 allocator_type& __na_;
540
541 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
542
543public:
544 bool __first_constructed;
545 bool __second_constructed;
546
Howard Hinnantee6ccd02010-09-23 18:58:28547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24548 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16549 : __na_(__na),
550 __first_constructed(false),
551 __second_constructed(false)
552 {}
553
Howard Hinnant73d21a42010-09-04 23:28:19554#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16556 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24557 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16558 : __na_(__x.__na_),
559 __first_constructed(__x.__value_constructed),
560 __second_constructed(__x.__value_constructed)
561 {
562 __x.__value_constructed = false;
563 }
Howard Hinnant73d21a42010-09-04 23:28:19564#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16566 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
567 : __na_(__x.__na_),
568 __first_constructed(__x.__value_constructed),
569 __second_constructed(__x.__value_constructed)
570 {
571 const_cast<bool&>(__x.__value_constructed) = false;
572 }
Howard Hinnant73d21a42010-09-04 23:28:19573#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16574
Howard Hinnantee6ccd02010-09-23 18:58:28575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24576 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16577 {
578 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29579 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16580 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29581 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16582 if (__p)
583 __alloc_traits::deallocate(__na_, __p, 1);
584 }
585};
586
Eric Fiselier2960ae22016-02-11 11:59:44587#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantff7546e2013-09-30 19:08:22588template <class _Key, class _Tp>
589union __hash_value_type
590{
591 typedef _Key key_type;
592 typedef _Tp mapped_type;
593 typedef pair<const key_type, mapped_type> value_type;
594 typedef pair<key_type, mapped_type> __nc_value_type;
595
596 value_type __cc;
597 __nc_value_type __nc;
598
Howard Hinnantff7546e2013-09-30 19:08:22599 _LIBCPP_INLINE_VISIBILITY
600 __hash_value_type& operator=(const __hash_value_type& __v)
601 {__nc = __v.__cc; return *this;}
602
603 _LIBCPP_INLINE_VISIBILITY
604 __hash_value_type& operator=(__hash_value_type&& __v)
Marshall Clowcd137822015-05-06 12:11:22605 {__nc = _VSTD::move(__v.__nc); return *this;}
Howard Hinnantff7546e2013-09-30 19:08:22606
Eric Fiselier2960ae22016-02-11 11:59:44607 template <class _ValueTp,
608 class = typename enable_if<
609 __is_same_uncvref<_ValueTp, value_type>::value
610 >::type
611 >
Howard Hinnantff7546e2013-09-30 19:08:22612 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2960ae22016-02-11 11:59:44613 __hash_value_type& operator=(_ValueTp&& __v) {
614 __nc = _VSTD::forward<_ValueTp>(__v); return *this;
615 }
616
617private:
618 __hash_value_type(const __hash_value_type& __v) = delete;
619 __hash_value_type(__hash_value_type&& __v) = delete;
620 template <class ..._Args>
621 explicit __hash_value_type(_Args&& ...__args) = delete;
622
623 ~__hash_value_type() = delete;
Howard Hinnantff7546e2013-09-30 19:08:22624};
625
626#else
627
628template <class _Key, class _Tp>
629struct __hash_value_type
630{
631 typedef _Key key_type;
632 typedef _Tp mapped_type;
633 typedef pair<const key_type, mapped_type> value_type;
634
635 value_type __cc;
636
Eric Fiselier2960ae22016-02-11 11:59:44637private:
638 ~__hash_value_type();
Howard Hinnantff7546e2013-09-30 19:08:22639};
640
641#endif
642
Howard Hinnantbc8d3f92010-05-11 19:42:16643template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34644class _LIBCPP_TYPE_VIS_ONLY __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16645{
646 _HashIterator __i_;
647
Eric Fiselier774c7c52016-02-10 20:46:23648 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
649
Howard Hinnantbc8d3f92010-05-11 19:42:16650public:
651 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23652 typedef typename _NodeTypes::__map_value_type value_type;
653 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16654 typedef value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23655 typedef typename _NodeTypes::__map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16656
Howard Hinnantee6ccd02010-09-23 18:58:28657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24658 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16659
Howard Hinnantee6ccd02010-09-23 18:58:28660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24661 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16662
Howard Hinnantee6ccd02010-09-23 18:58:28663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29664 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29666 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16667
Howard Hinnantee6ccd02010-09-23 18:58:28668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16669 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16671 __hash_map_iterator operator++(int)
672 {
673 __hash_map_iterator __t(*this);
674 ++(*this);
675 return __t;
676 }
677
Howard Hinnantee6ccd02010-09-23 18:58:28678 friend _LIBCPP_INLINE_VISIBILITY
679 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16680 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28681 friend _LIBCPP_INLINE_VISIBILITY
682 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16683 {return __x.__i_ != __y.__i_;}
684
Howard Hinnant0f678bd2013-08-12 18:38:34685 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
686 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
687 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
688 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
689 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16690};
691
692template <class _HashIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34693class _LIBCPP_TYPE_VIS_ONLY __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16694{
695 _HashIterator __i_;
696
Eric Fiselier774c7c52016-02-10 20:46:23697 typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
698
Howard Hinnantbc8d3f92010-05-11 19:42:16699public:
700 typedef forward_iterator_tag iterator_category;
Eric Fiselier774c7c52016-02-10 20:46:23701 typedef typename _NodeTypes::__map_value_type value_type;
702 typedef typename _NodeTypes::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16703 typedef const value_type& reference;
Eric Fiselier774c7c52016-02-10 20:46:23704 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16705
Howard Hinnantee6ccd02010-09-23 18:58:28706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24707 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16708
Howard Hinnantee6ccd02010-09-23 18:58:28709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24710 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16712 __hash_map_const_iterator(
713 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24714 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16715 : __i_(__i.__i_) {}
716
Howard Hinnantee6ccd02010-09-23 18:58:28717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29718 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29720 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16721
Howard Hinnantee6ccd02010-09-23 18:58:28722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16723 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16725 __hash_map_const_iterator operator++(int)
726 {
727 __hash_map_const_iterator __t(*this);
728 ++(*this);
729 return __t;
730 }
731
Howard Hinnantee6ccd02010-09-23 18:58:28732 friend _LIBCPP_INLINE_VISIBILITY
733 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16734 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28735 friend _LIBCPP_INLINE_VISIBILITY
736 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16737 {return __x.__i_ != __y.__i_;}
738
Howard Hinnant0f678bd2013-08-12 18:38:34739 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_map;
740 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS_ONLY unordered_multimap;
741 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_iterator;
742 template <class> friend class _LIBCPP_TYPE_VIS_ONLY __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16743};
744
745template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
746 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:34747class _LIBCPP_TYPE_VIS_ONLY unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16748{
749public:
750 // types
751 typedef _Key key_type;
752 typedef _Tp mapped_type;
753 typedef _Hash hasher;
754 typedef _Pred key_equal;
755 typedef _Alloc allocator_type;
756 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29757 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16758 typedef value_type& reference;
759 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58760 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
761 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16762
763private:
Howard Hinnantff7546e2013-09-30 19:08:22764 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:00765 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
766 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:38767 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
768 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16769
770 typedef __hash_table<__value_type, __hasher,
771 __key_equal, __allocator_type> __table;
772
773 __table __table_;
774
Eric Fiselier2960ae22016-02-11 11:59:44775 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:16776 typedef typename __table::__node_pointer __node_pointer;
777 typedef typename __table::__node_const_pointer __node_const_pointer;
778 typedef typename __table::__node_traits __node_traits;
779 typedef typename __table::__node_allocator __node_allocator;
780 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50781 typedef __hash_map_node_destructor<__node_allocator> _Dp;
782 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16783 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier2960ae22016-02-11 11:59:44784
785 static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
786 static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
Howard Hinnantbc8d3f92010-05-11 19:42:16787public:
788 typedef typename __alloc_traits::pointer pointer;
789 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:23790 typedef typename __table::size_type size_type;
791 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16792
793 typedef __hash_map_iterator<typename __table::iterator> iterator;
794 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
795 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
796 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
797
Howard Hinnantee6ccd02010-09-23 18:58:28798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24799 unordered_map()
800 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58801 {
802#if _LIBCPP_DEBUG_LEVEL >= 2
803 __get_db()->__insert_c(this);
804#endif
805 }
Howard Hinnantbc8d3f92010-05-11 19:42:16806 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
807 const key_equal& __eql = key_equal());
808 unordered_map(size_type __n, const hasher& __hf,
809 const key_equal& __eql,
810 const allocator_type& __a);
811 template <class _InputIterator>
812 unordered_map(_InputIterator __first, _InputIterator __last);
813 template <class _InputIterator>
814 unordered_map(_InputIterator __first, _InputIterator __last,
815 size_type __n, const hasher& __hf = hasher(),
816 const key_equal& __eql = key_equal());
817 template <class _InputIterator>
818 unordered_map(_InputIterator __first, _InputIterator __last,
819 size_type __n, const hasher& __hf,
820 const key_equal& __eql,
821 const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16823 explicit unordered_map(const allocator_type& __a);
824 unordered_map(const unordered_map& __u);
825 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19826#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24828 unordered_map(unordered_map&& __u)
829 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16830 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19831#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02832#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16833 unordered_map(initializer_list<value_type> __il);
834 unordered_map(initializer_list<value_type> __il, size_type __n,
835 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
836 unordered_map(initializer_list<value_type> __il, size_type __n,
837 const hasher& __hf, const key_equal& __eql,
838 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02839#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:31840#if _LIBCPP_STD_VER > 11
841 _LIBCPP_INLINE_VISIBILITY
842 unordered_map(size_type __n, const allocator_type& __a)
843 : unordered_map(__n, hasher(), key_equal(), __a) {}
844 _LIBCPP_INLINE_VISIBILITY
845 unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
846 : unordered_map(__n, __hf, key_equal(), __a) {}
847 template <class _InputIterator>
848 _LIBCPP_INLINE_VISIBILITY
849 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
850 : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
851 template <class _InputIterator>
852 _LIBCPP_INLINE_VISIBILITY
853 unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
854 const allocator_type& __a)
855 : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
856 _LIBCPP_INLINE_VISIBILITY
857 unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
858 : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
859 _LIBCPP_INLINE_VISIBILITY
860 unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
861 const allocator_type& __a)
862 : unordered_map(__il, __n, __hf, key_equal(), __a) {}
863#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16864 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36865 _LIBCPP_INLINE_VISIBILITY
866 unordered_map& operator=(const unordered_map& __u)
867 {
Marshall Clow3f013892016-07-18 13:19:00868#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant61aa6012011-07-01 19:24:36869 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29870#else
Marshall Clowebfc50e2014-02-08 04:03:14871 if (this != &__u) {
872 __table_.clear();
873 __table_.hash_function() = __u.__table_.hash_function();
874 __table_.key_eq() = __u.__table_.key_eq();
875 __table_.max_load_factor() = __u.__table_.max_load_factor();
876 __table_.__copy_assign_alloc(__u.__table_);
877 insert(__u.begin(), __u.end());
878 }
Howard Hinnant7a6b7ce2013-06-22 15:21:29879#endif
Howard Hinnant61aa6012011-07-01 19:24:36880 return *this;
881 }
Howard Hinnant73d21a42010-09-04 23:28:19882#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24884 unordered_map& operator=(unordered_map&& __u)
885 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16886#endif
Howard Hinnante3e32912011-08-12 21:56:02887#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanov9341a8a2016-04-22 01:04:55888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16889 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16891
Howard Hinnantee6ccd02010-09-23 18:58:28892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24893 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16894 {return allocator_type(__table_.__node_alloc());}
895
Howard Hinnantee6ccd02010-09-23 18:58:28896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24897 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24899 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24901 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16902
Howard Hinnantee6ccd02010-09-23 18:58:28903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24904 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24906 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24908 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24910 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24912 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24914 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16915
Eric Fiselier91a15652016-04-18 01:40:45916 _LIBCPP_INLINE_VISIBILITY
917 pair<iterator, bool> insert(const value_type& __x)
918 {return __table_.__insert_unique(__x);}
919
920 iterator insert(const_iterator __p, const value_type& __x) {
921#if _LIBCPP_DEBUG_LEVEL >= 2
922 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
923 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
924 " referring to this unordered_map");
925#endif
926 return insert(__x).first;
927 }
928
929 template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55930 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a15652016-04-18 01:40:45931 void insert(_InputIterator __first, _InputIterator __last);
932
933#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
934 _LIBCPP_INLINE_VISIBILITY
935 void insert(initializer_list<value_type> __il)
936 {insert(__il.begin(), __il.end());}
937#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
938
Eric Fiselier2960ae22016-02-11 11:59:44939#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier91a15652016-04-18 01:40:45940 _LIBCPP_INLINE_VISIBILITY
941 pair<iterator, bool> insert(value_type&& __x)
942 {return __table_.__insert_unique(_VSTD::move(__x));}
943
944 iterator insert(const_iterator __p, value_type&& __x) {
945#if _LIBCPP_DEBUG_LEVEL >= 2
946 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
947 "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
948 " referring to this unordered_map");
949#endif
950 return __table_.__insert_unique(_VSTD::move(__x)).first;
951 }
952
953 template <class _Pp,
954 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
955 _LIBCPP_INLINE_VISIBILITY
956 pair<iterator, bool> insert(_Pp&& __x)
957 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
958
959 template <class _Pp,
960 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
961 _LIBCPP_INLINE_VISIBILITY
962 iterator insert(const_iterator __p, _Pp&& __x)
963 {
964#if _LIBCPP_DEBUG_LEVEL >= 2
965 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
966 "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
967 " referring to this unordered_map");
968#endif
969 return insert(_VSTD::forward<_Pp>(__x)).first;
970 }
971
Eric Fiselier2960ae22016-02-11 11:59:44972 template <class... _Args>
973 _LIBCPP_INLINE_VISIBILITY
974 pair<iterator, bool> emplace(_Args&&... __args) {
975 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
976 }
Howard Hinnant73d21a42010-09-04 23:28:19977
Howard Hinnant635ce1d2012-05-25 22:04:21978 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:44979 _LIBCPP_INLINE_VISIBILITY
980 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
Howard Hinnantf890d9b2013-07-30 21:04:42981#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier2960ae22016-02-11 11:59:44982 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
983 "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
984 " referring to this unordered_map");
Howard Hinnantf890d9b2013-07-30 21:04:42985#endif
Eric Fiselier2960ae22016-02-11 11:59:44986 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
987 }
988
Eric Fiselier91a15652016-04-18 01:40:45989#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16990
Marshall Clow0ce05a92015-07-07 05:45:35991#if _LIBCPP_STD_VER > 14
Marshall Clow0ce05a92015-07-07 05:45:35992 template <class... _Args>
993 _LIBCPP_INLINE_VISIBILITY
994 pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
995 {
Eric Fiselier2e37f922016-04-18 06:51:33996 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
997 _VSTD::forward_as_tuple(__k),
998 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow0ce05a92015-07-07 05:45:35999 }
1000
1001 template <class... _Args>
1002 _LIBCPP_INLINE_VISIBILITY
1003 pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1004 {
Eric Fiselier2e37f922016-04-18 06:51:331005 return __table_.__emplace_unique_key_args(__k, _VSTD::piecewise_construct,
1006 _VSTD::forward_as_tuple(_VSTD::move(__k)),
1007 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
Marshall Clow0ce05a92015-07-07 05:45:351008 }
1009
1010 template <class... _Args>
1011 _LIBCPP_INLINE_VISIBILITY
1012 iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1013 {
Eric Fiselier2e37f922016-04-18 06:51:331014#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyy3ba3ad42016-09-26 21:39:381015 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier2e37f922016-04-18 06:51:331016 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1017 " referring to this unordered_map");
1018#endif
1019 return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
Marshall Clow0ce05a92015-07-07 05:45:351020 }
1021
1022 template <class... _Args>
1023 _LIBCPP_INLINE_VISIBILITY
1024 iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1025 {
Eric Fiselier2e37f922016-04-18 06:51:331026#if _LIBCPP_DEBUG_LEVEL >= 2
Oleg Ranevskyy3ba3ad42016-09-26 21:39:381027 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
Eric Fiselier2e37f922016-04-18 06:51:331028 "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1029 " referring to this unordered_map");
1030#endif
1031 return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
Marshall Clow0ce05a92015-07-07 05:45:351032 }
1033
1034 template <class _Vp>
1035 _LIBCPP_INLINE_VISIBILITY
1036 pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1037 {
Eric Fiselier2e37f922016-04-18 06:51:331038 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1039 __k, _VSTD::forward<_Vp>(__v));
1040 if (!__res.second) {
1041 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clow0ce05a92015-07-07 05:45:351042 }
Eric Fiselier2e37f922016-04-18 06:51:331043 return __res;
Marshall Clow0ce05a92015-07-07 05:45:351044 }
Eric Fiselier2e37f922016-04-18 06:51:331045
Marshall Clow0ce05a92015-07-07 05:45:351046 template <class _Vp>
1047 _LIBCPP_INLINE_VISIBILITY
1048 pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1049 {
Eric Fiselier2e37f922016-04-18 06:51:331050 pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1051 _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1052 if (!__res.second) {
1053 __res.first->second = _VSTD::forward<_Vp>(__v);
Marshall Clow0ce05a92015-07-07 05:45:351054 }
Eric Fiselier2e37f922016-04-18 06:51:331055 return __res;
Marshall Clow0ce05a92015-07-07 05:45:351056 }
1057
1058 template <class _Vp>
1059 _LIBCPP_INLINE_VISIBILITY
1060 iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
1061 {
Eric Fiselier2e37f922016-04-18 06:51:331062 return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
Marshall Clow0ce05a92015-07-07 05:45:351063 }
1064
1065 template <class _Vp>
1066 _LIBCPP_INLINE_VISIBILITY
1067 iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
1068 {
Eric Fiselier2e37f922016-04-18 06:51:331069 return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
Marshall Clow0ce05a92015-07-07 05:45:351070 }
1071#endif
Marshall Clow0ce05a92015-07-07 05:45:351072
Howard Hinnantee6ccd02010-09-23 18:58:281073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161074 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:281075 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001076 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161078 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161080 iterator erase(const_iterator __first, const_iterator __last)
1081 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:281082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241083 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161084
Howard Hinnantee6ccd02010-09-23 18:58:281085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241086 void swap(unordered_map& __u)
1087 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1088 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161089
Howard Hinnantee6ccd02010-09-23 18:58:281090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161091 hasher hash_function() const
1092 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:281093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161094 key_equal key_eq() const
1095 {return __table_.key_eq().key_eq();}
1096
Howard Hinnantee6ccd02010-09-23 18:58:281097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161098 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161100 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161102 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161104 pair<iterator, iterator> equal_range(const key_type& __k)
1105 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161107 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1108 {return __table_.__equal_range_unique(__k);}
1109
1110 mapped_type& operator[](const key_type& __k);
Eric Fiselier410ed302016-02-11 21:45:531111#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161112 mapped_type& operator[](key_type&& __k);
1113#endif
1114
1115 mapped_type& at(const key_type& __k);
1116 const mapped_type& at(const key_type& __k) const;
1117
Howard Hinnantee6ccd02010-09-23 18:58:281118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241119 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:281120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241121 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:161122
Howard Hinnantee6ccd02010-09-23 18:58:281123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161124 size_type bucket_size(size_type __n) const
1125 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161127 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1128
Howard Hinnantee6ccd02010-09-23 18:58:281129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161130 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161132 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161134 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161136 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161138 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161140 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1141
Howard Hinnantee6ccd02010-09-23 18:58:281142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241143 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241145 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161147 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:281148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161149 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161151 void reserve(size_type __n) {__table_.reserve(__n);}
1152
Howard Hinnant39213642013-07-23 22:01:581153#if _LIBCPP_DEBUG_LEVEL >= 2
1154
1155 bool __dereferenceable(const const_iterator* __i) const
1156 {return __table_.__dereferenceable(&__i->__i_);}
1157 bool __decrementable(const const_iterator* __i) const
1158 {return __table_.__decrementable(&__i->__i_);}
1159 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1160 {return __table_.__addable(&__i->__i_, __n);}
1161 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1162 {return __table_.__addable(&__i->__i_, __n);}
1163
1164#endif // _LIBCPP_DEBUG_LEVEL >= 2
1165
Howard Hinnantbc8d3f92010-05-11 19:42:161166private:
Eric Fiselier410ed302016-02-11 21:45:531167
1168#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantb66e1c32013-07-04 20:59:161169 __node_holder __construct_node_with_key(const key_type& __k);
Eric Fiselier410ed302016-02-11 21:45:531170#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161171};
1172
1173template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1174unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1175 size_type __n, const hasher& __hf, const key_equal& __eql)
1176 : __table_(__hf, __eql)
1177{
Howard Hinnant39213642013-07-23 22:01:581178#if _LIBCPP_DEBUG_LEVEL >= 2
1179 __get_db()->__insert_c(this);
1180#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161181 __table_.rehash(__n);
1182}
1183
1184template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1185unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1186 size_type __n, const hasher& __hf, const key_equal& __eql,
1187 const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401188 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161189{
Howard Hinnant39213642013-07-23 22:01:581190#if _LIBCPP_DEBUG_LEVEL >= 2
1191 __get_db()->__insert_c(this);
1192#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161193 __table_.rehash(__n);
1194}
1195
1196template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551197inline
Howard Hinnantbc8d3f92010-05-11 19:42:161198unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1199 const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401200 : __table_(typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161201{
Howard Hinnant39213642013-07-23 22:01:581202#if _LIBCPP_DEBUG_LEVEL >= 2
1203 __get_db()->__insert_c(this);
1204#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161205}
1206
1207template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1208template <class _InputIterator>
1209unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1210 _InputIterator __first, _InputIterator __last)
1211{
Howard Hinnant39213642013-07-23 22:01:581212#if _LIBCPP_DEBUG_LEVEL >= 2
1213 __get_db()->__insert_c(this);
1214#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161215 insert(__first, __last);
1216}
1217
1218template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1219template <class _InputIterator>
1220unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1221 _InputIterator __first, _InputIterator __last, size_type __n,
1222 const hasher& __hf, const key_equal& __eql)
1223 : __table_(__hf, __eql)
1224{
Howard Hinnant39213642013-07-23 22:01:581225#if _LIBCPP_DEBUG_LEVEL >= 2
1226 __get_db()->__insert_c(this);
1227#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161228 __table_.rehash(__n);
1229 insert(__first, __last);
1230}
1231
1232template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1233template <class _InputIterator>
1234unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1235 _InputIterator __first, _InputIterator __last, size_type __n,
1236 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401237 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161238{
Howard Hinnant39213642013-07-23 22:01:581239#if _LIBCPP_DEBUG_LEVEL >= 2
1240 __get_db()->__insert_c(this);
1241#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161242 __table_.rehash(__n);
1243 insert(__first, __last);
1244}
1245
1246template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1247unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1248 const unordered_map& __u)
1249 : __table_(__u.__table_)
1250{
Howard Hinnant39213642013-07-23 22:01:581251#if _LIBCPP_DEBUG_LEVEL >= 2
1252 __get_db()->__insert_c(this);
1253#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161254 __table_.rehash(__u.bucket_count());
1255 insert(__u.begin(), __u.end());
1256}
1257
1258template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1259unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1260 const unordered_map& __u, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401261 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161262{
Howard Hinnant39213642013-07-23 22:01:581263#if _LIBCPP_DEBUG_LEVEL >= 2
1264 __get_db()->__insert_c(this);
1265#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161266 __table_.rehash(__u.bucket_count());
1267 insert(__u.begin(), __u.end());
1268}
1269
Howard Hinnant73d21a42010-09-04 23:28:191270#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161271
1272template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551273inline
Howard Hinnantbc8d3f92010-05-11 19:42:161274unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1275 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:241276 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:191277 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:161278{
Howard Hinnant39213642013-07-23 22:01:581279#if _LIBCPP_DEBUG_LEVEL >= 2
1280 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:421281 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:581282#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161283}
1284
1285template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1286unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1287 unordered_map&& __u, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401288 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161289{
Howard Hinnant39213642013-07-23 22:01:581290#if _LIBCPP_DEBUG_LEVEL >= 2
1291 __get_db()->__insert_c(this);
1292#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161293 if (__a != __u.get_allocator())
1294 {
1295 iterator __i = __u.begin();
Eric Fiselier2960ae22016-02-11 11:59:441296 while (__u.size() != 0) {
1297 __table_.__emplace_unique(_VSTD::move(
1298 __u.__table_.remove((__i++).__i_)->__value_.__nc));
1299 }
Howard Hinnantbc8d3f92010-05-11 19:42:161300 }
Howard Hinnantf890d9b2013-07-30 21:04:421301#if _LIBCPP_DEBUG_LEVEL >= 2
1302 else
1303 __get_db()->swap(this, &__u);
1304#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161305}
1306
Howard Hinnant73d21a42010-09-04 23:28:191307#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161308
Howard Hinnante3e32912011-08-12 21:56:021309#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1310
Howard Hinnantbc8d3f92010-05-11 19:42:161311template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1312unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1313 initializer_list<value_type> __il)
1314{
Howard Hinnant39213642013-07-23 22:01:581315#if _LIBCPP_DEBUG_LEVEL >= 2
1316 __get_db()->__insert_c(this);
1317#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161318 insert(__il.begin(), __il.end());
1319}
1320
1321template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1322unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1323 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1324 const key_equal& __eql)
1325 : __table_(__hf, __eql)
1326{
Howard Hinnant39213642013-07-23 22:01:581327#if _LIBCPP_DEBUG_LEVEL >= 2
1328 __get_db()->__insert_c(this);
1329#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161330 __table_.rehash(__n);
1331 insert(__il.begin(), __il.end());
1332}
1333
1334template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1335unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1336 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1337 const key_equal& __eql, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401338 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161339{
Howard Hinnant39213642013-07-23 22:01:581340#if _LIBCPP_DEBUG_LEVEL >= 2
1341 __get_db()->__insert_c(this);
1342#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161343 __table_.rehash(__n);
1344 insert(__il.begin(), __il.end());
1345}
1346
Howard Hinnante3e32912011-08-12 21:56:021347#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1348
Howard Hinnant73d21a42010-09-04 23:28:191349#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161350
1351template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551352inline
Howard Hinnantbc8d3f92010-05-11 19:42:161353unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1354unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:241355 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161356{
Howard Hinnant0949eed2011-06-30 21:18:191357 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:161358 return *this;
1359}
1360
Howard Hinnant73d21a42010-09-04 23:28:191361#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161362
Howard Hinnante3e32912011-08-12 21:56:021363#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1364
Howard Hinnantbc8d3f92010-05-11 19:42:161365template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551366inline
Howard Hinnantbc8d3f92010-05-11 19:42:161367unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1368unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1369 initializer_list<value_type> __il)
1370{
1371 __table_.__assign_unique(__il.begin(), __il.end());
1372 return *this;
1373}
1374
Howard Hinnante3e32912011-08-12 21:56:021375#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1376
Eric Fiselier410ed302016-02-11 21:45:531377#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161378template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1379typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:161380unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:161381{
1382 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501383 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:291384 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:161385 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:291386 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:161387 __h.get_deleter().__second_constructed = true;
Dimitry Andric89663502015-08-19 06:43:331388 return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
Howard Hinnantbc8d3f92010-05-11 19:42:161389}
Eric Fiselier410ed302016-02-11 21:45:531390#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161391
Howard Hinnantbc8d3f92010-05-11 19:42:161392template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1393template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551394inline
Howard Hinnantbc8d3f92010-05-11 19:42:161395void
1396unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1397 _InputIterator __last)
1398{
1399 for (; __first != __last; ++__first)
1400 __table_.__insert_unique(*__first);
1401}
1402
Eric Fiselier410ed302016-02-11 21:45:531403#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161404template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1405_Tp&
1406unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1407{
1408 iterator __i = find(__k);
1409 if (__i != end())
1410 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:161411 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:161412 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1413 __h.release();
1414 return __r.first->second;
1415}
Eric Fiselier410ed302016-02-11 21:45:531416#else
Howard Hinnantbc8d3f92010-05-11 19:42:161417
Eric Fiselier410ed302016-02-11 21:45:531418template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1419_Tp&
1420unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1421{
1422 return __table_.__emplace_unique_key_args(__k,
1423 std::piecewise_construct, std::forward_as_tuple(__k),
1424 std::forward_as_tuple()).first->__cc.second;
1425}
Howard Hinnantbc8d3f92010-05-11 19:42:161426
1427template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1428_Tp&
1429unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1430{
Eric Fiselier410ed302016-02-11 21:45:531431 return __table_.__emplace_unique_key_args(__k,
1432 std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
1433 std::forward_as_tuple()).first->__cc.second;
Howard Hinnantbc8d3f92010-05-11 19:42:161434}
1435
Eric Fiselier410ed302016-02-11 21:45:531436#endif // !_LIBCPP_CXX03_MODE
Howard Hinnantbc8d3f92010-05-11 19:42:161437
1438template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1439_Tp&
1440unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1441{
1442 iterator __i = find(__k);
1443#ifndef _LIBCPP_NO_EXCEPTIONS
1444 if (__i == end())
1445 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431446#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161447 return __i->second;
1448}
1449
1450template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1451const _Tp&
1452unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1453{
1454 const_iterator __i = find(__k);
1455#ifndef _LIBCPP_NO_EXCEPTIONS
1456 if (__i == end())
1457 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:431458#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161459 return __i->second;
1460}
1461
1462template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:281463inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161464void
1465swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1466 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:241467 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161468{
1469 __x.swap(__y);
1470}
1471
1472template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1473bool
1474operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1475 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1476{
1477 if (__x.size() != __y.size())
1478 return false;
1479 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1480 const_iterator;
1481 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1482 __i != __ex; ++__i)
1483 {
1484 const_iterator __j = __y.find(__i->first);
1485 if (__j == __ey || !(*__i == *__j))
1486 return false;
1487 }
1488 return true;
1489}
1490
1491template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:281492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161493bool
1494operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1495 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1496{
1497 return !(__x == __y);
1498}
1499
1500template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1501 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant0f678bd2013-08-12 18:38:341502class _LIBCPP_TYPE_VIS_ONLY unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:161503{
1504public:
1505 // types
1506 typedef _Key key_type;
1507 typedef _Tp mapped_type;
1508 typedef _Hash hasher;
1509 typedef _Pred key_equal;
1510 typedef _Alloc allocator_type;
1511 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:291512 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161513 typedef value_type& reference;
1514 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:581515 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1516 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:161517
1518private:
Howard Hinnantff7546e2013-09-30 19:08:221519 typedef __hash_value_type<key_type, mapped_type> __value_type;
Howard Hinnant9b128e02013-07-05 18:06:001520 typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
1521 typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
Marshall Clow66302c62015-04-07 05:21:381522 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1523 __value_type>::type __allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161524
1525 typedef __hash_table<__value_type, __hasher,
1526 __key_equal, __allocator_type> __table;
1527
1528 __table __table_;
1529
Eric Fiselier2960ae22016-02-11 11:59:441530 typedef typename __table::_NodeTypes _NodeTypes;
Howard Hinnantbc8d3f92010-05-11 19:42:161531 typedef typename __table::__node_traits __node_traits;
1532 typedef typename __table::__node_allocator __node_allocator;
1533 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:501534 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1535 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:161536 typedef allocator_traits<allocator_type> __alloc_traits;
Eric Fiselier774c7c52016-02-10 20:46:231537 static_assert((is_same<typename __node_traits::size_type,
1538 typename __alloc_traits::size_type>::value),
1539 "Allocator uses different size_type for different types");
Howard Hinnantbc8d3f92010-05-11 19:42:161540public:
1541 typedef typename __alloc_traits::pointer pointer;
1542 typedef typename __alloc_traits::const_pointer const_pointer;
Eric Fiselier774c7c52016-02-10 20:46:231543 typedef typename __table::size_type size_type;
1544 typedef typename __table::difference_type difference_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161545
1546 typedef __hash_map_iterator<typename __table::iterator> iterator;
1547 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1548 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1549 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1550
Howard Hinnantee6ccd02010-09-23 18:58:281551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241552 unordered_multimap()
1553 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:581554 {
1555#if _LIBCPP_DEBUG_LEVEL >= 2
1556 __get_db()->__insert_c(this);
1557#endif
1558 }
Howard Hinnantbc8d3f92010-05-11 19:42:161559 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1560 const key_equal& __eql = key_equal());
1561 unordered_multimap(size_type __n, const hasher& __hf,
1562 const key_equal& __eql,
1563 const allocator_type& __a);
1564 template <class _InputIterator>
1565 unordered_multimap(_InputIterator __first, _InputIterator __last);
1566 template <class _InputIterator>
1567 unordered_multimap(_InputIterator __first, _InputIterator __last,
1568 size_type __n, const hasher& __hf = hasher(),
1569 const key_equal& __eql = key_equal());
1570 template <class _InputIterator>
1571 unordered_multimap(_InputIterator __first, _InputIterator __last,
1572 size_type __n, const hasher& __hf,
1573 const key_equal& __eql,
1574 const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161576 explicit unordered_multimap(const allocator_type& __a);
1577 unordered_multimap(const unordered_multimap& __u);
1578 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:191579#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:551580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241581 unordered_multimap(unordered_multimap&& __u)
1582 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161583 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:191584#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:021585#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161586 unordered_multimap(initializer_list<value_type> __il);
1587 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1588 const hasher& __hf = hasher(),
1589 const key_equal& __eql = key_equal());
1590 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1591 const hasher& __hf, const key_equal& __eql,
1592 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:021593#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Marshall Clow6dff6182013-09-12 03:00:311594#if _LIBCPP_STD_VER > 11
1595 _LIBCPP_INLINE_VISIBILITY
1596 unordered_multimap(size_type __n, const allocator_type& __a)
1597 : unordered_multimap(__n, hasher(), key_equal(), __a) {}
1598 _LIBCPP_INLINE_VISIBILITY
1599 unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
1600 : unordered_multimap(__n, __hf, key_equal(), __a) {}
1601 template <class _InputIterator>
1602 _LIBCPP_INLINE_VISIBILITY
1603 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1604 : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
1605 template <class _InputIterator>
1606 _LIBCPP_INLINE_VISIBILITY
1607 unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1608 const allocator_type& __a)
1609 : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
1610 _LIBCPP_INLINE_VISIBILITY
1611 unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1612 : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
1613 _LIBCPP_INLINE_VISIBILITY
1614 unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1615 const allocator_type& __a)
1616 : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
1617#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161618 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:361619 _LIBCPP_INLINE_VISIBILITY
1620 unordered_multimap& operator=(const unordered_multimap& __u)
1621 {
Marshall Clow3f013892016-07-18 13:19:001622#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant61aa6012011-07-01 19:24:361623 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:291624#else
Marshall Clowebfc50e2014-02-08 04:03:141625 if (this != &__u) {
1626 __table_.clear();
1627 __table_.hash_function() = __u.__table_.hash_function();
1628 __table_.key_eq() = __u.__table_.key_eq();
1629 __table_.max_load_factor() = __u.__table_.max_load_factor();
1630 __table_.__copy_assign_alloc(__u.__table_);
1631 insert(__u.begin(), __u.end());
1632 }
Howard Hinnant7a6b7ce2013-06-22 15:21:291633#endif
Howard Hinnant61aa6012011-07-01 19:24:361634 return *this;
1635 }
Howard Hinnant73d21a42010-09-04 23:28:191636#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:551637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241638 unordered_multimap& operator=(unordered_multimap&& __u)
1639 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161640#endif
Howard Hinnante3e32912011-08-12 21:56:021641#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanov9341a8a2016-04-22 01:04:551642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161643 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:021644#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161645
Howard Hinnantee6ccd02010-09-23 18:58:281646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241647 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161648 {return allocator_type(__table_.__node_alloc());}
1649
Howard Hinnantee6ccd02010-09-23 18:58:281650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241651 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:281652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241653 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:281654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241655 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:161656
Howard Hinnantee6ccd02010-09-23 18:58:281657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241658 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:281659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241660 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:281661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241662 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:281663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241664 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:281665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241666 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:281667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241668 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:161669
Eric Fiselier91a15652016-04-18 01:40:451670 _LIBCPP_INLINE_VISIBILITY
1671 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1672
1673 _LIBCPP_INLINE_VISIBILITY
1674 iterator insert(const_iterator __p, const value_type& __x)
1675 {return __table_.__insert_multi(__p.__i_, __x);}
1676
1677 template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551678 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier91a15652016-04-18 01:40:451679 void insert(_InputIterator __first, _InputIterator __last);
1680
1681#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1682 _LIBCPP_INLINE_VISIBILITY
1683 void insert(initializer_list<value_type> __il)
1684 {insert(__il.begin(), __il.end());}
1685#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1686
Eric Fiselier2960ae22016-02-11 11:59:441687#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier91a15652016-04-18 01:40:451688 _LIBCPP_INLINE_VISIBILITY
1689 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1690
1691 _LIBCPP_INLINE_VISIBILITY
1692 iterator insert(const_iterator __p, value_type&& __x)
1693 {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
1694
1695 template <class _Pp,
1696 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1697 _LIBCPP_INLINE_VISIBILITY
1698 iterator insert(_Pp&& __x)
1699 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
1700
1701 template <class _Pp,
1702 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1703 _LIBCPP_INLINE_VISIBILITY
1704 iterator insert(const_iterator __p, _Pp&& __x)
1705 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
1706
Eric Fiselier2960ae22016-02-11 11:59:441707 template <class... _Args>
1708 iterator emplace(_Args&&... __args) {
1709 return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
1710 }
Howard Hinnant73d21a42010-09-04 23:28:191711
Howard Hinnant635ce1d2012-05-25 22:04:211712 template <class... _Args>
Eric Fiselier2960ae22016-02-11 11:59:441713 iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1714 return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
1715 }
1716#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161717
Howard Hinnantbc8d3f92010-05-11 19:42:161718
Howard Hinnantee6ccd02010-09-23 18:58:281719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161720 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:281721 _LIBCPP_INLINE_VISIBILITY
Marshall Clow488025c2015-05-10 13:35:001722 iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
1723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161724 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161726 iterator erase(const_iterator __first, const_iterator __last)
1727 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:281728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241729 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161730
Howard Hinnantee6ccd02010-09-23 18:58:281731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241732 void swap(unordered_multimap& __u)
1733 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1734 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:161735
Howard Hinnantee6ccd02010-09-23 18:58:281736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161737 hasher hash_function() const
1738 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:281739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161740 key_equal key_eq() const
1741 {return __table_.key_eq().key_eq();}
1742
Howard Hinnantee6ccd02010-09-23 18:58:281743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161744 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161746 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161748 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161750 pair<iterator, iterator> equal_range(const key_type& __k)
1751 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:281752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161753 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1754 {return __table_.__equal_range_multi(__k);}
1755
Howard Hinnantee6ccd02010-09-23 18:58:281756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241757 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:281758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241759 size_type max_bucket_count() const _NOEXCEPT
1760 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:161761
Howard Hinnantee6ccd02010-09-23 18:58:281762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161763 size_type bucket_size(size_type __n) const
1764 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161766 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1767
Howard Hinnantee6ccd02010-09-23 18:58:281768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161769 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161771 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161773 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161775 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161777 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161779 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1780
Howard Hinnantee6ccd02010-09-23 18:58:281781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241782 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:241784 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161786 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:281787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161788 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161790 void reserve(size_type __n) {__table_.reserve(__n);}
1791
Howard Hinnant39213642013-07-23 22:01:581792#if _LIBCPP_DEBUG_LEVEL >= 2
1793
1794 bool __dereferenceable(const const_iterator* __i) const
1795 {return __table_.__dereferenceable(&__i->__i_);}
1796 bool __decrementable(const const_iterator* __i) const
1797 {return __table_.__decrementable(&__i->__i_);}
1798 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1799 {return __table_.__addable(&__i->__i_, __n);}
1800 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1801 {return __table_.__addable(&__i->__i_, __n);}
1802
1803#endif // _LIBCPP_DEBUG_LEVEL >= 2
1804
Eric Fiselier2960ae22016-02-11 11:59:441805
Howard Hinnantbc8d3f92010-05-11 19:42:161806};
1807
1808template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1809unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1810 size_type __n, const hasher& __hf, const key_equal& __eql)
1811 : __table_(__hf, __eql)
1812{
Howard Hinnant39213642013-07-23 22:01:581813#if _LIBCPP_DEBUG_LEVEL >= 2
1814 __get_db()->__insert_c(this);
1815#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161816 __table_.rehash(__n);
1817}
1818
1819template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1820unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1821 size_type __n, const hasher& __hf, const key_equal& __eql,
1822 const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401823 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161824{
Howard Hinnant39213642013-07-23 22:01:581825#if _LIBCPP_DEBUG_LEVEL >= 2
1826 __get_db()->__insert_c(this);
1827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161828 __table_.rehash(__n);
1829}
1830
1831template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1832template <class _InputIterator>
1833unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1834 _InputIterator __first, _InputIterator __last)
1835{
Howard Hinnant39213642013-07-23 22:01:581836#if _LIBCPP_DEBUG_LEVEL >= 2
1837 __get_db()->__insert_c(this);
1838#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161839 insert(__first, __last);
1840}
1841
1842template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1843template <class _InputIterator>
1844unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1845 _InputIterator __first, _InputIterator __last, size_type __n,
1846 const hasher& __hf, const key_equal& __eql)
1847 : __table_(__hf, __eql)
1848{
Howard Hinnant39213642013-07-23 22:01:581849#if _LIBCPP_DEBUG_LEVEL >= 2
1850 __get_db()->__insert_c(this);
1851#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161852 __table_.rehash(__n);
1853 insert(__first, __last);
1854}
1855
1856template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1857template <class _InputIterator>
1858unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1859 _InputIterator __first, _InputIterator __last, size_type __n,
1860 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401861 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161862{
Howard Hinnant39213642013-07-23 22:01:581863#if _LIBCPP_DEBUG_LEVEL >= 2
1864 __get_db()->__insert_c(this);
1865#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161866 __table_.rehash(__n);
1867 insert(__first, __last);
1868}
1869
Howard Hinnantbc8d3f92010-05-11 19:42:161870template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551871inline
Howard Hinnantbc8d3f92010-05-11 19:42:161872unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1873 const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401874 : __table_(typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161875{
Howard Hinnant39213642013-07-23 22:01:581876#if _LIBCPP_DEBUG_LEVEL >= 2
1877 __get_db()->__insert_c(this);
1878#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161879}
1880
1881template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1882unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1883 const unordered_multimap& __u)
1884 : __table_(__u.__table_)
1885{
Howard Hinnant39213642013-07-23 22:01:581886#if _LIBCPP_DEBUG_LEVEL >= 2
1887 __get_db()->__insert_c(this);
1888#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161889 __table_.rehash(__u.bucket_count());
1890 insert(__u.begin(), __u.end());
1891}
1892
1893template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1894unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1895 const unordered_multimap& __u, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401896 : __table_(__u.__table_, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161897{
Howard Hinnant39213642013-07-23 22:01:581898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 __get_db()->__insert_c(this);
1900#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161901 __table_.rehash(__u.bucket_count());
1902 insert(__u.begin(), __u.end());
1903}
1904
Howard Hinnant73d21a42010-09-04 23:28:191905#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161906
1907template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551908inline
Howard Hinnantbc8d3f92010-05-11 19:42:161909unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1910 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:241911 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:191912 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:161913{
Howard Hinnant39213642013-07-23 22:01:581914#if _LIBCPP_DEBUG_LEVEL >= 2
1915 __get_db()->__insert_c(this);
Howard Hinnantf890d9b2013-07-30 21:04:421916 __get_db()->swap(this, &__u);
Howard Hinnant39213642013-07-23 22:01:581917#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161918}
1919
1920template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1921unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1922 unordered_multimap&& __u, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401923 : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161924{
Howard Hinnant39213642013-07-23 22:01:581925#if _LIBCPP_DEBUG_LEVEL >= 2
1926 __get_db()->__insert_c(this);
1927#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161928 if (__a != __u.get_allocator())
1929 {
1930 iterator __i = __u.begin();
1931 while (__u.size() != 0)
Howard Hinnant39213642013-07-23 22:01:581932 {
Howard Hinnantbc8d3f92010-05-11 19:42:161933 __table_.__insert_multi(
Eric Fiselier2960ae22016-02-11 11:59:441934 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_.__nc)
Howard Hinnantbc8d3f92010-05-11 19:42:161935 );
Howard Hinnant39213642013-07-23 22:01:581936 }
Howard Hinnantbc8d3f92010-05-11 19:42:161937 }
Howard Hinnantf890d9b2013-07-30 21:04:421938#if _LIBCPP_DEBUG_LEVEL >= 2
1939 else
1940 __get_db()->swap(this, &__u);
1941#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161942}
1943
Howard Hinnant73d21a42010-09-04 23:28:191944#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161945
Howard Hinnante3e32912011-08-12 21:56:021946#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1947
Howard Hinnantbc8d3f92010-05-11 19:42:161948template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1949unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1950 initializer_list<value_type> __il)
1951{
Howard Hinnant39213642013-07-23 22:01:581952#if _LIBCPP_DEBUG_LEVEL >= 2
1953 __get_db()->__insert_c(this);
1954#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161955 insert(__il.begin(), __il.end());
1956}
1957
1958template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1959unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1960 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1961 const key_equal& __eql)
1962 : __table_(__hf, __eql)
1963{
Howard Hinnant39213642013-07-23 22:01:581964#if _LIBCPP_DEBUG_LEVEL >= 2
1965 __get_db()->__insert_c(this);
1966#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161967 __table_.rehash(__n);
1968 insert(__il.begin(), __il.end());
1969}
1970
1971template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1972unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1973 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1974 const key_equal& __eql, const allocator_type& __a)
Marshall Clowd4badbb2016-08-17 05:58:401975 : __table_(__hf, __eql, typename __table::allocator_type(__a))
Howard Hinnantbc8d3f92010-05-11 19:42:161976{
Howard Hinnant39213642013-07-23 22:01:581977#if _LIBCPP_DEBUG_LEVEL >= 2
1978 __get_db()->__insert_c(this);
1979#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161980 __table_.rehash(__n);
1981 insert(__il.begin(), __il.end());
1982}
1983
Howard Hinnante3e32912011-08-12 21:56:021984#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1985
Howard Hinnant73d21a42010-09-04 23:28:191986#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161987
1988template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551989inline
Howard Hinnantbc8d3f92010-05-11 19:42:161990unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1991unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:241992 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161993{
Howard Hinnant0949eed2011-06-30 21:18:191994 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:161995 return *this;
1996}
1997
Howard Hinnant73d21a42010-09-04 23:28:191998#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161999
Howard Hinnante3e32912011-08-12 21:56:022000#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2001
Howard Hinnantbc8d3f92010-05-11 19:42:162002template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552003inline
Howard Hinnantbc8d3f92010-05-11 19:42:162004unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2005unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2006 initializer_list<value_type> __il)
2007{
2008 __table_.__assign_multi(__il.begin(), __il.end());
2009 return *this;
2010}
2011
Howard Hinnante3e32912011-08-12 21:56:022012#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2013
Howard Hinnantbc8d3f92010-05-11 19:42:162014
Howard Hinnantbc8d3f92010-05-11 19:42:162015
2016template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2017template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552018inline
Howard Hinnantbc8d3f92010-05-11 19:42:162019void
2020unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2021 _InputIterator __last)
2022{
2023 for (; __first != __last; ++__first)
2024 __table_.__insert_multi(*__first);
2025}
2026
2027template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:282028inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162029void
2030swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2031 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:242032 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162033{
2034 __x.swap(__y);
2035}
2036
2037template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2038bool
2039operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2040 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2041{
2042 if (__x.size() != __y.size())
2043 return false;
2044 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2045 const_iterator;
2046 typedef pair<const_iterator, const_iterator> _EqRng;
2047 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2048 {
2049 _EqRng __xeq = __x.equal_range(__i->first);
2050 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:192051 if (_VSTD::distance(__xeq.first, __xeq.second) !=
2052 _VSTD::distance(__yeq.first, __yeq.second) ||
2053 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:162054 return false;
2055 __i = __xeq.second;
2056 }
2057 return true;
2058}
2059
2060template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:282061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162062bool
2063operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2064 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2065{
2066 return !(__x == __y);
2067}
2068
2069_LIBCPP_END_NAMESPACE_STD
2070
2071#endif // _LIBCPP_UNORDERED_MAP