blob: fc53c82711091f0a879956ec5f8b914a9f301a71 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-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 Hinnant3e519522010-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 Hinnant557da862011-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 Hinnant3e519522010-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 Hinnant557da862011-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 Hinnant3e519522010-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 Clow45b983c2013-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 Hinnant3e519522010-05-11 19:42:16 +000081 ~unordered_set();
82 unordered_set& operator=(const unordered_set&);
Howard Hinnant557da862011-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 Hinnant3e519522010-05-11 19:42:16 +000089 unordered_set& operator=(initializer_list<value_type>);
90
Howard Hinnant557da862011-06-04 20:18:37 +000091 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000092
Howard Hinnant557da862011-06-04 20:18:37 +000093 bool empty() const noexcept;
94 size_type size() const noexcept;
95 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000096
Howard Hinnant557da862011-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 Hinnant3e519522010-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 Clowec392962015-05-10 13:35:00 +0000117 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000118 size_type erase(const key_type& k);
119 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant557da862011-06-04 20:18:37 +0000120 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000121
Howard Hinnant557da862011-06-04 20:18:37 +0000122 void swap(unordered_set&)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000123 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
124 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
125 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnant3e519522010-05-11 19:42:16 +0000126
127 hasher hash_function() const;
128 key_equal key_eq() const;
129
130 iterator find(const key_type& k);
131 const_iterator find(const key_type& k) const;
132 size_type count(const key_type& k) const;
133 pair<iterator, iterator> equal_range(const key_type& k);
134 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
135
Howard Hinnant557da862011-06-04 20:18:37 +0000136 size_type bucket_count() const noexcept;
137 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000138
139 size_type bucket_size(size_type n) const;
140 size_type bucket(const key_type& k) const;
141
142 local_iterator begin(size_type n);
143 local_iterator end(size_type n);
144 const_local_iterator begin(size_type n) const;
145 const_local_iterator end(size_type n) const;
146 const_local_iterator cbegin(size_type n) const;
147 const_local_iterator cend(size_type n) const;
148
Howard Hinnant557da862011-06-04 20:18:37 +0000149 float load_factor() const noexcept;
150 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000151 void max_load_factor(float z);
152 void rehash(size_type n);
153 void reserve(size_type n);
154};
155
156template <class Value, class Hash, class Pred, class Alloc>
157 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant557da862011-06-04 20:18:37 +0000158 unordered_set<Value, Hash, Pred, Alloc>& y)
159 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000160
161template <class Value, class Hash, class Pred, class Alloc>
162 bool
163 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
164 const unordered_set<Value, Hash, Pred, Alloc>& y);
165
166template <class Value, class Hash, class Pred, class Alloc>
167 bool
168 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
169 const unordered_set<Value, Hash, Pred, Alloc>& y);
170
171template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
172 class Alloc = allocator<Value>>
173class unordered_multiset
174{
175public:
176 // types
177 typedef Value key_type;
178 typedef key_type value_type;
179 typedef Hash hasher;
180 typedef Pred key_equal;
181 typedef Alloc allocator_type;
182 typedef value_type& reference;
183 typedef const value_type& const_reference;
184 typedef typename allocator_traits<allocator_type>::pointer pointer;
185 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
186 typedef typename allocator_traits<allocator_type>::size_type size_type;
187 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
188
189 typedef /unspecified/ iterator;
190 typedef /unspecified/ const_iterator;
191 typedef /unspecified/ local_iterator;
192 typedef /unspecified/ const_local_iterator;
193
Howard Hinnant557da862011-06-04 20:18:37 +0000194 unordered_multiset()
195 noexcept(
196 is_nothrow_default_constructible<hasher>::value &&
197 is_nothrow_default_constructible<key_equal>::value &&
198 is_nothrow_default_constructible<allocator_type>::value);
199 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +0000200 const key_equal& eql = key_equal(),
201 const allocator_type& a = allocator_type());
202 template <class InputIterator>
203 unordered_multiset(InputIterator f, InputIterator l,
204 size_type n = 0, const hasher& hf = hasher(),
205 const key_equal& eql = key_equal(),
206 const allocator_type& a = allocator_type());
207 explicit unordered_multiset(const allocator_type&);
208 unordered_multiset(const unordered_multiset&);
209 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant557da862011-06-04 20:18:37 +0000210 unordered_multiset(unordered_multiset&&)
211 noexcept(
212 is_nothrow_move_constructible<hasher>::value &&
213 is_nothrow_move_constructible<key_equal>::value &&
214 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000215 unordered_multiset(unordered_multiset&&, const Allocator&);
216 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
217 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
218 const allocator_type& a = allocator_type());
Marshall Clow45b983c2013-09-30 21:33:51 +0000219 unordered_multiset(size_type n, const allocator_type& a); // C++14
220 unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
221 template <class InputIterator>
222 unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
223 template <class InputIterator>
224 unordered_multiset(InputIterator f, InputIterator l, size_type n,
225 const hasher& hf, const allocator_type& a); // C++14
226 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
227 unordered_multiset(initializer_list<value_type> il, size_type n,
228 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000229 ~unordered_multiset();
230 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant557da862011-06-04 20:18:37 +0000231 unordered_multiset& operator=(unordered_multiset&&)
232 noexcept(
233 allocator_type::propagate_on_container_move_assignment::value &&
234 is_nothrow_move_assignable<allocator_type>::value &&
235 is_nothrow_move_assignable<hasher>::value &&
236 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000237 unordered_multiset& operator=(initializer_list<value_type>);
238
Howard Hinnant557da862011-06-04 20:18:37 +0000239 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000240
Howard Hinnant557da862011-06-04 20:18:37 +0000241 bool empty() const noexcept;
242 size_type size() const noexcept;
243 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000244
Howard Hinnant557da862011-06-04 20:18:37 +0000245 iterator begin() noexcept;
246 iterator end() noexcept;
247 const_iterator begin() const noexcept;
248 const_iterator end() const noexcept;
249 const_iterator cbegin() const noexcept;
250 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000251
252 template <class... Args>
253 iterator emplace(Args&&... args);
254 template <class... Args>
255 iterator emplace_hint(const_iterator position, Args&&... args);
256 iterator insert(const value_type& obj);
257 iterator insert(value_type&& obj);
258 iterator insert(const_iterator hint, const value_type& obj);
259 iterator insert(const_iterator hint, value_type&& obj);
260 template <class InputIterator>
261 void insert(InputIterator first, InputIterator last);
262 void insert(initializer_list<value_type>);
263
264 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000265 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000266 size_type erase(const key_type& k);
267 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant557da862011-06-04 20:18:37 +0000268 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000269
Howard Hinnant557da862011-06-04 20:18:37 +0000270 void swap(unordered_multiset&)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000271 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
272 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
273 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnant3e519522010-05-11 19:42:16 +0000274
275 hasher hash_function() const;
276 key_equal key_eq() const;
277
278 iterator find(const key_type& k);
279 const_iterator find(const key_type& k) const;
280 size_type count(const key_type& k) const;
281 pair<iterator, iterator> equal_range(const key_type& k);
282 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
283
Howard Hinnant557da862011-06-04 20:18:37 +0000284 size_type bucket_count() const noexcept;
285 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000286
287 size_type bucket_size(size_type n) const;
288 size_type bucket(const key_type& k) const;
289
290 local_iterator begin(size_type n);
291 local_iterator end(size_type n);
292 const_local_iterator begin(size_type n) const;
293 const_local_iterator end(size_type n) const;
294 const_local_iterator cbegin(size_type n) const;
295 const_local_iterator cend(size_type n) const;
296
Howard Hinnant557da862011-06-04 20:18:37 +0000297 float load_factor() const noexcept;
298 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000299 void max_load_factor(float z);
300 void rehash(size_type n);
301 void reserve(size_type n);
302};
303
304template <class Value, class Hash, class Pred, class Alloc>
305 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant557da862011-06-04 20:18:37 +0000306 unordered_multiset<Value, Hash, Pred, Alloc>& y)
307 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000308
309template <class Value, class Hash, class Pred, class Alloc>
310 bool
311 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
312 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
313
314template <class Value, class Hash, class Pred, class Alloc>
315 bool
316 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
317 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
318} // std
319
320*/
321
322#include <__config>
323#include <__hash_table>
324#include <functional>
325
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000326#include <__debug>
327
Howard Hinnant073458b2011-10-17 20:05:10 +0000328#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000329#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000330#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000331
332_LIBCPP_BEGIN_NAMESPACE_STD
333
334template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
335 class _Alloc = allocator<_Value> >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000336class _LIBCPP_TEMPLATE_VIS unordered_set
Howard Hinnant3e519522010-05-11 19:42:16 +0000337{
338public:
339 // types
340 typedef _Value key_type;
341 typedef key_type value_type;
342 typedef _Hash hasher;
343 typedef _Pred key_equal;
344 typedef _Alloc allocator_type;
345 typedef value_type& reference;
346 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000347 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
348 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000349
350private:
351 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
352
353 __table __table_;
354
355public:
356 typedef typename __table::pointer pointer;
357 typedef typename __table::const_pointer const_pointer;
358 typedef typename __table::size_type size_type;
359 typedef typename __table::difference_type difference_type;
360
361 typedef typename __table::const_iterator iterator;
362 typedef typename __table::const_iterator const_iterator;
363 typedef typename __table::const_local_iterator local_iterator;
364 typedef typename __table::const_local_iterator const_local_iterator;
365
Howard Hinnant789847d2010-09-23 18:58:28 +0000366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000367 unordered_set()
368 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000369 {
370#if _LIBCPP_DEBUG_LEVEL >= 2
371 __get_db()->__insert_c(this);
372#endif
373 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000374 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
375 const key_equal& __eql = key_equal());
Marshall Clow45b983c2013-09-30 21:33:51 +0000376#if _LIBCPP_STD_VER > 11
377 inline _LIBCPP_INLINE_VISIBILITY
378 unordered_set(size_type __n, const allocator_type& __a)
379 : unordered_set(__n, hasher(), key_equal(), __a) {}
380 inline _LIBCPP_INLINE_VISIBILITY
381 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
382 : unordered_set(__n, __hf, key_equal(), __a) {}
383#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000384 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
385 const allocator_type& __a);
386 template <class _InputIterator>
387 unordered_set(_InputIterator __first, _InputIterator __last);
388 template <class _InputIterator>
389 unordered_set(_InputIterator __first, _InputIterator __last,
390 size_type __n, const hasher& __hf = hasher(),
391 const key_equal& __eql = key_equal());
392 template <class _InputIterator>
393 unordered_set(_InputIterator __first, _InputIterator __last,
394 size_type __n, const hasher& __hf, const key_equal& __eql,
395 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000396#if _LIBCPP_STD_VER > 11
397 template <class _InputIterator>
398 inline _LIBCPP_INLINE_VISIBILITY
399 unordered_set(_InputIterator __first, _InputIterator __last,
400 size_type __n, const allocator_type& __a)
401 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
402 template <class _InputIterator>
403 unordered_set(_InputIterator __first, _InputIterator __last,
404 size_type __n, const hasher& __hf, const allocator_type& __a)
405 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
406#endif
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000408 explicit unordered_set(const allocator_type& __a);
409 unordered_set(const unordered_set& __u);
410 unordered_set(const unordered_set& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000411#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000413 unordered_set(unordered_set&& __u)
414 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000415 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000416#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000417#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000418 unordered_set(initializer_list<value_type> __il);
419 unordered_set(initializer_list<value_type> __il, size_type __n,
420 const hasher& __hf = hasher(),
421 const key_equal& __eql = key_equal());
422 unordered_set(initializer_list<value_type> __il, size_type __n,
423 const hasher& __hf, const key_equal& __eql,
424 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000425#if _LIBCPP_STD_VER > 11
426 inline _LIBCPP_INLINE_VISIBILITY
427 unordered_set(initializer_list<value_type> __il, size_type __n,
428 const allocator_type& __a)
429 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
430 inline _LIBCPP_INLINE_VISIBILITY
431 unordered_set(initializer_list<value_type> __il, size_type __n,
432 const hasher& __hf, const allocator_type& __a)
433 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
434#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000435#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000436 // ~unordered_set() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000437 _LIBCPP_INLINE_VISIBILITY
438 unordered_set& operator=(const unordered_set& __u)
439 {
440 __table_ = __u.__table_;
441 return *this;
442 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000443#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000445 unordered_set& operator=(unordered_set&& __u)
446 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000447#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000448#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000450 unordered_set& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000451#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000452
Howard Hinnant789847d2010-09-23 18:58:28 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000454 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000455 {return allocator_type(__table_.__node_alloc());}
456
Howard Hinnant789847d2010-09-23 18:58:28 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000458 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000460 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000462 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000463
Howard Hinnant789847d2010-09-23 18:58:28 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000465 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000467 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000469 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000471 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000473 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000475 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000476
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000477#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:16 +0000478 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000480 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +0000481 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000482 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-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 Hinnant3e519522010-05-11 19:42:16 +0000493 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +0000494 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000495#endif
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000496#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant789847d2010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000498 pair<iterator, bool> insert(const value_type& __x)
499 {return __table_.__insert_unique(__x);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000500#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000502 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +0000503 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000504#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-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 Hinnant3e519522010-05-11 19:42:16 +0000515 iterator insert(const_iterator, const value_type& __x)
516 {return insert(__x).first;}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000517#endif
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000518#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-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 Hinnant3e519522010-05-11 19:42:16 +0000529 iterator insert(const_iterator, value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +0000530 {return insert(_VSTD::move(__x)).first;}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000531#endif
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000532#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000533 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000535 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant54976f22011-08-12 21:56:02 +0000536#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant789847d2010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000538 void insert(initializer_list<value_type> __il)
539 {insert(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000540#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000541
Howard Hinnant789847d2010-09-23 18:58:28 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000543 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000545 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000547 iterator erase(const_iterator __first, const_iterator __last)
548 {return __table_.erase(__first, __last);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000550 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000551
Howard Hinnant789847d2010-09-23 18:58:28 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000553 void swap(unordered_set& __u)
554 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
555 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000556
Howard Hinnant789847d2010-09-23 18:58:28 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000558 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000560 key_equal key_eq() const {return __table_.key_eq();}
561
Howard Hinnant789847d2010-09-23 18:58:28 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000563 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000565 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000567 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000569 pair<iterator, iterator> equal_range(const key_type& __k)
570 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000572 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
573 {return __table_.__equal_range_unique(__k);}
574
Howard Hinnant789847d2010-09-23 18:58:28 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000576 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000578 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000579
Howard Hinnant789847d2010-09-23 18:58:28 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000581 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000583 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
584
Howard Hinnant789847d2010-09-23 18:58:28 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000586 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000588 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000590 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000592 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000594 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000596 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
597
Howard Hinnant789847d2010-09-23 18:58:28 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000599 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000601 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000605 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000607 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000608
609#if _LIBCPP_DEBUG_LEVEL >= 2
610
611 bool __dereferenceable(const const_iterator* __i) const
612 {return __table_.__dereferenceable(__i);}
613 bool __decrementable(const const_iterator* __i) const
614 {return __table_.__decrementable(__i);}
615 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
616 {return __table_.__addable(__i, __n);}
617 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
618 {return __table_.__addable(__i, __n);}
619
620#endif // _LIBCPP_DEBUG_LEVEL >= 2
621
Howard Hinnant3e519522010-05-11 19:42:16 +0000622};
623
624template <class _Value, class _Hash, class _Pred, class _Alloc>
625unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
626 const hasher& __hf, const key_equal& __eql)
627 : __table_(__hf, __eql)
628{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000629#if _LIBCPP_DEBUG_LEVEL >= 2
630 __get_db()->__insert_c(this);
631#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000632 __table_.rehash(__n);
633}
634
635template <class _Value, class _Hash, class _Pred, class _Alloc>
636unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
637 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
638 : __table_(__hf, __eql, __a)
639{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000640#if _LIBCPP_DEBUG_LEVEL >= 2
641 __get_db()->__insert_c(this);
642#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000643 __table_.rehash(__n);
644}
645
646template <class _Value, class _Hash, class _Pred, class _Alloc>
647template <class _InputIterator>
648unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
649 _InputIterator __first, _InputIterator __last)
650{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000651#if _LIBCPP_DEBUG_LEVEL >= 2
652 __get_db()->__insert_c(this);
653#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000654 insert(__first, __last);
655}
656
657template <class _Value, class _Hash, class _Pred, class _Alloc>
658template <class _InputIterator>
659unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
660 _InputIterator __first, _InputIterator __last, size_type __n,
661 const hasher& __hf, const key_equal& __eql)
662 : __table_(__hf, __eql)
663{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000664#if _LIBCPP_DEBUG_LEVEL >= 2
665 __get_db()->__insert_c(this);
666#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000667 __table_.rehash(__n);
668 insert(__first, __last);
669}
670
671template <class _Value, class _Hash, class _Pred, class _Alloc>
672template <class _InputIterator>
673unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
674 _InputIterator __first, _InputIterator __last, size_type __n,
675 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
676 : __table_(__hf, __eql, __a)
677{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000678#if _LIBCPP_DEBUG_LEVEL >= 2
679 __get_db()->__insert_c(this);
680#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000681 __table_.rehash(__n);
682 insert(__first, __last);
683}
684
685template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000686inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000687unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
688 const allocator_type& __a)
689 : __table_(__a)
690{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000691#if _LIBCPP_DEBUG_LEVEL >= 2
692 __get_db()->__insert_c(this);
693#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000694}
695
696template <class _Value, class _Hash, class _Pred, class _Alloc>
697unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
698 const unordered_set& __u)
699 : __table_(__u.__table_)
700{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000701#if _LIBCPP_DEBUG_LEVEL >= 2
702 __get_db()->__insert_c(this);
703#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000704 __table_.rehash(__u.bucket_count());
705 insert(__u.begin(), __u.end());
706}
707
708template <class _Value, class _Hash, class _Pred, class _Alloc>
709unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
710 const unordered_set& __u, const allocator_type& __a)
711 : __table_(__u.__table_, __a)
712{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000713#if _LIBCPP_DEBUG_LEVEL >= 2
714 __get_db()->__insert_c(this);
715#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000716 __table_.rehash(__u.bucket_count());
717 insert(__u.begin(), __u.end());
718}
719
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000720#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000721
722template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000723inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000724unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
725 unordered_set&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +0000726 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000727 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000728{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000729#if _LIBCPP_DEBUG_LEVEL >= 2
730 __get_db()->__insert_c(this);
731 __get_db()->swap(this, &__u);
732#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000733}
734
735template <class _Value, class _Hash, class _Pred, class _Alloc>
736unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
737 unordered_set&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000738 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000739{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000740#if _LIBCPP_DEBUG_LEVEL >= 2
741 __get_db()->__insert_c(this);
742#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000743 if (__a != __u.get_allocator())
744 {
745 iterator __i = __u.begin();
746 while (__u.size() != 0)
Howard Hinnantce48a112011-06-30 21:18:19 +0000747 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000748 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000749#if _LIBCPP_DEBUG_LEVEL >= 2
750 else
751 __get_db()->swap(this, &__u);
752#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000753}
754
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000755#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000756
Howard Hinnant54976f22011-08-12 21:56:02 +0000757#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
758
Howard Hinnant3e519522010-05-11 19:42:16 +0000759template <class _Value, class _Hash, class _Pred, class _Alloc>
760unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
761 initializer_list<value_type> __il)
762{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000763#if _LIBCPP_DEBUG_LEVEL >= 2
764 __get_db()->__insert_c(this);
765#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000766 insert(__il.begin(), __il.end());
767}
768
769template <class _Value, class _Hash, class _Pred, class _Alloc>
770unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
771 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
772 const key_equal& __eql)
773 : __table_(__hf, __eql)
774{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000775#if _LIBCPP_DEBUG_LEVEL >= 2
776 __get_db()->__insert_c(this);
777#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000778 __table_.rehash(__n);
779 insert(__il.begin(), __il.end());
780}
781
782template <class _Value, class _Hash, class _Pred, class _Alloc>
783unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
784 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
785 const key_equal& __eql, const allocator_type& __a)
786 : __table_(__hf, __eql, __a)
787{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000788#if _LIBCPP_DEBUG_LEVEL >= 2
789 __get_db()->__insert_c(this);
790#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000791 __table_.rehash(__n);
792 insert(__il.begin(), __il.end());
793}
794
Howard Hinnant54976f22011-08-12 21:56:02 +0000795#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
796
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000797#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000798
799template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000800inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000801unordered_set<_Value, _Hash, _Pred, _Alloc>&
802unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +0000803 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000804{
Howard Hinnantce48a112011-06-30 21:18:19 +0000805 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +0000806 return *this;
807}
808
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000809#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000810
Howard Hinnant54976f22011-08-12 21:56:02 +0000811#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
812
Howard Hinnant3e519522010-05-11 19:42:16 +0000813template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000814inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000815unordered_set<_Value, _Hash, _Pred, _Alloc>&
816unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
817 initializer_list<value_type> __il)
818{
819 __table_.__assign_unique(__il.begin(), __il.end());
820 return *this;
821}
822
Howard Hinnant54976f22011-08-12 21:56:02 +0000823#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
824
Howard Hinnant3e519522010-05-11 19:42:16 +0000825template <class _Value, class _Hash, class _Pred, class _Alloc>
826template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000827inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000828void
829unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
830 _InputIterator __last)
831{
832 for (; __first != __last; ++__first)
833 __table_.__insert_unique(*__first);
834}
835
836template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +0000837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000838void
839swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
840 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant557da862011-06-04 20:18:37 +0000841 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +0000842{
843 __x.swap(__y);
844}
845
846template <class _Value, class _Hash, class _Pred, class _Alloc>
847bool
848operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
849 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
850{
851 if (__x.size() != __y.size())
852 return false;
853 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
854 const_iterator;
855 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
856 __i != __ex; ++__i)
857 {
858 const_iterator __j = __y.find(*__i);
859 if (__j == __ey || !(*__i == *__j))
860 return false;
861 }
862 return true;
863}
864
865template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +0000866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000867bool
868operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
869 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
870{
871 return !(__x == __y);
872}
873
874template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
875 class _Alloc = allocator<_Value> >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000876class _LIBCPP_TEMPLATE_VIS unordered_multiset
Howard Hinnant3e519522010-05-11 19:42:16 +0000877{
878public:
879 // types
880 typedef _Value key_type;
881 typedef key_type value_type;
882 typedef _Hash hasher;
883 typedef _Pred key_equal;
884 typedef _Alloc allocator_type;
885 typedef value_type& reference;
886 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000887 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
888 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000889
890private:
891 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
892
893 __table __table_;
894
895public:
896 typedef typename __table::pointer pointer;
897 typedef typename __table::const_pointer const_pointer;
898 typedef typename __table::size_type size_type;
899 typedef typename __table::difference_type difference_type;
900
901 typedef typename __table::const_iterator iterator;
902 typedef typename __table::const_iterator const_iterator;
903 typedef typename __table::const_local_iterator local_iterator;
904 typedef typename __table::const_local_iterator const_local_iterator;
905
Howard Hinnant789847d2010-09-23 18:58:28 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000907 unordered_multiset()
908 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000909 {
910#if _LIBCPP_DEBUG_LEVEL >= 2
911 __get_db()->__insert_c(this);
912#endif
913 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000914 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
915 const key_equal& __eql = key_equal());
916 unordered_multiset(size_type __n, const hasher& __hf,
917 const key_equal& __eql, const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000918#if _LIBCPP_STD_VER > 11
919 inline _LIBCPP_INLINE_VISIBILITY
920 unordered_multiset(size_type __n, const allocator_type& __a)
921 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
922 inline _LIBCPP_INLINE_VISIBILITY
923 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
924 : unordered_multiset(__n, __hf, key_equal(), __a) {}
925#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000926 template <class _InputIterator>
927 unordered_multiset(_InputIterator __first, _InputIterator __last);
928 template <class _InputIterator>
929 unordered_multiset(_InputIterator __first, _InputIterator __last,
930 size_type __n, const hasher& __hf = hasher(),
931 const key_equal& __eql = key_equal());
932 template <class _InputIterator>
933 unordered_multiset(_InputIterator __first, _InputIterator __last,
934 size_type __n , const hasher& __hf,
935 const key_equal& __eql, const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000936#if _LIBCPP_STD_VER > 11
937 template <class _InputIterator>
938 inline _LIBCPP_INLINE_VISIBILITY
939 unordered_multiset(_InputIterator __first, _InputIterator __last,
940 size_type __n, const allocator_type& __a)
941 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
942 template <class _InputIterator>
943 inline _LIBCPP_INLINE_VISIBILITY
944 unordered_multiset(_InputIterator __first, _InputIterator __last,
945 size_type __n, const hasher& __hf, const allocator_type& __a)
946 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
947#endif
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000948 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000949 explicit unordered_multiset(const allocator_type& __a);
950 unordered_multiset(const unordered_multiset& __u);
951 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000952#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000954 unordered_multiset(unordered_multiset&& __u)
955 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000956 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000957#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000958#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000959 unordered_multiset(initializer_list<value_type> __il);
960 unordered_multiset(initializer_list<value_type> __il, size_type __n,
961 const hasher& __hf = hasher(),
962 const key_equal& __eql = key_equal());
963 unordered_multiset(initializer_list<value_type> __il, size_type __n,
964 const hasher& __hf, const key_equal& __eql,
965 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000966#if _LIBCPP_STD_VER > 11
967 inline _LIBCPP_INLINE_VISIBILITY
968 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
969 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
970 inline _LIBCPP_INLINE_VISIBILITY
971 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
972 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
973#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000974#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000975 // ~unordered_multiset() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000976 _LIBCPP_INLINE_VISIBILITY
977 unordered_multiset& operator=(const unordered_multiset& __u)
978 {
979 __table_ = __u.__table_;
980 return *this;
981 }
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000982#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000984 unordered_multiset& operator=(unordered_multiset&& __u)
985 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000986#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000987#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000988 unordered_multiset& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000989#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000990
Howard Hinnant789847d2010-09-23 18:58:28 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000992 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000993 {return allocator_type(__table_.__node_alloc());}
994
Howard Hinnant789847d2010-09-23 18:58:28 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000996 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000998 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001000 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001001
Howard Hinnant789847d2010-09-23 18:58:28 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001003 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001005 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001007 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001009 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001011 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001013 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001014
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001015#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:16 +00001016 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001018 iterator emplace(_Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +00001019 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001020 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001022 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +00001023 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001024#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant789847d2010-09-23 18:58:28 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001026 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001027#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantce48a112011-06-30 21:18:19 +00001029 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnant3e519522010-05-11 19:42:16 +00001030#endif
Howard Hinnant789847d2010-09-23 18:58:28 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001032 iterator insert(const_iterator __p, const value_type& __x)
1033 {return __table_.__insert_multi(__p, __x);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001034#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant789847d2010-09-23 18:58:28 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001036 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +00001037 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001038#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001039 template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001041 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant54976f22011-08-12 21:56:02 +00001042#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant789847d2010-09-23 18:58:28 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001044 void insert(initializer_list<value_type> __il)
1045 {insert(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +00001046#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +00001047
Howard Hinnant789847d2010-09-23 18:58:28 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001049 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001051 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001053 iterator erase(const_iterator __first, const_iterator __last)
1054 {return __table_.erase(__first, __last);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001056 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001057
Howard Hinnant789847d2010-09-23 18:58:28 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001059 void swap(unordered_multiset& __u)
1060 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1061 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001062
Howard Hinnant789847d2010-09-23 18:58:28 +00001063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001064 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001066 key_equal key_eq() const {return __table_.key_eq();}
1067
Howard Hinnant789847d2010-09-23 18:58:28 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001069 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001071 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001073 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001075 pair<iterator, iterator> equal_range(const key_type& __k)
1076 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001078 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1079 {return __table_.__equal_range_multi(__k);}
1080
Howard Hinnant789847d2010-09-23 18:58:28 +00001081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001082 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001084 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001085
Howard Hinnant789847d2010-09-23 18:58:28 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001087 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001089 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1090
Howard Hinnant789847d2010-09-23 18:58:28 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001092 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001094 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001096 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001098 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001100 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001102 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1103
Howard Hinnant789847d2010-09-23 18:58:28 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001105 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001107 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001109 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001111 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001113 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnantb24c8022013-07-23 22:01:58 +00001114
1115#if _LIBCPP_DEBUG_LEVEL >= 2
1116
1117 bool __dereferenceable(const const_iterator* __i) const
1118 {return __table_.__dereferenceable(__i);}
1119 bool __decrementable(const const_iterator* __i) const
1120 {return __table_.__decrementable(__i);}
1121 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1122 {return __table_.__addable(__i, __n);}
1123 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1124 {return __table_.__addable(__i, __n);}
1125
1126#endif // _LIBCPP_DEBUG_LEVEL >= 2
1127
Howard Hinnant3e519522010-05-11 19:42:16 +00001128};
1129
1130template <class _Value, class _Hash, class _Pred, class _Alloc>
1131unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1132 size_type __n, const hasher& __hf, const key_equal& __eql)
1133 : __table_(__hf, __eql)
1134{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001135#if _LIBCPP_DEBUG_LEVEL >= 2
1136 __get_db()->__insert_c(this);
1137#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001138 __table_.rehash(__n);
1139}
1140
1141template <class _Value, class _Hash, class _Pred, class _Alloc>
1142unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1143 size_type __n, const hasher& __hf, const key_equal& __eql,
1144 const allocator_type& __a)
1145 : __table_(__hf, __eql, __a)
1146{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001147#if _LIBCPP_DEBUG_LEVEL >= 2
1148 __get_db()->__insert_c(this);
1149#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001150 __table_.rehash(__n);
1151}
1152
1153template <class _Value, class _Hash, class _Pred, class _Alloc>
1154template <class _InputIterator>
1155unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1156 _InputIterator __first, _InputIterator __last)
1157{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001158#if _LIBCPP_DEBUG_LEVEL >= 2
1159 __get_db()->__insert_c(this);
1160#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001161 insert(__first, __last);
1162}
1163
1164template <class _Value, class _Hash, class _Pred, class _Alloc>
1165template <class _InputIterator>
1166unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1167 _InputIterator __first, _InputIterator __last, size_type __n,
1168 const hasher& __hf, const key_equal& __eql)
1169 : __table_(__hf, __eql)
1170{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001171#if _LIBCPP_DEBUG_LEVEL >= 2
1172 __get_db()->__insert_c(this);
1173#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001174 __table_.rehash(__n);
1175 insert(__first, __last);
1176}
1177
1178template <class _Value, class _Hash, class _Pred, class _Alloc>
1179template <class _InputIterator>
1180unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1181 _InputIterator __first, _InputIterator __last, size_type __n,
1182 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1183 : __table_(__hf, __eql, __a)
1184{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001185#if _LIBCPP_DEBUG_LEVEL >= 2
1186 __get_db()->__insert_c(this);
1187#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001188 __table_.rehash(__n);
1189 insert(__first, __last);
1190}
1191
1192template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001193inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001194unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1195 const allocator_type& __a)
1196 : __table_(__a)
1197{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001198#if _LIBCPP_DEBUG_LEVEL >= 2
1199 __get_db()->__insert_c(this);
1200#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001201}
1202
1203template <class _Value, class _Hash, class _Pred, class _Alloc>
1204unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1205 const unordered_multiset& __u)
1206 : __table_(__u.__table_)
1207{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001208#if _LIBCPP_DEBUG_LEVEL >= 2
1209 __get_db()->__insert_c(this);
1210#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001211 __table_.rehash(__u.bucket_count());
1212 insert(__u.begin(), __u.end());
1213}
1214
1215template <class _Value, class _Hash, class _Pred, class _Alloc>
1216unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1217 const unordered_multiset& __u, const allocator_type& __a)
1218 : __table_(__u.__table_, __a)
1219{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001220#if _LIBCPP_DEBUG_LEVEL >= 2
1221 __get_db()->__insert_c(this);
1222#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001223 __table_.rehash(__u.bucket_count());
1224 insert(__u.begin(), __u.end());
1225}
1226
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001227#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001228
1229template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001230inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001231unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1232 unordered_multiset&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +00001233 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001234 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001235{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001236#if _LIBCPP_DEBUG_LEVEL >= 2
1237 __get_db()->__insert_c(this);
1238 __get_db()->swap(this, &__u);
1239#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001240}
1241
1242template <class _Value, class _Hash, class _Pred, class _Alloc>
1243unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1244 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +00001245 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +00001246{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001247#if _LIBCPP_DEBUG_LEVEL >= 2
1248 __get_db()->__insert_c(this);
1249#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001250 if (__a != __u.get_allocator())
1251 {
1252 iterator __i = __u.begin();
1253 while (__u.size() != 0)
Howard Hinnantce48a112011-06-30 21:18:19 +00001254 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001255 }
Howard Hinnantb24c8022013-07-23 22:01:58 +00001256#if _LIBCPP_DEBUG_LEVEL >= 2
1257 else
1258 __get_db()->swap(this, &__u);
1259#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001260}
1261
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001262#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001263
Howard Hinnant54976f22011-08-12 21:56:02 +00001264#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1265
Howard Hinnant3e519522010-05-11 19:42:16 +00001266template <class _Value, class _Hash, class _Pred, class _Alloc>
1267unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1268 initializer_list<value_type> __il)
1269{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001270#if _LIBCPP_DEBUG_LEVEL >= 2
1271 __get_db()->__insert_c(this);
1272#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001273 insert(__il.begin(), __il.end());
1274}
1275
1276template <class _Value, class _Hash, class _Pred, class _Alloc>
1277unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1278 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1279 const key_equal& __eql)
1280 : __table_(__hf, __eql)
1281{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001282#if _LIBCPP_DEBUG_LEVEL >= 2
1283 __get_db()->__insert_c(this);
1284#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001285 __table_.rehash(__n);
1286 insert(__il.begin(), __il.end());
1287}
1288
1289template <class _Value, class _Hash, class _Pred, class _Alloc>
1290unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1291 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1292 const key_equal& __eql, const allocator_type& __a)
1293 : __table_(__hf, __eql, __a)
1294{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001295#if _LIBCPP_DEBUG_LEVEL >= 2
1296 __get_db()->__insert_c(this);
1297#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001298 __table_.rehash(__n);
1299 insert(__il.begin(), __il.end());
1300}
1301
Howard Hinnant54976f22011-08-12 21:56:02 +00001302#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1303
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001304#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001305
1306template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001307inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001308unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1309unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1310 unordered_multiset&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +00001311 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001312{
Howard Hinnantce48a112011-06-30 21:18:19 +00001313 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001314 return *this;
1315}
1316
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001317#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001318
Howard Hinnant54976f22011-08-12 21:56:02 +00001319#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1320
Howard Hinnant3e519522010-05-11 19:42:16 +00001321template <class _Value, class _Hash, class _Pred, class _Alloc>
1322inline
1323unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1324unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1325 initializer_list<value_type> __il)
1326{
1327 __table_.__assign_multi(__il.begin(), __il.end());
1328 return *this;
1329}
1330
Howard Hinnant54976f22011-08-12 21:56:02 +00001331#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1332
Howard Hinnant3e519522010-05-11 19:42:16 +00001333template <class _Value, class _Hash, class _Pred, class _Alloc>
1334template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001335inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001336void
1337unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1338 _InputIterator __last)
1339{
1340 for (; __first != __last; ++__first)
1341 __table_.__insert_multi(*__first);
1342}
1343
1344template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001346void
1347swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1348 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant557da862011-06-04 20:18:37 +00001349 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001350{
1351 __x.swap(__y);
1352}
1353
1354template <class _Value, class _Hash, class _Pred, class _Alloc>
1355bool
1356operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1357 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1358{
1359 if (__x.size() != __y.size())
1360 return false;
1361 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1362 const_iterator;
1363 typedef pair<const_iterator, const_iterator> _EqRng;
1364 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1365 {
1366 _EqRng __xeq = __x.equal_range(*__i);
1367 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnantce48a112011-06-30 21:18:19 +00001368 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1369 _VSTD::distance(__yeq.first, __yeq.second) ||
1370 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00001371 return false;
1372 __i = __xeq.second;
1373 }
1374 return true;
1375}
1376
1377template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001379bool
1380operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1381 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1382{
1383 return !(__x == __y);
1384}
1385
1386_LIBCPP_END_NAMESPACE_STD
1387
1388#endif // _LIBCPP_UNORDERED_SET