blob: a219fa6091203d0889b6902efdfbede7d7601ccc [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
Erik Pilkingtonb0386a52018-08-01 01:33:38 +000046 typedef unspecified node_type unspecified; // C++17
47 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
48
Howard Hinnant557da862011-06-04 20:18:37 +000049 unordered_set()
50 noexcept(
51 is_nothrow_default_constructible<hasher>::value &&
52 is_nothrow_default_constructible<key_equal>::value &&
53 is_nothrow_default_constructible<allocator_type>::value);
54 explicit unordered_set(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +000055 const key_equal& eql = key_equal(),
56 const allocator_type& a = allocator_type());
57 template <class InputIterator>
58 unordered_set(InputIterator f, InputIterator l,
59 size_type n = 0, const hasher& hf = hasher(),
60 const key_equal& eql = key_equal(),
61 const allocator_type& a = allocator_type());
62 explicit unordered_set(const allocator_type&);
63 unordered_set(const unordered_set&);
64 unordered_set(const unordered_set&, const Allocator&);
Howard Hinnant557da862011-06-04 20:18:37 +000065 unordered_set(unordered_set&&)
66 noexcept(
67 is_nothrow_move_constructible<hasher>::value &&
68 is_nothrow_move_constructible<key_equal>::value &&
69 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000070 unordered_set(unordered_set&&, const Allocator&);
71 unordered_set(initializer_list<value_type>, size_type n = 0,
72 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
73 const allocator_type& a = allocator_type());
Marshall Clow45b983c2013-09-30 21:33:51 +000074 unordered_set(size_type n, const allocator_type& a); // C++14
75 unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
76 template <class InputIterator>
77 unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
78 template <class InputIterator>
79 unordered_set(InputIterator f, InputIterator l, size_type n,
80 const hasher& hf, const allocator_type& a); // C++14
81 unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
82 unordered_set(initializer_list<value_type> il, size_type n,
83 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000084 ~unordered_set();
85 unordered_set& operator=(const unordered_set&);
Howard Hinnant557da862011-06-04 20:18:37 +000086 unordered_set& operator=(unordered_set&&)
87 noexcept(
88 allocator_type::propagate_on_container_move_assignment::value &&
89 is_nothrow_move_assignable<allocator_type>::value &&
90 is_nothrow_move_assignable<hasher>::value &&
91 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000092 unordered_set& operator=(initializer_list<value_type>);
93
Howard Hinnant557da862011-06-04 20:18:37 +000094 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000095
Howard Hinnant557da862011-06-04 20:18:37 +000096 bool empty() const noexcept;
97 size_type size() const noexcept;
98 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000099
Howard Hinnant557da862011-06-04 20:18:37 +0000100 iterator begin() noexcept;
101 iterator end() noexcept;
102 const_iterator begin() const noexcept;
103 const_iterator end() const noexcept;
104 const_iterator cbegin() const noexcept;
105 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000106
107 template <class... Args>
108 pair<iterator, bool> emplace(Args&&... args);
109 template <class... Args>
110 iterator emplace_hint(const_iterator position, Args&&... args);
111 pair<iterator, bool> insert(const value_type& obj);
112 pair<iterator, bool> insert(value_type&& obj);
113 iterator insert(const_iterator hint, const value_type& obj);
114 iterator insert(const_iterator hint, value_type&& obj);
115 template <class InputIterator>
116 void insert(InputIterator first, InputIterator last);
117 void insert(initializer_list<value_type>);
118
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000119 node_type extract(const_iterator position); // C++17
120 node_type extract(const key_type& x); // C++17
121 insert_return_type insert(node_type&& nh); // C++17
122 iterator insert(const_iterator hint, node_type&& nh); // C++17
123
Howard Hinnant3e519522010-05-11 19:42:16 +0000124 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000125 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000126 size_type erase(const key_type& k);
127 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant557da862011-06-04 20:18:37 +0000128 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000129
Howard Hinnant557da862011-06-04 20:18:37 +0000130 void swap(unordered_set&)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000131 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
132 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
133 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnant3e519522010-05-11 19:42:16 +0000134
135 hasher hash_function() const;
136 key_equal key_eq() const;
137
138 iterator find(const key_type& k);
139 const_iterator find(const key_type& k) const;
140 size_type count(const key_type& k) const;
141 pair<iterator, iterator> equal_range(const key_type& k);
142 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
143
Howard Hinnant557da862011-06-04 20:18:37 +0000144 size_type bucket_count() const noexcept;
145 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000146
147 size_type bucket_size(size_type n) const;
148 size_type bucket(const key_type& k) const;
149
150 local_iterator begin(size_type n);
151 local_iterator end(size_type n);
152 const_local_iterator begin(size_type n) const;
153 const_local_iterator end(size_type n) const;
154 const_local_iterator cbegin(size_type n) const;
155 const_local_iterator cend(size_type n) const;
156
Howard Hinnant557da862011-06-04 20:18:37 +0000157 float load_factor() const noexcept;
158 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000159 void max_load_factor(float z);
160 void rehash(size_type n);
161 void reserve(size_type n);
162};
163
164template <class Value, class Hash, class Pred, class Alloc>
165 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant557da862011-06-04 20:18:37 +0000166 unordered_set<Value, Hash, Pred, Alloc>& y)
167 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000168
169template <class Value, class Hash, class Pred, class Alloc>
170 bool
171 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
172 const unordered_set<Value, Hash, Pred, Alloc>& y);
173
174template <class Value, class Hash, class Pred, class Alloc>
175 bool
176 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
177 const unordered_set<Value, Hash, Pred, Alloc>& y);
178
179template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
180 class Alloc = allocator<Value>>
181class unordered_multiset
182{
183public:
184 // types
185 typedef Value key_type;
186 typedef key_type value_type;
187 typedef Hash hasher;
188 typedef Pred key_equal;
189 typedef Alloc allocator_type;
190 typedef value_type& reference;
191 typedef const value_type& const_reference;
192 typedef typename allocator_traits<allocator_type>::pointer pointer;
193 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
194 typedef typename allocator_traits<allocator_type>::size_type size_type;
195 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
196
197 typedef /unspecified/ iterator;
198 typedef /unspecified/ const_iterator;
199 typedef /unspecified/ local_iterator;
200 typedef /unspecified/ const_local_iterator;
201
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000202 typedef unspecified node_type unspecified; // C++17
203
Howard Hinnant557da862011-06-04 20:18:37 +0000204 unordered_multiset()
205 noexcept(
206 is_nothrow_default_constructible<hasher>::value &&
207 is_nothrow_default_constructible<key_equal>::value &&
208 is_nothrow_default_constructible<allocator_type>::value);
209 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnant3e519522010-05-11 19:42:16 +0000210 const key_equal& eql = key_equal(),
211 const allocator_type& a = allocator_type());
212 template <class InputIterator>
213 unordered_multiset(InputIterator f, InputIterator l,
214 size_type n = 0, const hasher& hf = hasher(),
215 const key_equal& eql = key_equal(),
216 const allocator_type& a = allocator_type());
217 explicit unordered_multiset(const allocator_type&);
218 unordered_multiset(const unordered_multiset&);
219 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant557da862011-06-04 20:18:37 +0000220 unordered_multiset(unordered_multiset&&)
221 noexcept(
222 is_nothrow_move_constructible<hasher>::value &&
223 is_nothrow_move_constructible<key_equal>::value &&
224 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000225 unordered_multiset(unordered_multiset&&, const Allocator&);
226 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
227 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
228 const allocator_type& a = allocator_type());
Marshall Clow45b983c2013-09-30 21:33:51 +0000229 unordered_multiset(size_type n, const allocator_type& a); // C++14
230 unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
231 template <class InputIterator>
232 unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
233 template <class InputIterator>
234 unordered_multiset(InputIterator f, InputIterator l, size_type n,
235 const hasher& hf, const allocator_type& a); // C++14
236 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
237 unordered_multiset(initializer_list<value_type> il, size_type n,
238 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000239 ~unordered_multiset();
240 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant557da862011-06-04 20:18:37 +0000241 unordered_multiset& operator=(unordered_multiset&&)
242 noexcept(
243 allocator_type::propagate_on_container_move_assignment::value &&
244 is_nothrow_move_assignable<allocator_type>::value &&
245 is_nothrow_move_assignable<hasher>::value &&
246 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000247 unordered_multiset& operator=(initializer_list<value_type>);
248
Howard Hinnant557da862011-06-04 20:18:37 +0000249 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000250
Howard Hinnant557da862011-06-04 20:18:37 +0000251 bool empty() const noexcept;
252 size_type size() const noexcept;
253 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000254
Howard Hinnant557da862011-06-04 20:18:37 +0000255 iterator begin() noexcept;
256 iterator end() noexcept;
257 const_iterator begin() const noexcept;
258 const_iterator end() const noexcept;
259 const_iterator cbegin() const noexcept;
260 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000261
262 template <class... Args>
263 iterator emplace(Args&&... args);
264 template <class... Args>
265 iterator emplace_hint(const_iterator position, Args&&... args);
266 iterator insert(const value_type& obj);
267 iterator insert(value_type&& obj);
268 iterator insert(const_iterator hint, const value_type& obj);
269 iterator insert(const_iterator hint, value_type&& obj);
270 template <class InputIterator>
271 void insert(InputIterator first, InputIterator last);
272 void insert(initializer_list<value_type>);
273
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000274 node_type extract(const_iterator position); // C++17
275 node_type extract(const key_type& x); // C++17
276 iterator insert(node_type&& nh); // C++17
277 iterator insert(const_iterator hint, node_type&& nh); // C++17
278
Howard Hinnant3e519522010-05-11 19:42:16 +0000279 iterator erase(const_iterator position);
Marshall Clowec392962015-05-10 13:35:00 +0000280 iterator erase(iterator position); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +0000281 size_type erase(const key_type& k);
282 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant557da862011-06-04 20:18:37 +0000283 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000284
Howard Hinnant557da862011-06-04 20:18:37 +0000285 void swap(unordered_multiset&)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000286 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
287 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
288 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnant3e519522010-05-11 19:42:16 +0000289
290 hasher hash_function() const;
291 key_equal key_eq() const;
292
293 iterator find(const key_type& k);
294 const_iterator find(const key_type& k) const;
295 size_type count(const key_type& k) const;
296 pair<iterator, iterator> equal_range(const key_type& k);
297 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
298
Howard Hinnant557da862011-06-04 20:18:37 +0000299 size_type bucket_count() const noexcept;
300 size_type max_bucket_count() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000301
302 size_type bucket_size(size_type n) const;
303 size_type bucket(const key_type& k) const;
304
305 local_iterator begin(size_type n);
306 local_iterator end(size_type n);
307 const_local_iterator begin(size_type n) const;
308 const_local_iterator end(size_type n) const;
309 const_local_iterator cbegin(size_type n) const;
310 const_local_iterator cend(size_type n) const;
311
Howard Hinnant557da862011-06-04 20:18:37 +0000312 float load_factor() const noexcept;
313 float max_load_factor() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000314 void max_load_factor(float z);
315 void rehash(size_type n);
316 void reserve(size_type n);
317};
318
319template <class Value, class Hash, class Pred, class Alloc>
320 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant557da862011-06-04 20:18:37 +0000321 unordered_multiset<Value, Hash, Pred, Alloc>& y)
322 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000323
324template <class Value, class Hash, class Pred, class Alloc>
325 bool
326 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
327 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
328
329template <class Value, class Hash, class Pred, class Alloc>
330 bool
331 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
332 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
333} // std
334
335*/
336
337#include <__config>
338#include <__hash_table>
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000339#include <__node_handle>
Howard Hinnant3e519522010-05-11 19:42:16 +0000340#include <functional>
Marshall Clowf56972e2018-09-12 19:41:40 +0000341#include <version>
Howard Hinnant3e519522010-05-11 19:42:16 +0000342
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000343#include <__debug>
344
Howard Hinnant073458b2011-10-17 20:05:10 +0000345#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000346#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000347#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000348
349_LIBCPP_BEGIN_NAMESPACE_STD
350
351template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
352 class _Alloc = allocator<_Value> >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000353class _LIBCPP_TEMPLATE_VIS unordered_set
Howard Hinnant3e519522010-05-11 19:42:16 +0000354{
355public:
356 // types
357 typedef _Value key_type;
358 typedef key_type value_type;
359 typedef _Hash hasher;
360 typedef _Pred key_equal;
361 typedef _Alloc allocator_type;
362 typedef value_type& reference;
363 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000364 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
365 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000366
367private:
368 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
369
370 __table __table_;
371
372public:
373 typedef typename __table::pointer pointer;
374 typedef typename __table::const_pointer const_pointer;
375 typedef typename __table::size_type size_type;
376 typedef typename __table::difference_type difference_type;
377
378 typedef typename __table::const_iterator iterator;
379 typedef typename __table::const_iterator const_iterator;
380 typedef typename __table::const_local_iterator local_iterator;
381 typedef typename __table::const_local_iterator const_local_iterator;
382
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000383#if _LIBCPP_STD_VER > 14
384 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
385 typedef __insert_return_type<iterator, node_type> insert_return_type;
386#endif
387
Howard Hinnant789847d2010-09-23 18:58:28 +0000388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000389 unordered_set()
390 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000391 {
392#if _LIBCPP_DEBUG_LEVEL >= 2
393 __get_db()->__insert_c(this);
394#endif
395 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000396 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
397 const key_equal& __eql = key_equal());
Marshall Clow45b983c2013-09-30 21:33:51 +0000398#if _LIBCPP_STD_VER > 11
399 inline _LIBCPP_INLINE_VISIBILITY
400 unordered_set(size_type __n, const allocator_type& __a)
401 : unordered_set(__n, hasher(), key_equal(), __a) {}
402 inline _LIBCPP_INLINE_VISIBILITY
403 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
404 : unordered_set(__n, __hf, key_equal(), __a) {}
405#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000406 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
407 const allocator_type& __a);
408 template <class _InputIterator>
409 unordered_set(_InputIterator __first, _InputIterator __last);
410 template <class _InputIterator>
411 unordered_set(_InputIterator __first, _InputIterator __last,
412 size_type __n, const hasher& __hf = hasher(),
413 const key_equal& __eql = key_equal());
414 template <class _InputIterator>
415 unordered_set(_InputIterator __first, _InputIterator __last,
416 size_type __n, const hasher& __hf, const key_equal& __eql,
417 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000418#if _LIBCPP_STD_VER > 11
419 template <class _InputIterator>
420 inline _LIBCPP_INLINE_VISIBILITY
421 unordered_set(_InputIterator __first, _InputIterator __last,
422 size_type __n, const allocator_type& __a)
423 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
424 template <class _InputIterator>
425 unordered_set(_InputIterator __first, _InputIterator __last,
426 size_type __n, const hasher& __hf, const allocator_type& __a)
427 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
428#endif
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000430 explicit unordered_set(const allocator_type& __a);
431 unordered_set(const unordered_set& __u);
432 unordered_set(const unordered_set& __u, const allocator_type& __a);
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000433#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000435 unordered_set(unordered_set&& __u)
436 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000437 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +0000438 unordered_set(initializer_list<value_type> __il);
439 unordered_set(initializer_list<value_type> __il, size_type __n,
440 const hasher& __hf = hasher(),
441 const key_equal& __eql = key_equal());
442 unordered_set(initializer_list<value_type> __il, size_type __n,
443 const hasher& __hf, const key_equal& __eql,
444 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000445#if _LIBCPP_STD_VER > 11
446 inline _LIBCPP_INLINE_VISIBILITY
447 unordered_set(initializer_list<value_type> __il, size_type __n,
448 const allocator_type& __a)
449 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
450 inline _LIBCPP_INLINE_VISIBILITY
451 unordered_set(initializer_list<value_type> __il, size_type __n,
452 const hasher& __hf, const allocator_type& __a)
453 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
454#endif
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000455#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000456 // ~unordered_set() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +0000457 _LIBCPP_INLINE_VISIBILITY
458 unordered_set& operator=(const unordered_set& __u)
459 {
460 __table_ = __u.__table_;
461 return *this;
462 }
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000463#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000465 unordered_set& operator=(unordered_set&& __u)
466 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000468 unordered_set& operator=(initializer_list<value_type> __il);
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000469#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000470
Howard Hinnant789847d2010-09-23 18:58:28 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000472 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000473 {return allocator_type(__table_.__node_alloc());}
474
Marshall Clow72c8fad2017-11-15 05:51:26 +0000475 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000476 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000478 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000480 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000481
Howard Hinnant789847d2010-09-23 18:58:28 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000483 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000485 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000487 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000489 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000491 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000493 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000494
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000495#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000496 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000498 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +0000499 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000500 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +0000501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000502#if _LIBCPP_DEBUG_LEVEL >= 2
503 iterator emplace_hint(const_iterator __p, _Args&&... __args)
504 {
505 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
506 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
507 " referring to this unordered_set");
508 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
509 }
510#else
Howard Hinnant3e519522010-05-11 19:42:16 +0000511 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +0000512 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000513#endif
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000514
Howard Hinnant789847d2010-09-23 18:58:28 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000516 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +0000517 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnant789847d2010-09-23 18:58:28 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb24c8022013-07-23 22:01:58 +0000519#if _LIBCPP_DEBUG_LEVEL >= 2
520 iterator insert(const_iterator __p, value_type&& __x)
521 {
522 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
523 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
524 " referring to this unordered_set");
525 return insert(_VSTD::move(__x)).first;
526 }
527#else
Howard Hinnant3e519522010-05-11 19:42:16 +0000528 iterator insert(const_iterator, value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +0000529 {return insert(_VSTD::move(__x)).first;}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000530#endif
Howard Hinnant789847d2010-09-23 18:58:28 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000532 void insert(initializer_list<value_type> __il)
533 {insert(__il.begin(), __il.end());}
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000534#endif // _LIBCPP_CXX03_LANG
535 _LIBCPP_INLINE_VISIBILITY
536 pair<iterator, bool> insert(const value_type& __x)
537 {return __table_.__insert_unique(__x);}
538
539 _LIBCPP_INLINE_VISIBILITY
540#if _LIBCPP_DEBUG_LEVEL >= 2
541 iterator insert(const_iterator __p, const value_type& __x)
542 {
543 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
544 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
545 " referring to this unordered_set");
546 return insert(__x).first;
547 }
548#else
549 iterator insert(const_iterator, const value_type& __x)
550 {return insert(__x).first;}
551#endif
552 template <class _InputIterator>
553 _LIBCPP_INLINE_VISIBILITY
554 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant3e519522010-05-11 19:42:16 +0000555
Howard Hinnant789847d2010-09-23 18:58:28 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000557 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000559 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000561 iterator erase(const_iterator __first, const_iterator __last)
562 {return __table_.erase(__first, __last);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000564 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000565
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000566#if _LIBCPP_STD_VER > 14
567 _LIBCPP_INLINE_VISIBILITY
568 insert_return_type insert(node_type&& __nh)
569 {
570 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
571 "node_type with incompatible allocator passed to unordered_set::insert()");
572 return __table_.template __node_handle_insert_unique<
573 node_type, insert_return_type>(_VSTD::move(__nh));
574 }
575 _LIBCPP_INLINE_VISIBILITY
576 iterator insert(const_iterator __h, node_type&& __nh)
577 {
578 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
579 "node_type with incompatible allocator passed to unordered_set::insert()");
580 return __table_.template __node_handle_insert_unique<node_type>(
581 __h, _VSTD::move(__nh));
582 }
583 _LIBCPP_INLINE_VISIBILITY
584 node_type extract(key_type const& __key)
585 {
586 return __table_.template __node_handle_extract<node_type>(__key);
587 }
588 _LIBCPP_INLINE_VISIBILITY
589 node_type extract(const_iterator __it)
590 {
591 return __table_.template __node_handle_extract<node_type>(__it);
592 }
593#endif
594
Howard Hinnant789847d2010-09-23 18:58:28 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000596 void swap(unordered_set& __u)
597 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
598 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000599
Howard Hinnant789847d2010-09-23 18:58:28 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000601 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 key_equal key_eq() const {return __table_.key_eq();}
604
Howard Hinnant789847d2010-09-23 18:58:28 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000606 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000608 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000610 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000612 pair<iterator, iterator> equal_range(const key_type& __k)
613 {return __table_.__equal_range_unique(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000615 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
616 {return __table_.__equal_range_unique(__k);}
617
Howard Hinnant789847d2010-09-23 18:58:28 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000619 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000621 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000622
Howard Hinnant789847d2010-09-23 18:58:28 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000624 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000626 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
627
Howard Hinnant789847d2010-09-23 18:58:28 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000629 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000631 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000633 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000635 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000637 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000639 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
640
Howard Hinnant789847d2010-09-23 18:58:28 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000642 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000644 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000646 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000648 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000650 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnantb24c8022013-07-23 22:01:58 +0000651
652#if _LIBCPP_DEBUG_LEVEL >= 2
653
654 bool __dereferenceable(const const_iterator* __i) const
655 {return __table_.__dereferenceable(__i);}
656 bool __decrementable(const const_iterator* __i) const
657 {return __table_.__decrementable(__i);}
658 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
659 {return __table_.__addable(__i, __n);}
660 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
661 {return __table_.__addable(__i, __n);}
662
663#endif // _LIBCPP_DEBUG_LEVEL >= 2
664
Howard Hinnant3e519522010-05-11 19:42:16 +0000665};
666
667template <class _Value, class _Hash, class _Pred, class _Alloc>
668unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
669 const hasher& __hf, const key_equal& __eql)
670 : __table_(__hf, __eql)
671{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000672#if _LIBCPP_DEBUG_LEVEL >= 2
673 __get_db()->__insert_c(this);
674#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000675 __table_.rehash(__n);
676}
677
678template <class _Value, class _Hash, class _Pred, class _Alloc>
679unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
680 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
681 : __table_(__hf, __eql, __a)
682{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000683#if _LIBCPP_DEBUG_LEVEL >= 2
684 __get_db()->__insert_c(this);
685#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000686 __table_.rehash(__n);
687}
688
689template <class _Value, class _Hash, class _Pred, class _Alloc>
690template <class _InputIterator>
691unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
692 _InputIterator __first, _InputIterator __last)
693{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000694#if _LIBCPP_DEBUG_LEVEL >= 2
695 __get_db()->__insert_c(this);
696#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000697 insert(__first, __last);
698}
699
700template <class _Value, class _Hash, class _Pred, class _Alloc>
701template <class _InputIterator>
702unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
703 _InputIterator __first, _InputIterator __last, size_type __n,
704 const hasher& __hf, const key_equal& __eql)
705 : __table_(__hf, __eql)
706{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000707#if _LIBCPP_DEBUG_LEVEL >= 2
708 __get_db()->__insert_c(this);
709#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000710 __table_.rehash(__n);
711 insert(__first, __last);
712}
713
714template <class _Value, class _Hash, class _Pred, class _Alloc>
715template <class _InputIterator>
716unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
717 _InputIterator __first, _InputIterator __last, size_type __n,
718 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
719 : __table_(__hf, __eql, __a)
720{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000721#if _LIBCPP_DEBUG_LEVEL >= 2
722 __get_db()->__insert_c(this);
723#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000724 __table_.rehash(__n);
725 insert(__first, __last);
726}
727
728template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000729inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000730unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
731 const allocator_type& __a)
732 : __table_(__a)
733{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000734#if _LIBCPP_DEBUG_LEVEL >= 2
735 __get_db()->__insert_c(this);
736#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000737}
738
739template <class _Value, class _Hash, class _Pred, class _Alloc>
740unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
741 const unordered_set& __u)
742 : __table_(__u.__table_)
743{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000744#if _LIBCPP_DEBUG_LEVEL >= 2
745 __get_db()->__insert_c(this);
746#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000747 __table_.rehash(__u.bucket_count());
748 insert(__u.begin(), __u.end());
749}
750
751template <class _Value, class _Hash, class _Pred, class _Alloc>
752unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
753 const unordered_set& __u, const allocator_type& __a)
754 : __table_(__u.__table_, __a)
755{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000756#if _LIBCPP_DEBUG_LEVEL >= 2
757 __get_db()->__insert_c(this);
758#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000759 __table_.rehash(__u.bucket_count());
760 insert(__u.begin(), __u.end());
761}
762
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000763#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000764
765template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000766inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000767unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
768 unordered_set&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +0000769 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000770 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000771{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000772#if _LIBCPP_DEBUG_LEVEL >= 2
773 __get_db()->__insert_c(this);
774 __get_db()->swap(this, &__u);
775#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000776}
777
778template <class _Value, class _Hash, class _Pred, class _Alloc>
779unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
780 unordered_set&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000781 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000782{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000783#if _LIBCPP_DEBUG_LEVEL >= 2
784 __get_db()->__insert_c(this);
785#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000786 if (__a != __u.get_allocator())
787 {
788 iterator __i = __u.begin();
789 while (__u.size() != 0)
Howard Hinnantce48a112011-06-30 21:18:19 +0000790 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000791 }
Howard Hinnantb24c8022013-07-23 22:01:58 +0000792#if _LIBCPP_DEBUG_LEVEL >= 2
793 else
794 __get_db()->swap(this, &__u);
795#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000796}
797
Howard Hinnant3e519522010-05-11 19:42:16 +0000798template <class _Value, class _Hash, class _Pred, class _Alloc>
799unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
800 initializer_list<value_type> __il)
801{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000802#if _LIBCPP_DEBUG_LEVEL >= 2
803 __get_db()->__insert_c(this);
804#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000805 insert(__il.begin(), __il.end());
806}
807
808template <class _Value, class _Hash, class _Pred, class _Alloc>
809unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
810 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
811 const key_equal& __eql)
812 : __table_(__hf, __eql)
813{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000814#if _LIBCPP_DEBUG_LEVEL >= 2
815 __get_db()->__insert_c(this);
816#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000817 __table_.rehash(__n);
818 insert(__il.begin(), __il.end());
819}
820
821template <class _Value, class _Hash, class _Pred, class _Alloc>
822unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
823 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
824 const key_equal& __eql, const allocator_type& __a)
825 : __table_(__hf, __eql, __a)
826{
Howard Hinnantb24c8022013-07-23 22:01:58 +0000827#if _LIBCPP_DEBUG_LEVEL >= 2
828 __get_db()->__insert_c(this);
829#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000830 __table_.rehash(__n);
831 insert(__il.begin(), __il.end());
832}
833
Howard Hinnant3e519522010-05-11 19:42:16 +0000834template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000835inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000836unordered_set<_Value, _Hash, _Pred, _Alloc>&
837unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +0000838 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000839{
Howard Hinnantce48a112011-06-30 21:18:19 +0000840 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +0000841 return *this;
842}
843
Howard Hinnant3e519522010-05-11 19:42:16 +0000844template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000845inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000846unordered_set<_Value, _Hash, _Pred, _Alloc>&
847unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
848 initializer_list<value_type> __il)
849{
850 __table_.__assign_unique(__il.begin(), __il.end());
851 return *this;
852}
853
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000854#endif // _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +0000855
Howard Hinnant3e519522010-05-11 19:42:16 +0000856template <class _Value, class _Hash, class _Pred, class _Alloc>
857template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000858inline
Howard Hinnant3e519522010-05-11 19:42:16 +0000859void
860unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
861 _InputIterator __last)
862{
863 for (; __first != __last; ++__first)
864 __table_.__insert_unique(*__first);
865}
866
867template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +0000868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000869void
870swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
871 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant557da862011-06-04 20:18:37 +0000872 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +0000873{
874 __x.swap(__y);
875}
876
877template <class _Value, class _Hash, class _Pred, class _Alloc>
878bool
879operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
880 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
881{
882 if (__x.size() != __y.size())
883 return false;
884 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
885 const_iterator;
886 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
887 __i != __ex; ++__i)
888 {
889 const_iterator __j = __y.find(*__i);
890 if (__j == __ey || !(*__i == *__j))
891 return false;
892 }
893 return true;
894}
895
896template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +0000897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000898bool
899operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
900 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
901{
902 return !(__x == __y);
903}
904
905template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
906 class _Alloc = allocator<_Value> >
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000907class _LIBCPP_TEMPLATE_VIS unordered_multiset
Howard Hinnant3e519522010-05-11 19:42:16 +0000908{
909public:
910 // types
911 typedef _Value key_type;
912 typedef key_type value_type;
913 typedef _Hash hasher;
914 typedef _Pred key_equal;
915 typedef _Alloc allocator_type;
916 typedef value_type& reference;
917 typedef const value_type& const_reference;
Howard Hinnantb24c8022013-07-23 22:01:58 +0000918 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
919 "Invalid allocator::value_type");
Howard Hinnant3e519522010-05-11 19:42:16 +0000920
921private:
922 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
923
924 __table __table_;
925
926public:
927 typedef typename __table::pointer pointer;
928 typedef typename __table::const_pointer const_pointer;
929 typedef typename __table::size_type size_type;
930 typedef typename __table::difference_type difference_type;
931
932 typedef typename __table::const_iterator iterator;
933 typedef typename __table::const_iterator const_iterator;
934 typedef typename __table::const_local_iterator local_iterator;
935 typedef typename __table::const_local_iterator const_local_iterator;
936
Erik Pilkingtonb0386a52018-08-01 01:33:38 +0000937#if _LIBCPP_STD_VER > 14
938 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
939#endif
940
Howard Hinnant789847d2010-09-23 18:58:28 +0000941 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000942 unordered_multiset()
943 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnantb24c8022013-07-23 22:01:58 +0000944 {
945#if _LIBCPP_DEBUG_LEVEL >= 2
946 __get_db()->__insert_c(this);
947#endif
948 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000949 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
950 const key_equal& __eql = key_equal());
951 unordered_multiset(size_type __n, const hasher& __hf,
952 const key_equal& __eql, const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000953#if _LIBCPP_STD_VER > 11
954 inline _LIBCPP_INLINE_VISIBILITY
955 unordered_multiset(size_type __n, const allocator_type& __a)
956 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
957 inline _LIBCPP_INLINE_VISIBILITY
958 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
959 : unordered_multiset(__n, __hf, key_equal(), __a) {}
960#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000961 template <class _InputIterator>
962 unordered_multiset(_InputIterator __first, _InputIterator __last);
963 template <class _InputIterator>
964 unordered_multiset(_InputIterator __first, _InputIterator __last,
965 size_type __n, const hasher& __hf = hasher(),
966 const key_equal& __eql = key_equal());
967 template <class _InputIterator>
968 unordered_multiset(_InputIterator __first, _InputIterator __last,
969 size_type __n , const hasher& __hf,
970 const key_equal& __eql, const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000971#if _LIBCPP_STD_VER > 11
972 template <class _InputIterator>
973 inline _LIBCPP_INLINE_VISIBILITY
974 unordered_multiset(_InputIterator __first, _InputIterator __last,
975 size_type __n, const allocator_type& __a)
976 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
977 template <class _InputIterator>
978 inline _LIBCPP_INLINE_VISIBILITY
979 unordered_multiset(_InputIterator __first, _InputIterator __last,
980 size_type __n, const hasher& __hf, const allocator_type& __a)
981 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
982#endif
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000984 explicit unordered_multiset(const allocator_type& __a);
985 unordered_multiset(const unordered_multiset& __u);
986 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Eric Fiselierf0f86ef2017-04-18 22:37:32 +0000987#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +0000989 unordered_multiset(unordered_multiset&& __u)
990 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000991 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnant3e519522010-05-11 19:42:16 +0000992 unordered_multiset(initializer_list<value_type> __il);
993 unordered_multiset(initializer_list<value_type> __il, size_type __n,
994 const hasher& __hf = hasher(),
995 const key_equal& __eql = key_equal());
996 unordered_multiset(initializer_list<value_type> __il, size_type __n,
997 const hasher& __hf, const key_equal& __eql,
998 const allocator_type& __a);
Marshall Clow45b983c2013-09-30 21:33:51 +0000999#if _LIBCPP_STD_VER > 11
1000 inline _LIBCPP_INLINE_VISIBILITY
1001 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1002 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
1003 inline _LIBCPP_INLINE_VISIBILITY
1004 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
1005 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1006#endif
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001007#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001008 // ~unordered_multiset() = default;
Howard Hinnant5a336872011-07-01 19:24:36 +00001009 _LIBCPP_INLINE_VISIBILITY
1010 unordered_multiset& operator=(const unordered_multiset& __u)
1011 {
1012 __table_ = __u.__table_;
1013 return *this;
1014 }
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001015#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001017 unordered_multiset& operator=(unordered_multiset&& __u)
1018 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001019 unordered_multiset& operator=(initializer_list<value_type> __il);
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001020#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001021
Howard Hinnant789847d2010-09-23 18:58:28 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001023 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001024 {return allocator_type(__table_.__node_alloc());}
1025
Marshall Clow72c8fad2017-11-15 05:51:26 +00001026 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001027 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnant789847d2010-09-23 18:58:28 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001029 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001031 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001032
Howard Hinnant789847d2010-09-23 18:58:28 +00001033 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001034 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001036 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001038 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001040 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001042 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001044 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001045
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001046#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001047 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001049 iterator emplace(_Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +00001050 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001051 template <class... _Args>
Howard Hinnant789847d2010-09-23 18:58:28 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001053 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:19 +00001054 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001055
Howard Hinnant789847d2010-09-23 18:58:28 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantce48a112011-06-30 21:18:19 +00001057 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnant789847d2010-09-23 18:58:28 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001059 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnantce48a112011-06-30 21:18:19 +00001060 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnant789847d2010-09-23 18:58:28 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001062 void insert(initializer_list<value_type> __il)
1063 {insert(__il.begin(), __il.end());}
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001064#endif // _LIBCPP_CXX03_LANG
1065
1066 _LIBCPP_INLINE_VISIBILITY
1067 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1068
1069 _LIBCPP_INLINE_VISIBILITY
1070 iterator insert(const_iterator __p, const value_type& __x)
1071 {return __table_.__insert_multi(__p, __x);}
1072
1073 template <class _InputIterator>
1074 _LIBCPP_INLINE_VISIBILITY
1075 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnant3e519522010-05-11 19:42:16 +00001076
Erik Pilkingtonb0386a52018-08-01 01:33:38 +00001077#if _LIBCPP_STD_VER > 14
1078 _LIBCPP_INLINE_VISIBILITY
1079 iterator insert(node_type&& __nh)
1080 {
1081 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1082 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1083 return __table_.template __node_handle_insert_multi<node_type>(
1084 _VSTD::move(__nh));
1085 }
1086 _LIBCPP_INLINE_VISIBILITY
1087 iterator insert(const_iterator __hint, node_type&& __nh)
1088 {
1089 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1090 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1091 return __table_.template __node_handle_insert_multi<node_type>(
1092 __hint, _VSTD::move(__nh));
1093 }
1094 _LIBCPP_INLINE_VISIBILITY
1095 node_type extract(const_iterator __position)
1096 {
1097 return __table_.template __node_handle_extract<node_type>(
1098 __position);
1099 }
1100 _LIBCPP_INLINE_VISIBILITY
1101 node_type extract(key_type const& __key)
1102 {
1103 return __table_.template __node_handle_extract<node_type>(__key);
1104 }
1105#endif
1106
Howard Hinnant789847d2010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001108 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001110 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001112 iterator erase(const_iterator __first, const_iterator __last)
1113 {return __table_.erase(__first, __last);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001115 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001116
Howard Hinnant789847d2010-09-23 18:58:28 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001118 void swap(unordered_multiset& __u)
1119 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1120 {__table_.swap(__u.__table_);}
Howard Hinnant3e519522010-05-11 19:42:16 +00001121
Howard Hinnant789847d2010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001123 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001125 key_equal key_eq() const {return __table_.key_eq();}
1126
Howard Hinnant789847d2010-09-23 18:58:28 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001128 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001130 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001132 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001134 pair<iterator, iterator> equal_range(const key_type& __k)
1135 {return __table_.__equal_range_multi(__k);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001137 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1138 {return __table_.__equal_range_multi(__k);}
1139
Howard Hinnant789847d2010-09-23 18:58:28 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001141 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001143 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnant3e519522010-05-11 19:42:16 +00001144
Howard Hinnant789847d2010-09-23 18:58:28 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001146 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001148 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1149
Howard Hinnant789847d2010-09-23 18:58:28 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001151 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001153 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001155 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001157 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001159 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001161 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1162
Howard Hinnant789847d2010-09-23 18:58:28 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001164 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant557da862011-06-04 20:18:37 +00001166 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnant789847d2010-09-23 18:58:28 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001168 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001170 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnant789847d2010-09-23 18:58:28 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001172 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnantb24c8022013-07-23 22:01:58 +00001173
1174#if _LIBCPP_DEBUG_LEVEL >= 2
1175
1176 bool __dereferenceable(const const_iterator* __i) const
1177 {return __table_.__dereferenceable(__i);}
1178 bool __decrementable(const const_iterator* __i) const
1179 {return __table_.__decrementable(__i);}
1180 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1181 {return __table_.__addable(__i, __n);}
1182 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1183 {return __table_.__addable(__i, __n);}
1184
1185#endif // _LIBCPP_DEBUG_LEVEL >= 2
1186
Howard Hinnant3e519522010-05-11 19:42:16 +00001187};
1188
1189template <class _Value, class _Hash, class _Pred, class _Alloc>
1190unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1191 size_type __n, const hasher& __hf, const key_equal& __eql)
1192 : __table_(__hf, __eql)
1193{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001194#if _LIBCPP_DEBUG_LEVEL >= 2
1195 __get_db()->__insert_c(this);
1196#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001197 __table_.rehash(__n);
1198}
1199
1200template <class _Value, class _Hash, class _Pred, class _Alloc>
1201unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1202 size_type __n, const hasher& __hf, const key_equal& __eql,
1203 const allocator_type& __a)
1204 : __table_(__hf, __eql, __a)
1205{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001206#if _LIBCPP_DEBUG_LEVEL >= 2
1207 __get_db()->__insert_c(this);
1208#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001209 __table_.rehash(__n);
1210}
1211
1212template <class _Value, class _Hash, class _Pred, class _Alloc>
1213template <class _InputIterator>
1214unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1215 _InputIterator __first, _InputIterator __last)
1216{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001217#if _LIBCPP_DEBUG_LEVEL >= 2
1218 __get_db()->__insert_c(this);
1219#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001220 insert(__first, __last);
1221}
1222
1223template <class _Value, class _Hash, class _Pred, class _Alloc>
1224template <class _InputIterator>
1225unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1226 _InputIterator __first, _InputIterator __last, size_type __n,
1227 const hasher& __hf, const key_equal& __eql)
1228 : __table_(__hf, __eql)
1229{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001230#if _LIBCPP_DEBUG_LEVEL >= 2
1231 __get_db()->__insert_c(this);
1232#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001233 __table_.rehash(__n);
1234 insert(__first, __last);
1235}
1236
1237template <class _Value, class _Hash, class _Pred, class _Alloc>
1238template <class _InputIterator>
1239unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1240 _InputIterator __first, _InputIterator __last, size_type __n,
1241 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1242 : __table_(__hf, __eql, __a)
1243{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001244#if _LIBCPP_DEBUG_LEVEL >= 2
1245 __get_db()->__insert_c(this);
1246#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001247 __table_.rehash(__n);
1248 insert(__first, __last);
1249}
1250
1251template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001252inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001253unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1254 const allocator_type& __a)
1255 : __table_(__a)
1256{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001257#if _LIBCPP_DEBUG_LEVEL >= 2
1258 __get_db()->__insert_c(this);
1259#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001260}
1261
1262template <class _Value, class _Hash, class _Pred, class _Alloc>
1263unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1264 const unordered_multiset& __u)
1265 : __table_(__u.__table_)
1266{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001267#if _LIBCPP_DEBUG_LEVEL >= 2
1268 __get_db()->__insert_c(this);
1269#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001270 __table_.rehash(__u.bucket_count());
1271 insert(__u.begin(), __u.end());
1272}
1273
1274template <class _Value, class _Hash, class _Pred, class _Alloc>
1275unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1276 const unordered_multiset& __u, const allocator_type& __a)
1277 : __table_(__u.__table_, __a)
1278{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001279#if _LIBCPP_DEBUG_LEVEL >= 2
1280 __get_db()->__insert_c(this);
1281#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001282 __table_.rehash(__u.bucket_count());
1283 insert(__u.begin(), __u.end());
1284}
1285
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001286#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +00001287
1288template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001289inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001290unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1291 unordered_multiset&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +00001292 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001293 : __table_(_VSTD::move(__u.__table_))
Howard Hinnant3e519522010-05-11 19:42:16 +00001294{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001295#if _LIBCPP_DEBUG_LEVEL >= 2
1296 __get_db()->__insert_c(this);
1297 __get_db()->swap(this, &__u);
1298#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001299}
1300
1301template <class _Value, class _Hash, class _Pred, class _Alloc>
1302unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1303 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +00001304 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +00001305{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001306#if _LIBCPP_DEBUG_LEVEL >= 2
1307 __get_db()->__insert_c(this);
1308#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001309 if (__a != __u.get_allocator())
1310 {
1311 iterator __i = __u.begin();
1312 while (__u.size() != 0)
Howard Hinnantce48a112011-06-30 21:18:19 +00001313 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001314 }
Howard Hinnantb24c8022013-07-23 22:01:58 +00001315#if _LIBCPP_DEBUG_LEVEL >= 2
1316 else
1317 __get_db()->swap(this, &__u);
1318#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001319}
1320
Howard Hinnant3e519522010-05-11 19:42:16 +00001321template <class _Value, class _Hash, class _Pred, class _Alloc>
1322unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1323 initializer_list<value_type> __il)
1324{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001325#if _LIBCPP_DEBUG_LEVEL >= 2
1326 __get_db()->__insert_c(this);
1327#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001328 insert(__il.begin(), __il.end());
1329}
1330
1331template <class _Value, class _Hash, class _Pred, class _Alloc>
1332unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1333 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1334 const key_equal& __eql)
1335 : __table_(__hf, __eql)
1336{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001337#if _LIBCPP_DEBUG_LEVEL >= 2
1338 __get_db()->__insert_c(this);
1339#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001340 __table_.rehash(__n);
1341 insert(__il.begin(), __il.end());
1342}
1343
1344template <class _Value, class _Hash, class _Pred, class _Alloc>
1345unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1346 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1347 const key_equal& __eql, const allocator_type& __a)
1348 : __table_(__hf, __eql, __a)
1349{
Howard Hinnantb24c8022013-07-23 22:01:58 +00001350#if _LIBCPP_DEBUG_LEVEL >= 2
1351 __get_db()->__insert_c(this);
1352#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001353 __table_.rehash(__n);
1354 insert(__il.begin(), __il.end());
1355}
1356
Howard Hinnant3e519522010-05-11 19:42:16 +00001357template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001358inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001359unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1360unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1361 unordered_multiset&& __u)
Howard Hinnant557da862011-06-04 20:18:37 +00001362 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001363{
Howard Hinnantce48a112011-06-30 21:18:19 +00001364 __table_ = _VSTD::move(__u.__table_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001365 return *this;
1366}
1367
Howard Hinnant3e519522010-05-11 19:42:16 +00001368template <class _Value, class _Hash, class _Pred, class _Alloc>
1369inline
1370unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1371unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1372 initializer_list<value_type> __il)
1373{
1374 __table_.__assign_multi(__il.begin(), __il.end());
1375 return *this;
1376}
1377
Eric Fiselierf0f86ef2017-04-18 22:37:32 +00001378#endif // _LIBCPP_CXX03_LANG
Howard Hinnant54976f22011-08-12 21:56:02 +00001379
Howard Hinnant3e519522010-05-11 19:42:16 +00001380template <class _Value, class _Hash, class _Pred, class _Alloc>
1381template <class _InputIterator>
Evgeniy Stepanovcd31b432016-04-22 01:04:55 +00001382inline
Howard Hinnant3e519522010-05-11 19:42:16 +00001383void
1384unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1385 _InputIterator __last)
1386{
1387 for (; __first != __last; ++__first)
1388 __table_.__insert_multi(*__first);
1389}
1390
1391template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001393void
1394swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1395 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant557da862011-06-04 20:18:37 +00001396 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001397{
1398 __x.swap(__y);
1399}
1400
1401template <class _Value, class _Hash, class _Pred, class _Alloc>
1402bool
1403operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1404 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1405{
1406 if (__x.size() != __y.size())
1407 return false;
1408 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1409 const_iterator;
1410 typedef pair<const_iterator, const_iterator> _EqRng;
1411 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1412 {
1413 _EqRng __xeq = __x.equal_range(*__i);
1414 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnantce48a112011-06-30 21:18:19 +00001415 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1416 _VSTD::distance(__yeq.first, __yeq.second) ||
1417 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnant3e519522010-05-11 19:42:16 +00001418 return false;
1419 __i = __xeq.second;
1420 }
1421 return true;
1422}
1423
1424template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnant789847d2010-09-23 18:58:28 +00001425inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001426bool
1427operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1428 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1429{
1430 return !(__x == __y);
1431}
1432
1433_LIBCPP_END_NAMESPACE_STD
1434
1435#endif // _LIBCPP_UNORDERED_SET