blob: 0d2ce29207659b54dabbfffd98c9a777b0a77213 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_MAP
12#define _LIBCPP_UNORDERED_MAP
13
14/*
15
16 unordered_map synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
25class unordered_map
26{
27public:
28 // types
29 typedef Key key_type;
30 typedef T mapped_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef pair<const key_type, mapped_type> value_type;
35 typedef value_type& reference;
36 typedef const value_type& const_reference;
37 typedef typename allocator_traits<allocator_type>::pointer pointer;
38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
39 typedef typename allocator_traits<allocator_type>::size_type size_type;
40 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
41
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
46
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000047 unordered_map()
48 noexcept(
49 is_nothrow_default_constructible<hasher>::value &&
50 is_nothrow_default_constructible<key_equal>::value &&
51 is_nothrow_default_constructible<allocator_type>::value);
52 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 const key_equal& eql = key_equal(),
54 const allocator_type& a = allocator_type());
55 template <class InputIterator>
56 unordered_map(InputIterator f, InputIterator l,
57 size_type n = 0, const hasher& hf = hasher(),
58 const key_equal& eql = key_equal(),
59 const allocator_type& a = allocator_type());
60 explicit unordered_map(const allocator_type&);
61 unordered_map(const unordered_map&);
62 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000063 unordered_map(unordered_map&&)
64 noexcept(
65 is_nothrow_move_constructible<hasher>::value &&
66 is_nothrow_move_constructible<key_equal>::value &&
67 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 unordered_map(unordered_map&&, const Allocator&);
69 unordered_map(initializer_list<value_type>, size_type n = 0,
70 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
71 const allocator_type& a = allocator_type());
72 ~unordered_map();
73 unordered_map& operator=(const unordered_map&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000074 unordered_map& operator=(unordered_map&&)
75 noexcept(
76 allocator_type::propagate_on_container_move_assignment::value &&
77 is_nothrow_move_assignable<allocator_type>::value &&
78 is_nothrow_move_assignable<hasher>::value &&
79 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000080 unordered_map& operator=(initializer_list<value_type>);
81
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000082 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000084 bool empty() const noexcept;
85 size_type size() const noexcept;
86 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087
Howard Hinnant5f2f14c2011-06-04 18:54:24 +000088 iterator begin() noexcept;
89 iterator end() noexcept;
90 const_iterator begin() const noexcept;
91 const_iterator end() const noexcept;
92 const_iterator cbegin() const noexcept;
93 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094
95 template <class... Args>
96 pair<iterator, bool> emplace(Args&&... args);
97 template <class... Args>
98 iterator emplace_hint(const_iterator position, Args&&... args);
99 pair<iterator, bool> insert(const value_type& obj);
100 template <class P>
101 pair<iterator, bool> insert(P&& obj);
102 iterator insert(const_iterator hint, const value_type& obj);
103 template <class P>
104 iterator insert(const_iterator hint, P&& obj);
105 template <class InputIterator>
106 void insert(InputIterator first, InputIterator last);
107 void insert(initializer_list<value_type>);
108
109 iterator erase(const_iterator position);
110 size_type erase(const key_type& k);
111 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000112 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000113
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000114 void swap(unordered_map&)
115 noexcept(
116 (!allocator_type::propagate_on_container_swap::value ||
117 __is_nothrow_swappable<allocator_type>::value) &&
118 __is_nothrow_swappable<hasher>::value &&
119 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120
121 hasher hash_function() const;
122 key_equal key_eq() const;
123
124 iterator find(const key_type& k);
125 const_iterator find(const key_type& k) const;
126 size_type count(const key_type& k) const;
127 pair<iterator, iterator> equal_range(const key_type& k);
128 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
129
130 mapped_type& operator[](const key_type& k);
131 mapped_type& operator[](key_type&& k);
132
133 mapped_type& at(const key_type& k);
134 const mapped_type& at(const key_type& k) const;
135
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000136 size_type bucket_count() const noexcept;
137 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138
139 size_type bucket_size(size_type n) const;
140 size_type bucket(const key_type& k) const;
141
142 local_iterator begin(size_type n);
143 local_iterator end(size_type n);
144 const_local_iterator begin(size_type n) const;
145 const_local_iterator end(size_type n) const;
146 const_local_iterator cbegin(size_type n) const;
147 const_local_iterator cend(size_type n) const;
148
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000149 float load_factor() const noexcept;
150 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151 void max_load_factor(float z);
152 void rehash(size_type n);
153 void reserve(size_type n);
154};
155
156template <class Key, class T, class Hash, class Pred, class Alloc>
157 void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000158 unordered_map<Key, T, Hash, Pred, Alloc>& y)
159 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160
161template <class Key, class T, class Hash, class Pred, class Alloc>
162 bool
163 operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
164 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
165
166template <class Key, class T, class Hash, class Pred, class Alloc>
167 bool
168 operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
169 const unordered_map<Key, T, Hash, Pred, Alloc>& y);
170
171template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
172 class Alloc = allocator<pair<const Key, T>>>
173class unordered_multimap
174{
175public:
176 // types
177 typedef Key key_type;
178 typedef T mapped_type;
179 typedef Hash hasher;
180 typedef Pred key_equal;
181 typedef Alloc allocator_type;
182 typedef pair<const key_type, mapped_type> value_type;
183 typedef value_type& reference;
184 typedef const value_type& const_reference;
185 typedef typename allocator_traits<allocator_type>::pointer pointer;
186 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
187 typedef typename allocator_traits<allocator_type>::size_type size_type;
188 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
189
190 typedef /unspecified/ iterator;
191 typedef /unspecified/ const_iterator;
192 typedef /unspecified/ local_iterator;
193 typedef /unspecified/ const_local_iterator;
194
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000195 unordered_multimap()
196 noexcept(
197 is_nothrow_default_constructible<hasher>::value &&
198 is_nothrow_default_constructible<key_equal>::value &&
199 is_nothrow_default_constructible<allocator_type>::value);
200 explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 const key_equal& eql = key_equal(),
202 const allocator_type& a = allocator_type());
203 template <class InputIterator>
204 unordered_multimap(InputIterator f, InputIterator l,
205 size_type n = 0, const hasher& hf = hasher(),
206 const key_equal& eql = key_equal(),
207 const allocator_type& a = allocator_type());
208 explicit unordered_multimap(const allocator_type&);
209 unordered_multimap(const unordered_multimap&);
210 unordered_multimap(const unordered_multimap&, const Allocator&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000211 unordered_multimap(unordered_multimap&&)
212 noexcept(
213 is_nothrow_move_constructible<hasher>::value &&
214 is_nothrow_move_constructible<key_equal>::value &&
215 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000216 unordered_multimap(unordered_multimap&&, const Allocator&);
217 unordered_multimap(initializer_list<value_type>, size_type n = 0,
218 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
219 const allocator_type& a = allocator_type());
220 ~unordered_multimap();
221 unordered_multimap& operator=(const unordered_multimap&);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000222 unordered_multimap& operator=(unordered_multimap&&)
223 noexcept(
224 allocator_type::propagate_on_container_move_assignment::value &&
225 is_nothrow_move_assignable<allocator_type>::value &&
226 is_nothrow_move_assignable<hasher>::value &&
227 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 unordered_multimap& operator=(initializer_list<value_type>);
229
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000230 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000232 bool empty() const noexcept;
233 size_type size() const noexcept;
234 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000236 iterator begin() noexcept;
237 iterator end() noexcept;
238 const_iterator begin() const noexcept;
239 const_iterator end() const noexcept;
240 const_iterator cbegin() const noexcept;
241 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000242
243 template <class... Args>
244 iterator emplace(Args&&... args);
245 template <class... Args>
246 iterator emplace_hint(const_iterator position, Args&&... args);
247 iterator insert(const value_type& obj);
248 template <class P>
249 iterator insert(P&& obj);
250 iterator insert(const_iterator hint, const value_type& obj);
251 template <class P>
252 iterator insert(const_iterator hint, P&& obj);
253 template <class InputIterator>
254 void insert(InputIterator first, InputIterator last);
255 void insert(initializer_list<value_type>);
256
257 iterator erase(const_iterator position);
258 size_type erase(const key_type& k);
259 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000260 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000262 void swap(unordered_multimap&)
263 noexcept(
264 (!allocator_type::propagate_on_container_swap::value ||
265 __is_nothrow_swappable<allocator_type>::value) &&
266 __is_nothrow_swappable<hasher>::value &&
267 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
269 hasher hash_function() const;
270 key_equal key_eq() const;
271
272 iterator find(const key_type& k);
273 const_iterator find(const key_type& k) const;
274 size_type count(const key_type& k) const;
275 pair<iterator, iterator> equal_range(const key_type& k);
276 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
277
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000278 size_type bucket_count() const noexcept;
279 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280
281 size_type bucket_size(size_type n) const;
282 size_type bucket(const key_type& k) const;
283
284 local_iterator begin(size_type n);
285 local_iterator end(size_type n);
286 const_local_iterator begin(size_type n) const;
287 const_local_iterator end(size_type n) const;
288 const_local_iterator cbegin(size_type n) const;
289 const_local_iterator cend(size_type n) const;
290
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000291 float load_factor() const noexcept;
292 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 void max_load_factor(float z);
294 void rehash(size_type n);
295 void reserve(size_type n);
296};
297
298template <class Key, class T, class Hash, class Pred, class Alloc>
299 void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000300 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
301 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
303template <class Key, class T, class Hash, class Pred, class Alloc>
304 bool
305 operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
306 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
307
308template <class Key, class T, class Hash, class Pred, class Alloc>
309 bool
310 operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
311 const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
312
313} // std
314
315*/
316
317#include <__config>
318#include <__hash_table>
319#include <functional>
320#include <stdexcept>
321
Howard Hinnant08e17472011-10-17 20:05:10 +0000322#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000324#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326_LIBCPP_BEGIN_NAMESPACE_STD
327
Howard Hinnantf8880d02011-12-12 17:26:24 +0000328template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000329#if __has_feature(is_final)
330 && !__is_final(_Hash)
331#endif
332 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333class __unordered_map_hasher
334 : private _Hash
335{
Howard Hinnantf8880d02011-12-12 17:26:24 +0000336 typedef pair<const _Key, _Tp> _Cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000339 __unordered_map_hasher()
340 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
341 : _Hash() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000343 __unordered_map_hasher(const _Hash& __h)
344 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
345 : _Hash(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000347 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000349 size_t operator()(const _Cp& __x) const
350 {return static_cast<const _Hash&>(*this)(__x.first);}
351 _LIBCPP_INLINE_VISIBILITY
352 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353 {return static_cast<const _Hash&>(*this)(__x);}
354};
355
Howard Hinnantf8880d02011-12-12 17:26:24 +0000356template <class _Key, class _Tp, class _Hash>
357class __unordered_map_hasher<_Key, _Tp, _Hash, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358{
359 _Hash __hash_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000360
Howard Hinnantf8880d02011-12-12 17:26:24 +0000361 typedef pair<const _Key, _Tp> _Cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000363 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000364 __unordered_map_hasher()
365 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
366 : __hash_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000368 __unordered_map_hasher(const _Hash& __h)
369 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
370 : __hash_(__h) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000372 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000374 size_t operator()(const _Cp& __x) const
375 {return __hash_(__x.first);}
376 _LIBCPP_INLINE_VISIBILITY
377 size_t operator()(const _Key& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 {return __hash_(__x);}
379};
380
Howard Hinnantf8880d02011-12-12 17:26:24 +0000381template <class _Key, class _Tp, class _Pred, bool = is_empty<_Pred>::value
Howard Hinnantd4cf2152011-12-11 20:31:33 +0000382#if __has_feature(is_final)
383 && !__is_final(_Pred)
384#endif
385 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386class __unordered_map_equal
387 : private _Pred
388{
Howard Hinnantf8880d02011-12-12 17:26:24 +0000389 typedef pair<const _Key, _Tp> _Cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000392 __unordered_map_equal()
393 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
394 : _Pred() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000396 __unordered_map_equal(const _Pred& __p)
397 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
398 : _Pred(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000400 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000402 bool operator()(const _Cp& __x, const _Cp& __y) const
403 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
404 _LIBCPP_INLINE_VISIBILITY
405 bool operator()(const _Cp& __x, const _Key& __y) const
406 {return static_cast<const _Pred&>(*this)(__x.first, __y);}
407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000408 bool operator()(const _Key& __x, const _Cp& __y) const
409 {return static_cast<const _Pred&>(*this)(__x, __y.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410};
411
Howard Hinnantf8880d02011-12-12 17:26:24 +0000412template <class _Key, class _Tp, class _Pred>
413class __unordered_map_equal<_Key, _Tp, _Pred, false>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414{
415 _Pred __pred_;
Howard Hinnantf8880d02011-12-12 17:26:24 +0000416
Howard Hinnantf8880d02011-12-12 17:26:24 +0000417 typedef pair<const _Key, _Tp> _Cp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418public:
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000420 __unordered_map_equal()
421 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
422 : __pred_() {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000424 __unordered_map_equal(const _Pred& __p)
425 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
426 : __pred_(__p) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000428 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000430 bool operator()(const _Cp& __x, const _Cp& __y) const
431 {return __pred_(__x.first, __y.first);}
432 _LIBCPP_INLINE_VISIBILITY
433 bool operator()(const _Cp& __x, const _Key& __y) const
434 {return __pred_(__x.first, __y);}
435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8880d02011-12-12 17:26:24 +0000436 bool operator()(const _Key& __x, const _Cp& __y) const
437 {return __pred_(__x, __y.first);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438};
439
440template <class _Alloc>
441class __hash_map_node_destructor
442{
443 typedef _Alloc allocator_type;
444 typedef allocator_traits<allocator_type> __alloc_traits;
445 typedef typename __alloc_traits::value_type::value_type value_type;
446public:
447 typedef typename __alloc_traits::pointer pointer;
448private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000449 typedef typename value_type::value_type::first_type first_type;
450 typedef typename value_type::value_type::second_type second_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451
452 allocator_type& __na_;
453
454 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
455
456public:
457 bool __first_constructed;
458 bool __second_constructed;
459
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000461 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 : __na_(__na),
463 __first_constructed(false),
464 __second_constructed(false)
465 {}
466
Howard Hinnant73d21a42010-09-04 23:28:19 +0000467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000470 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 : __na_(__x.__na_),
472 __first_constructed(__x.__value_constructed),
473 __second_constructed(__x.__value_constructed)
474 {
475 __x.__value_constructed = false;
476 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000477#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
480 : __na_(__x.__na_),
481 __first_constructed(__x.__value_constructed),
482 __second_constructed(__x.__value_constructed)
483 {
484 const_cast<bool&>(__x.__value_constructed) = false;
485 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000486#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000489 void operator()(pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 {
491 if (__second_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000492 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 if (__first_constructed)
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000494 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495 if (__p)
496 __alloc_traits::deallocate(__na_, __p, 1);
497 }
498};
499
500template <class _HashIterator>
Howard Hinnant83eade62013-03-06 23:30:19 +0000501class _LIBCPP_TYPE_VIS __hash_map_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502{
503 _HashIterator __i_;
504
505 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000506 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
507 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508public:
509 typedef forward_iterator_tag iterator_category;
510 typedef pair<key_type, mapped_type> value_type;
511 typedef typename _HashIterator::difference_type difference_type;
512 typedef value_type& reference;
513 typedef typename __pointer_traits::template
514#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
515 rebind<value_type>
516#else
517 rebind<value_type>::other
518#endif
519 pointer;
520
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000522 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000525 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000528 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000530 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 __hash_map_iterator operator++(int)
536 {
537 __hash_map_iterator __t(*this);
538 ++(*this);
539 return __t;
540 }
541
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000542 friend _LIBCPP_INLINE_VISIBILITY
543 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000545 friend _LIBCPP_INLINE_VISIBILITY
546 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 {return __x.__i_ != __y.__i_;}
548
Howard Hinnant83eade62013-03-06 23:30:19 +0000549 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
550 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
551 template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
552 template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
553 template <class> friend class _LIBCPP_TYPE_VIS __hash_map_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554};
555
556template <class _HashIterator>
Howard Hinnant83eade62013-03-06 23:30:19 +0000557class _LIBCPP_TYPE_VIS __hash_map_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558{
559 _HashIterator __i_;
560
561 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000562 typedef const typename _HashIterator::value_type::value_type::first_type key_type;
563 typedef typename _HashIterator::value_type::value_type::second_type mapped_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564public:
565 typedef forward_iterator_tag iterator_category;
566 typedef pair<key_type, mapped_type> value_type;
567 typedef typename _HashIterator::difference_type difference_type;
568 typedef const value_type& reference;
569 typedef typename __pointer_traits::template
570#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant099084d2011-07-23 16:14:35 +0000571 rebind<const value_type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572#else
Howard Hinnant099084d2011-07-23 16:14:35 +0000573 rebind<const value_type>::other
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574#endif
575 pointer;
576
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000578 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000581 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583 __hash_map_const_iterator(
584 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000585 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586 : __i_(__i.__i_) {}
587
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000589 reference operator*() const {return __i_->__cc;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000591 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596 __hash_map_const_iterator operator++(int)
597 {
598 __hash_map_const_iterator __t(*this);
599 ++(*this);
600 return __t;
601 }
602
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000603 friend _LIBCPP_INLINE_VISIBILITY
604 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 {return __x.__i_ == __y.__i_;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000606 friend _LIBCPP_INLINE_VISIBILITY
607 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 {return __x.__i_ != __y.__i_;}
609
Howard Hinnant83eade62013-03-06 23:30:19 +0000610 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_map;
611 template <class, class, class, class, class> friend class _LIBCPP_TYPE_VIS unordered_multimap;
612 template <class> friend class _LIBCPP_TYPE_VIS __hash_const_iterator;
613 template <class> friend class _LIBCPP_TYPE_VIS __hash_const_local_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614};
615
616template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
617 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant83eade62013-03-06 23:30:19 +0000618class _LIBCPP_TYPE_VIS unordered_map
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619{
620public:
621 // types
622 typedef _Key key_type;
623 typedef _Tp mapped_type;
624 typedef _Hash hasher;
625 typedef _Pred key_equal;
626 typedef _Alloc allocator_type;
627 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000628 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629 typedef value_type& reference;
630 typedef const value_type& const_reference;
631
632private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000633#if __cplusplus >= 201103L
634 union __value_type
635 {
636 typedef typename unordered_map::value_type value_type;
637 typedef typename unordered_map::__nc_value_type __nc_value_type;
638 value_type __cc;
639 __nc_value_type __nc;
640
641 template <class ..._Args>
642 __value_type(_Args&& ...__args)
643 : __cc(std::forward<_Args>(__args)...) {}
644
645 __value_type(const __value_type& __v)
646 : __cc(std::move(__v.__cc)) {}
647
648 __value_type(__value_type&& __v)
649 : __nc(std::move(__v.__nc)) {}
650
651 __value_type& operator=(const __value_type& __v)
652 {__nc = __v.__cc; return *this;}
653
654 __value_type& operator=(__value_type&& __v)
655 {__nc = std::move(__v.__nc); return *this;}
656
657 ~__value_type() {__cc.~value_type();}
658
659 operator const value_type& () const {return __cc;}
660 };
661#else
662 struct __value_type
663 {
664 typedef typename unordered_map::value_type value_type;
665 value_type __cc;
666
667 __value_type() {}
668
669 template <class _A0>
670 __value_type(const _A0& __a0)
671 : __cc(__a0) {}
672
673 template <class _A0, class _A1>
674 __value_type(const _A0& __a0, const _A1& __a1)
675 : __cc(__a0, __a1) {}
676
677 operator const value_type& () const {return __cc;}
678 };
679#endif
Howard Hinnantf8880d02011-12-12 17:26:24 +0000680 typedef __unordered_map_hasher<key_type, mapped_type, hasher> __hasher;
681 typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682 typedef typename allocator_traits<allocator_type>::template
683#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
684 rebind_alloc<__value_type>
685#else
686 rebind_alloc<__value_type>::other
687#endif
688 __allocator_type;
689
690 typedef __hash_table<__value_type, __hasher,
691 __key_equal, __allocator_type> __table;
692
693 __table __table_;
694
695 typedef typename __table::__node_pointer __node_pointer;
696 typedef typename __table::__node_const_pointer __node_const_pointer;
697 typedef typename __table::__node_traits __node_traits;
698 typedef typename __table::__node_allocator __node_allocator;
699 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +0000700 typedef __hash_map_node_destructor<__node_allocator> _Dp;
701 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 typedef allocator_traits<allocator_type> __alloc_traits;
703public:
704 typedef typename __alloc_traits::pointer pointer;
705 typedef typename __alloc_traits::const_pointer const_pointer;
706 typedef typename __alloc_traits::size_type size_type;
707 typedef typename __alloc_traits::difference_type difference_type;
708
709 typedef __hash_map_iterator<typename __table::iterator> iterator;
710 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
711 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
712 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
713
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000715 unordered_map()
716 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
717 {} // = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
719 const key_equal& __eql = key_equal());
720 unordered_map(size_type __n, const hasher& __hf,
721 const key_equal& __eql,
722 const allocator_type& __a);
723 template <class _InputIterator>
724 unordered_map(_InputIterator __first, _InputIterator __last);
725 template <class _InputIterator>
726 unordered_map(_InputIterator __first, _InputIterator __last,
727 size_type __n, const hasher& __hf = hasher(),
728 const key_equal& __eql = key_equal());
729 template <class _InputIterator>
730 unordered_map(_InputIterator __first, _InputIterator __last,
731 size_type __n, const hasher& __hf,
732 const key_equal& __eql,
733 const allocator_type& __a);
734 explicit unordered_map(const allocator_type& __a);
735 unordered_map(const unordered_map& __u);
736 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000737#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000738 unordered_map(unordered_map&& __u)
739 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000741#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000742#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 unordered_map(initializer_list<value_type> __il);
744 unordered_map(initializer_list<value_type> __il, size_type __n,
745 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
746 unordered_map(initializer_list<value_type> __il, size_type __n,
747 const hasher& __hf, const key_equal& __eql,
748 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000749#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 // ~unordered_map() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000751 _LIBCPP_INLINE_VISIBILITY
752 unordered_map& operator=(const unordered_map& __u)
753 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000754#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +0000755 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +0000756#else
757 __table_.clear();
758 __table_.hash_function() = __u.__table_.hash_function();
759 __table_.key_eq() = __u.__table_.key_eq();
760 __table_.max_load_factor() = __u.__table_.max_load_factor();
761 __table_.__copy_assign_alloc(__u.__table_);
762 insert(__u.begin(), __u.end());
763#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +0000764 return *this;
765 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000766#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000767 unordered_map& operator=(unordered_map&& __u)
768 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000770#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000772#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000775 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 {return allocator_type(__table_.__node_alloc());}
777
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000779 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000781 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000783 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000786 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000788 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000790 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000792 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000794 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000796 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797
Howard Hinnant73d21a42010-09-04 23:28:19 +0000798#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +0000799#ifndef _LIBCPP_HAS_NO_VARIADICS
800
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000801 template <class... _Args>
802 pair<iterator, bool> emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000804 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000806 iterator emplace_hint(const_iterator, _Args&&... __args)
807 {return emplace(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000808#endif // _LIBCPP_HAS_NO_VARIADICS
809#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811 pair<iterator, bool> insert(const value_type& __x)
812 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000813#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000814 template <class _Pp,
815 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000817 pair<iterator, bool> insert(_Pp&& __x)
818 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000819#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 iterator insert(const_iterator, const value_type& __x)
822 {return insert(__x).first;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000823#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +0000824 template <class _Pp,
825 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +0000827 iterator insert(const_iterator, _Pp&& __x)
828 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000829#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 template <class _InputIterator>
831 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000832#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834 void insert(initializer_list<value_type> __il)
835 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000836#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000842 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843 iterator erase(const_iterator __first, const_iterator __last)
844 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000846 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000849 void swap(unordered_map& __u)
850 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
851 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 hasher hash_function() const
855 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 key_equal key_eq() const
858 {return __table_.key_eq().key_eq();}
859
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867 pair<iterator, iterator> equal_range(const key_type& __k)
868 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
871 {return __table_.__equal_range_unique(__k);}
872
873 mapped_type& operator[](const key_type& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000874#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875 mapped_type& operator[](key_type&& __k);
876#endif
877
878 mapped_type& at(const key_type& __k);
879 const mapped_type& at(const key_type& __k) const;
880
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000882 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000884 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 size_type bucket_size(size_type __n) const
888 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
891
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
904
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000906 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +0000908 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000910 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 void reserve(size_type __n) {__table_.reserve(__n);}
915
916private:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000917#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000918 __node_holder __construct_node();
919 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +0000920 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000921 __construct_node(_A0&& __a0);
Howard Hinnantb66e1c32013-07-04 20:59:16 +0000922 __node_holder __construct_node_with_key(key_type&& __k);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000923#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant635ce1d2012-05-25 22:04:21 +0000924 template <class _A0, class _A1, class ..._Args>
925 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000926#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +0000927#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
928 __node_holder __construct_node_with_key(const key_type& __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929};
930
931template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
932unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
933 size_type __n, const hasher& __hf, const key_equal& __eql)
934 : __table_(__hf, __eql)
935{
936 __table_.rehash(__n);
937}
938
939template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
940unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
941 size_type __n, const hasher& __hf, const key_equal& __eql,
942 const allocator_type& __a)
943 : __table_(__hf, __eql, __a)
944{
945 __table_.rehash(__n);
946}
947
948template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
951 const allocator_type& __a)
952 : __table_(__a)
953{
954}
955
956template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
957template <class _InputIterator>
958unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
959 _InputIterator __first, _InputIterator __last)
960{
961 insert(__first, __last);
962}
963
964template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
965template <class _InputIterator>
966unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
967 _InputIterator __first, _InputIterator __last, size_type __n,
968 const hasher& __hf, const key_equal& __eql)
969 : __table_(__hf, __eql)
970{
971 __table_.rehash(__n);
972 insert(__first, __last);
973}
974
975template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
976template <class _InputIterator>
977unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
978 _InputIterator __first, _InputIterator __last, size_type __n,
979 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
980 : __table_(__hf, __eql, __a)
981{
982 __table_.rehash(__n);
983 insert(__first, __last);
984}
985
986template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
987unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
988 const unordered_map& __u)
989 : __table_(__u.__table_)
990{
991 __table_.rehash(__u.bucket_count());
992 insert(__u.begin(), __u.end());
993}
994
995template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
996unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
997 const unordered_map& __u, const allocator_type& __a)
998 : __table_(__u.__table_, __a)
999{
1000 __table_.rehash(__u.bucket_count());
1001 insert(__u.begin(), __u.end());
1002}
1003
Howard Hinnant73d21a42010-09-04 23:28:19 +00001004#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005
1006template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1009 unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001010 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001011 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012{
1013}
1014
1015template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1016unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1017 unordered_map&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001018 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019{
1020 if (__a != __u.get_allocator())
1021 {
1022 iterator __i = __u.begin();
1023 while (__u.size() != 0)
1024 __table_.__insert_unique(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001025 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026 );
1027 }
1028}
1029
Howard Hinnant73d21a42010-09-04 23:28:19 +00001030#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031
Howard Hinnante3e32912011-08-12 21:56:02 +00001032#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1033
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001034template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1035unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1036 initializer_list<value_type> __il)
1037{
1038 insert(__il.begin(), __il.end());
1039}
1040
1041template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1042unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1043 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1044 const key_equal& __eql)
1045 : __table_(__hf, __eql)
1046{
1047 __table_.rehash(__n);
1048 insert(__il.begin(), __il.end());
1049}
1050
1051template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1052unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1053 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1054 const key_equal& __eql, const allocator_type& __a)
1055 : __table_(__hf, __eql, __a)
1056{
1057 __table_.rehash(__n);
1058 insert(__il.begin(), __il.end());
1059}
1060
Howard Hinnante3e32912011-08-12 21:56:02 +00001061#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1062
Howard Hinnant73d21a42010-09-04 23:28:19 +00001063#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064
1065template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1068unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001069 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001071 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 return *this;
1073}
1074
Howard Hinnant73d21a42010-09-04 23:28:19 +00001075#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076
Howard Hinnante3e32912011-08-12 21:56:02 +00001077#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1078
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1082unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1083 initializer_list<value_type> __il)
1084{
1085 __table_.__assign_unique(__il.begin(), __il.end());
1086 return *this;
1087}
1088
Howard Hinnante3e32912011-08-12 21:56:02 +00001089#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1090
Howard Hinnant73d21a42010-09-04 23:28:19 +00001091#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092
1093template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001095unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096{
1097 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001098 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001099 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101 __h.get_deleter().__second_constructed = true;
1102 return __h;
1103}
1104
1105template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001106template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001107typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1109{
1110 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001111 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001112 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1113 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 __h.get_deleter().__first_constructed = true;
1115 __h.get_deleter().__second_constructed = true;
1116 return __h;
1117}
1118
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001119template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001120typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1121unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(key_type&& __k)
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001122{
1123 __node_allocator& __na = __table_.__node_alloc();
1124 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001125 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::move(__k));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001126 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001127 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001128 __h.get_deleter().__second_constructed = true;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001129 return _VSTD::move(__h);
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001130}
1131
Howard Hinnant73d21a42010-09-04 23:28:19 +00001132#ifndef _LIBCPP_HAS_NO_VARIADICS
1133
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001135template <class _A0, class _A1, class ..._Args>
1136typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1137unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1138 _A1&& __a1,
1139 _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001141 __node_allocator& __na = __table_.__node_alloc();
1142 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1143 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1144 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1145 _VSTD::forward<_Args>(__args)...);
1146 __h.get_deleter().__first_constructed = true;
1147 __h.get_deleter().__second_constructed = true;
1148 return __h;
1149}
1150
1151template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1152template <class... _Args>
1153pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
1154unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1155{
1156 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1158 if (__r.second)
1159 __h.release();
1160 return __r;
1161}
1162
Howard Hinnant73d21a42010-09-04 23:28:19 +00001163#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001164#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165
1166template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1167typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001168unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169{
1170 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001171 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001172 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173 __h.get_deleter().__first_constructed = true;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001174 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175 __h.get_deleter().__second_constructed = true;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001176 return _VSTD::move(__h);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177}
1178
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1180template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182void
1183unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1184 _InputIterator __last)
1185{
1186 for (; __first != __last; ++__first)
1187 __table_.__insert_unique(*__first);
1188}
1189
1190template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1191_Tp&
1192unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1193{
1194 iterator __i = find(__k);
1195 if (__i != end())
1196 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001197 __node_holder __h = __construct_node_with_key(__k);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1199 __h.release();
1200 return __r.first->second;
1201}
1202
Howard Hinnant73d21a42010-09-04 23:28:19 +00001203#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204
1205template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1206_Tp&
1207unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1208{
1209 iterator __i = find(__k);
1210 if (__i != end())
1211 return __i->second;
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001212 __node_holder __h = __construct_node_with_key(_VSTD::move(__k));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1214 __h.release();
1215 return __r.first->second;
1216}
1217
Howard Hinnant73d21a42010-09-04 23:28:19 +00001218#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219
1220template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1221_Tp&
1222unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1223{
1224 iterator __i = find(__k);
1225#ifndef _LIBCPP_NO_EXCEPTIONS
1226 if (__i == end())
1227 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001228#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229 return __i->second;
1230}
1231
1232template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1233const _Tp&
1234unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1235{
1236 const_iterator __i = find(__k);
1237#ifndef _LIBCPP_NO_EXCEPTIONS
1238 if (__i == end())
1239 throw out_of_range("unordered_map::at: key not found");
Howard Hinnant324bb032010-08-22 00:02:43 +00001240#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241 return __i->second;
1242}
1243
1244template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001245inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246void
1247swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1248 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001249 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250{
1251 __x.swap(__y);
1252}
1253
1254template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1255bool
1256operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1257 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1258{
1259 if (__x.size() != __y.size())
1260 return false;
1261 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1262 const_iterator;
1263 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1264 __i != __ex; ++__i)
1265 {
1266 const_iterator __j = __y.find(__i->first);
1267 if (__j == __ey || !(*__i == *__j))
1268 return false;
1269 }
1270 return true;
1271}
1272
1273template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001274inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275bool
1276operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1277 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1278{
1279 return !(__x == __y);
1280}
1281
1282template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1283 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant83eade62013-03-06 23:30:19 +00001284class _LIBCPP_TYPE_VIS unordered_multimap
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285{
1286public:
1287 // types
1288 typedef _Key key_type;
1289 typedef _Tp mapped_type;
1290 typedef _Hash hasher;
1291 typedef _Pred key_equal;
1292 typedef _Alloc allocator_type;
1293 typedef pair<const key_type, mapped_type> value_type;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001294 typedef pair<key_type, mapped_type> __nc_value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295 typedef value_type& reference;
1296 typedef const value_type& const_reference;
1297
1298private:
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001299#if __cplusplus >= 201103L
1300 union __value_type
1301 {
1302 typedef typename unordered_multimap::value_type value_type;
1303 typedef typename unordered_multimap::__nc_value_type __nc_value_type;
1304 value_type __cc;
1305 __nc_value_type __nc;
1306
1307 template <class ..._Args>
1308 __value_type(_Args&& ...__args)
1309 : __cc(std::forward<_Args>(__args)...) {}
1310
1311 __value_type(const __value_type& __v)
1312 : __cc(std::move(__v.__cc)) {}
1313
1314 __value_type(__value_type&& __v)
1315 : __nc(std::move(__v.__nc)) {}
1316
1317 __value_type& operator=(const __value_type& __v)
1318 {__nc = __v.__cc; return *this;}
1319
1320 __value_type& operator=(__value_type&& __v)
1321 {__nc = std::move(__v.__nc); return *this;}
1322
1323 ~__value_type() {__cc.~value_type();}
1324
1325 operator const value_type& () const {return __cc;}
1326 };
1327#else
1328 struct __value_type
1329 {
1330 typedef typename unordered_multimap::value_type value_type;
1331 value_type __cc;
1332
1333 __value_type() {}
1334
1335 template <class _A0>
1336 __value_type(const _A0& __a0)
1337 : __cc(__a0) {}
1338
1339 template <class _A0, class _A1>
1340 __value_type(const _A0& __a0, const _A1& __a1)
1341 : __cc(__a0, __a1) {}
1342
1343 operator const value_type& () const {return __cc;}
1344 };
1345#endif
Howard Hinnantf8880d02011-12-12 17:26:24 +00001346 typedef __unordered_map_hasher<key_type, mapped_type, hasher> __hasher;
1347 typedef __unordered_map_equal<key_type, mapped_type, key_equal> __key_equal;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001348 typedef typename allocator_traits<allocator_type>::template
1349#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1350 rebind_alloc<__value_type>
1351#else
1352 rebind_alloc<__value_type>::other
1353#endif
1354 __allocator_type;
1355
1356 typedef __hash_table<__value_type, __hasher,
1357 __key_equal, __allocator_type> __table;
1358
1359 __table __table_;
1360
1361 typedef typename __table::__node_traits __node_traits;
1362 typedef typename __table::__node_allocator __node_allocator;
1363 typedef typename __table::__node __node;
Howard Hinnant99968442011-11-29 18:15:50 +00001364 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1365 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 typedef allocator_traits<allocator_type> __alloc_traits;
1367public:
1368 typedef typename __alloc_traits::pointer pointer;
1369 typedef typename __alloc_traits::const_pointer const_pointer;
1370 typedef typename __alloc_traits::size_type size_type;
1371 typedef typename __alloc_traits::difference_type difference_type;
1372
1373 typedef __hash_map_iterator<typename __table::iterator> iterator;
1374 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1375 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1376 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1377
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001379 unordered_multimap()
1380 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1381 {} // = default;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1383 const key_equal& __eql = key_equal());
1384 unordered_multimap(size_type __n, const hasher& __hf,
1385 const key_equal& __eql,
1386 const allocator_type& __a);
1387 template <class _InputIterator>
1388 unordered_multimap(_InputIterator __first, _InputIterator __last);
1389 template <class _InputIterator>
1390 unordered_multimap(_InputIterator __first, _InputIterator __last,
1391 size_type __n, const hasher& __hf = hasher(),
1392 const key_equal& __eql = key_equal());
1393 template <class _InputIterator>
1394 unordered_multimap(_InputIterator __first, _InputIterator __last,
1395 size_type __n, const hasher& __hf,
1396 const key_equal& __eql,
1397 const allocator_type& __a);
1398 explicit unordered_multimap(const allocator_type& __a);
1399 unordered_multimap(const unordered_multimap& __u);
1400 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001401#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001402 unordered_multimap(unordered_multimap&& __u)
1403 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001405#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +00001406#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407 unordered_multimap(initializer_list<value_type> __il);
1408 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1409 const hasher& __hf = hasher(),
1410 const key_equal& __eql = key_equal());
1411 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1412 const hasher& __hf, const key_equal& __eql,
1413 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001414#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415 // ~unordered_multimap() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +00001416 _LIBCPP_INLINE_VISIBILITY
1417 unordered_multimap& operator=(const unordered_multimap& __u)
1418 {
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001419#if __cplusplus >= 201103L
Howard Hinnant61aa6012011-07-01 19:24:36 +00001420 __table_ = __u.__table_;
Howard Hinnant7a6b7ce2013-06-22 15:21:29 +00001421#else
1422 __table_.clear();
1423 __table_.hash_function() = __u.__table_.hash_function();
1424 __table_.key_eq() = __u.__table_.key_eq();
1425 __table_.max_load_factor() = __u.__table_.max_load_factor();
1426 __table_.__copy_assign_alloc(__u.__table_);
1427 insert(__u.begin(), __u.end());
1428#endif
Howard Hinnant61aa6012011-07-01 19:24:36 +00001429 return *this;
1430 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001431#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001432 unordered_multimap& operator=(unordered_multimap&& __u)
1433 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00001435#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +00001437#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001440 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441 {return allocator_type(__table_.__node_alloc());}
1442
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001444 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001446 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001448 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001451 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001453 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001455 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001457 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001459 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001461 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462
Howard Hinnant73d21a42010-09-04 23:28:19 +00001463#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant73d21a42010-09-04 23:28:19 +00001464#ifndef _LIBCPP_HAS_NO_VARIADICS
1465
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001466 template <class... _Args>
1467 iterator emplace(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001469 template <class... _Args>
1470 iterator emplace_hint(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001471#endif // _LIBCPP_HAS_NO_VARIADICS
1472#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001475#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001476 template <class _Pp,
1477 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001479 iterator insert(_Pp&& __x)
1480 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001481#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 iterator insert(const_iterator __p, const value_type& __x)
1484 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001485#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant99968442011-11-29 18:15:50 +00001486 template <class _Pp,
1487 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001489 iterator insert(const_iterator __p, _Pp&& __x)
1490 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001491#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492 template <class _InputIterator>
1493 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001494#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496 void insert(initializer_list<value_type> __il)
1497 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001498#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 iterator erase(const_iterator __first, const_iterator __last)
1506 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001508 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001511 void swap(unordered_multimap& __u)
1512 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1513 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516 hasher hash_function() const
1517 {return __table_.hash_function().hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 key_equal key_eq() const
1520 {return __table_.key_eq().key_eq();}
1521
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 pair<iterator, iterator> equal_range(const key_type& __k)
1530 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1533 {return __table_.__equal_range_multi(__k);}
1534
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001536 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001538 size_type max_bucket_count() const _NOEXCEPT
1539 {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 size_type bucket_size(size_type __n) const
1543 {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1546
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001556 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1559
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001561 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001563 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569 void reserve(size_type __n) {__table_.reserve(__n);}
1570
1571private:
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001572#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1573 __node_holder __construct_node();
1574 template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001575 __node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001576 __construct_node(_A0&& __a0);
1577#ifndef _LIBCPP_HAS_NO_VARIADICS
1578 template <class _A0, class _A1, class ..._Args>
1579 __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args);
1580#endif // _LIBCPP_HAS_NO_VARIADICS
1581#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582};
1583
1584template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1585unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1586 size_type __n, const hasher& __hf, const key_equal& __eql)
1587 : __table_(__hf, __eql)
1588{
1589 __table_.rehash(__n);
1590}
1591
1592template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1593unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1594 size_type __n, const hasher& __hf, const key_equal& __eql,
1595 const allocator_type& __a)
1596 : __table_(__hf, __eql, __a)
1597{
1598 __table_.rehash(__n);
1599}
1600
1601template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1602template <class _InputIterator>
1603unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1604 _InputIterator __first, _InputIterator __last)
1605{
1606 insert(__first, __last);
1607}
1608
1609template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1610template <class _InputIterator>
1611unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1612 _InputIterator __first, _InputIterator __last, size_type __n,
1613 const hasher& __hf, const key_equal& __eql)
1614 : __table_(__hf, __eql)
1615{
1616 __table_.rehash(__n);
1617 insert(__first, __last);
1618}
1619
1620template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1621template <class _InputIterator>
1622unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1623 _InputIterator __first, _InputIterator __last, size_type __n,
1624 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1625 : __table_(__hf, __eql, __a)
1626{
1627 __table_.rehash(__n);
1628 insert(__first, __last);
1629}
1630
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1634 const allocator_type& __a)
1635 : __table_(__a)
1636{
1637}
1638
1639template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1640unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1641 const unordered_multimap& __u)
1642 : __table_(__u.__table_)
1643{
1644 __table_.rehash(__u.bucket_count());
1645 insert(__u.begin(), __u.end());
1646}
1647
1648template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1649unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1650 const unordered_multimap& __u, const allocator_type& __a)
1651 : __table_(__u.__table_, __a)
1652{
1653 __table_.rehash(__u.bucket_count());
1654 insert(__u.begin(), __u.end());
1655}
1656
Howard Hinnant73d21a42010-09-04 23:28:19 +00001657#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658
1659template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1662 unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001663 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001664 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665{
1666}
1667
1668template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1669unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1670 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001671 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672{
1673 if (__a != __u.get_allocator())
1674 {
1675 iterator __i = __u.begin();
1676 while (__u.size() != 0)
1677{
1678 __table_.__insert_multi(
Howard Hinnant0949eed2011-06-30 21:18:19 +00001679 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680 );
1681}
1682 }
1683}
1684
Howard Hinnant73d21a42010-09-04 23:28:19 +00001685#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686
Howard Hinnante3e32912011-08-12 21:56:02 +00001687#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1688
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1690unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1691 initializer_list<value_type> __il)
1692{
1693 insert(__il.begin(), __il.end());
1694}
1695
1696template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1697unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1698 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1699 const key_equal& __eql)
1700 : __table_(__hf, __eql)
1701{
1702 __table_.rehash(__n);
1703 insert(__il.begin(), __il.end());
1704}
1705
1706template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1707unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1708 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1709 const key_equal& __eql, const allocator_type& __a)
1710 : __table_(__hf, __eql, __a)
1711{
1712 __table_.rehash(__n);
1713 insert(__il.begin(), __il.end());
1714}
1715
Howard Hinnante3e32912011-08-12 21:56:02 +00001716#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1717
Howard Hinnant73d21a42010-09-04 23:28:19 +00001718#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719
1720template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1723unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001724 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001726 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727 return *this;
1728}
1729
Howard Hinnant73d21a42010-09-04 23:28:19 +00001730#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731
Howard Hinnante3e32912011-08-12 21:56:02 +00001732#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1737unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1738 initializer_list<value_type> __il)
1739{
1740 __table_.__assign_multi(__il.begin(), __il.end());
1741 return *this;
1742}
1743
Howard Hinnante3e32912011-08-12 21:56:02 +00001744#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1745
Howard Hinnant73d21a42010-09-04 23:28:19 +00001746#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747
1748template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001749typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001750unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751{
1752 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001753 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001754 __node_traits::construct(__na, _VSTD::addressof(__h->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 __h.get_deleter().__first_constructed = true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 __h.get_deleter().__second_constructed = true;
1757 return __h;
1758}
1759
1760template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001761template <class _A0>
Howard Hinnantb66e1c32013-07-04 20:59:16 +00001762typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1764{
1765 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001766 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001767 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1768 _VSTD::forward<_A0>(__a0));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 __h.get_deleter().__first_constructed = true;
1770 __h.get_deleter().__second_constructed = true;
1771 return __h;
1772}
1773
Howard Hinnant73d21a42010-09-04 23:28:19 +00001774#ifndef _LIBCPP_HAS_NO_VARIADICS
1775
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001776template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001777template <class _A0, class _A1, class ..._Args>
1778typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1779unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
1780 _A0&& __a0, _A1&& __a1, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001782 __node_allocator& __na = __table_.__node_alloc();
1783 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1784 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1785 _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1),
1786 _VSTD::forward<_Args>(__args)...);
1787 __h.get_deleter().__first_constructed = true;
1788 __h.get_deleter().__second_constructed = true;
1789 return __h;
1790}
1791
1792template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1793template <class... _Args>
1794typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
1795unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_Args&&... __args)
1796{
1797 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001798 iterator __r = __table_.__node_insert_multi(__h.get());
1799 __h.release();
1800 return __r;
1801}
1802
1803template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001804template <class... _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
1806unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001807 const_iterator __p, _Args&&... __args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808{
Howard Hinnant635ce1d2012-05-25 22:04:21 +00001809 __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
1811 __h.release();
1812 return __r;
1813}
1814
Howard Hinnant73d21a42010-09-04 23:28:19 +00001815#endif // _LIBCPP_HAS_NO_VARIADICS
1816#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001817
1818template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1819template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821void
1822unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1823 _InputIterator __last)
1824{
1825 for (; __first != __last; ++__first)
1826 __table_.__insert_multi(*__first);
1827}
1828
1829template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001830inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831void
1832swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1833 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant5f2f14c2011-06-04 18:54:24 +00001834 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835{
1836 __x.swap(__y);
1837}
1838
1839template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1840bool
1841operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1842 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1843{
1844 if (__x.size() != __y.size())
1845 return false;
1846 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1847 const_iterator;
1848 typedef pair<const_iterator, const_iterator> _EqRng;
1849 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1850 {
1851 _EqRng __xeq = __x.equal_range(__i->first);
1852 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001853 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1854 _VSTD::distance(__yeq.first, __yeq.second) ||
1855 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856 return false;
1857 __i = __xeq.second;
1858 }
1859 return true;
1860}
1861
1862template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864bool
1865operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1866 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1867{
1868 return !(__x == __y);
1869}
1870
1871_LIBCPP_END_NAMESPACE_STD
1872
1873#endif // _LIBCPP_UNORDERED_MAP