blob: 0862e3fe0a353d339a6091ed77352b2ff0f43da5 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- unordered_map -----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:165//
Howard Hinnant412dbeb2010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_MAP
12#define _LIBCPP_UNORDERED_MAP
13
14/*
15
16 unordered_map synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
24 class Alloc = allocator<pair<const Key, T>>>
25class unordered_map
26{
27public:
28 // types
29 typedef Key key_type;
30 typedef T mapped_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef pair<const key_type, mapped_type> value_type;
35 typedef value_type& reference;
36 typedef const value_type& const_reference;
37 typedef typename allocator_traits<allocator_type>::pointer pointer;
38 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
39 typedef typename allocator_traits<allocator_type>::size_type size_type;
40 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
41
42 typedef /unspecified/ iterator;
43 typedef /unspecified/ const_iterator;
44 typedef /unspecified/ local_iterator;
45 typedef /unspecified/ const_local_iterator;
46
Howard Hinnant37141072011-06-04 18:54:2447 unordered_map()
48 noexcept(
49 is_nothrow_default_constructible<hasher>::value &&
50 is_nothrow_default_constructible<key_equal>::value &&
51 is_nothrow_default_constructible<allocator_type>::value);
52 explicit unordered_map(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:1653 const key_equal& eql = key_equal(),
54 const allocator_type& a = allocator_type());
55 template <class InputIterator>
56 unordered_map(InputIterator f, InputIterator l,
57 size_type n = 0, const hasher& hf = hasher(),
58 const key_equal& eql = key_equal(),
59 const allocator_type& a = allocator_type());
60 explicit unordered_map(const allocator_type&);
61 unordered_map(const unordered_map&);
62 unordered_map(const unordered_map&, const Allocator&);
Howard Hinnant37141072011-06-04 18:54:2463 unordered_map(unordered_map&&)
64 noexcept(
65 is_nothrow_move_constructible<hasher>::value &&
66 is_nothrow_move_constructible<key_equal>::value &&
67 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:1668 unordered_map(unordered_map&&, const Allocator&);
69 unordered_map(initializer_list<value_type>, size_type n = 0,
70 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
71 const allocator_type& a = allocator_type());
72 ~unordered_map();
73 unordered_map& operator=(const unordered_map&);
Howard Hinnant37141072011-06-04 18:54:2474 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 Hinnant3e519522010-05-11 19:42:1680 unordered_map& operator=(initializer_list<value_type>);
81
Howard Hinnant37141072011-06-04 18:54:2482 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1683
Howard Hinnant37141072011-06-04 18:54:2484 bool empty() const noexcept;
85 size_type size() const noexcept;
86 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:1687
Howard Hinnant37141072011-06-04 18:54:2488 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 Hinnant3e519522010-05-11 19:42:1694
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 Hinnant37141072011-06-04 18:54:24112 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16113
Howard Hinnant37141072011-06-04 18:54:24114 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 Hinnant3e519522010-05-11 19:42:16120
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 Hinnant37141072011-06-04 18:54:24136 size_type bucket_count() const noexcept;
137 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16138
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 Hinnant37141072011-06-04 18:54:24149 float load_factor() const noexcept;
150 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16151 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 Hinnant37141072011-06-04 18:54:24158 unordered_map<Key, T, Hash, Pred, Alloc>& y)
159 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16160
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 Hinnant37141072011-06-04 18:54:24195 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 Hinnant3e519522010-05-11 19:42:16201 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 Hinnant37141072011-06-04 18:54:24211 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 Hinnant3e519522010-05-11 19:42:16216 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 Hinnant37141072011-06-04 18:54:24222 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 Hinnant3e519522010-05-11 19:42:16228 unordered_multimap& operator=(initializer_list<value_type>);
229
Howard Hinnant37141072011-06-04 18:54:24230 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16231
Howard Hinnant37141072011-06-04 18:54:24232 bool empty() const noexcept;
233 size_type size() const noexcept;
234 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16235
Howard Hinnant37141072011-06-04 18:54:24236 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 Hinnant3e519522010-05-11 19:42:16242
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 Hinnant37141072011-06-04 18:54:24260 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16261
Howard Hinnant37141072011-06-04 18:54:24262 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 Hinnant3e519522010-05-11 19:42:16268
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 Hinnant37141072011-06-04 18:54:24278 size_type bucket_count() const noexcept;
279 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16280
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 Hinnant37141072011-06-04 18:54:24291 float load_factor() const noexcept;
292 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16293 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 Hinnant37141072011-06-04 18:54:24300 unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
301 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16302
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 Hinnant073458b2011-10-17 20:05:10322#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16323#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10324#endif
Howard Hinnant3e519522010-05-11 19:42:16325
326_LIBCPP_BEGIN_NAMESPACE_STD
327
328template <class _Tp, class _Hash, bool = is_empty<_Hash>::value>
329class __unordered_map_hasher
330 : private _Hash
331{
332public:
Howard Hinnant789847d2010-09-23 18:58:28333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24334 __unordered_map_hasher()
335 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
336 : _Hash() {}
Howard Hinnant789847d2010-09-23 18:58:28337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24338 __unordered_map_hasher(const _Hash& __h)
339 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
340 : _Hash(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24342 const _Hash& hash_function() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16344 size_t operator()(const _Tp& __x) const
345 {return static_cast<const _Hash&>(*this)(__x.first);}
Howard Hinnant789847d2010-09-23 18:58:28346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16347 size_t operator()(const typename _Tp::first_type& __x) const
348 {return static_cast<const _Hash&>(*this)(__x);}
349};
350
351template <class _Tp, class _Hash>
352class __unordered_map_hasher<_Tp, _Hash, false>
353{
354 _Hash __hash_;
355public:
Howard Hinnant789847d2010-09-23 18:58:28356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24357 __unordered_map_hasher()
358 _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
359 : __hash_() {}
Howard Hinnant789847d2010-09-23 18:58:28360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24361 __unordered_map_hasher(const _Hash& __h)
362 _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
363 : __hash_(__h) {}
Howard Hinnant789847d2010-09-23 18:58:28364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24365 const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
Howard Hinnant789847d2010-09-23 18:58:28366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16367 size_t operator()(const _Tp& __x) const
368 {return __hash_(__x.first);}
Howard Hinnant789847d2010-09-23 18:58:28369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16370 size_t operator()(const typename _Tp::first_type& __x) const
371 {return __hash_(__x);}
372};
373
374template <class _Tp, class _Pred, bool = is_empty<_Pred>::value>
375class __unordered_map_equal
376 : private _Pred
377{
378public:
Howard Hinnant789847d2010-09-23 18:58:28379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24380 __unordered_map_equal()
381 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
382 : _Pred() {}
Howard Hinnant789847d2010-09-23 18:58:28383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24384 __unordered_map_equal(const _Pred& __p)
385 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
386 : _Pred(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24388 const _Pred& key_eq() const _NOEXCEPT {return *this;}
Howard Hinnant789847d2010-09-23 18:58:28389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16390 bool operator()(const _Tp& __x, const _Tp& __y) const
391 {return static_cast<const _Pred&>(*this)(__x.first, __y.first);}
Howard Hinnant789847d2010-09-23 18:58:28392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16393 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
394 {return static_cast<const _Pred&>(*this)(__x, __y.first);}
Howard Hinnant789847d2010-09-23 18:58:28395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16396 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
397 {return static_cast<const _Pred&>(*this)(__x.first, __y);}
Howard Hinnant789847d2010-09-23 18:58:28398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb3371f62010-08-22 00:02:43399 bool operator()(const typename _Tp::first_type& __x,
Howard Hinnant3e519522010-05-11 19:42:16400 const typename _Tp::first_type& __y) const
401 {return static_cast<const _Pred&>(*this)(__x, __y);}
402};
403
404template <class _Tp, class _Pred>
405class __unordered_map_equal<_Tp, _Pred, false>
406{
407 _Pred __pred_;
408public:
Howard Hinnant789847d2010-09-23 18:58:28409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24410 __unordered_map_equal()
411 _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
412 : __pred_() {}
Howard Hinnant789847d2010-09-23 18:58:28413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24414 __unordered_map_equal(const _Pred& __p)
415 _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
416 : __pred_(__p) {}
Howard Hinnant789847d2010-09-23 18:58:28417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24418 const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
Howard Hinnant789847d2010-09-23 18:58:28419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16420 bool operator()(const _Tp& __x, const _Tp& __y) const
421 {return __pred_(__x.first, __y.first);}
Howard Hinnant789847d2010-09-23 18:58:28422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16423 bool operator()(const typename _Tp::first_type& __x, const _Tp& __y) const
424 {return __pred_(__x, __y.first);}
Howard Hinnant789847d2010-09-23 18:58:28425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16426 bool operator()(const _Tp& __x, const typename _Tp::first_type& __y) const
427 {return __pred_(__x.first, __y);}
Howard Hinnant789847d2010-09-23 18:58:28428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16429 bool operator()(const typename _Tp::first_type& __x,
430 const typename _Tp::first_type& __y) const
431 {return __pred_(__x, __y);}
432};
433
434template <class _Alloc>
435class __hash_map_node_destructor
436{
437 typedef _Alloc allocator_type;
438 typedef allocator_traits<allocator_type> __alloc_traits;
439 typedef typename __alloc_traits::value_type::value_type value_type;
440public:
441 typedef typename __alloc_traits::pointer pointer;
442private:
443 typedef typename value_type::first_type first_type;
444 typedef typename value_type::second_type second_type;
445
446 allocator_type& __na_;
447
448 __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
449
450public:
451 bool __first_constructed;
452 bool __second_constructed;
453
Howard Hinnant789847d2010-09-23 18:58:28454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24455 explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16456 : __na_(__na),
457 __first_constructed(false),
458 __second_constructed(false)
459 {}
460
Howard Hinnant7609c9b2010-09-04 23:28:19461#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16463 __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
Howard Hinnant37141072011-06-04 18:54:24464 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16465 : __na_(__x.__na_),
466 __first_constructed(__x.__value_constructed),
467 __second_constructed(__x.__value_constructed)
468 {
469 __x.__value_constructed = false;
470 }
Howard Hinnant7609c9b2010-09-04 23:28:19471#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16473 __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
474 : __na_(__x.__na_),
475 __first_constructed(__x.__value_constructed),
476 __second_constructed(__x.__value_constructed)
477 {
478 const_cast<bool&>(__x.__value_constructed) = false;
479 }
Howard Hinnant7609c9b2010-09-04 23:28:19480#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16481
Howard Hinnant789847d2010-09-23 18:58:28482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24483 void operator()(pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16484 {
485 if (__second_constructed)
Howard Hinnantce48a112011-06-30 21:18:19486 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:16487 if (__first_constructed)
Howard Hinnantce48a112011-06-30 21:18:19488 __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first));
Howard Hinnant3e519522010-05-11 19:42:16489 if (__p)
490 __alloc_traits::deallocate(__na_, __p, 1);
491 }
492};
493
494template <class _HashIterator>
Howard Hinnant789847d2010-09-23 18:58:28495class _LIBCPP_VISIBLE __hash_map_iterator
Howard Hinnant3e519522010-05-11 19:42:16496{
497 _HashIterator __i_;
498
499 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
500 typedef const typename _HashIterator::value_type::first_type key_type;
501 typedef typename _HashIterator::value_type::second_type mapped_type;
502public:
503 typedef forward_iterator_tag iterator_category;
504 typedef pair<key_type, mapped_type> value_type;
505 typedef typename _HashIterator::difference_type difference_type;
506 typedef value_type& reference;
507 typedef typename __pointer_traits::template
508#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
509 rebind<value_type>
510#else
511 rebind<value_type>::other
512#endif
513 pointer;
514
Howard Hinnant789847d2010-09-23 18:58:28515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24516 __hash_map_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16517
Howard Hinnant789847d2010-09-23 18:58:28518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24519 __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant3e519522010-05-11 19:42:16520
Howard Hinnant789847d2010-09-23 18:58:28521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16522 reference operator*() const {return *operator->();}
Howard Hinnant789847d2010-09-23 18:58:28523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16524 pointer operator->() const {return (pointer)__i_.operator->();}
525
Howard Hinnant789847d2010-09-23 18:58:28526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16527 __hash_map_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16529 __hash_map_iterator operator++(int)
530 {
531 __hash_map_iterator __t(*this);
532 ++(*this);
533 return __t;
534 }
535
Howard Hinnant789847d2010-09-23 18:58:28536 friend _LIBCPP_INLINE_VISIBILITY
537 bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16538 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28539 friend _LIBCPP_INLINE_VISIBILITY
540 bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16541 {return __x.__i_ != __y.__i_;}
542
Howard Hinnant789847d2010-09-23 18:58:28543 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
544 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
545 template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
546 template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
547 template <class> friend class _LIBCPP_VISIBLE __hash_map_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16548};
549
550template <class _HashIterator>
Howard Hinnant789847d2010-09-23 18:58:28551class _LIBCPP_VISIBLE __hash_map_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16552{
553 _HashIterator __i_;
554
555 typedef pointer_traits<typename _HashIterator::pointer> __pointer_traits;
556 typedef const typename _HashIterator::value_type::first_type key_type;
557 typedef typename _HashIterator::value_type::second_type mapped_type;
558public:
559 typedef forward_iterator_tag iterator_category;
560 typedef pair<key_type, mapped_type> value_type;
561 typedef typename _HashIterator::difference_type difference_type;
562 typedef const value_type& reference;
563 typedef typename __pointer_traits::template
564#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant7e6ca972011-07-23 16:14:35565 rebind<const value_type>
Howard Hinnant3e519522010-05-11 19:42:16566#else
Howard Hinnant7e6ca972011-07-23 16:14:35567 rebind<const value_type>::other
Howard Hinnant3e519522010-05-11 19:42:16568#endif
569 pointer;
570
Howard Hinnant789847d2010-09-23 18:58:28571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24572 __hash_map_const_iterator() _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:16573
Howard Hinnant789847d2010-09-23 18:58:28574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24575 __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
Howard Hinnant789847d2010-09-23 18:58:28576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16577 __hash_map_const_iterator(
578 __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
Howard Hinnant37141072011-06-04 18:54:24579 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16580 : __i_(__i.__i_) {}
581
Howard Hinnant789847d2010-09-23 18:58:28582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16583 reference operator*() const {return *operator->();}
Howard Hinnant789847d2010-09-23 18:58:28584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16585 pointer operator->() const {return (pointer)__i_.operator->();}
586
Howard Hinnant789847d2010-09-23 18:58:28587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16588 __hash_map_const_iterator& operator++() {++__i_; return *this;}
Howard Hinnant789847d2010-09-23 18:58:28589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16590 __hash_map_const_iterator operator++(int)
591 {
592 __hash_map_const_iterator __t(*this);
593 ++(*this);
594 return __t;
595 }
596
Howard Hinnant789847d2010-09-23 18:58:28597 friend _LIBCPP_INLINE_VISIBILITY
598 bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16599 {return __x.__i_ == __y.__i_;}
Howard Hinnant789847d2010-09-23 18:58:28600 friend _LIBCPP_INLINE_VISIBILITY
601 bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16602 {return __x.__i_ != __y.__i_;}
603
Howard Hinnant789847d2010-09-23 18:58:28604 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_map;
605 template <class, class, class, class, class> friend class _LIBCPP_VISIBLE unordered_multimap;
606 template <class> friend class _LIBCPP_VISIBLE __hash_const_iterator;
607 template <class> friend class _LIBCPP_VISIBLE __hash_const_local_iterator;
Howard Hinnant3e519522010-05-11 19:42:16608};
609
610template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
611 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant789847d2010-09-23 18:58:28612class _LIBCPP_VISIBLE unordered_map
Howard Hinnant3e519522010-05-11 19:42:16613{
614public:
615 // types
616 typedef _Key key_type;
617 typedef _Tp mapped_type;
618 typedef _Hash hasher;
619 typedef _Pred key_equal;
620 typedef _Alloc allocator_type;
621 typedef pair<const key_type, mapped_type> value_type;
622 typedef value_type& reference;
623 typedef const value_type& const_reference;
624
625private:
626 typedef pair<key_type, mapped_type> __value_type;
627 typedef __unordered_map_hasher<__value_type, hasher> __hasher;
628 typedef __unordered_map_equal<__value_type, key_equal> __key_equal;
629 typedef typename allocator_traits<allocator_type>::template
630#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
631 rebind_alloc<__value_type>
632#else
633 rebind_alloc<__value_type>::other
634#endif
635 __allocator_type;
636
637 typedef __hash_table<__value_type, __hasher,
638 __key_equal, __allocator_type> __table;
639
640 __table __table_;
641
642 typedef typename __table::__node_pointer __node_pointer;
643 typedef typename __table::__node_const_pointer __node_const_pointer;
644 typedef typename __table::__node_traits __node_traits;
645 typedef typename __table::__node_allocator __node_allocator;
646 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:50647 typedef __hash_map_node_destructor<__node_allocator> _Dp;
648 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:16649 typedef allocator_traits<allocator_type> __alloc_traits;
650public:
651 typedef typename __alloc_traits::pointer pointer;
652 typedef typename __alloc_traits::const_pointer const_pointer;
653 typedef typename __alloc_traits::size_type size_type;
654 typedef typename __alloc_traits::difference_type difference_type;
655
656 typedef __hash_map_iterator<typename __table::iterator> iterator;
657 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
658 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
659 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
660
Howard Hinnant789847d2010-09-23 18:58:28661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24662 unordered_map()
663 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
664 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:16665 explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
666 const key_equal& __eql = key_equal());
667 unordered_map(size_type __n, const hasher& __hf,
668 const key_equal& __eql,
669 const allocator_type& __a);
670 template <class _InputIterator>
671 unordered_map(_InputIterator __first, _InputIterator __last);
672 template <class _InputIterator>
673 unordered_map(_InputIterator __first, _InputIterator __last,
674 size_type __n, const hasher& __hf = hasher(),
675 const key_equal& __eql = key_equal());
676 template <class _InputIterator>
677 unordered_map(_InputIterator __first, _InputIterator __last,
678 size_type __n, const hasher& __hf,
679 const key_equal& __eql,
680 const allocator_type& __a);
681 explicit unordered_map(const allocator_type& __a);
682 unordered_map(const unordered_map& __u);
683 unordered_map(const unordered_map& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19684#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant37141072011-06-04 18:54:24685 unordered_map(unordered_map&& __u)
686 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16687 unordered_map(unordered_map&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19688#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02689#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16690 unordered_map(initializer_list<value_type> __il);
691 unordered_map(initializer_list<value_type> __il, size_type __n,
692 const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
693 unordered_map(initializer_list<value_type> __il, size_type __n,
694 const hasher& __hf, const key_equal& __eql,
695 const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02696#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16697 // ~unordered_map() = default;
Howard Hinnant5a336872011-07-01 19:24:36698 _LIBCPP_INLINE_VISIBILITY
699 unordered_map& operator=(const unordered_map& __u)
700 {
701 __table_ = __u.__table_;
702 return *this;
703 }
Howard Hinnant7609c9b2010-09-04 23:28:19704#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant37141072011-06-04 18:54:24705 unordered_map& operator=(unordered_map&& __u)
706 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16707#endif
Howard Hinnant54976f22011-08-12 21:56:02708#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16709 unordered_map& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02710#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16711
Howard Hinnant789847d2010-09-23 18:58:28712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24713 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16714 {return allocator_type(__table_.__node_alloc());}
715
Howard Hinnant789847d2010-09-23 18:58:28716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24717 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24719 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24721 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16722
Howard Hinnant789847d2010-09-23 18:58:28723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24724 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24726 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24728 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24730 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24732 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24734 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16735
Howard Hinnant7609c9b2010-09-04 23:28:19736#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16738 pair<iterator, bool> emplace()
739 {return __table_.__emplace_unique();}
740
741 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:00742 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:28743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16744 pair<iterator, bool> emplace(_A0&& __a0)
Howard Hinnantce48a112011-06-30 21:18:19745 {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0));}
Howard Hinnant3e519522010-05-11 19:42:16746
Howard Hinnant7609c9b2010-09-04 23:28:19747#ifndef _LIBCPP_HAS_NO_VARIADICS
748
Howard Hinnant3e519522010-05-11 19:42:16749 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:00750 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:16751 pair<iterator, bool> emplace(_A0&& __a0, _Args&&... __args);
752
Howard Hinnant7609c9b2010-09-04 23:28:19753#endif // _LIBCPP_HAS_NO_VARIADICS
754
Howard Hinnant789847d2010-09-23 18:58:28755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16756 iterator emplace_hint(const_iterator)
757 {return __table_.__emplace_unique().first;}
758
759 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:00760 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:28761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16762 iterator emplace_hint(const_iterator, _A0&& __a0)
Howard Hinnantce48a112011-06-30 21:18:19763 {return __table_.__emplace_unique(_VSTD::forward<_A0>(__a0)).first;}
Howard Hinnant3e519522010-05-11 19:42:16764
Howard Hinnant7609c9b2010-09-04 23:28:19765#ifndef _LIBCPP_HAS_NO_VARIADICS
766
Howard Hinnant3e519522010-05-11 19:42:16767 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:00768 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:28769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16770 iterator emplace_hint(const_iterator, _A0&& __a0, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19771 {return emplace(_VSTD::forward<_A0>(__a0),
772 _VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant7609c9b2010-09-04 23:28:19773#endif // _LIBCPP_HAS_NO_VARIADICS
774#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16776 pair<iterator, bool> insert(const value_type& __x)
777 {return __table_.__insert_unique(__x);}
Howard Hinnant7609c9b2010-09-04 23:28:19778#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc003db12011-11-29 18:15:50779 template <class _Pp,
780 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:28781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50782 pair<iterator, bool> insert(_Pp&& __x)
783 {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
Howard Hinnant7609c9b2010-09-04 23:28:19784#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16786 iterator insert(const_iterator, const value_type& __x)
787 {return insert(__x).first;}
Howard Hinnant7609c9b2010-09-04 23:28:19788#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc003db12011-11-29 18:15:50789 template <class _Pp,
790 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:28791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:50792 iterator insert(const_iterator, _Pp&& __x)
793 {return insert(_VSTD::forward<_Pp>(__x)).first;}
Howard Hinnant7609c9b2010-09-04 23:28:19794#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16795 template <class _InputIterator>
796 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant54976f22011-08-12 21:56:02797#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant789847d2010-09-23 18:58:28798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16799 void insert(initializer_list<value_type> __il)
800 {insert(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02801#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16802
Howard Hinnant789847d2010-09-23 18:58:28803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16804 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16806 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16808 iterator erase(const_iterator __first, const_iterator __last)
809 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:28810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24811 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16812
Howard Hinnant789847d2010-09-23 18:58:28813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24814 void swap(unordered_map& __u)
815 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
816 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16817
Howard Hinnant789847d2010-09-23 18:58:28818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16819 hasher hash_function() const
820 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16822 key_equal key_eq() const
823 {return __table_.key_eq().key_eq();}
824
Howard Hinnant789847d2010-09-23 18:58:28825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16826 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16828 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16830 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16832 pair<iterator, iterator> equal_range(const key_type& __k)
833 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16835 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
836 {return __table_.__equal_range_unique(__k);}
837
838 mapped_type& operator[](const key_type& __k);
Howard Hinnant7609c9b2010-09-04 23:28:19839#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16840 mapped_type& operator[](key_type&& __k);
841#endif
842
843 mapped_type& at(const key_type& __k);
844 const mapped_type& at(const key_type& __k) const;
845
Howard Hinnant789847d2010-09-23 18:58:28846 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24847 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24849 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16850
Howard Hinnant789847d2010-09-23 18:58:28851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16852 size_type bucket_size(size_type __n) const
853 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16855 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
856
Howard Hinnant789847d2010-09-23 18:58:28857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16858 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16860 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16862 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16864 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16866 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16868 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
869
Howard Hinnant789847d2010-09-23 18:58:28870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24871 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:24873 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28874 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16875 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16877 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16879 void reserve(size_type __n) {__table_.reserve(__n);}
880
881private:
Howard Hinnant7609c9b2010-09-04 23:28:19882#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
883#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16884 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:00885 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:16886 __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19887#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16888 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:00889 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:16890 __node_holder __construct_node(_A0&& __a0);
Howard Hinnant7609c9b2010-09-04 23:28:19891#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16892 __node_holder __construct_node(const key_type& __k);
893#endif
894};
895
896template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
897unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
898 size_type __n, const hasher& __hf, const key_equal& __eql)
899 : __table_(__hf, __eql)
900{
901 __table_.rehash(__n);
902}
903
904template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
905unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
906 size_type __n, const hasher& __hf, const key_equal& __eql,
907 const allocator_type& __a)
908 : __table_(__hf, __eql, __a)
909{
910 __table_.rehash(__n);
911}
912
913template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16915unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
916 const allocator_type& __a)
917 : __table_(__a)
918{
919}
920
921template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
922template <class _InputIterator>
923unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
924 _InputIterator __first, _InputIterator __last)
925{
926 insert(__first, __last);
927}
928
929template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
930template <class _InputIterator>
931unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
932 _InputIterator __first, _InputIterator __last, size_type __n,
933 const hasher& __hf, const key_equal& __eql)
934 : __table_(__hf, __eql)
935{
936 __table_.rehash(__n);
937 insert(__first, __last);
938}
939
940template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
941template <class _InputIterator>
942unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
943 _InputIterator __first, _InputIterator __last, size_type __n,
944 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
945 : __table_(__hf, __eql, __a)
946{
947 __table_.rehash(__n);
948 insert(__first, __last);
949}
950
951template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
952unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
953 const unordered_map& __u)
954 : __table_(__u.__table_)
955{
956 __table_.rehash(__u.bucket_count());
957 insert(__u.begin(), __u.end());
958}
959
960template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
961unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
962 const unordered_map& __u, const allocator_type& __a)
963 : __table_(__u.__table_, __a)
964{
965 __table_.rehash(__u.bucket_count());
966 insert(__u.begin(), __u.end());
967}
968
Howard Hinnant7609c9b2010-09-04 23:28:19969#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16970
971template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16973unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
974 unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:24975 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19976 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16977{
978}
979
980template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
981unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
982 unordered_map&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19983 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:16984{
985 if (__a != __u.get_allocator())
986 {
987 iterator __i = __u.begin();
988 while (__u.size() != 0)
989 __table_.__insert_unique(
Howard Hinnantce48a112011-06-30 21:18:19990 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnant3e519522010-05-11 19:42:16991 );
992 }
993}
994
Howard Hinnant7609c9b2010-09-04 23:28:19995#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16996
Howard Hinnant54976f22011-08-12 21:56:02997#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
998
Howard Hinnant3e519522010-05-11 19:42:16999template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1000unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1001 initializer_list<value_type> __il)
1002{
1003 insert(__il.begin(), __il.end());
1004}
1005
1006template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1007unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1008 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1009 const key_equal& __eql)
1010 : __table_(__hf, __eql)
1011{
1012 __table_.rehash(__n);
1013 insert(__il.begin(), __il.end());
1014}
1015
1016template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1017unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1018 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1019 const key_equal& __eql, const allocator_type& __a)
1020 : __table_(__hf, __eql, __a)
1021{
1022 __table_.rehash(__n);
1023 insert(__il.begin(), __il.end());
1024}
1025
Howard Hinnant54976f22011-08-12 21:56:021026#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1027
Howard Hinnant7609c9b2010-09-04 23:28:191028#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161029
1030template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161032unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1033unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
Howard Hinnant37141072011-06-04 18:54:241034 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:161035{
Howard Hinnantce48a112011-06-30 21:18:191036 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:161037 return *this;
1038}
1039
Howard Hinnant7609c9b2010-09-04 23:28:191040#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161041
Howard Hinnant54976f22011-08-12 21:56:021042#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1043
Howard Hinnant3e519522010-05-11 19:42:161044template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161046unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1047unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1048 initializer_list<value_type> __il)
1049{
1050 __table_.__assign_unique(__il.begin(), __il.end());
1051 return *this;
1052}
1053
Howard Hinnant54976f22011-08-12 21:56:021054#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1055
Howard Hinnant7609c9b2010-09-04 23:28:191056#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1057#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161058
1059template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1060template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001061 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161062 >
1063typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1064unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0,
1065 _Args&&... __args)
1066{
1067 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:501068 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:191069 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first),
1070 _VSTD::forward<_A0>(__a0));
Howard Hinnant3e519522010-05-11 19:42:161071 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:191072 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second),
1073 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161074 __h.get_deleter().__second_constructed = true;
1075 return __h;
1076}
1077
Howard Hinnant7609c9b2010-09-04 23:28:191078#endif // _LIBCPP_HAS_NO_VARIADICS
1079
Howard Hinnant3e519522010-05-11 19:42:161080template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1081template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:001082 class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161083 >
1084typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1085unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1086{
1087 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:501088 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:191089 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1090 _VSTD::forward<_A0>(__a0));
Howard Hinnant3e519522010-05-11 19:42:161091 __h.get_deleter().__first_constructed = true;
1092 __h.get_deleter().__second_constructed = true;
1093 return __h;
1094}
1095
Howard Hinnant7609c9b2010-09-04 23:28:191096#ifndef _LIBCPP_HAS_NO_VARIADICS
1097
Howard Hinnant3e519522010-05-11 19:42:161098template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1099template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001100 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161101 >
1102pair<typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator, bool>
1103unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
1104{
Howard Hinnantce48a112011-06-30 21:18:191105 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1106 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161107 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1108 if (__r.second)
1109 __h.release();
1110 return __r;
1111}
1112
Howard Hinnant7609c9b2010-09-04 23:28:191113#endif // _LIBCPP_HAS_NO_VARIADICS
1114#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161115
1116template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1117typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1118unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(const key_type& __k)
1119{
1120 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:501121 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:191122 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k);
Howard Hinnant3e519522010-05-11 19:42:161123 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:191124 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second));
Howard Hinnant3e519522010-05-11 19:42:161125 __h.get_deleter().__second_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:191126 return _VSTD::move(__h);
Howard Hinnant3e519522010-05-11 19:42:161127}
1128
Howard Hinnant7609c9b2010-09-04 23:28:191129#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161130
1131template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1132template <class _InputIterator>
Howard Hinnant789847d2010-09-23 18:58:281133inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161134void
1135unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1136 _InputIterator __last)
1137{
1138 for (; __first != __last; ++__first)
1139 __table_.__insert_unique(*__first);
1140}
1141
1142template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1143_Tp&
1144unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1145{
1146 iterator __i = find(__k);
1147 if (__i != end())
1148 return __i->second;
1149 __node_holder __h = __construct_node(__k);
1150 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1151 __h.release();
1152 return __r.first->second;
1153}
1154
Howard Hinnant7609c9b2010-09-04 23:28:191155#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161156
1157template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1158_Tp&
1159unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1160{
1161 iterator __i = find(__k);
1162 if (__i != end())
1163 return __i->second;
Howard Hinnantce48a112011-06-30 21:18:191164 __node_holder __h = __construct_node(_VSTD::move(__k));
Howard Hinnant3e519522010-05-11 19:42:161165 pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1166 __h.release();
1167 return __r.first->second;
1168}
1169
Howard Hinnant7609c9b2010-09-04 23:28:191170#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161171
1172template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1173_Tp&
1174unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1175{
1176 iterator __i = find(__k);
1177#ifndef _LIBCPP_NO_EXCEPTIONS
1178 if (__i == end())
1179 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:431180#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:161181 return __i->second;
1182}
1183
1184template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1185const _Tp&
1186unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1187{
1188 const_iterator __i = find(__k);
1189#ifndef _LIBCPP_NO_EXCEPTIONS
1190 if (__i == end())
1191 throw out_of_range("unordered_map::at: key not found");
Howard Hinnantb3371f62010-08-22 00:02:431192#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:161193 return __i->second;
1194}
1195
1196template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161198void
1199swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1200 unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:241201 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:161202{
1203 __x.swap(__y);
1204}
1205
1206template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1207bool
1208operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1209 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1210{
1211 if (__x.size() != __y.size())
1212 return false;
1213 typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1214 const_iterator;
1215 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1216 __i != __ex; ++__i)
1217 {
1218 const_iterator __j = __y.find(__i->first);
1219 if (__j == __ey || !(*__i == *__j))
1220 return false;
1221 }
1222 return true;
1223}
1224
1225template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281226inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161227bool
1228operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1229 const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1230{
1231 return !(__x == __y);
1232}
1233
1234template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1235 class _Alloc = allocator<pair<const _Key, _Tp> > >
Howard Hinnant789847d2010-09-23 18:58:281236class _LIBCPP_VISIBLE unordered_multimap
Howard Hinnant3e519522010-05-11 19:42:161237{
1238public:
1239 // types
1240 typedef _Key key_type;
1241 typedef _Tp mapped_type;
1242 typedef _Hash hasher;
1243 typedef _Pred key_equal;
1244 typedef _Alloc allocator_type;
1245 typedef pair<const key_type, mapped_type> value_type;
1246 typedef value_type& reference;
1247 typedef const value_type& const_reference;
1248
1249private:
1250 typedef pair<key_type, mapped_type> __value_type;
1251 typedef __unordered_map_hasher<__value_type, hasher> __hasher;
1252 typedef __unordered_map_equal<__value_type, key_equal> __key_equal;
1253 typedef typename allocator_traits<allocator_type>::template
1254#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1255 rebind_alloc<__value_type>
1256#else
1257 rebind_alloc<__value_type>::other
1258#endif
1259 __allocator_type;
1260
1261 typedef __hash_table<__value_type, __hasher,
1262 __key_equal, __allocator_type> __table;
1263
1264 __table __table_;
1265
1266 typedef typename __table::__node_traits __node_traits;
1267 typedef typename __table::__node_allocator __node_allocator;
1268 typedef typename __table::__node __node;
Howard Hinnantc003db12011-11-29 18:15:501269 typedef __hash_map_node_destructor<__node_allocator> _Dp;
1270 typedef unique_ptr<__node, _Dp> __node_holder;
Howard Hinnant3e519522010-05-11 19:42:161271 typedef allocator_traits<allocator_type> __alloc_traits;
1272public:
1273 typedef typename __alloc_traits::pointer pointer;
1274 typedef typename __alloc_traits::const_pointer const_pointer;
1275 typedef typename __alloc_traits::size_type size_type;
1276 typedef typename __alloc_traits::difference_type difference_type;
1277
1278 typedef __hash_map_iterator<typename __table::iterator> iterator;
1279 typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1280 typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1281 typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1282
Howard Hinnant789847d2010-09-23 18:58:281283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241284 unordered_multimap()
1285 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1286 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:161287 explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1288 const key_equal& __eql = key_equal());
1289 unordered_multimap(size_type __n, const hasher& __hf,
1290 const key_equal& __eql,
1291 const allocator_type& __a);
1292 template <class _InputIterator>
1293 unordered_multimap(_InputIterator __first, _InputIterator __last);
1294 template <class _InputIterator>
1295 unordered_multimap(_InputIterator __first, _InputIterator __last,
1296 size_type __n, const hasher& __hf = hasher(),
1297 const key_equal& __eql = key_equal());
1298 template <class _InputIterator>
1299 unordered_multimap(_InputIterator __first, _InputIterator __last,
1300 size_type __n, const hasher& __hf,
1301 const key_equal& __eql,
1302 const allocator_type& __a);
1303 explicit unordered_multimap(const allocator_type& __a);
1304 unordered_multimap(const unordered_multimap& __u);
1305 unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:191306#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant37141072011-06-04 18:54:241307 unordered_multimap(unordered_multimap&& __u)
1308 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:161309 unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:191310#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:021311#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161312 unordered_multimap(initializer_list<value_type> __il);
1313 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1314 const hasher& __hf = hasher(),
1315 const key_equal& __eql = key_equal());
1316 unordered_multimap(initializer_list<value_type> __il, size_type __n,
1317 const hasher& __hf, const key_equal& __eql,
1318 const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:021319#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161320 // ~unordered_multimap() = default;
Howard Hinnant5a336872011-07-01 19:24:361321 _LIBCPP_INLINE_VISIBILITY
1322 unordered_multimap& operator=(const unordered_multimap& __u)
1323 {
1324 __table_ = __u.__table_;
1325 return *this;
1326 }
Howard Hinnant7609c9b2010-09-04 23:28:191327#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant37141072011-06-04 18:54:241328 unordered_multimap& operator=(unordered_multimap&& __u)
1329 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:161330#endif
Howard Hinnant54976f22011-08-12 21:56:021331#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161332 unordered_multimap& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:021333#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161334
Howard Hinnant789847d2010-09-23 18:58:281335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241336 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161337 {return allocator_type(__table_.__node_alloc());}
1338
Howard Hinnant789847d2010-09-23 18:58:281339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241340 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:281341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241342 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:281343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241344 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:161345
Howard Hinnant789847d2010-09-23 18:58:281346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241347 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:281348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241349 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:281350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241351 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:281352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241353 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:281354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241355 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:281356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241357 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:161358
Howard Hinnant7609c9b2010-09-04 23:28:191359#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:281360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161361 iterator emplace()
1362 {return __table_.__emplace_multi();}
1363
1364 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:001365 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:281366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161367 iterator emplace(_A0&& __a0)
Howard Hinnantce48a112011-06-30 21:18:191368 {return __table_.__emplace_multi(_VSTD::forward<_A0>(__a0));}
Howard Hinnant3e519522010-05-11 19:42:161369
Howard Hinnant7609c9b2010-09-04 23:28:191370#ifndef _LIBCPP_HAS_NO_VARIADICS
1371
Howard Hinnant3e519522010-05-11 19:42:161372 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001373 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:161374 iterator emplace(_A0&& __a0, _Args&&... __args);
1375
Howard Hinnant7609c9b2010-09-04 23:28:191376#endif // _LIBCPP_HAS_NO_VARIADICS
1377
Howard Hinnant789847d2010-09-23 18:58:281378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161379 iterator emplace_hint(const_iterator __p)
1380 {return __table_.__emplace_hint_multi(__p.__i_);}
1381
1382 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:001383 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:281384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161385 iterator emplace_hint(const_iterator __p, _A0&& __a0)
Howard Hinnantce48a112011-06-30 21:18:191386 {return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));}
Howard Hinnant3e519522010-05-11 19:42:161387
Howard Hinnant7609c9b2010-09-04 23:28:191388#ifndef _LIBCPP_HAS_NO_VARIADICS
1389
Howard Hinnant3e519522010-05-11 19:42:161390 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001391 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:161392 iterator emplace_hint(const_iterator __p, _A0&& __a0, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:191393#endif // _LIBCPP_HAS_NO_VARIADICS
1394#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:281395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161396 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant7609c9b2010-09-04 23:28:191397#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc003db12011-11-29 18:15:501398 template <class _Pp,
1399 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:281400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:501401 iterator insert(_Pp&& __x)
1402 {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
Howard Hinnant7609c9b2010-09-04 23:28:191403#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:281404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161405 iterator insert(const_iterator __p, const value_type& __x)
1406 {return __table_.__insert_multi(__p.__i_, __x);}
Howard Hinnant7609c9b2010-09-04 23:28:191407#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc003db12011-11-29 18:15:501408 template <class _Pp,
1409 class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
Howard Hinnant789847d2010-09-23 18:58:281410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:501411 iterator insert(const_iterator __p, _Pp&& __x)
1412 {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
Howard Hinnant7609c9b2010-09-04 23:28:191413#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161414 template <class _InputIterator>
1415 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant54976f22011-08-12 21:56:021416#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant789847d2010-09-23 18:58:281417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161418 void insert(initializer_list<value_type> __il)
1419 {insert(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:021420#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:161421
Howard Hinnant789847d2010-09-23 18:58:281422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161423 iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
Howard Hinnant789847d2010-09-23 18:58:281424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161425 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:281426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161427 iterator erase(const_iterator __first, const_iterator __last)
1428 {return __table_.erase(__first.__i_, __last.__i_);}
Howard Hinnant789847d2010-09-23 18:58:281429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241430 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:161431
Howard Hinnant789847d2010-09-23 18:58:281432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241433 void swap(unordered_multimap& __u)
1434 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1435 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:161436
Howard Hinnant789847d2010-09-23 18:58:281437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161438 hasher hash_function() const
1439 {return __table_.hash_function().hash_function();}
Howard Hinnant789847d2010-09-23 18:58:281440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161441 key_equal key_eq() const
1442 {return __table_.key_eq().key_eq();}
1443
Howard Hinnant789847d2010-09-23 18:58:281444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161445 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:281446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161447 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:281448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161449 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:281450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161451 pair<iterator, iterator> equal_range(const key_type& __k)
1452 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:281453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161454 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1455 {return __table_.__equal_range_multi(__k);}
1456
Howard Hinnant789847d2010-09-23 18:58:281457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241458 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:281459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241460 size_type max_bucket_count() const _NOEXCEPT
1461 {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:161462
Howard Hinnant789847d2010-09-23 18:58:281463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161464 size_type bucket_size(size_type __n) const
1465 {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:281466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161467 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1468
Howard Hinnant789847d2010-09-23 18:58:281469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161470 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:281471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161472 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:281473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161474 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:281475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161476 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:281477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161478 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:281479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161480 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1481
Howard Hinnant789847d2010-09-23 18:58:281482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241483 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:281484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37141072011-06-04 18:54:241485 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:281486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161487 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:281488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161489 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:281490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161491 void reserve(size_type __n) {__table_.reserve(__n);}
1492
1493private:
Howard Hinnant7609c9b2010-09-04 23:28:191494#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:161495 template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001496 class = typename enable_if<is_constructible<key_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:161497 __node_holder __construct_node(_A0&& __a0, _Args&&... __args);
1498 template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:001499 class = typename enable_if<is_constructible<value_type, _A0>::value>::type>
Howard Hinnant3e519522010-05-11 19:42:161500 __node_holder __construct_node(_A0&& __a0);
Howard Hinnant7609c9b2010-09-04 23:28:191501#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:161502};
1503
1504template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1505unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1506 size_type __n, const hasher& __hf, const key_equal& __eql)
1507 : __table_(__hf, __eql)
1508{
1509 __table_.rehash(__n);
1510}
1511
1512template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1513unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1514 size_type __n, const hasher& __hf, const key_equal& __eql,
1515 const allocator_type& __a)
1516 : __table_(__hf, __eql, __a)
1517{
1518 __table_.rehash(__n);
1519}
1520
1521template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1522template <class _InputIterator>
1523unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1524 _InputIterator __first, _InputIterator __last)
1525{
1526 insert(__first, __last);
1527}
1528
1529template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1530template <class _InputIterator>
1531unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1532 _InputIterator __first, _InputIterator __last, size_type __n,
1533 const hasher& __hf, const key_equal& __eql)
1534 : __table_(__hf, __eql)
1535{
1536 __table_.rehash(__n);
1537 insert(__first, __last);
1538}
1539
1540template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1541template <class _InputIterator>
1542unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1543 _InputIterator __first, _InputIterator __last, size_type __n,
1544 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1545 : __table_(__hf, __eql, __a)
1546{
1547 __table_.rehash(__n);
1548 insert(__first, __last);
1549}
1550
Howard Hinnant3e519522010-05-11 19:42:161551template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161553unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1554 const allocator_type& __a)
1555 : __table_(__a)
1556{
1557}
1558
1559template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1560unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1561 const unordered_multimap& __u)
1562 : __table_(__u.__table_)
1563{
1564 __table_.rehash(__u.bucket_count());
1565 insert(__u.begin(), __u.end());
1566}
1567
1568template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1569unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1570 const unordered_multimap& __u, const allocator_type& __a)
1571 : __table_(__u.__table_, __a)
1572{
1573 __table_.rehash(__u.bucket_count());
1574 insert(__u.begin(), __u.end());
1575}
1576
Howard Hinnant7609c9b2010-09-04 23:28:191577#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161578
1579template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281580inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161581unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1582 unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:241583 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:191584 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:161585{
1586}
1587
1588template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1589unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1590 unordered_multimap&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:191591 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:161592{
1593 if (__a != __u.get_allocator())
1594 {
1595 iterator __i = __u.begin();
1596 while (__u.size() != 0)
1597{
1598 __table_.__insert_multi(
Howard Hinnantce48a112011-06-30 21:18:191599 _VSTD::move(__u.__table_.remove((__i++).__i_)->__value_)
Howard Hinnant3e519522010-05-11 19:42:161600 );
1601}
1602 }
1603}
1604
Howard Hinnant7609c9b2010-09-04 23:28:191605#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161606
Howard Hinnant54976f22011-08-12 21:56:021607#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1608
Howard Hinnant3e519522010-05-11 19:42:161609template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1610unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1611 initializer_list<value_type> __il)
1612{
1613 insert(__il.begin(), __il.end());
1614}
1615
1616template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1617unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1618 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1619 const key_equal& __eql)
1620 : __table_(__hf, __eql)
1621{
1622 __table_.rehash(__n);
1623 insert(__il.begin(), __il.end());
1624}
1625
1626template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1627unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
1628 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1629 const key_equal& __eql, const allocator_type& __a)
1630 : __table_(__hf, __eql, __a)
1631{
1632 __table_.rehash(__n);
1633 insert(__il.begin(), __il.end());
1634}
1635
Howard Hinnant54976f22011-08-12 21:56:021636#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1637
Howard Hinnant7609c9b2010-09-04 23:28:191638#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161639
1640template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161642unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1643unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
Howard Hinnant37141072011-06-04 18:54:241644 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:161645{
Howard Hinnantce48a112011-06-30 21:18:191646 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:161647 return *this;
1648}
1649
Howard Hinnant7609c9b2010-09-04 23:28:191650#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161651
Howard Hinnant54976f22011-08-12 21:56:021652#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1653
Howard Hinnant3e519522010-05-11 19:42:161654template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161656unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
1657unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1658 initializer_list<value_type> __il)
1659{
1660 __table_.__assign_multi(__il.begin(), __il.end());
1661 return *this;
1662}
1663
Howard Hinnant54976f22011-08-12 21:56:021664#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1665
Howard Hinnant7609c9b2010-09-04 23:28:191666#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1667#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161668
1669template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1670template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001671 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161672 >
1673typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1674unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(
1675 _A0&& __a0, _Args&&... __args)
1676{
1677 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:501678 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:191679 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first),
1680 _VSTD::forward<_A0>(__a0));
Howard Hinnant3e519522010-05-11 19:42:161681 __h.get_deleter().__first_constructed = true;
Howard Hinnantce48a112011-06-30 21:18:191682 __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second),
1683 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161684 __h.get_deleter().__second_constructed = true;
1685 return __h;
1686}
1687
Howard Hinnant7609c9b2010-09-04 23:28:191688#endif // _LIBCPP_HAS_NO_VARIADICS
1689
Howard Hinnant3e519522010-05-11 19:42:161690template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1691template <class _A0,
Howard Hinnanta945a322011-06-19 21:45:001692 class // = typename enable_if<is_constructible<value_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161693 >
1694typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1695unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node(_A0&& __a0)
1696{
1697 __node_allocator& __na = __table_.__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:501698 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
Howard Hinnantce48a112011-06-30 21:18:191699 __node_traits::construct(__na, _VSTD::addressof(__h->__value_),
1700 _VSTD::forward<_A0>(__a0));
Howard Hinnant3e519522010-05-11 19:42:161701 __h.get_deleter().__first_constructed = true;
1702 __h.get_deleter().__second_constructed = true;
1703 return __h;
1704}
1705
Howard Hinnant7609c9b2010-09-04 23:28:191706#ifndef _LIBCPP_HAS_NO_VARIADICS
1707
Howard Hinnant3e519522010-05-11 19:42:161708template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1709template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001710 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161711 >
1712typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
1713unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace(_A0&& __a0, _Args&&... __args)
1714{
Howard Hinnantce48a112011-06-30 21:18:191715 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1716 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161717 iterator __r = __table_.__node_insert_multi(__h.get());
1718 __h.release();
1719 return __r;
1720}
1721
1722template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1723template <class _A0, class... _Args,
Howard Hinnanta945a322011-06-19 21:45:001724 class // = typename enable_if<is_constructible<key_type, _A0>::value>::type
Howard Hinnant3e519522010-05-11 19:42:161725 >
1726typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::iterator
1727unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::emplace_hint(
1728 const_iterator __p, _A0&& __a0, _Args&&... __args)
1729{
Howard Hinnantce48a112011-06-30 21:18:191730 __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0),
1731 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161732 iterator __r = __table_.__node_insert_multi(__p.__i_, __h.get());
1733 __h.release();
1734 return __r;
1735}
1736
Howard Hinnant7609c9b2010-09-04 23:28:191737#endif // _LIBCPP_HAS_NO_VARIADICS
1738#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:161739
1740template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1741template <class _InputIterator>
Howard Hinnant789847d2010-09-23 18:58:281742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161743void
1744unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1745 _InputIterator __last)
1746{
1747 for (; __first != __last; ++__first)
1748 __table_.__insert_multi(*__first);
1749}
1750
1751template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281752inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161753void
1754swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1755 unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant37141072011-06-04 18:54:241756 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:161757{
1758 __x.swap(__y);
1759}
1760
1761template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1762bool
1763operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1764 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1765{
1766 if (__x.size() != __y.size())
1767 return false;
1768 typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1769 const_iterator;
1770 typedef pair<const_iterator, const_iterator> _EqRng;
1771 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1772 {
1773 _EqRng __xeq = __x.equal_range(__i->first);
1774 _EqRng __yeq = __y.equal_range(__i->first);
Howard Hinnantce48a112011-06-30 21:18:191775 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1776 _VSTD::distance(__yeq.first, __yeq.second) ||
1777 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:161778 return false;
1779 __i = __xeq.second;
1780 }
1781 return true;
1782}
1783
1784template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:281785inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161786bool
1787operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1788 const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1789{
1790 return !(__x == __y);
1791}
1792
1793_LIBCPP_END_NAMESPACE_STD
1794
1795#endif // _LIBCPP_UNORDERED_MAP