blob: 26ef6fd6af1380212f40dc810c48038dd41a738a [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_SET
12#define _LIBCPP_UNORDERED_SET
13
14/*
15
16 unordered_set synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
24 class Alloc = allocator<Value>>
25class unordered_set
26{
27public:
28 // types
29 typedef Value key_type;
30 typedef key_type value_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef value_type& reference;
35 typedef const value_type& const_reference;
36 typedef typename allocator_traits<allocator_type>::pointer pointer;
37 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
38 typedef typename allocator_traits<allocator_type>::size_type size_type;
39 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
40
41 typedef /unspecified/ iterator;
42 typedef /unspecified/ const_iterator;
43 typedef /unspecified/ local_iterator;
44 typedef /unspecified/ const_local_iterator;
45
Howard Hinnant04dae1d2011-06-04 20:18:37 +000046 unordered_set()
47 noexcept(
48 is_nothrow_default_constructible<hasher>::value &&
49 is_nothrow_default_constructible<key_equal>::value &&
50 is_nothrow_default_constructible<allocator_type>::value);
51 explicit unordered_set(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052 const key_equal& eql = key_equal(),
53 const allocator_type& a = allocator_type());
54 template <class InputIterator>
55 unordered_set(InputIterator f, InputIterator l,
56 size_type n = 0, const hasher& hf = hasher(),
57 const key_equal& eql = key_equal(),
58 const allocator_type& a = allocator_type());
59 explicit unordered_set(const allocator_type&);
60 unordered_set(const unordered_set&);
61 unordered_set(const unordered_set&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000062 unordered_set(unordered_set&&)
63 noexcept(
64 is_nothrow_move_constructible<hasher>::value &&
65 is_nothrow_move_constructible<key_equal>::value &&
66 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 unordered_set(unordered_set&&, const Allocator&);
68 unordered_set(initializer_list<value_type>, size_type n = 0,
69 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
70 const allocator_type& a = allocator_type());
Marshall Clowbd444af2013-09-30 21:33:51 +000071 unordered_set(size_type n, const allocator_type& a); // C++14
72 unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
73 template <class InputIterator>
74 unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
75 template <class InputIterator>
76 unordered_set(InputIterator f, InputIterator l, size_type n,
77 const hasher& hf, const allocator_type& a); // C++14
78 unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
79 unordered_set(initializer_list<value_type> il, size_type n,
80 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081 ~unordered_set();
82 unordered_set& operator=(const unordered_set&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000083 unordered_set& operator=(unordered_set&&)
84 noexcept(
85 allocator_type::propagate_on_container_move_assignment::value &&
86 is_nothrow_move_assignable<allocator_type>::value &&
87 is_nothrow_move_assignable<hasher>::value &&
88 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000089 unordered_set& operator=(initializer_list<value_type>);
90
Howard Hinnant04dae1d2011-06-04 20:18:37 +000091 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092
Howard Hinnant04dae1d2011-06-04 20:18:37 +000093 bool empty() const noexcept;
94 size_type size() const noexcept;
95 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096
Howard Hinnant04dae1d2011-06-04 20:18:37 +000097 iterator begin() noexcept;
98 iterator end() noexcept;
99 const_iterator begin() const noexcept;
100 const_iterator end() const noexcept;
101 const_iterator cbegin() const noexcept;
102 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000103
104 template <class... Args>
105 pair<iterator, bool> emplace(Args&&... args);
106 template <class... Args>
107 iterator emplace_hint(const_iterator position, Args&&... args);
108 pair<iterator, bool> insert(const value_type& obj);
109 pair<iterator, bool> insert(value_type&& obj);
110 iterator insert(const_iterator hint, const value_type& obj);
111 iterator insert(const_iterator hint, value_type&& obj);
112 template <class InputIterator>
113 void insert(InputIterator first, InputIterator last);
114 void insert(initializer_list<value_type>);
115
116 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000117 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000118 size_type erase(const key_type& k);
119 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000120 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000121
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000122 void swap(unordered_set&)
123 noexcept(
124 (!allocator_type::propagate_on_container_swap::value ||
125 __is_nothrow_swappable<allocator_type>::value) &&
126 __is_nothrow_swappable<hasher>::value &&
127 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128
129 hasher hash_function() const;
130 key_equal key_eq() const;
131
132 iterator find(const key_type& k);
133 const_iterator find(const key_type& k) const;
134 size_type count(const key_type& k) const;
135 pair<iterator, iterator> equal_range(const key_type& k);
136 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
137
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000138 size_type bucket_count() const noexcept;
139 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140
141 size_type bucket_size(size_type n) const;
142 size_type bucket(const key_type& k) const;
143
144 local_iterator begin(size_type n);
145 local_iterator end(size_type n);
146 const_local_iterator begin(size_type n) const;
147 const_local_iterator end(size_type n) const;
148 const_local_iterator cbegin(size_type n) const;
149 const_local_iterator cend(size_type n) const;
150
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000151 float load_factor() const noexcept;
152 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000153 void max_load_factor(float z);
154 void rehash(size_type n);
155 void reserve(size_type n);
156};
157
158template <class Value, class Hash, class Pred, class Alloc>
159 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000160 unordered_set<Value, Hash, Pred, Alloc>& y)
161 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162
163template <class Value, class Hash, class Pred, class Alloc>
164 bool
165 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
166 const unordered_set<Value, Hash, Pred, Alloc>& y);
167
168template <class Value, class Hash, class Pred, class Alloc>
169 bool
170 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
171 const unordered_set<Value, Hash, Pred, Alloc>& y);
172
173template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
174 class Alloc = allocator<Value>>
175class unordered_multiset
176{
177public:
178 // types
179 typedef Value key_type;
180 typedef key_type value_type;
181 typedef Hash hasher;
182 typedef Pred key_equal;
183 typedef Alloc allocator_type;
184 typedef value_type& reference;
185 typedef const value_type& const_reference;
186 typedef typename allocator_traits<allocator_type>::pointer pointer;
187 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
188 typedef typename allocator_traits<allocator_type>::size_type size_type;
189 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
190
191 typedef /unspecified/ iterator;
192 typedef /unspecified/ const_iterator;
193 typedef /unspecified/ local_iterator;
194 typedef /unspecified/ const_local_iterator;
195
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000196 unordered_multiset()
197 noexcept(
198 is_nothrow_default_constructible<hasher>::value &&
199 is_nothrow_default_constructible<key_equal>::value &&
200 is_nothrow_default_constructible<allocator_type>::value);
201 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202 const key_equal& eql = key_equal(),
203 const allocator_type& a = allocator_type());
204 template <class InputIterator>
205 unordered_multiset(InputIterator f, InputIterator l,
206 size_type n = 0, const hasher& hf = hasher(),
207 const key_equal& eql = key_equal(),
208 const allocator_type& a = allocator_type());
209 explicit unordered_multiset(const allocator_type&);
210 unordered_multiset(const unordered_multiset&);
211 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000212 unordered_multiset(unordered_multiset&&)
213 noexcept(
214 is_nothrow_move_constructible<hasher>::value &&
215 is_nothrow_move_constructible<key_equal>::value &&
216 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 unordered_multiset(unordered_multiset&&, const Allocator&);
218 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
219 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
220 const allocator_type& a = allocator_type());
Marshall Clowbd444af2013-09-30 21:33:51 +0000221 unordered_multiset(size_type n, const allocator_type& a); // C++14
222 unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
223 template <class InputIterator>
224 unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
225 template <class InputIterator>
226 unordered_multiset(InputIterator f, InputIterator l, size_type n,
227 const hasher& hf, const allocator_type& a); // C++14
228 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
229 unordered_multiset(initializer_list<value_type> il, size_type n,
230 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231 ~unordered_multiset();
232 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000233 unordered_multiset& operator=(unordered_multiset&&)
234 noexcept(
235 allocator_type::propagate_on_container_move_assignment::value &&
236 is_nothrow_move_assignable<allocator_type>::value &&
237 is_nothrow_move_assignable<hasher>::value &&
238 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 unordered_multiset& operator=(initializer_list<value_type>);
240
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000241 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000242
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000243 bool empty() const noexcept;
244 size_type size() const noexcept;
245 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000247 iterator begin() noexcept;
248 iterator end() noexcept;
249 const_iterator begin() const noexcept;
250 const_iterator end() const noexcept;
251 const_iterator cbegin() const noexcept;
252 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253
254 template <class... Args>
255 iterator emplace(Args&&... args);
256 template <class... Args>
257 iterator emplace_hint(const_iterator position, Args&&... args);
258 iterator insert(const value_type& obj);
259 iterator insert(value_type&& obj);
260 iterator insert(const_iterator hint, const value_type& obj);
261 iterator insert(const_iterator hint, value_type&& obj);
262 template <class InputIterator>
263 void insert(InputIterator first, InputIterator last);
264 void insert(initializer_list<value_type>);
265
266 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000267 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268 size_type erase(const key_type& k);
269 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000270 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000271
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000272 void swap(unordered_multiset&)
273 noexcept(
274 (!allocator_type::propagate_on_container_swap::value ||
275 __is_nothrow_swappable<allocator_type>::value) &&
276 __is_nothrow_swappable<hasher>::value &&
277 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278
279 hasher hash_function() const;
280 key_equal key_eq() const;
281
282 iterator find(const key_type& k);
283 const_iterator find(const key_type& k) const;
284 size_type count(const key_type& k) const;
285 pair<iterator, iterator> equal_range(const key_type& k);
286 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
287
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000288 size_type bucket_count() const noexcept;
289 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
291 size_type bucket_size(size_type n) const;
292 size_type bucket(const key_type& k) const;
293
294 local_iterator begin(size_type n);
295 local_iterator end(size_type n);
296 const_local_iterator begin(size_type n) const;
297 const_local_iterator end(size_type n) const;
298 const_local_iterator cbegin(size_type n) const;
299 const_local_iterator cend(size_type n) const;
300
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000301 float load_factor() const noexcept;
302 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303 void max_load_factor(float z);
304 void rehash(size_type n);
305 void reserve(size_type n);
306};
307
308template <class Value, class Hash, class Pred, class Alloc>
309 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000310 unordered_multiset<Value, Hash, Pred, Alloc>& y)
311 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template <class Value, class Hash, class Pred, class Alloc>
314 bool
315 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
316 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
317
318template <class Value, class Hash, class Pred, class Alloc>
319 bool
320 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
321 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
322} // std
323
324*/
325
326#include <__config>
327#include <__hash_table>
328#include <functional>
329
Eric Fiselierb9536102014-08-10 23:53:08 +0000330#include <__debug>
331
Howard Hinnant08e17472011-10-17 20:05:10 +0000332#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000334#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336_LIBCPP_BEGIN_NAMESPACE_STD
337
338template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
339 class _Alloc = allocator<_Value> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000340class _LIBCPP_TYPE_VIS_ONLY unordered_set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341{
342public:
343 // types
344 typedef _Value key_type;
345 typedef key_type value_type;
346 typedef _Hash hasher;
347 typedef _Pred key_equal;
348 typedef _Alloc allocator_type;
349 typedef value_type& reference;
350 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000351 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
352 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
354private:
355 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
356
357 __table __table_;
358
359public:
360 typedef typename __table::pointer pointer;
361 typedef typename __table::const_pointer const_pointer;
362 typedef typename __table::size_type size_type;
363 typedef typename __table::difference_type difference_type;
364
365 typedef typename __table::const_iterator iterator;
366 typedef typename __table::const_iterator const_iterator;
367 typedef typename __table::const_local_iterator local_iterator;
368 typedef typename __table::const_local_iterator const_local_iterator;
369
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000371 unordered_set()
372 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000373 {
374#if _LIBCPP_DEBUG_LEVEL >= 2
375 __get_db()->__insert_c(this);
376#endif
377 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
379 const key_equal& __eql = key_equal());
Marshall Clowbd444af2013-09-30 21:33:51 +0000380#if _LIBCPP_STD_VER > 11
381 inline _LIBCPP_INLINE_VISIBILITY
382 unordered_set(size_type __n, const allocator_type& __a)
383 : unordered_set(__n, hasher(), key_equal(), __a) {}
384 inline _LIBCPP_INLINE_VISIBILITY
385 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
386 : unordered_set(__n, __hf, key_equal(), __a) {}
387#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
389 const allocator_type& __a);
390 template <class _InputIterator>
391 unordered_set(_InputIterator __first, _InputIterator __last);
392 template <class _InputIterator>
393 unordered_set(_InputIterator __first, _InputIterator __last,
394 size_type __n, const hasher& __hf = hasher(),
395 const key_equal& __eql = key_equal());
396 template <class _InputIterator>
397 unordered_set(_InputIterator __first, _InputIterator __last,
398 size_type __n, const hasher& __hf, const key_equal& __eql,
399 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000400#if _LIBCPP_STD_VER > 11
401 template <class _InputIterator>
402 inline _LIBCPP_INLINE_VISIBILITY
403 unordered_set(_InputIterator __first, _InputIterator __last,
404 size_type __n, const allocator_type& __a)
405 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
406 template <class _InputIterator>
407 unordered_set(_InputIterator __first, _InputIterator __last,
408 size_type __n, const hasher& __hf, const allocator_type& __a)
409 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
410#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411 explicit unordered_set(const allocator_type& __a);
412 unordered_set(const unordered_set& __u);
413 unordered_set(const unordered_set& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000414#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000415 unordered_set(unordered_set&& __u)
416 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000418#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000419#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 unordered_set(initializer_list<value_type> __il);
421 unordered_set(initializer_list<value_type> __il, size_type __n,
422 const hasher& __hf = hasher(),
423 const key_equal& __eql = key_equal());
424 unordered_set(initializer_list<value_type> __il, size_type __n,
425 const hasher& __hf, const key_equal& __eql,
426 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000427#if _LIBCPP_STD_VER > 11
428 inline _LIBCPP_INLINE_VISIBILITY
429 unordered_set(initializer_list<value_type> __il, size_type __n,
430 const allocator_type& __a)
431 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
432 inline _LIBCPP_INLINE_VISIBILITY
433 unordered_set(initializer_list<value_type> __il, size_type __n,
434 const hasher& __hf, const allocator_type& __a)
435 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
436#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000437#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438 // ~unordered_set() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000439 _LIBCPP_INLINE_VISIBILITY
440 unordered_set& operator=(const unordered_set& __u)
441 {
442 __table_ = __u.__table_;
443 return *this;
444 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000445#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000446 unordered_set& operator=(unordered_set&& __u)
447 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000449#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 unordered_set& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000451#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000454 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 {return allocator_type(__table_.__node_alloc());}
456
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000458 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000460 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000462 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000465 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000467 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000469 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000471 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000473 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000475 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476
Howard Hinnant73d21a42010-09-04 23:28:19 +0000477#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000481 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000484#if _LIBCPP_DEBUG_LEVEL >= 2
485 iterator emplace_hint(const_iterator __p, _Args&&... __args)
486 {
487 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
488 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
489 " referring to this unordered_set");
490 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
491 }
492#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000494 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000495#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000496#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 pair<iterator, bool> insert(const value_type& __x)
499 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000500#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000503 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000504#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000506#if _LIBCPP_DEBUG_LEVEL >= 2
507 iterator insert(const_iterator __p, const value_type& __x)
508 {
509 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
510 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
511 " referring to this unordered_set");
512 return insert(__x).first;
513 }
514#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 iterator insert(const_iterator, const value_type& __x)
516 {return insert(__x).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000517#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000518#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000520#if _LIBCPP_DEBUG_LEVEL >= 2
521 iterator insert(const_iterator __p, value_type&& __x)
522 {
523 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
524 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
525 " referring to this unordered_set");
526 return insert(_VSTD::move(__x)).first;
527 }
528#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 iterator insert(const_iterator, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000530 {return insert(_VSTD::move(__x)).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000531#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000532#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 template <class _InputIterator>
534 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000535#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 void insert(initializer_list<value_type> __il)
538 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000539#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546 iterator erase(const_iterator __first, const_iterator __last)
547 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000549 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000552 void swap(unordered_set& __u)
553 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
554 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559 key_equal key_eq() const {return __table_.key_eq();}
560
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 pair<iterator, iterator> equal_range(const key_type& __k)
569 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
572 {return __table_.__equal_range_unique(__k);}
573
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000575 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000577 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
583
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
596
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000598 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000600 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +0000607
608#if _LIBCPP_DEBUG_LEVEL >= 2
609
610 bool __dereferenceable(const const_iterator* __i) const
611 {return __table_.__dereferenceable(__i);}
612 bool __decrementable(const const_iterator* __i) const
613 {return __table_.__decrementable(__i);}
614 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
615 {return __table_.__addable(__i, __n);}
616 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
617 {return __table_.__addable(__i, __n);}
618
619#endif // _LIBCPP_DEBUG_LEVEL >= 2
620
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621};
622
623template <class _Value, class _Hash, class _Pred, class _Alloc>
624unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
625 const hasher& __hf, const key_equal& __eql)
626 : __table_(__hf, __eql)
627{
Howard Hinnant39213642013-07-23 22:01:58 +0000628#if _LIBCPP_DEBUG_LEVEL >= 2
629 __get_db()->__insert_c(this);
630#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 __table_.rehash(__n);
632}
633
634template <class _Value, class _Hash, class _Pred, class _Alloc>
635unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
636 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
637 : __table_(__hf, __eql, __a)
638{
Howard Hinnant39213642013-07-23 22:01:58 +0000639#if _LIBCPP_DEBUG_LEVEL >= 2
640 __get_db()->__insert_c(this);
641#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642 __table_.rehash(__n);
643}
644
645template <class _Value, class _Hash, class _Pred, class _Alloc>
646template <class _InputIterator>
647unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
648 _InputIterator __first, _InputIterator __last)
649{
Howard Hinnant39213642013-07-23 22:01:58 +0000650#if _LIBCPP_DEBUG_LEVEL >= 2
651 __get_db()->__insert_c(this);
652#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653 insert(__first, __last);
654}
655
656template <class _Value, class _Hash, class _Pred, class _Alloc>
657template <class _InputIterator>
658unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
659 _InputIterator __first, _InputIterator __last, size_type __n,
660 const hasher& __hf, const key_equal& __eql)
661 : __table_(__hf, __eql)
662{
Howard Hinnant39213642013-07-23 22:01:58 +0000663#if _LIBCPP_DEBUG_LEVEL >= 2
664 __get_db()->__insert_c(this);
665#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 __table_.rehash(__n);
667 insert(__first, __last);
668}
669
670template <class _Value, class _Hash, class _Pred, class _Alloc>
671template <class _InputIterator>
672unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
673 _InputIterator __first, _InputIterator __last, size_type __n,
674 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
675 : __table_(__hf, __eql, __a)
676{
Howard Hinnant39213642013-07-23 22:01:58 +0000677#if _LIBCPP_DEBUG_LEVEL >= 2
678 __get_db()->__insert_c(this);
679#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680 __table_.rehash(__n);
681 insert(__first, __last);
682}
683
684template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
687 const allocator_type& __a)
688 : __table_(__a)
689{
Howard Hinnant39213642013-07-23 22:01:58 +0000690#if _LIBCPP_DEBUG_LEVEL >= 2
691 __get_db()->__insert_c(this);
692#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693}
694
695template <class _Value, class _Hash, class _Pred, class _Alloc>
696unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
697 const unordered_set& __u)
698 : __table_(__u.__table_)
699{
Howard Hinnant39213642013-07-23 22:01:58 +0000700#if _LIBCPP_DEBUG_LEVEL >= 2
701 __get_db()->__insert_c(this);
702#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 __table_.rehash(__u.bucket_count());
704 insert(__u.begin(), __u.end());
705}
706
707template <class _Value, class _Hash, class _Pred, class _Alloc>
708unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
709 const unordered_set& __u, const allocator_type& __a)
710 : __table_(__u.__table_, __a)
711{
Howard Hinnant39213642013-07-23 22:01:58 +0000712#if _LIBCPP_DEBUG_LEVEL >= 2
713 __get_db()->__insert_c(this);
714#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 __table_.rehash(__u.bucket_count());
716 insert(__u.begin(), __u.end());
717}
718
Howard Hinnant73d21a42010-09-04 23:28:19 +0000719#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720
721template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
724 unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000725 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000726 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727{
Howard Hinnant39213642013-07-23 22:01:58 +0000728#if _LIBCPP_DEBUG_LEVEL >= 2
729 __get_db()->__insert_c(this);
730 __get_db()->swap(this, &__u);
731#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732}
733
734template <class _Value, class _Hash, class _Pred, class _Alloc>
735unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
736 unordered_set&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000737 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738{
Howard Hinnant39213642013-07-23 22:01:58 +0000739#if _LIBCPP_DEBUG_LEVEL >= 2
740 __get_db()->__insert_c(this);
741#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 if (__a != __u.get_allocator())
743 {
744 iterator __i = __u.begin();
745 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000746 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 }
Howard Hinnant39213642013-07-23 22:01:58 +0000748#if _LIBCPP_DEBUG_LEVEL >= 2
749 else
750 __get_db()->swap(this, &__u);
751#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752}
753
Howard Hinnant73d21a42010-09-04 23:28:19 +0000754#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755
Howard Hinnante3e32912011-08-12 21:56:02 +0000756#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
757
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758template <class _Value, class _Hash, class _Pred, class _Alloc>
759unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
760 initializer_list<value_type> __il)
761{
Howard Hinnant39213642013-07-23 22:01:58 +0000762#if _LIBCPP_DEBUG_LEVEL >= 2
763 __get_db()->__insert_c(this);
764#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 insert(__il.begin(), __il.end());
766}
767
768template <class _Value, class _Hash, class _Pred, class _Alloc>
769unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
770 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
771 const key_equal& __eql)
772 : __table_(__hf, __eql)
773{
Howard Hinnant39213642013-07-23 22:01:58 +0000774#if _LIBCPP_DEBUG_LEVEL >= 2
775 __get_db()->__insert_c(this);
776#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 __table_.rehash(__n);
778 insert(__il.begin(), __il.end());
779}
780
781template <class _Value, class _Hash, class _Pred, class _Alloc>
782unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
783 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
784 const key_equal& __eql, const allocator_type& __a)
785 : __table_(__hf, __eql, __a)
786{
Howard Hinnant39213642013-07-23 22:01:58 +0000787#if _LIBCPP_DEBUG_LEVEL >= 2
788 __get_db()->__insert_c(this);
789#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790 __table_.rehash(__n);
791 insert(__il.begin(), __il.end());
792}
793
Howard Hinnante3e32912011-08-12 21:56:02 +0000794#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
795
Howard Hinnant73d21a42010-09-04 23:28:19 +0000796#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797
798template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800unordered_set<_Value, _Hash, _Pred, _Alloc>&
801unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000802 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000804 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805 return *this;
806}
807
Howard Hinnant73d21a42010-09-04 23:28:19 +0000808#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809
Howard Hinnante3e32912011-08-12 21:56:02 +0000810#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
811
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814unordered_set<_Value, _Hash, _Pred, _Alloc>&
815unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
816 initializer_list<value_type> __il)
817{
818 __table_.__assign_unique(__il.begin(), __il.end());
819 return *this;
820}
821
Howard Hinnante3e32912011-08-12 21:56:02 +0000822#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
823
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824template <class _Value, class _Hash, class _Pred, class _Alloc>
825template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000826inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827void
828unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
829 _InputIterator __last)
830{
831 for (; __first != __last; ++__first)
832 __table_.__insert_unique(*__first);
833}
834
835template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837void
838swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
839 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000840 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841{
842 __x.swap(__y);
843}
844
845template <class _Value, class _Hash, class _Pred, class _Alloc>
846bool
847operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
848 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
849{
850 if (__x.size() != __y.size())
851 return false;
852 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
853 const_iterator;
854 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
855 __i != __ex; ++__i)
856 {
857 const_iterator __j = __y.find(*__i);
858 if (__j == __ey || !(*__i == *__j))
859 return false;
860 }
861 return true;
862}
863
864template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866bool
867operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
868 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
869{
870 return !(__x == __y);
871}
872
873template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
874 class _Alloc = allocator<_Value> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000875class _LIBCPP_TYPE_VIS_ONLY unordered_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876{
877public:
878 // types
879 typedef _Value key_type;
880 typedef key_type value_type;
881 typedef _Hash hasher;
882 typedef _Pred key_equal;
883 typedef _Alloc allocator_type;
884 typedef value_type& reference;
885 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000886 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
887 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888
889private:
890 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
891
892 __table __table_;
893
894public:
895 typedef typename __table::pointer pointer;
896 typedef typename __table::const_pointer const_pointer;
897 typedef typename __table::size_type size_type;
898 typedef typename __table::difference_type difference_type;
899
900 typedef typename __table::const_iterator iterator;
901 typedef typename __table::const_iterator const_iterator;
902 typedef typename __table::const_local_iterator local_iterator;
903 typedef typename __table::const_local_iterator const_local_iterator;
904
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000906 unordered_multiset()
907 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000908 {
909#if _LIBCPP_DEBUG_LEVEL >= 2
910 __get_db()->__insert_c(this);
911#endif
912 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
914 const key_equal& __eql = key_equal());
915 unordered_multiset(size_type __n, const hasher& __hf,
916 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000917#if _LIBCPP_STD_VER > 11
918 inline _LIBCPP_INLINE_VISIBILITY
919 unordered_multiset(size_type __n, const allocator_type& __a)
920 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
921 inline _LIBCPP_INLINE_VISIBILITY
922 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
923 : unordered_multiset(__n, __hf, key_equal(), __a) {}
924#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 template <class _InputIterator>
926 unordered_multiset(_InputIterator __first, _InputIterator __last);
927 template <class _InputIterator>
928 unordered_multiset(_InputIterator __first, _InputIterator __last,
929 size_type __n, const hasher& __hf = hasher(),
930 const key_equal& __eql = key_equal());
931 template <class _InputIterator>
932 unordered_multiset(_InputIterator __first, _InputIterator __last,
933 size_type __n , const hasher& __hf,
934 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000935#if _LIBCPP_STD_VER > 11
936 template <class _InputIterator>
937 inline _LIBCPP_INLINE_VISIBILITY
938 unordered_multiset(_InputIterator __first, _InputIterator __last,
939 size_type __n, const allocator_type& __a)
940 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
941 template <class _InputIterator>
942 inline _LIBCPP_INLINE_VISIBILITY
943 unordered_multiset(_InputIterator __first, _InputIterator __last,
944 size_type __n, const hasher& __hf, const allocator_type& __a)
945 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
946#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 explicit unordered_multiset(const allocator_type& __a);
948 unordered_multiset(const unordered_multiset& __u);
949 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000950#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000951 unordered_multiset(unordered_multiset&& __u)
952 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000954#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000955#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 unordered_multiset(initializer_list<value_type> __il);
957 unordered_multiset(initializer_list<value_type> __il, size_type __n,
958 const hasher& __hf = hasher(),
959 const key_equal& __eql = key_equal());
960 unordered_multiset(initializer_list<value_type> __il, size_type __n,
961 const hasher& __hf, const key_equal& __eql,
962 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000963#if _LIBCPP_STD_VER > 11
964 inline _LIBCPP_INLINE_VISIBILITY
965 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
966 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
967 inline _LIBCPP_INLINE_VISIBILITY
968 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
969 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
970#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000971#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 // ~unordered_multiset() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000973 _LIBCPP_INLINE_VISIBILITY
974 unordered_multiset& operator=(const unordered_multiset& __u)
975 {
976 __table_ = __u.__table_;
977 return *this;
978 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000979#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000980 unordered_multiset& operator=(unordered_multiset&& __u)
981 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000983#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 unordered_multiset& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000985#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000988 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 {return allocator_type(__table_.__node_alloc());}
990
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000992 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000994 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000996 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000999 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001001 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001003 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001005 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001007 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001009 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010
Howard Hinnant73d21a42010-09-04 23:28:19 +00001011#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001015 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001019 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001020#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001022 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +00001025 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026#endif
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028 iterator insert(const_iterator __p, const value_type& __x)
1029 {return __table_.__insert_multi(__p, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001030#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001033 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001034#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 template <class _InputIterator>
1036 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001037#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039 void insert(initializer_list<value_type> __il)
1040 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001041#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001048 iterator erase(const_iterator __first, const_iterator __last)
1049 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001051 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001054 void swap(unordered_multiset& __u)
1055 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1056 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001059 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001061 key_equal key_eq() const {return __table_.key_eq();}
1062
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070 pair<iterator, iterator> equal_range(const key_type& __k)
1071 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1074 {return __table_.__equal_range_multi(__k);}
1075
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001077 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001079 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001084 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1085
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001095 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1098
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001100 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001102 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +00001109
1110#if _LIBCPP_DEBUG_LEVEL >= 2
1111
1112 bool __dereferenceable(const const_iterator* __i) const
1113 {return __table_.__dereferenceable(__i);}
1114 bool __decrementable(const const_iterator* __i) const
1115 {return __table_.__decrementable(__i);}
1116 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1117 {return __table_.__addable(__i, __n);}
1118 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1119 {return __table_.__addable(__i, __n);}
1120
1121#endif // _LIBCPP_DEBUG_LEVEL >= 2
1122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123};
1124
1125template <class _Value, class _Hash, class _Pred, class _Alloc>
1126unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1127 size_type __n, const hasher& __hf, const key_equal& __eql)
1128 : __table_(__hf, __eql)
1129{
Howard Hinnant39213642013-07-23 22:01:58 +00001130#if _LIBCPP_DEBUG_LEVEL >= 2
1131 __get_db()->__insert_c(this);
1132#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001133 __table_.rehash(__n);
1134}
1135
1136template <class _Value, class _Hash, class _Pred, class _Alloc>
1137unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1138 size_type __n, const hasher& __hf, const key_equal& __eql,
1139 const allocator_type& __a)
1140 : __table_(__hf, __eql, __a)
1141{
Howard Hinnant39213642013-07-23 22:01:58 +00001142#if _LIBCPP_DEBUG_LEVEL >= 2
1143 __get_db()->__insert_c(this);
1144#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145 __table_.rehash(__n);
1146}
1147
1148template <class _Value, class _Hash, class _Pred, class _Alloc>
1149template <class _InputIterator>
1150unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1151 _InputIterator __first, _InputIterator __last)
1152{
Howard Hinnant39213642013-07-23 22:01:58 +00001153#if _LIBCPP_DEBUG_LEVEL >= 2
1154 __get_db()->__insert_c(this);
1155#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156 insert(__first, __last);
1157}
1158
1159template <class _Value, class _Hash, class _Pred, class _Alloc>
1160template <class _InputIterator>
1161unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1162 _InputIterator __first, _InputIterator __last, size_type __n,
1163 const hasher& __hf, const key_equal& __eql)
1164 : __table_(__hf, __eql)
1165{
Howard Hinnant39213642013-07-23 22:01:58 +00001166#if _LIBCPP_DEBUG_LEVEL >= 2
1167 __get_db()->__insert_c(this);
1168#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 __table_.rehash(__n);
1170 insert(__first, __last);
1171}
1172
1173template <class _Value, class _Hash, class _Pred, class _Alloc>
1174template <class _InputIterator>
1175unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1176 _InputIterator __first, _InputIterator __last, size_type __n,
1177 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1178 : __table_(__hf, __eql, __a)
1179{
Howard Hinnant39213642013-07-23 22:01:58 +00001180#if _LIBCPP_DEBUG_LEVEL >= 2
1181 __get_db()->__insert_c(this);
1182#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 __table_.rehash(__n);
1184 insert(__first, __last);
1185}
1186
1187template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001188inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1190 const allocator_type& __a)
1191 : __table_(__a)
1192{
Howard Hinnant39213642013-07-23 22:01:58 +00001193#if _LIBCPP_DEBUG_LEVEL >= 2
1194 __get_db()->__insert_c(this);
1195#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196}
1197
1198template <class _Value, class _Hash, class _Pred, class _Alloc>
1199unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1200 const unordered_multiset& __u)
1201 : __table_(__u.__table_)
1202{
Howard Hinnant39213642013-07-23 22:01:58 +00001203#if _LIBCPP_DEBUG_LEVEL >= 2
1204 __get_db()->__insert_c(this);
1205#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206 __table_.rehash(__u.bucket_count());
1207 insert(__u.begin(), __u.end());
1208}
1209
1210template <class _Value, class _Hash, class _Pred, class _Alloc>
1211unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1212 const unordered_multiset& __u, const allocator_type& __a)
1213 : __table_(__u.__table_, __a)
1214{
Howard Hinnant39213642013-07-23 22:01:58 +00001215#if _LIBCPP_DEBUG_LEVEL >= 2
1216 __get_db()->__insert_c(this);
1217#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 __table_.rehash(__u.bucket_count());
1219 insert(__u.begin(), __u.end());
1220}
1221
Howard Hinnant73d21a42010-09-04 23:28:19 +00001222#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223
1224template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1227 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001228 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001229 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230{
Howard Hinnant39213642013-07-23 22:01:58 +00001231#if _LIBCPP_DEBUG_LEVEL >= 2
1232 __get_db()->__insert_c(this);
1233 __get_db()->swap(this, &__u);
1234#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235}
1236
1237template <class _Value, class _Hash, class _Pred, class _Alloc>
1238unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1239 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001240 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241{
Howard Hinnant39213642013-07-23 22:01:58 +00001242#if _LIBCPP_DEBUG_LEVEL >= 2
1243 __get_db()->__insert_c(this);
1244#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 if (__a != __u.get_allocator())
1246 {
1247 iterator __i = __u.begin();
1248 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001249 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 }
Howard Hinnant39213642013-07-23 22:01:58 +00001251#if _LIBCPP_DEBUG_LEVEL >= 2
1252 else
1253 __get_db()->swap(this, &__u);
1254#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255}
1256
Howard Hinnant73d21a42010-09-04 23:28:19 +00001257#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258
Howard Hinnante3e32912011-08-12 21:56:02 +00001259#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1260
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001261template <class _Value, class _Hash, class _Pred, class _Alloc>
1262unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1263 initializer_list<value_type> __il)
1264{
Howard Hinnant39213642013-07-23 22:01:58 +00001265#if _LIBCPP_DEBUG_LEVEL >= 2
1266 __get_db()->__insert_c(this);
1267#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 insert(__il.begin(), __il.end());
1269}
1270
1271template <class _Value, class _Hash, class _Pred, class _Alloc>
1272unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1273 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1274 const key_equal& __eql)
1275 : __table_(__hf, __eql)
1276{
Howard Hinnant39213642013-07-23 22:01:58 +00001277#if _LIBCPP_DEBUG_LEVEL >= 2
1278 __get_db()->__insert_c(this);
1279#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280 __table_.rehash(__n);
1281 insert(__il.begin(), __il.end());
1282}
1283
1284template <class _Value, class _Hash, class _Pred, class _Alloc>
1285unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1286 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1287 const key_equal& __eql, const allocator_type& __a)
1288 : __table_(__hf, __eql, __a)
1289{
Howard Hinnant39213642013-07-23 22:01:58 +00001290#if _LIBCPP_DEBUG_LEVEL >= 2
1291 __get_db()->__insert_c(this);
1292#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293 __table_.rehash(__n);
1294 insert(__il.begin(), __il.end());
1295}
1296
Howard Hinnante3e32912011-08-12 21:56:02 +00001297#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1298
Howard Hinnant73d21a42010-09-04 23:28:19 +00001299#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300
1301template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001302inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1304unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1305 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001306 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001308 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 return *this;
1310}
1311
Howard Hinnant73d21a42010-09-04 23:28:19 +00001312#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313
Howard Hinnante3e32912011-08-12 21:56:02 +00001314#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1315
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001316template <class _Value, class _Hash, class _Pred, class _Alloc>
1317inline
1318unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1319unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1320 initializer_list<value_type> __il)
1321{
1322 __table_.__assign_multi(__il.begin(), __il.end());
1323 return *this;
1324}
1325
Howard Hinnante3e32912011-08-12 21:56:02 +00001326#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1327
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328template <class _Value, class _Hash, class _Pred, class _Alloc>
1329template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331void
1332unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1333 _InputIterator __last)
1334{
1335 for (; __first != __last; ++__first)
1336 __table_.__insert_multi(*__first);
1337}
1338
1339template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341void
1342swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1343 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001344 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345{
1346 __x.swap(__y);
1347}
1348
1349template <class _Value, class _Hash, class _Pred, class _Alloc>
1350bool
1351operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1352 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1353{
1354 if (__x.size() != __y.size())
1355 return false;
1356 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1357 const_iterator;
1358 typedef pair<const_iterator, const_iterator> _EqRng;
1359 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1360 {
1361 _EqRng __xeq = __x.equal_range(*__i);
1362 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001363 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1364 _VSTD::distance(__yeq.first, __yeq.second) ||
1365 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 return false;
1367 __i = __xeq.second;
1368 }
1369 return true;
1370}
1371
1372template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374bool
1375operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1376 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1377{
1378 return !(__x == __y);
1379}
1380
1381_LIBCPP_END_NAMESPACE_STD
1382
1383#endif // _LIBCPP_UNORDERED_SET