blob: 68f777a4ea3eb203080f26d36930a206b01b0d66 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
3//
Chandler Carruth7c3769d2019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_UNORDERED_SET
11#define _LIBCPP_UNORDERED_SET
12
13/*
14
15 unordered_set synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
23 class Alloc = allocator<Value>>
24class unordered_set
25{
26public:
27 // types
28 typedef Value key_type;
29 typedef key_type value_type;
30 typedef Hash hasher;
31 typedef Pred key_equal;
32 typedef Alloc allocator_type;
33 typedef value_type& reference;
34 typedef const value_type& const_reference;
35 typedef typename allocator_traits<allocator_type>::pointer pointer;
36 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
37 typedef typename allocator_traits<allocator_type>::size_type size_type;
38 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
39
40 typedef /unspecified/ iterator;
41 typedef /unspecified/ const_iterator;
42 typedef /unspecified/ local_iterator;
43 typedef /unspecified/ const_local_iterator;
44
Erik Pilkington36fc7372018-08-01 01:33:38 +000045 typedef unspecified node_type unspecified; // C++17
46 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
47
Howard Hinnant04dae1d2011-06-04 20:18:37 +000048 unordered_set()
49 noexcept(
50 is_nothrow_default_constructible<hasher>::value &&
51 is_nothrow_default_constructible<key_equal>::value &&
52 is_nothrow_default_constructible<allocator_type>::value);
53 explicit unordered_set(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 const key_equal& eql = key_equal(),
55 const allocator_type& a = allocator_type());
56 template <class InputIterator>
57 unordered_set(InputIterator f, InputIterator l,
58 size_type n = 0, const hasher& hf = hasher(),
59 const key_equal& eql = key_equal(),
60 const allocator_type& a = allocator_type());
61 explicit unordered_set(const allocator_type&);
62 unordered_set(const unordered_set&);
63 unordered_set(const unordered_set&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000064 unordered_set(unordered_set&&)
65 noexcept(
66 is_nothrow_move_constructible<hasher>::value &&
67 is_nothrow_move_constructible<key_equal>::value &&
68 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069 unordered_set(unordered_set&&, const Allocator&);
70 unordered_set(initializer_list<value_type>, size_type n = 0,
71 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
72 const allocator_type& a = allocator_type());
Marshall Clowbd444af2013-09-30 21:33:51 +000073 unordered_set(size_type n, const allocator_type& a); // C++14
74 unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
75 template <class InputIterator>
76 unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
77 template <class InputIterator>
Louis Dionnec30e2d92019-05-29 16:01:36 +000078 unordered_set(InputIterator f, InputIterator l, size_type n,
Marshall Clowbd444af2013-09-30 21:33:51 +000079 const hasher& hf, const allocator_type& a); // C++14
80 unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
81 unordered_set(initializer_list<value_type> il, size_type n,
82 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083 ~unordered_set();
84 unordered_set& operator=(const unordered_set&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000085 unordered_set& operator=(unordered_set&&)
86 noexcept(
87 allocator_type::propagate_on_container_move_assignment::value &&
88 is_nothrow_move_assignable<allocator_type>::value &&
89 is_nothrow_move_assignable<hasher>::value &&
90 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000091 unordered_set& operator=(initializer_list<value_type>);
92
Howard Hinnant04dae1d2011-06-04 20:18:37 +000093 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094
Howard Hinnant04dae1d2011-06-04 20:18:37 +000095 bool empty() const noexcept;
96 size_type size() const noexcept;
97 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
Howard Hinnant04dae1d2011-06-04 20:18:37 +000099 iterator begin() noexcept;
100 iterator end() noexcept;
101 const_iterator begin() const noexcept;
102 const_iterator end() const noexcept;
103 const_iterator cbegin() const noexcept;
104 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000105
106 template <class... Args>
107 pair<iterator, bool> emplace(Args&&... args);
108 template <class... Args>
109 iterator emplace_hint(const_iterator position, Args&&... args);
110 pair<iterator, bool> insert(const value_type& obj);
111 pair<iterator, bool> insert(value_type&& obj);
112 iterator insert(const_iterator hint, const value_type& obj);
113 iterator insert(const_iterator hint, value_type&& obj);
114 template <class InputIterator>
115 void insert(InputIterator first, InputIterator last);
116 void insert(initializer_list<value_type>);
117
Erik Pilkington36fc7372018-08-01 01:33:38 +0000118 node_type extract(const_iterator position); // C++17
119 node_type extract(const key_type& x); // C++17
120 insert_return_type insert(node_type&& nh); // C++17
121 iterator insert(const_iterator hint, node_type&& nh); // C++17
122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000124 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000125 size_type erase(const key_type& k);
126 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000127 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000129 template<class H2, class P2>
130 void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
131 template<class H2, class P2>
132 void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
133 template<class H2, class P2>
134 void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
135 template<class H2, class P2>
136 void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
137
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000138 void swap(unordered_set&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000139 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
140 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
141 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000142
143 hasher hash_function() const;
144 key_equal key_eq() const;
145
146 iterator find(const key_type& k);
147 const_iterator find(const key_type& k) const;
148 size_type count(const key_type& k) const;
Zoe Carver3f39fe32019-07-16 03:21:01 +0000149 bool contains(const key_type& k) const; // C++20
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150 pair<iterator, iterator> equal_range(const key_type& k);
151 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
152
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000153 size_type bucket_count() const noexcept;
154 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155
156 size_type bucket_size(size_type n) const;
157 size_type bucket(const key_type& k) const;
158
159 local_iterator begin(size_type n);
160 local_iterator end(size_type n);
161 const_local_iterator begin(size_type n) const;
162 const_local_iterator end(size_type n) const;
163 const_local_iterator cbegin(size_type n) const;
164 const_local_iterator cend(size_type n) const;
165
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000166 float load_factor() const noexcept;
167 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000168 void max_load_factor(float z);
169 void rehash(size_type n);
170 void reserve(size_type n);
171};
172
173template <class Value, class Hash, class Pred, class Alloc>
174 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000175 unordered_set<Value, Hash, Pred, Alloc>& y)
176 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177
178template <class Value, class Hash, class Pred, class Alloc>
179 bool
180 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
181 const unordered_set<Value, Hash, Pred, Alloc>& y);
182
183template <class Value, class Hash, class Pred, class Alloc>
184 bool
185 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
186 const unordered_set<Value, Hash, Pred, Alloc>& y);
187
188template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
189 class Alloc = allocator<Value>>
190class unordered_multiset
191{
192public:
193 // types
194 typedef Value key_type;
195 typedef key_type value_type;
196 typedef Hash hasher;
197 typedef Pred key_equal;
198 typedef Alloc allocator_type;
199 typedef value_type& reference;
200 typedef const value_type& const_reference;
201 typedef typename allocator_traits<allocator_type>::pointer pointer;
202 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
203 typedef typename allocator_traits<allocator_type>::size_type size_type;
204 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
205
206 typedef /unspecified/ iterator;
207 typedef /unspecified/ const_iterator;
208 typedef /unspecified/ local_iterator;
209 typedef /unspecified/ const_local_iterator;
210
Erik Pilkington36fc7372018-08-01 01:33:38 +0000211 typedef unspecified node_type unspecified; // C++17
212
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000213 unordered_multiset()
214 noexcept(
215 is_nothrow_default_constructible<hasher>::value &&
216 is_nothrow_default_constructible<key_equal>::value &&
217 is_nothrow_default_constructible<allocator_type>::value);
218 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000219 const key_equal& eql = key_equal(),
220 const allocator_type& a = allocator_type());
221 template <class InputIterator>
222 unordered_multiset(InputIterator f, InputIterator l,
223 size_type n = 0, const hasher& hf = hasher(),
224 const key_equal& eql = key_equal(),
225 const allocator_type& a = allocator_type());
226 explicit unordered_multiset(const allocator_type&);
227 unordered_multiset(const unordered_multiset&);
228 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000229 unordered_multiset(unordered_multiset&&)
230 noexcept(
231 is_nothrow_move_constructible<hasher>::value &&
232 is_nothrow_move_constructible<key_equal>::value &&
233 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234 unordered_multiset(unordered_multiset&&, const Allocator&);
235 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
236 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
237 const allocator_type& a = allocator_type());
Marshall Clowbd444af2013-09-30 21:33:51 +0000238 unordered_multiset(size_type n, const allocator_type& a); // C++14
239 unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
240 template <class InputIterator>
241 unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
242 template <class InputIterator>
243 unordered_multiset(InputIterator f, InputIterator l, size_type n,
244 const hasher& hf, const allocator_type& a); // C++14
245 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
Louis Dionnec30e2d92019-05-29 16:01:36 +0000246 unordered_multiset(initializer_list<value_type> il, size_type n,
Marshall Clowbd444af2013-09-30 21:33:51 +0000247 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248 ~unordered_multiset();
249 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000250 unordered_multiset& operator=(unordered_multiset&&)
251 noexcept(
252 allocator_type::propagate_on_container_move_assignment::value &&
253 is_nothrow_move_assignable<allocator_type>::value &&
254 is_nothrow_move_assignable<hasher>::value &&
255 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 unordered_multiset& operator=(initializer_list<value_type>);
257
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000258 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000260 bool empty() const noexcept;
261 size_type size() const noexcept;
262 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000264 iterator begin() noexcept;
265 iterator end() noexcept;
266 const_iterator begin() const noexcept;
267 const_iterator end() const noexcept;
268 const_iterator cbegin() const noexcept;
269 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
271 template <class... Args>
272 iterator emplace(Args&&... args);
273 template <class... Args>
274 iterator emplace_hint(const_iterator position, Args&&... args);
275 iterator insert(const value_type& obj);
276 iterator insert(value_type&& obj);
277 iterator insert(const_iterator hint, const value_type& obj);
278 iterator insert(const_iterator hint, value_type&& obj);
279 template <class InputIterator>
280 void insert(InputIterator first, InputIterator last);
281 void insert(initializer_list<value_type>);
282
Erik Pilkington36fc7372018-08-01 01:33:38 +0000283 node_type extract(const_iterator position); // C++17
284 node_type extract(const key_type& x); // C++17
285 iterator insert(node_type&& nh); // C++17
286 iterator insert(const_iterator hint, node_type&& nh); // C++17
287
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000289 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290 size_type erase(const key_type& k);
291 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000292 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000294 template<class H2, class P2>
295 void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
296 template<class H2, class P2>
297 void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
298 template<class H2, class P2>
299 void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
300 template<class H2, class P2>
301 void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
302
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000303 void swap(unordered_multiset&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000304 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
305 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
306 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307
308 hasher hash_function() const;
309 key_equal key_eq() const;
310
311 iterator find(const key_type& k);
312 const_iterator find(const key_type& k) const;
313 size_type count(const key_type& k) const;
Zoe Carver3f39fe32019-07-16 03:21:01 +0000314 bool contains(const key_type& k) const; // C++20
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315 pair<iterator, iterator> equal_range(const key_type& k);
316 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
317
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000318 size_type bucket_count() const noexcept;
319 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
321 size_type bucket_size(size_type n) const;
322 size_type bucket(const key_type& k) const;
323
324 local_iterator begin(size_type n);
325 local_iterator end(size_type n);
326 const_local_iterator begin(size_type n) const;
327 const_local_iterator end(size_type n) const;
328 const_local_iterator cbegin(size_type n) const;
329 const_local_iterator cend(size_type n) const;
330
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000331 float load_factor() const noexcept;
332 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 void max_load_factor(float z);
334 void rehash(size_type n);
335 void reserve(size_type n);
336};
337
338template <class Value, class Hash, class Pred, class Alloc>
339 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000340 unordered_multiset<Value, Hash, Pred, Alloc>& y)
341 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
Marshall Clowf9276352018-12-14 18:49:35 +0000343template <class K, class T, class H, class P, class A, class Predicate>
344 void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
345
346template <class K, class T, class H, class P, class A, class Predicate>
347 void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
348
349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350template <class Value, class Hash, class Pred, class Alloc>
351 bool
352 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
353 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
354
355template <class Value, class Hash, class Pred, class Alloc>
356 bool
357 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
358 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
359} // std
360
361*/
362
363#include <__config>
364#include <__hash_table>
Erik Pilkington36fc7372018-08-01 01:33:38 +0000365#include <__node_handle>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366#include <functional>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000367#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
Eric Fiselierb9536102014-08-10 23:53:08 +0000369#include <__debug>
370
Howard Hinnant08e17472011-10-17 20:05:10 +0000371#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000373#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375_LIBCPP_BEGIN_NAMESPACE_STD
376
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000377template <class _Value, class _Hash, class _Pred, class _Alloc>
378class unordered_multiset;
379
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
381 class _Alloc = allocator<_Value> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000382class _LIBCPP_TEMPLATE_VIS unordered_set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383{
384public:
385 // types
386 typedef _Value key_type;
387 typedef key_type value_type;
Louis Dionne29808502019-07-11 15:16:39 +0000388 typedef typename __identity<_Hash>::type hasher;
389 typedef typename __identity<_Pred>::type key_equal;
390 typedef typename __identity<_Alloc>::type allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391 typedef value_type& reference;
392 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000393 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
394 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395
396private:
397 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
398
399 __table __table_;
400
401public:
402 typedef typename __table::pointer pointer;
403 typedef typename __table::const_pointer const_pointer;
404 typedef typename __table::size_type size_type;
405 typedef typename __table::difference_type difference_type;
406
407 typedef typename __table::const_iterator iterator;
408 typedef typename __table::const_iterator const_iterator;
409 typedef typename __table::const_local_iterator local_iterator;
410 typedef typename __table::const_local_iterator const_local_iterator;
411
Erik Pilkington36fc7372018-08-01 01:33:38 +0000412#if _LIBCPP_STD_VER > 14
413 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
414 typedef __insert_return_type<iterator, node_type> insert_return_type;
415#endif
416
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000417 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
418 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
419 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
420 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
421
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000423 unordered_set()
424 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000425 {
426#if _LIBCPP_DEBUG_LEVEL >= 2
427 __get_db()->__insert_c(this);
428#endif
429 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
431 const key_equal& __eql = key_equal());
Marshall Clowbd444af2013-09-30 21:33:51 +0000432#if _LIBCPP_STD_VER > 11
433 inline _LIBCPP_INLINE_VISIBILITY
434 unordered_set(size_type __n, const allocator_type& __a)
435 : unordered_set(__n, hasher(), key_equal(), __a) {}
436 inline _LIBCPP_INLINE_VISIBILITY
437 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
438 : unordered_set(__n, __hf, key_equal(), __a) {}
439#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
441 const allocator_type& __a);
442 template <class _InputIterator>
443 unordered_set(_InputIterator __first, _InputIterator __last);
444 template <class _InputIterator>
445 unordered_set(_InputIterator __first, _InputIterator __last,
446 size_type __n, const hasher& __hf = hasher(),
447 const key_equal& __eql = key_equal());
448 template <class _InputIterator>
449 unordered_set(_InputIterator __first, _InputIterator __last,
450 size_type __n, const hasher& __hf, const key_equal& __eql,
451 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000452#if _LIBCPP_STD_VER > 11
453 template <class _InputIterator>
454 inline _LIBCPP_INLINE_VISIBILITY
Louis Dionnec30e2d92019-05-29 16:01:36 +0000455 unordered_set(_InputIterator __first, _InputIterator __last,
Marshall Clowbd444af2013-09-30 21:33:51 +0000456 size_type __n, const allocator_type& __a)
457 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
458 template <class _InputIterator>
Louis Dionnec30e2d92019-05-29 16:01:36 +0000459 unordered_set(_InputIterator __first, _InputIterator __last,
Marshall Clowbd444af2013-09-30 21:33:51 +0000460 size_type __n, const hasher& __hf, const allocator_type& __a)
461 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
462#endif
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464 explicit unordered_set(const allocator_type& __a);
465 unordered_set(const unordered_set& __u);
466 unordered_set(const unordered_set& __u, const allocator_type& __a);
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000467#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000469 unordered_set(unordered_set&& __u)
470 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472 unordered_set(initializer_list<value_type> __il);
473 unordered_set(initializer_list<value_type> __il, size_type __n,
474 const hasher& __hf = hasher(),
475 const key_equal& __eql = key_equal());
476 unordered_set(initializer_list<value_type> __il, size_type __n,
477 const hasher& __hf, const key_equal& __eql,
478 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000479#if _LIBCPP_STD_VER > 11
480 inline _LIBCPP_INLINE_VISIBILITY
481 unordered_set(initializer_list<value_type> __il, size_type __n,
482 const allocator_type& __a)
483 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
484 inline _LIBCPP_INLINE_VISIBILITY
Louis Dionnec30e2d92019-05-29 16:01:36 +0000485 unordered_set(initializer_list<value_type> __il, size_type __n,
Marshall Clowbd444af2013-09-30 21:33:51 +0000486 const hasher& __hf, const allocator_type& __a)
487 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
488#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000489#endif // _LIBCPP_CXX03_LANG
Louis Dionneac7b2ec2019-04-11 16:14:56 +0000490 _LIBCPP_INLINE_VISIBILITY
491 ~unordered_set() {
492 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
493 }
494
Howard Hinnant61aa6012011-07-01 19:24:36 +0000495 _LIBCPP_INLINE_VISIBILITY
496 unordered_set& operator=(const unordered_set& __u)
497 {
498 __table_ = __u.__table_;
499 return *this;
500 }
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000501#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000503 unordered_set& operator=(unordered_set&& __u)
504 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506 unordered_set& operator=(initializer_list<value_type> __il);
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000507#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000510 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 {return allocator_type(__table_.__node_alloc());}
512
Marshall Clow88626bf2017-11-15 05:51:26 +0000513 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000514 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000516 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000518 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000521 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000523 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000525 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000527 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000529 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000531 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000533#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000537 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000540#if _LIBCPP_DEBUG_LEVEL >= 2
541 iterator emplace_hint(const_iterator __p, _Args&&... __args)
542 {
543 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
544 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
545 " referring to this unordered_set");
546 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
547 }
548#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000550 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000551#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000552
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000555 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000557#if _LIBCPP_DEBUG_LEVEL >= 2
558 iterator insert(const_iterator __p, value_type&& __x)
559 {
560 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
561 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
562 " referring to this unordered_set");
563 return insert(_VSTD::move(__x)).first;
564 }
565#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 iterator insert(const_iterator, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000567 {return insert(_VSTD::move(__x)).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000568#endif
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 void insert(initializer_list<value_type> __il)
571 {insert(__il.begin(), __il.end());}
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000572#endif // _LIBCPP_CXX03_LANG
573 _LIBCPP_INLINE_VISIBILITY
574 pair<iterator, bool> insert(const value_type& __x)
575 {return __table_.__insert_unique(__x);}
576
577 _LIBCPP_INLINE_VISIBILITY
578#if _LIBCPP_DEBUG_LEVEL >= 2
579 iterator insert(const_iterator __p, const value_type& __x)
580 {
581 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
582 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
583 " referring to this unordered_set");
584 return insert(__x).first;
585 }
586#else
587 iterator insert(const_iterator, const value_type& __x)
588 {return insert(__x).first;}
589#endif
590 template <class _InputIterator>
591 _LIBCPP_INLINE_VISIBILITY
592 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599 iterator erase(const_iterator __first, const_iterator __last)
600 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000602 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603
Erik Pilkington36fc7372018-08-01 01:33:38 +0000604#if _LIBCPP_STD_VER > 14
605 _LIBCPP_INLINE_VISIBILITY
606 insert_return_type insert(node_type&& __nh)
607 {
608 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
609 "node_type with incompatible allocator passed to unordered_set::insert()");
610 return __table_.template __node_handle_insert_unique<
611 node_type, insert_return_type>(_VSTD::move(__nh));
612 }
613 _LIBCPP_INLINE_VISIBILITY
614 iterator insert(const_iterator __h, node_type&& __nh)
615 {
616 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
617 "node_type with incompatible allocator passed to unordered_set::insert()");
618 return __table_.template __node_handle_insert_unique<node_type>(
619 __h, _VSTD::move(__nh));
620 }
621 _LIBCPP_INLINE_VISIBILITY
622 node_type extract(key_type const& __key)
623 {
624 return __table_.template __node_handle_extract<node_type>(__key);
625 }
626 _LIBCPP_INLINE_VISIBILITY
627 node_type extract(const_iterator __it)
628 {
629 return __table_.template __node_handle_extract<node_type>(__it);
630 }
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000631
632 template<class _H2, class _P2>
633 _LIBCPP_INLINE_VISIBILITY
634 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
635 {
636 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
637 "merging container with incompatible allocator");
638 __table_.__node_handle_merge_unique(__source.__table_);
639 }
640 template<class _H2, class _P2>
641 _LIBCPP_INLINE_VISIBILITY
642 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
643 {
644 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
645 "merging container with incompatible allocator");
646 __table_.__node_handle_merge_unique(__source.__table_);
647 }
648 template<class _H2, class _P2>
649 _LIBCPP_INLINE_VISIBILITY
650 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
651 {
652 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
653 "merging container with incompatible allocator");
654 __table_.__node_handle_merge_unique(__source.__table_);
655 }
656 template<class _H2, class _P2>
657 _LIBCPP_INLINE_VISIBILITY
658 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
659 {
660 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
661 "merging container with incompatible allocator");
662 __table_.__node_handle_merge_unique(__source.__table_);
663 }
Erik Pilkington36fc7372018-08-01 01:33:38 +0000664#endif
665
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000667 void swap(unordered_set& __u)
668 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
669 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674 key_equal key_eq() const {return __table_.key_eq();}
675
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Zoe Carver3f39fe32019-07-16 03:21:01 +0000682 #if _LIBCPP_STD_VER > 17
683 _LIBCPP_INLINE_VISIBILITY
684 bool contains(const key_type& __k) const {return find(__k) != end();}
685 #endif // _LIBCPP_STD_VER > 17
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 pair<iterator, iterator> equal_range(const key_type& __k)
688 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
691 {return __table_.__equal_range_unique(__k);}
692
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000694 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000696 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
702
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
715
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000717 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000719 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +0000726
727#if _LIBCPP_DEBUG_LEVEL >= 2
728
729 bool __dereferenceable(const const_iterator* __i) const
730 {return __table_.__dereferenceable(__i);}
731 bool __decrementable(const const_iterator* __i) const
732 {return __table_.__decrementable(__i);}
733 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
734 {return __table_.__addable(__i, __n);}
735 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
736 {return __table_.__addable(__i, __n);}
737
738#endif // _LIBCPP_DEBUG_LEVEL >= 2
739
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740};
741
Louis Dionne29808502019-07-11 15:16:39 +0000742#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
743template<class _InputIterator,
744 class _Hash = hash<__iter_value_type<_InputIterator>>,
745 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
746 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
747 class = _EnableIf<!__is_allocator<_Hash>::value>,
748 class = _EnableIf<!is_integral<_Hash>::value>,
749 class = _EnableIf<!__is_allocator<_Pred>::value>,
750 class = _EnableIf<__is_allocator<_Allocator>::value>>
751unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
752 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
753 -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
754
755template<class _Tp, class _Hash = hash<_Tp>,
756 class _Pred = equal_to<_Tp>,
757 class _Allocator = allocator<_Tp>,
758 class = _EnableIf<!__is_allocator<_Hash>::value>,
759 class = _EnableIf<!is_integral<_Hash>::value>,
760 class = _EnableIf<!__is_allocator<_Pred>::value>,
761 class = _EnableIf<__is_allocator<_Allocator>::value>>
762unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
763 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
764 -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
765
766template<class _InputIterator, class _Allocator,
767 class = _EnableIf<__is_allocator<_Allocator>::value>>
768unordered_set(_InputIterator, _InputIterator,
769 typename allocator_traits<_Allocator>::size_type, _Allocator)
770 -> unordered_set<__iter_value_type<_InputIterator>,
771 hash<__iter_value_type<_InputIterator>>,
772 equal_to<__iter_value_type<_InputIterator>>,
773 _Allocator>;
774
775template<class _InputIterator, class _Hash, class _Allocator,
776 class = _EnableIf<!__is_allocator<_Hash>::value>,
777 class = _EnableIf<!is_integral<_Hash>::value>,
778 class = _EnableIf<__is_allocator<_Allocator>::value>>
779unordered_set(_InputIterator, _InputIterator,
780 typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
781 -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
782 equal_to<__iter_value_type<_InputIterator>>,
783 _Allocator>;
784
785template<class _Tp, class _Allocator,
786 class = _EnableIf<__is_allocator<_Allocator>::value>>
787unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
788 -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
789
790template<class _Tp, class _Hash, class _Allocator,
791 class = _EnableIf<!__is_allocator<_Hash>::value>,
792 class = _EnableIf<!is_integral<_Hash>::value>,
793 class = _EnableIf<__is_allocator<_Allocator>::value>>
794unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
795 -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
796#endif
797
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798template <class _Value, class _Hash, class _Pred, class _Alloc>
799unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
800 const hasher& __hf, const key_equal& __eql)
801 : __table_(__hf, __eql)
802{
Howard Hinnant39213642013-07-23 22:01:58 +0000803#if _LIBCPP_DEBUG_LEVEL >= 2
804 __get_db()->__insert_c(this);
805#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 __table_.rehash(__n);
807}
808
809template <class _Value, class _Hash, class _Pred, class _Alloc>
810unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
811 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
812 : __table_(__hf, __eql, __a)
813{
Howard Hinnant39213642013-07-23 22:01:58 +0000814#if _LIBCPP_DEBUG_LEVEL >= 2
815 __get_db()->__insert_c(this);
816#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 __table_.rehash(__n);
818}
819
820template <class _Value, class _Hash, class _Pred, class _Alloc>
821template <class _InputIterator>
822unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
823 _InputIterator __first, _InputIterator __last)
824{
Howard Hinnant39213642013-07-23 22:01:58 +0000825#if _LIBCPP_DEBUG_LEVEL >= 2
826 __get_db()->__insert_c(this);
827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828 insert(__first, __last);
829}
830
831template <class _Value, class _Hash, class _Pred, class _Alloc>
832template <class _InputIterator>
833unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
834 _InputIterator __first, _InputIterator __last, size_type __n,
835 const hasher& __hf, const key_equal& __eql)
836 : __table_(__hf, __eql)
837{
Howard Hinnant39213642013-07-23 22:01:58 +0000838#if _LIBCPP_DEBUG_LEVEL >= 2
839 __get_db()->__insert_c(this);
840#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841 __table_.rehash(__n);
842 insert(__first, __last);
843}
844
845template <class _Value, class _Hash, class _Pred, class _Alloc>
846template <class _InputIterator>
847unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
848 _InputIterator __first, _InputIterator __last, size_type __n,
849 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
850 : __table_(__hf, __eql, __a)
851{
Howard Hinnant39213642013-07-23 22:01:58 +0000852#if _LIBCPP_DEBUG_LEVEL >= 2
853 __get_db()->__insert_c(this);
854#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 __table_.rehash(__n);
856 insert(__first, __last);
857}
858
859template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000860inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
862 const allocator_type& __a)
863 : __table_(__a)
864{
Howard Hinnant39213642013-07-23 22:01:58 +0000865#if _LIBCPP_DEBUG_LEVEL >= 2
866 __get_db()->__insert_c(this);
867#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868}
869
870template <class _Value, class _Hash, class _Pred, class _Alloc>
871unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
872 const unordered_set& __u)
873 : __table_(__u.__table_)
874{
Howard Hinnant39213642013-07-23 22:01:58 +0000875#if _LIBCPP_DEBUG_LEVEL >= 2
876 __get_db()->__insert_c(this);
877#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878 __table_.rehash(__u.bucket_count());
879 insert(__u.begin(), __u.end());
880}
881
882template <class _Value, class _Hash, class _Pred, class _Alloc>
883unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
884 const unordered_set& __u, const allocator_type& __a)
885 : __table_(__u.__table_, __a)
886{
Howard Hinnant39213642013-07-23 22:01:58 +0000887#if _LIBCPP_DEBUG_LEVEL >= 2
888 __get_db()->__insert_c(this);
889#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 __table_.rehash(__u.bucket_count());
891 insert(__u.begin(), __u.end());
892}
893
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000894#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895
896template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000897inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
899 unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000900 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000901 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902{
Howard Hinnant39213642013-07-23 22:01:58 +0000903#if _LIBCPP_DEBUG_LEVEL >= 2
904 __get_db()->__insert_c(this);
905 __get_db()->swap(this, &__u);
906#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907}
908
909template <class _Value, class _Hash, class _Pred, class _Alloc>
910unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
911 unordered_set&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000912 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913{
Howard Hinnant39213642013-07-23 22:01:58 +0000914#if _LIBCPP_DEBUG_LEVEL >= 2
915 __get_db()->__insert_c(this);
916#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 if (__a != __u.get_allocator())
918 {
919 iterator __i = __u.begin();
920 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000921 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000922 }
Howard Hinnant39213642013-07-23 22:01:58 +0000923#if _LIBCPP_DEBUG_LEVEL >= 2
924 else
925 __get_db()->swap(this, &__u);
926#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927}
928
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929template <class _Value, class _Hash, class _Pred, class _Alloc>
930unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
931 initializer_list<value_type> __il)
932{
Howard Hinnant39213642013-07-23 22:01:58 +0000933#if _LIBCPP_DEBUG_LEVEL >= 2
934 __get_db()->__insert_c(this);
935#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936 insert(__il.begin(), __il.end());
937}
938
939template <class _Value, class _Hash, class _Pred, class _Alloc>
940unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
941 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
942 const key_equal& __eql)
943 : __table_(__hf, __eql)
944{
Howard Hinnant39213642013-07-23 22:01:58 +0000945#if _LIBCPP_DEBUG_LEVEL >= 2
946 __get_db()->__insert_c(this);
947#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000948 __table_.rehash(__n);
949 insert(__il.begin(), __il.end());
950}
951
952template <class _Value, class _Hash, class _Pred, class _Alloc>
953unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
954 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
955 const key_equal& __eql, const allocator_type& __a)
956 : __table_(__hf, __eql, __a)
957{
Howard Hinnant39213642013-07-23 22:01:58 +0000958#if _LIBCPP_DEBUG_LEVEL >= 2
959 __get_db()->__insert_c(this);
960#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961 __table_.rehash(__n);
962 insert(__il.begin(), __il.end());
963}
964
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000966inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967unordered_set<_Value, _Hash, _Pred, _Alloc>&
968unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000969 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000971 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 return *this;
973}
974
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000976inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977unordered_set<_Value, _Hash, _Pred, _Alloc>&
978unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
979 initializer_list<value_type> __il)
980{
981 __table_.__assign_unique(__il.begin(), __il.end());
982 return *this;
983}
984
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000985#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +0000986
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987template <class _Value, class _Hash, class _Pred, class _Alloc>
988template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000989inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990void
991unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
992 _InputIterator __last)
993{
994 for (; __first != __last; ++__first)
995 __table_.__insert_unique(*__first);
996}
997
998template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000999inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000void
1001swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1002 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001003 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004{
1005 __x.swap(__y);
1006}
1007
Marshall Clowf9276352018-12-14 18:49:35 +00001008#if _LIBCPP_STD_VER > 17
1009template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
1010inline _LIBCPP_INLINE_VISIBILITY
1011void erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1012{ __libcpp_erase_if_container(__c, __pred); }
1013#endif
1014
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015template <class _Value, class _Hash, class _Pred, class _Alloc>
1016bool
1017operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1018 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1019{
1020 if (__x.size() != __y.size())
1021 return false;
1022 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
1023 const_iterator;
1024 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1025 __i != __ex; ++__i)
1026 {
1027 const_iterator __j = __y.find(*__i);
1028 if (__j == __ey || !(*__i == *__j))
1029 return false;
1030 }
1031 return true;
1032}
1033
1034template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001035inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036bool
1037operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1038 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1039{
1040 return !(__x == __y);
1041}
1042
1043template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
1044 class _Alloc = allocator<_Value> >
Eric Fiselierc3589a82017-01-04 23:56:00 +00001045class _LIBCPP_TEMPLATE_VIS unordered_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046{
1047public:
1048 // types
1049 typedef _Value key_type;
1050 typedef key_type value_type;
Louis Dionne29808502019-07-11 15:16:39 +00001051 typedef typename __identity<_Hash>::type hasher;
1052 typedef typename __identity<_Pred>::type key_equal;
1053 typedef typename __identity<_Alloc>::type allocator_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 typedef value_type& reference;
1055 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +00001056 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1057 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058
1059private:
1060 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
1061
1062 __table __table_;
1063
1064public:
1065 typedef typename __table::pointer pointer;
1066 typedef typename __table::const_pointer const_pointer;
1067 typedef typename __table::size_type size_type;
1068 typedef typename __table::difference_type difference_type;
1069
1070 typedef typename __table::const_iterator iterator;
1071 typedef typename __table::const_iterator const_iterator;
1072 typedef typename __table::const_local_iterator local_iterator;
1073 typedef typename __table::const_local_iterator const_local_iterator;
1074
Erik Pilkington36fc7372018-08-01 01:33:38 +00001075#if _LIBCPP_STD_VER > 14
1076 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
1077#endif
1078
Erik Pilkington71ac96a2018-10-31 17:31:35 +00001079 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1080 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
1081 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1082 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
1083
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001085 unordered_multiset()
1086 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001087 {
1088#if _LIBCPP_DEBUG_LEVEL >= 2
1089 __get_db()->__insert_c(this);
1090#endif
1091 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
1093 const key_equal& __eql = key_equal());
1094 unordered_multiset(size_type __n, const hasher& __hf,
1095 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001096#if _LIBCPP_STD_VER > 11
1097 inline _LIBCPP_INLINE_VISIBILITY
1098 unordered_multiset(size_type __n, const allocator_type& __a)
1099 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
1100 inline _LIBCPP_INLINE_VISIBILITY
1101 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
1102 : unordered_multiset(__n, __hf, key_equal(), __a) {}
1103#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 template <class _InputIterator>
1105 unordered_multiset(_InputIterator __first, _InputIterator __last);
1106 template <class _InputIterator>
1107 unordered_multiset(_InputIterator __first, _InputIterator __last,
1108 size_type __n, const hasher& __hf = hasher(),
1109 const key_equal& __eql = key_equal());
1110 template <class _InputIterator>
1111 unordered_multiset(_InputIterator __first, _InputIterator __last,
1112 size_type __n , const hasher& __hf,
1113 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001114#if _LIBCPP_STD_VER > 11
1115 template <class _InputIterator>
1116 inline _LIBCPP_INLINE_VISIBILITY
Louis Dionnec30e2d92019-05-29 16:01:36 +00001117 unordered_multiset(_InputIterator __first, _InputIterator __last,
Marshall Clowbd444af2013-09-30 21:33:51 +00001118 size_type __n, const allocator_type& __a)
1119 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
1120 template <class _InputIterator>
1121 inline _LIBCPP_INLINE_VISIBILITY
1122 unordered_multiset(_InputIterator __first, _InputIterator __last,
1123 size_type __n, const hasher& __hf, const allocator_type& __a)
1124 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
1125#endif
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 explicit unordered_multiset(const allocator_type& __a);
1128 unordered_multiset(const unordered_multiset& __u);
1129 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001130#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001132 unordered_multiset(unordered_multiset&& __u)
1133 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 unordered_multiset(initializer_list<value_type> __il);
1136 unordered_multiset(initializer_list<value_type> __il, size_type __n,
1137 const hasher& __hf = hasher(),
1138 const key_equal& __eql = key_equal());
1139 unordered_multiset(initializer_list<value_type> __il, size_type __n,
1140 const hasher& __hf, const key_equal& __eql,
1141 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001142#if _LIBCPP_STD_VER > 11
1143 inline _LIBCPP_INLINE_VISIBILITY
1144 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1145 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
1146 inline _LIBCPP_INLINE_VISIBILITY
1147 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
1148 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1149#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001150#endif // _LIBCPP_CXX03_LANG
Louis Dionneac7b2ec2019-04-11 16:14:56 +00001151 _LIBCPP_INLINE_VISIBILITY
1152 ~unordered_multiset() {
1153 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
1154 }
1155
Howard Hinnant61aa6012011-07-01 19:24:36 +00001156 _LIBCPP_INLINE_VISIBILITY
1157 unordered_multiset& operator=(const unordered_multiset& __u)
1158 {
1159 __table_ = __u.__table_;
1160 return *this;
1161 }
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001162#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001164 unordered_multiset& operator=(unordered_multiset&& __u)
1165 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 unordered_multiset& operator=(initializer_list<value_type> __il);
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001167#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001170 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 {return allocator_type(__table_.__node_alloc());}
1172
Marshall Clow88626bf2017-11-15 05:51:26 +00001173 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001174 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001176 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001178 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001181 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001183 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001185 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001187 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001189 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001191 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001192
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001193#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001194 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001197 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001200 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001201 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001202
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +00001204 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001207 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209 void insert(initializer_list<value_type> __il)
1210 {insert(__il.begin(), __il.end());}
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001211#endif // _LIBCPP_CXX03_LANG
1212
1213 _LIBCPP_INLINE_VISIBILITY
1214 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1215
1216 _LIBCPP_INLINE_VISIBILITY
1217 iterator insert(const_iterator __p, const value_type& __x)
1218 {return __table_.__insert_multi(__p, __x);}
1219
1220 template <class _InputIterator>
1221 _LIBCPP_INLINE_VISIBILITY
1222 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223
Erik Pilkington36fc7372018-08-01 01:33:38 +00001224#if _LIBCPP_STD_VER > 14
1225 _LIBCPP_INLINE_VISIBILITY
1226 iterator insert(node_type&& __nh)
1227 {
1228 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1229 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1230 return __table_.template __node_handle_insert_multi<node_type>(
1231 _VSTD::move(__nh));
1232 }
1233 _LIBCPP_INLINE_VISIBILITY
1234 iterator insert(const_iterator __hint, node_type&& __nh)
1235 {
1236 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1237 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1238 return __table_.template __node_handle_insert_multi<node_type>(
1239 __hint, _VSTD::move(__nh));
1240 }
1241 _LIBCPP_INLINE_VISIBILITY
1242 node_type extract(const_iterator __position)
1243 {
1244 return __table_.template __node_handle_extract<node_type>(
1245 __position);
1246 }
1247 _LIBCPP_INLINE_VISIBILITY
1248 node_type extract(key_type const& __key)
1249 {
1250 return __table_.template __node_handle_extract<node_type>(__key);
1251 }
Erik Pilkington71ac96a2018-10-31 17:31:35 +00001252
1253 template <class _H2, class _P2>
1254 _LIBCPP_INLINE_VISIBILITY
1255 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
1256 {
1257 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1258 "merging container with incompatible allocator");
1259 return __table_.__node_handle_merge_multi(__source.__table_);
1260 }
1261 template <class _H2, class _P2>
1262 _LIBCPP_INLINE_VISIBILITY
1263 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
1264 {
1265 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1266 "merging container with incompatible allocator");
1267 return __table_.__node_handle_merge_multi(__source.__table_);
1268 }
1269 template <class _H2, class _P2>
1270 _LIBCPP_INLINE_VISIBILITY
1271 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
1272 {
1273 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1274 "merging container with incompatible allocator");
1275 return __table_.__node_handle_merge_multi(__source.__table_);
1276 }
1277 template <class _H2, class _P2>
1278 _LIBCPP_INLINE_VISIBILITY
1279 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
1280 {
1281 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1282 "merging container with incompatible allocator");
1283 return __table_.__node_handle_merge_multi(__source.__table_);
1284 }
Erik Pilkington36fc7372018-08-01 01:33:38 +00001285#endif
1286
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292 iterator erase(const_iterator __first, const_iterator __last)
1293 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001295 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001296
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001298 void swap(unordered_multiset& __u)
1299 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1300 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305 key_equal key_eq() const {return __table_.key_eq();}
1306
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Zoe Carver3f39fe32019-07-16 03:21:01 +00001313 #if _LIBCPP_STD_VER > 17
1314 _LIBCPP_INLINE_VISIBILITY
1315 bool contains(const key_type& __k) const {return find(__k) != end();}
1316 #endif // _LIBCPP_STD_VER > 17
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318 pair<iterator, iterator> equal_range(const key_type& __k)
1319 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1322 {return __table_.__equal_range_multi(__k);}
1323
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001325 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001327 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1333
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001339 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001344 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1346
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001348 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001350 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +00001357
1358#if _LIBCPP_DEBUG_LEVEL >= 2
1359
1360 bool __dereferenceable(const const_iterator* __i) const
1361 {return __table_.__dereferenceable(__i);}
1362 bool __decrementable(const const_iterator* __i) const
1363 {return __table_.__decrementable(__i);}
1364 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1365 {return __table_.__addable(__i, __n);}
1366 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1367 {return __table_.__addable(__i, __n);}
1368
1369#endif // _LIBCPP_DEBUG_LEVEL >= 2
1370
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371};
1372
Louis Dionne29808502019-07-11 15:16:39 +00001373#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1374template<class _InputIterator,
1375 class _Hash = hash<__iter_value_type<_InputIterator>>,
1376 class _Pred = equal_to<__iter_value_type<_InputIterator>>,
1377 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1378 class = _EnableIf<!__is_allocator<_Hash>::value>,
1379 class = _EnableIf<!is_integral<_Hash>::value>,
1380 class = _EnableIf<!__is_allocator<_Pred>::value>,
1381 class = _EnableIf<__is_allocator<_Allocator>::value>>
1382unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
1383 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1384 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
1385
1386template<class _Tp, class _Hash = hash<_Tp>,
1387 class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
1388 class = _EnableIf<!__is_allocator<_Hash>::value>,
1389 class = _EnableIf<!is_integral<_Hash>::value>,
1390 class = _EnableIf<!__is_allocator<_Pred>::value>,
1391 class = _EnableIf<__is_allocator<_Allocator>::value>>
1392unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
1393 _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1394 -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
1395
1396template<class _InputIterator, class _Allocator,
1397 class = _EnableIf<__is_allocator<_Allocator>::value>>
1398unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
1399 -> unordered_multiset<__iter_value_type<_InputIterator>,
1400 hash<__iter_value_type<_InputIterator>>,
1401 equal_to<__iter_value_type<_InputIterator>>,
1402 _Allocator>;
1403
1404template<class _InputIterator, class _Hash, class _Allocator,
1405 class = _EnableIf<!__is_allocator<_Hash>::value>,
1406 class = _EnableIf<!is_integral<_Hash>::value>,
1407 class = _EnableIf<__is_allocator<_Allocator>::value>>
1408unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
1409 _Hash, _Allocator)
1410 -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
1411 equal_to<__iter_value_type<_InputIterator>>,
1412 _Allocator>;
1413
1414template<class _Tp, class _Allocator,
1415 class = _EnableIf<__is_allocator<_Allocator>::value>>
1416unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
1417 -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
1418
1419template<class _Tp, class _Hash, class _Allocator,
1420 class = _EnableIf<!__is_allocator<_Hash>::value>,
1421 class = _EnableIf<!is_integral<_Hash>::value>,
1422 class = _EnableIf<__is_allocator<_Allocator>::value>>
1423unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1424 -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1425#endif
1426
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427template <class _Value, class _Hash, class _Pred, class _Alloc>
1428unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1429 size_type __n, const hasher& __hf, const key_equal& __eql)
1430 : __table_(__hf, __eql)
1431{
Howard Hinnant39213642013-07-23 22:01:58 +00001432#if _LIBCPP_DEBUG_LEVEL >= 2
1433 __get_db()->__insert_c(this);
1434#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435 __table_.rehash(__n);
1436}
1437
1438template <class _Value, class _Hash, class _Pred, class _Alloc>
1439unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1440 size_type __n, const hasher& __hf, const key_equal& __eql,
1441 const allocator_type& __a)
1442 : __table_(__hf, __eql, __a)
1443{
Howard Hinnant39213642013-07-23 22:01:58 +00001444#if _LIBCPP_DEBUG_LEVEL >= 2
1445 __get_db()->__insert_c(this);
1446#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447 __table_.rehash(__n);
1448}
1449
1450template <class _Value, class _Hash, class _Pred, class _Alloc>
1451template <class _InputIterator>
1452unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1453 _InputIterator __first, _InputIterator __last)
1454{
Howard Hinnant39213642013-07-23 22:01:58 +00001455#if _LIBCPP_DEBUG_LEVEL >= 2
1456 __get_db()->__insert_c(this);
1457#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 insert(__first, __last);
1459}
1460
1461template <class _Value, class _Hash, class _Pred, class _Alloc>
1462template <class _InputIterator>
1463unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1464 _InputIterator __first, _InputIterator __last, size_type __n,
1465 const hasher& __hf, const key_equal& __eql)
1466 : __table_(__hf, __eql)
1467{
Howard Hinnant39213642013-07-23 22:01:58 +00001468#if _LIBCPP_DEBUG_LEVEL >= 2
1469 __get_db()->__insert_c(this);
1470#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 __table_.rehash(__n);
1472 insert(__first, __last);
1473}
1474
1475template <class _Value, class _Hash, class _Pred, class _Alloc>
1476template <class _InputIterator>
1477unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1478 _InputIterator __first, _InputIterator __last, size_type __n,
1479 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1480 : __table_(__hf, __eql, __a)
1481{
Howard Hinnant39213642013-07-23 22:01:58 +00001482#if _LIBCPP_DEBUG_LEVEL >= 2
1483 __get_db()->__insert_c(this);
1484#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485 __table_.rehash(__n);
1486 insert(__first, __last);
1487}
1488
1489template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001490inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1492 const allocator_type& __a)
1493 : __table_(__a)
1494{
Howard Hinnant39213642013-07-23 22:01:58 +00001495#if _LIBCPP_DEBUG_LEVEL >= 2
1496 __get_db()->__insert_c(this);
1497#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498}
1499
1500template <class _Value, class _Hash, class _Pred, class _Alloc>
1501unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1502 const unordered_multiset& __u)
1503 : __table_(__u.__table_)
1504{
Howard Hinnant39213642013-07-23 22:01:58 +00001505#if _LIBCPP_DEBUG_LEVEL >= 2
1506 __get_db()->__insert_c(this);
1507#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 __table_.rehash(__u.bucket_count());
1509 insert(__u.begin(), __u.end());
1510}
1511
1512template <class _Value, class _Hash, class _Pred, class _Alloc>
1513unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1514 const unordered_multiset& __u, const allocator_type& __a)
1515 : __table_(__u.__table_, __a)
1516{
Howard Hinnant39213642013-07-23 22:01:58 +00001517#if _LIBCPP_DEBUG_LEVEL >= 2
1518 __get_db()->__insert_c(this);
1519#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 __table_.rehash(__u.bucket_count());
1521 insert(__u.begin(), __u.end());
1522}
1523
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001524#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
1526template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001527inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1529 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001530 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001531 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532{
Howard Hinnant39213642013-07-23 22:01:58 +00001533#if _LIBCPP_DEBUG_LEVEL >= 2
1534 __get_db()->__insert_c(this);
1535 __get_db()->swap(this, &__u);
1536#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537}
1538
1539template <class _Value, class _Hash, class _Pred, class _Alloc>
1540unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1541 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001542 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543{
Howard Hinnant39213642013-07-23 22:01:58 +00001544#if _LIBCPP_DEBUG_LEVEL >= 2
1545 __get_db()->__insert_c(this);
1546#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547 if (__a != __u.get_allocator())
1548 {
1549 iterator __i = __u.begin();
1550 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001551 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 }
Howard Hinnant39213642013-07-23 22:01:58 +00001553#if _LIBCPP_DEBUG_LEVEL >= 2
1554 else
1555 __get_db()->swap(this, &__u);
1556#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557}
1558
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559template <class _Value, class _Hash, class _Pred, class _Alloc>
1560unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1561 initializer_list<value_type> __il)
1562{
Howard Hinnant39213642013-07-23 22:01:58 +00001563#if _LIBCPP_DEBUG_LEVEL >= 2
1564 __get_db()->__insert_c(this);
1565#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566 insert(__il.begin(), __il.end());
1567}
1568
1569template <class _Value, class _Hash, class _Pred, class _Alloc>
1570unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1571 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1572 const key_equal& __eql)
1573 : __table_(__hf, __eql)
1574{
Howard Hinnant39213642013-07-23 22:01:58 +00001575#if _LIBCPP_DEBUG_LEVEL >= 2
1576 __get_db()->__insert_c(this);
1577#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 __table_.rehash(__n);
1579 insert(__il.begin(), __il.end());
1580}
1581
1582template <class _Value, class _Hash, class _Pred, class _Alloc>
1583unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1584 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1585 const key_equal& __eql, const allocator_type& __a)
1586 : __table_(__hf, __eql, __a)
1587{
Howard Hinnant39213642013-07-23 22:01:58 +00001588#if _LIBCPP_DEBUG_LEVEL >= 2
1589 __get_db()->__insert_c(this);
1590#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591 __table_.rehash(__n);
1592 insert(__il.begin(), __il.end());
1593}
1594
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001596inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1598unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1599 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001600 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001602 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 return *this;
1604}
1605
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606template <class _Value, class _Hash, class _Pred, class _Alloc>
1607inline
1608unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1609unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1610 initializer_list<value_type> __il)
1611{
1612 __table_.__assign_multi(__il.begin(), __il.end());
1613 return *this;
1614}
1615
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001616#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001617
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618template <class _Value, class _Hash, class _Pred, class _Alloc>
1619template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001620inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621void
1622unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1623 _InputIterator __last)
1624{
1625 for (; __first != __last; ++__first)
1626 __table_.__insert_multi(*__first);
1627}
1628
1629template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001631void
1632swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1633 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001634 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635{
1636 __x.swap(__y);
1637}
1638
Marshall Clowf9276352018-12-14 18:49:35 +00001639#if _LIBCPP_STD_VER > 17
1640template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
1641inline _LIBCPP_INLINE_VISIBILITY
1642void erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1643{ __libcpp_erase_if_container(__c, __pred); }
1644#endif
1645
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646template <class _Value, class _Hash, class _Pred, class _Alloc>
1647bool
1648operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1649 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1650{
1651 if (__x.size() != __y.size())
1652 return false;
1653 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1654 const_iterator;
1655 typedef pair<const_iterator, const_iterator> _EqRng;
1656 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1657 {
1658 _EqRng __xeq = __x.equal_range(*__i);
1659 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001660 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1661 _VSTD::distance(__yeq.first, __yeq.second) ||
1662 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 return false;
1664 __i = __xeq.second;
1665 }
1666 return true;
1667}
1668
1669template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671bool
1672operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1673 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1674{
1675 return !(__x == __y);
1676}
1677
1678_LIBCPP_END_NAMESPACE_STD
1679
1680#endif // _LIBCPP_UNORDERED_SET