blob: b32e4cae2cdcfab58e146f6b59113cf5f9193c00 [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>
78 unordered_set(InputIterator f, InputIterator l, size_type n,
79 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;
149 pair<iterator, iterator> equal_range(const key_type& k);
150 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
151
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000152 size_type bucket_count() const noexcept;
153 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000154
155 size_type bucket_size(size_type n) const;
156 size_type bucket(const key_type& k) const;
157
158 local_iterator begin(size_type n);
159 local_iterator end(size_type n);
160 const_local_iterator begin(size_type n) const;
161 const_local_iterator end(size_type n) const;
162 const_local_iterator cbegin(size_type n) const;
163 const_local_iterator cend(size_type n) const;
164
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000165 float load_factor() const noexcept;
166 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 void max_load_factor(float z);
168 void rehash(size_type n);
169 void reserve(size_type n);
170};
171
172template <class Value, class Hash, class Pred, class Alloc>
173 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000174 unordered_set<Value, Hash, Pred, Alloc>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176
177template <class Value, class Hash, class Pred, class Alloc>
178 bool
179 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
180 const unordered_set<Value, Hash, Pred, Alloc>& y);
181
182template <class Value, class Hash, class Pred, class Alloc>
183 bool
184 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
185 const unordered_set<Value, Hash, Pred, Alloc>& y);
186
187template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
188 class Alloc = allocator<Value>>
189class unordered_multiset
190{
191public:
192 // types
193 typedef Value key_type;
194 typedef key_type value_type;
195 typedef Hash hasher;
196 typedef Pred key_equal;
197 typedef Alloc allocator_type;
198 typedef value_type& reference;
199 typedef const value_type& const_reference;
200 typedef typename allocator_traits<allocator_type>::pointer pointer;
201 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
202 typedef typename allocator_traits<allocator_type>::size_type size_type;
203 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
204
205 typedef /unspecified/ iterator;
206 typedef /unspecified/ const_iterator;
207 typedef /unspecified/ local_iterator;
208 typedef /unspecified/ const_local_iterator;
209
Erik Pilkington36fc7372018-08-01 01:33:38 +0000210 typedef unspecified node_type unspecified; // C++17
211
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000212 unordered_multiset()
213 noexcept(
214 is_nothrow_default_constructible<hasher>::value &&
215 is_nothrow_default_constructible<key_equal>::value &&
216 is_nothrow_default_constructible<allocator_type>::value);
217 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 const key_equal& eql = key_equal(),
219 const allocator_type& a = allocator_type());
220 template <class InputIterator>
221 unordered_multiset(InputIterator f, InputIterator l,
222 size_type n = 0, const hasher& hf = hasher(),
223 const key_equal& eql = key_equal(),
224 const allocator_type& a = allocator_type());
225 explicit unordered_multiset(const allocator_type&);
226 unordered_multiset(const unordered_multiset&);
227 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000228 unordered_multiset(unordered_multiset&&)
229 noexcept(
230 is_nothrow_move_constructible<hasher>::value &&
231 is_nothrow_move_constructible<key_equal>::value &&
232 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233 unordered_multiset(unordered_multiset&&, const Allocator&);
234 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
235 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
236 const allocator_type& a = allocator_type());
Marshall Clowbd444af2013-09-30 21:33:51 +0000237 unordered_multiset(size_type n, const allocator_type& a); // C++14
238 unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
239 template <class InputIterator>
240 unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
241 template <class InputIterator>
242 unordered_multiset(InputIterator f, InputIterator l, size_type n,
243 const hasher& hf, const allocator_type& a); // C++14
244 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
245 unordered_multiset(initializer_list<value_type> il, size_type n,
246 const hasher& hf, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247 ~unordered_multiset();
248 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000249 unordered_multiset& operator=(unordered_multiset&&)
250 noexcept(
251 allocator_type::propagate_on_container_move_assignment::value &&
252 is_nothrow_move_assignable<allocator_type>::value &&
253 is_nothrow_move_assignable<hasher>::value &&
254 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255 unordered_multiset& operator=(initializer_list<value_type>);
256
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000257 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000259 bool empty() const noexcept;
260 size_type size() const noexcept;
261 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000263 iterator begin() noexcept;
264 iterator end() noexcept;
265 const_iterator begin() const noexcept;
266 const_iterator end() const noexcept;
267 const_iterator cbegin() const noexcept;
268 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
270 template <class... Args>
271 iterator emplace(Args&&... args);
272 template <class... Args>
273 iterator emplace_hint(const_iterator position, Args&&... args);
274 iterator insert(const value_type& obj);
275 iterator insert(value_type&& obj);
276 iterator insert(const_iterator hint, const value_type& obj);
277 iterator insert(const_iterator hint, value_type&& obj);
278 template <class InputIterator>
279 void insert(InputIterator first, InputIterator last);
280 void insert(initializer_list<value_type>);
281
Erik Pilkington36fc7372018-08-01 01:33:38 +0000282 node_type extract(const_iterator position); // C++17
283 node_type extract(const key_type& x); // C++17
284 iterator insert(node_type&& nh); // C++17
285 iterator insert(const_iterator hint, node_type&& nh); // C++17
286
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287 iterator erase(const_iterator position);
Marshall Clow488025c2015-05-10 13:35:00 +0000288 iterator erase(iterator position); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289 size_type erase(const key_type& k);
290 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000291 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000292
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000293 template<class H2, class P2>
294 void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
295 template<class H2, class P2>
296 void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
297 template<class H2, class P2>
298 void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
299 template<class H2, class P2>
300 void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
301
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000302 void swap(unordered_multiset&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000303 noexcept(allocator_traits<Allocator>::is_always_equal::value &&
304 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
305 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307 hasher hash_function() const;
308 key_equal key_eq() const;
309
310 iterator find(const key_type& k);
311 const_iterator find(const key_type& k) const;
312 size_type count(const key_type& k) const;
313 pair<iterator, iterator> equal_range(const key_type& k);
314 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
315
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000316 size_type bucket_count() const noexcept;
317 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000318
319 size_type bucket_size(size_type n) const;
320 size_type bucket(const key_type& k) const;
321
322 local_iterator begin(size_type n);
323 local_iterator end(size_type n);
324 const_local_iterator begin(size_type n) const;
325 const_local_iterator end(size_type n) const;
326 const_local_iterator cbegin(size_type n) const;
327 const_local_iterator cend(size_type n) const;
328
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000329 float load_factor() const noexcept;
330 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331 void max_load_factor(float z);
332 void rehash(size_type n);
333 void reserve(size_type n);
334};
335
336template <class Value, class Hash, class Pred, class Alloc>
337 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000338 unordered_multiset<Value, Hash, Pred, Alloc>& y)
339 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
Marshall Clowf9276352018-12-14 18:49:35 +0000341template <class K, class T, class H, class P, class A, class Predicate>
342 void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
343
344template <class K, class T, class H, class P, class A, class Predicate>
345 void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
346
347
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348template <class Value, class Hash, class Pred, class Alloc>
349 bool
350 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
351 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
352
353template <class Value, class Hash, class Pred, class Alloc>
354 bool
355 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
356 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
357} // std
358
359*/
360
361#include <__config>
362#include <__hash_table>
Erik Pilkington36fc7372018-08-01 01:33:38 +0000363#include <__node_handle>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364#include <functional>
Marshall Clowe3973fd2018-09-12 19:41:40 +0000365#include <version>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366
Eric Fiselierb9536102014-08-10 23:53:08 +0000367#include <__debug>
368
Howard Hinnant08e17472011-10-17 20:05:10 +0000369#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000371#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372
373_LIBCPP_BEGIN_NAMESPACE_STD
374
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000375template <class _Value, class _Hash, class _Pred, class _Alloc>
376class unordered_multiset;
377
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
379 class _Alloc = allocator<_Value> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000380class _LIBCPP_TEMPLATE_VIS unordered_set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381{
382public:
383 // types
384 typedef _Value key_type;
385 typedef key_type value_type;
386 typedef _Hash hasher;
387 typedef _Pred key_equal;
388 typedef _Alloc allocator_type;
389 typedef value_type& reference;
390 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000391 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
392 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393
394private:
395 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
396
397 __table __table_;
398
399public:
400 typedef typename __table::pointer pointer;
401 typedef typename __table::const_pointer const_pointer;
402 typedef typename __table::size_type size_type;
403 typedef typename __table::difference_type difference_type;
404
405 typedef typename __table::const_iterator iterator;
406 typedef typename __table::const_iterator const_iterator;
407 typedef typename __table::const_local_iterator local_iterator;
408 typedef typename __table::const_local_iterator const_local_iterator;
409
Erik Pilkington36fc7372018-08-01 01:33:38 +0000410#if _LIBCPP_STD_VER > 14
411 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
412 typedef __insert_return_type<iterator, node_type> insert_return_type;
413#endif
414
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000415 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
416 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
417 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
418 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
419
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000421 unordered_set()
422 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000423 {
424#if _LIBCPP_DEBUG_LEVEL >= 2
425 __get_db()->__insert_c(this);
426#endif
427 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
429 const key_equal& __eql = key_equal());
Marshall Clowbd444af2013-09-30 21:33:51 +0000430#if _LIBCPP_STD_VER > 11
431 inline _LIBCPP_INLINE_VISIBILITY
432 unordered_set(size_type __n, const allocator_type& __a)
433 : unordered_set(__n, hasher(), key_equal(), __a) {}
434 inline _LIBCPP_INLINE_VISIBILITY
435 unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
436 : unordered_set(__n, __hf, key_equal(), __a) {}
437#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
439 const allocator_type& __a);
440 template <class _InputIterator>
441 unordered_set(_InputIterator __first, _InputIterator __last);
442 template <class _InputIterator>
443 unordered_set(_InputIterator __first, _InputIterator __last,
444 size_type __n, const hasher& __hf = hasher(),
445 const key_equal& __eql = key_equal());
446 template <class _InputIterator>
447 unordered_set(_InputIterator __first, _InputIterator __last,
448 size_type __n, const hasher& __hf, const key_equal& __eql,
449 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000450#if _LIBCPP_STD_VER > 11
451 template <class _InputIterator>
452 inline _LIBCPP_INLINE_VISIBILITY
453 unordered_set(_InputIterator __first, _InputIterator __last,
454 size_type __n, const allocator_type& __a)
455 : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
456 template <class _InputIterator>
457 unordered_set(_InputIterator __first, _InputIterator __last,
458 size_type __n, const hasher& __hf, const allocator_type& __a)
459 : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
460#endif
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 explicit unordered_set(const allocator_type& __a);
463 unordered_set(const unordered_set& __u);
464 unordered_set(const unordered_set& __u, const allocator_type& __a);
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000465#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000467 unordered_set(unordered_set&& __u)
468 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 unordered_set(initializer_list<value_type> __il);
471 unordered_set(initializer_list<value_type> __il, size_type __n,
472 const hasher& __hf = hasher(),
473 const key_equal& __eql = key_equal());
474 unordered_set(initializer_list<value_type> __il, size_type __n,
475 const hasher& __hf, const key_equal& __eql,
476 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +0000477#if _LIBCPP_STD_VER > 11
478 inline _LIBCPP_INLINE_VISIBILITY
479 unordered_set(initializer_list<value_type> __il, size_type __n,
480 const allocator_type& __a)
481 : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
482 inline _LIBCPP_INLINE_VISIBILITY
483 unordered_set(initializer_list<value_type> __il, size_type __n,
484 const hasher& __hf, const allocator_type& __a)
485 : unordered_set(__il, __n, __hf, key_equal(), __a) {}
486#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000487#endif // _LIBCPP_CXX03_LANG
Louis Dionneac7b2ec2019-04-11 16:14:56 +0000488 _LIBCPP_INLINE_VISIBILITY
489 ~unordered_set() {
490 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
491 }
492
Howard Hinnant61aa6012011-07-01 19:24:36 +0000493 _LIBCPP_INLINE_VISIBILITY
494 unordered_set& operator=(const unordered_set& __u)
495 {
496 __table_ = __u.__table_;
497 return *this;
498 }
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000499#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000501 unordered_set& operator=(unordered_set&& __u)
502 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 unordered_set& operator=(initializer_list<value_type> __il);
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000505#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000508 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 {return allocator_type(__table_.__node_alloc());}
510
Marshall Clow88626bf2017-11-15 05:51:26 +0000511 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000512 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000514 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000516 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000519 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000521 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000523 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000525 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000527 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000529 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000531#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000535 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000538#if _LIBCPP_DEBUG_LEVEL >= 2
539 iterator emplace_hint(const_iterator __p, _Args&&... __args)
540 {
541 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
542 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
543 " referring to this unordered_set");
544 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
545 }
546#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000548 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000549#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000550
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000553 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000555#if _LIBCPP_DEBUG_LEVEL >= 2
556 iterator insert(const_iterator __p, value_type&& __x)
557 {
558 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
559 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
560 " referring to this unordered_set");
561 return insert(_VSTD::move(__x)).first;
562 }
563#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564 iterator insert(const_iterator, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000565 {return insert(_VSTD::move(__x)).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000566#endif
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 void insert(initializer_list<value_type> __il)
569 {insert(__il.begin(), __il.end());}
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000570#endif // _LIBCPP_CXX03_LANG
571 _LIBCPP_INLINE_VISIBILITY
572 pair<iterator, bool> insert(const value_type& __x)
573 {return __table_.__insert_unique(__x);}
574
575 _LIBCPP_INLINE_VISIBILITY
576#if _LIBCPP_DEBUG_LEVEL >= 2
577 iterator insert(const_iterator __p, const value_type& __x)
578 {
579 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
580 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
581 " referring to this unordered_set");
582 return insert(__x).first;
583 }
584#else
585 iterator insert(const_iterator, const value_type& __x)
586 {return insert(__x).first;}
587#endif
588 template <class _InputIterator>
589 _LIBCPP_INLINE_VISIBILITY
590 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597 iterator erase(const_iterator __first, const_iterator __last)
598 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000600 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601
Erik Pilkington36fc7372018-08-01 01:33:38 +0000602#if _LIBCPP_STD_VER > 14
603 _LIBCPP_INLINE_VISIBILITY
604 insert_return_type insert(node_type&& __nh)
605 {
606 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
607 "node_type with incompatible allocator passed to unordered_set::insert()");
608 return __table_.template __node_handle_insert_unique<
609 node_type, insert_return_type>(_VSTD::move(__nh));
610 }
611 _LIBCPP_INLINE_VISIBILITY
612 iterator insert(const_iterator __h, node_type&& __nh)
613 {
614 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
615 "node_type with incompatible allocator passed to unordered_set::insert()");
616 return __table_.template __node_handle_insert_unique<node_type>(
617 __h, _VSTD::move(__nh));
618 }
619 _LIBCPP_INLINE_VISIBILITY
620 node_type extract(key_type const& __key)
621 {
622 return __table_.template __node_handle_extract<node_type>(__key);
623 }
624 _LIBCPP_INLINE_VISIBILITY
625 node_type extract(const_iterator __it)
626 {
627 return __table_.template __node_handle_extract<node_type>(__it);
628 }
Erik Pilkington71ac96a2018-10-31 17:31:35 +0000629
630 template<class _H2, class _P2>
631 _LIBCPP_INLINE_VISIBILITY
632 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
633 {
634 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
635 "merging container with incompatible allocator");
636 __table_.__node_handle_merge_unique(__source.__table_);
637 }
638 template<class _H2, class _P2>
639 _LIBCPP_INLINE_VISIBILITY
640 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
641 {
642 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
643 "merging container with incompatible allocator");
644 __table_.__node_handle_merge_unique(__source.__table_);
645 }
646 template<class _H2, class _P2>
647 _LIBCPP_INLINE_VISIBILITY
648 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
649 {
650 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
651 "merging container with incompatible allocator");
652 __table_.__node_handle_merge_unique(__source.__table_);
653 }
654 template<class _H2, class _P2>
655 _LIBCPP_INLINE_VISIBILITY
656 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
657 {
658 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
659 "merging container with incompatible allocator");
660 __table_.__node_handle_merge_unique(__source.__table_);
661 }
Erik Pilkington36fc7372018-08-01 01:33:38 +0000662#endif
663
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000665 void swap(unordered_set& __u)
666 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
667 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 key_equal key_eq() const {return __table_.key_eq();}
673
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681 pair<iterator, iterator> equal_range(const key_type& __k)
682 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
685 {return __table_.__equal_range_unique(__k);}
686
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000688 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000690 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
696
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
709
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000711 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000713 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +0000720
721#if _LIBCPP_DEBUG_LEVEL >= 2
722
723 bool __dereferenceable(const const_iterator* __i) const
724 {return __table_.__dereferenceable(__i);}
725 bool __decrementable(const const_iterator* __i) const
726 {return __table_.__decrementable(__i);}
727 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
728 {return __table_.__addable(__i, __n);}
729 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
730 {return __table_.__addable(__i, __n);}
731
732#endif // _LIBCPP_DEBUG_LEVEL >= 2
733
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734};
735
736template <class _Value, class _Hash, class _Pred, class _Alloc>
737unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
738 const hasher& __hf, const key_equal& __eql)
739 : __table_(__hf, __eql)
740{
Howard Hinnant39213642013-07-23 22:01:58 +0000741#if _LIBCPP_DEBUG_LEVEL >= 2
742 __get_db()->__insert_c(this);
743#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 __table_.rehash(__n);
745}
746
747template <class _Value, class _Hash, class _Pred, class _Alloc>
748unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
749 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
750 : __table_(__hf, __eql, __a)
751{
Howard Hinnant39213642013-07-23 22:01:58 +0000752#if _LIBCPP_DEBUG_LEVEL >= 2
753 __get_db()->__insert_c(this);
754#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000755 __table_.rehash(__n);
756}
757
758template <class _Value, class _Hash, class _Pred, class _Alloc>
759template <class _InputIterator>
760unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
761 _InputIterator __first, _InputIterator __last)
762{
Howard Hinnant39213642013-07-23 22:01:58 +0000763#if _LIBCPP_DEBUG_LEVEL >= 2
764 __get_db()->__insert_c(this);
765#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 insert(__first, __last);
767}
768
769template <class _Value, class _Hash, class _Pred, class _Alloc>
770template <class _InputIterator>
771unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
772 _InputIterator __first, _InputIterator __last, size_type __n,
773 const hasher& __hf, const key_equal& __eql)
774 : __table_(__hf, __eql)
775{
Howard Hinnant39213642013-07-23 22:01:58 +0000776#if _LIBCPP_DEBUG_LEVEL >= 2
777 __get_db()->__insert_c(this);
778#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000779 __table_.rehash(__n);
780 insert(__first, __last);
781}
782
783template <class _Value, class _Hash, class _Pred, class _Alloc>
784template <class _InputIterator>
785unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
786 _InputIterator __first, _InputIterator __last, size_type __n,
787 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
788 : __table_(__hf, __eql, __a)
789{
Howard Hinnant39213642013-07-23 22:01:58 +0000790#if _LIBCPP_DEBUG_LEVEL >= 2
791 __get_db()->__insert_c(this);
792#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 __table_.rehash(__n);
794 insert(__first, __last);
795}
796
797template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000798inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
800 const allocator_type& __a)
801 : __table_(__a)
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}
807
808template <class _Value, class _Hash, class _Pred, class _Alloc>
809unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
810 const unordered_set& __u)
811 : __table_(__u.__table_)
812{
Howard Hinnant39213642013-07-23 22:01:58 +0000813#if _LIBCPP_DEBUG_LEVEL >= 2
814 __get_db()->__insert_c(this);
815#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816 __table_.rehash(__u.bucket_count());
817 insert(__u.begin(), __u.end());
818}
819
820template <class _Value, class _Hash, class _Pred, class _Alloc>
821unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
822 const unordered_set& __u, const allocator_type& __a)
823 : __table_(__u.__table_, __a)
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 __table_.rehash(__u.bucket_count());
829 insert(__u.begin(), __u.end());
830}
831
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000832#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833
834template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000835inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000836unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
837 unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000838 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000839 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000840{
Howard Hinnant39213642013-07-23 22:01:58 +0000841#if _LIBCPP_DEBUG_LEVEL >= 2
842 __get_db()->__insert_c(this);
843 __get_db()->swap(this, &__u);
844#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845}
846
847template <class _Value, class _Hash, class _Pred, class _Alloc>
848unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
849 unordered_set&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000850 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851{
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 if (__a != __u.get_allocator())
856 {
857 iterator __i = __u.begin();
858 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000859 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 }
Howard Hinnant39213642013-07-23 22:01:58 +0000861#if _LIBCPP_DEBUG_LEVEL >= 2
862 else
863 __get_db()->swap(this, &__u);
864#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000865}
866
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867template <class _Value, class _Hash, class _Pred, class _Alloc>
868unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
869 initializer_list<value_type> __il)
870{
Howard Hinnant39213642013-07-23 22:01:58 +0000871#if _LIBCPP_DEBUG_LEVEL >= 2
872 __get_db()->__insert_c(this);
873#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 insert(__il.begin(), __il.end());
875}
876
877template <class _Value, class _Hash, class _Pred, class _Alloc>
878unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
879 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
880 const key_equal& __eql)
881 : __table_(__hf, __eql)
882{
Howard Hinnant39213642013-07-23 22:01:58 +0000883#if _LIBCPP_DEBUG_LEVEL >= 2
884 __get_db()->__insert_c(this);
885#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 __table_.rehash(__n);
887 insert(__il.begin(), __il.end());
888}
889
890template <class _Value, class _Hash, class _Pred, class _Alloc>
891unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
892 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
893 const key_equal& __eql, const allocator_type& __a)
894 : __table_(__hf, __eql, __a)
895{
Howard Hinnant39213642013-07-23 22:01:58 +0000896#if _LIBCPP_DEBUG_LEVEL >= 2
897 __get_db()->__insert_c(this);
898#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 __table_.rehash(__n);
900 insert(__il.begin(), __il.end());
901}
902
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000904inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905unordered_set<_Value, _Hash, _Pred, _Alloc>&
906unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000907 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000909 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000910 return *this;
911}
912
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000914inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915unordered_set<_Value, _Hash, _Pred, _Alloc>&
916unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
917 initializer_list<value_type> __il)
918{
919 __table_.__assign_unique(__il.begin(), __il.end());
920 return *this;
921}
922
Eric Fiselier6cdc0492017-04-18 22:37:32 +0000923#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +0000924
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925template <class _Value, class _Hash, class _Pred, class _Alloc>
926template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000927inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928void
929unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
930 _InputIterator __last)
931{
932 for (; __first != __last; ++__first)
933 __table_.__insert_unique(*__first);
934}
935
936template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938void
939swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
940 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000941 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942{
943 __x.swap(__y);
944}
945
Marshall Clowf9276352018-12-14 18:49:35 +0000946#if _LIBCPP_STD_VER > 17
947template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
948inline _LIBCPP_INLINE_VISIBILITY
949void erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
950{ __libcpp_erase_if_container(__c, __pred); }
951#endif
952
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000953template <class _Value, class _Hash, class _Pred, class _Alloc>
954bool
955operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
956 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
957{
958 if (__x.size() != __y.size())
959 return false;
960 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
961 const_iterator;
962 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
963 __i != __ex; ++__i)
964 {
965 const_iterator __j = __y.find(*__i);
966 if (__j == __ey || !(*__i == *__j))
967 return false;
968 }
969 return true;
970}
971
972template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000973inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000974bool
975operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
976 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
977{
978 return !(__x == __y);
979}
980
981template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
982 class _Alloc = allocator<_Value> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000983class _LIBCPP_TEMPLATE_VIS unordered_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984{
985public:
986 // types
987 typedef _Value key_type;
988 typedef key_type value_type;
989 typedef _Hash hasher;
990 typedef _Pred key_equal;
991 typedef _Alloc allocator_type;
992 typedef value_type& reference;
993 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000994 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
995 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996
997private:
998 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
999
1000 __table __table_;
1001
1002public:
1003 typedef typename __table::pointer pointer;
1004 typedef typename __table::const_pointer const_pointer;
1005 typedef typename __table::size_type size_type;
1006 typedef typename __table::difference_type difference_type;
1007
1008 typedef typename __table::const_iterator iterator;
1009 typedef typename __table::const_iterator const_iterator;
1010 typedef typename __table::const_local_iterator local_iterator;
1011 typedef typename __table::const_local_iterator const_local_iterator;
1012
Erik Pilkington36fc7372018-08-01 01:33:38 +00001013#if _LIBCPP_STD_VER > 14
1014 typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
1015#endif
1016
Erik Pilkington71ac96a2018-10-31 17:31:35 +00001017 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1018 friend class _LIBCPP_TEMPLATE_VIS unordered_set;
1019 template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1020 friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
1021
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001023 unordered_multiset()
1024 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +00001025 {
1026#if _LIBCPP_DEBUG_LEVEL >= 2
1027 __get_db()->__insert_c(this);
1028#endif
1029 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
1031 const key_equal& __eql = key_equal());
1032 unordered_multiset(size_type __n, const hasher& __hf,
1033 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001034#if _LIBCPP_STD_VER > 11
1035 inline _LIBCPP_INLINE_VISIBILITY
1036 unordered_multiset(size_type __n, const allocator_type& __a)
1037 : unordered_multiset(__n, hasher(), key_equal(), __a) {}
1038 inline _LIBCPP_INLINE_VISIBILITY
1039 unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
1040 : unordered_multiset(__n, __hf, key_equal(), __a) {}
1041#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 template <class _InputIterator>
1043 unordered_multiset(_InputIterator __first, _InputIterator __last);
1044 template <class _InputIterator>
1045 unordered_multiset(_InputIterator __first, _InputIterator __last,
1046 size_type __n, const hasher& __hf = hasher(),
1047 const key_equal& __eql = key_equal());
1048 template <class _InputIterator>
1049 unordered_multiset(_InputIterator __first, _InputIterator __last,
1050 size_type __n , const hasher& __hf,
1051 const key_equal& __eql, const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001052#if _LIBCPP_STD_VER > 11
1053 template <class _InputIterator>
1054 inline _LIBCPP_INLINE_VISIBILITY
1055 unordered_multiset(_InputIterator __first, _InputIterator __last,
1056 size_type __n, const allocator_type& __a)
1057 : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
1058 template <class _InputIterator>
1059 inline _LIBCPP_INLINE_VISIBILITY
1060 unordered_multiset(_InputIterator __first, _InputIterator __last,
1061 size_type __n, const hasher& __hf, const allocator_type& __a)
1062 : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
1063#endif
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 explicit unordered_multiset(const allocator_type& __a);
1066 unordered_multiset(const unordered_multiset& __u);
1067 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001068#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001070 unordered_multiset(unordered_multiset&& __u)
1071 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001073 unordered_multiset(initializer_list<value_type> __il);
1074 unordered_multiset(initializer_list<value_type> __il, size_type __n,
1075 const hasher& __hf = hasher(),
1076 const key_equal& __eql = key_equal());
1077 unordered_multiset(initializer_list<value_type> __il, size_type __n,
1078 const hasher& __hf, const key_equal& __eql,
1079 const allocator_type& __a);
Marshall Clowbd444af2013-09-30 21:33:51 +00001080#if _LIBCPP_STD_VER > 11
1081 inline _LIBCPP_INLINE_VISIBILITY
1082 unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1083 : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
1084 inline _LIBCPP_INLINE_VISIBILITY
1085 unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
1086 : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1087#endif
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001088#endif // _LIBCPP_CXX03_LANG
Louis Dionneac7b2ec2019-04-11 16:14:56 +00001089 _LIBCPP_INLINE_VISIBILITY
1090 ~unordered_multiset() {
1091 static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
1092 }
1093
Howard Hinnant61aa6012011-07-01 19:24:36 +00001094 _LIBCPP_INLINE_VISIBILITY
1095 unordered_multiset& operator=(const unordered_multiset& __u)
1096 {
1097 __table_ = __u.__table_;
1098 return *this;
1099 }
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001100#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001102 unordered_multiset& operator=(unordered_multiset&& __u)
1103 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 unordered_multiset& operator=(initializer_list<value_type> __il);
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001105#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001108 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 {return allocator_type(__table_.__node_alloc());}
1110
Marshall Clow88626bf2017-11-15 05:51:26 +00001111 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001112 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001114 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001116 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001119 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001121 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001123 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001125 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001127 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001129 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001131#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001135 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001139 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001140
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +00001142 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001145 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001147 void insert(initializer_list<value_type> __il)
1148 {insert(__il.begin(), __il.end());}
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001149#endif // _LIBCPP_CXX03_LANG
1150
1151 _LIBCPP_INLINE_VISIBILITY
1152 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1153
1154 _LIBCPP_INLINE_VISIBILITY
1155 iterator insert(const_iterator __p, const value_type& __x)
1156 {return __table_.__insert_multi(__p, __x);}
1157
1158 template <class _InputIterator>
1159 _LIBCPP_INLINE_VISIBILITY
1160 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161
Erik Pilkington36fc7372018-08-01 01:33:38 +00001162#if _LIBCPP_STD_VER > 14
1163 _LIBCPP_INLINE_VISIBILITY
1164 iterator insert(node_type&& __nh)
1165 {
1166 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1167 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1168 return __table_.template __node_handle_insert_multi<node_type>(
1169 _VSTD::move(__nh));
1170 }
1171 _LIBCPP_INLINE_VISIBILITY
1172 iterator insert(const_iterator __hint, node_type&& __nh)
1173 {
1174 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1175 "node_type with incompatible allocator passed to unordered_multiset::insert()");
1176 return __table_.template __node_handle_insert_multi<node_type>(
1177 __hint, _VSTD::move(__nh));
1178 }
1179 _LIBCPP_INLINE_VISIBILITY
1180 node_type extract(const_iterator __position)
1181 {
1182 return __table_.template __node_handle_extract<node_type>(
1183 __position);
1184 }
1185 _LIBCPP_INLINE_VISIBILITY
1186 node_type extract(key_type const& __key)
1187 {
1188 return __table_.template __node_handle_extract<node_type>(__key);
1189 }
Erik Pilkington71ac96a2018-10-31 17:31:35 +00001190
1191 template <class _H2, class _P2>
1192 _LIBCPP_INLINE_VISIBILITY
1193 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
1194 {
1195 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1196 "merging container with incompatible allocator");
1197 return __table_.__node_handle_merge_multi(__source.__table_);
1198 }
1199 template <class _H2, class _P2>
1200 _LIBCPP_INLINE_VISIBILITY
1201 void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
1202 {
1203 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1204 "merging container with incompatible allocator");
1205 return __table_.__node_handle_merge_multi(__source.__table_);
1206 }
1207 template <class _H2, class _P2>
1208 _LIBCPP_INLINE_VISIBILITY
1209 void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
1210 {
1211 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1212 "merging container with incompatible allocator");
1213 return __table_.__node_handle_merge_multi(__source.__table_);
1214 }
1215 template <class _H2, class _P2>
1216 _LIBCPP_INLINE_VISIBILITY
1217 void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
1218 {
1219 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1220 "merging container with incompatible allocator");
1221 return __table_.__node_handle_merge_multi(__source.__table_);
1222 }
Erik Pilkington36fc7372018-08-01 01:33:38 +00001223#endif
1224
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230 iterator erase(const_iterator __first, const_iterator __last)
1231 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001233 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001236 void swap(unordered_multiset& __u)
1237 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1238 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243 key_equal key_eq() const {return __table_.key_eq();}
1244
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001252 pair<iterator, iterator> equal_range(const key_type& __k)
1253 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1256 {return __table_.__equal_range_multi(__k);}
1257
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001259 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001261 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1267
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001270 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1280
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001282 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001284 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001290 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +00001291
1292#if _LIBCPP_DEBUG_LEVEL >= 2
1293
1294 bool __dereferenceable(const const_iterator* __i) const
1295 {return __table_.__dereferenceable(__i);}
1296 bool __decrementable(const const_iterator* __i) const
1297 {return __table_.__decrementable(__i);}
1298 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1299 {return __table_.__addable(__i, __n);}
1300 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1301 {return __table_.__addable(__i, __n);}
1302
1303#endif // _LIBCPP_DEBUG_LEVEL >= 2
1304
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305};
1306
1307template <class _Value, class _Hash, class _Pred, class _Alloc>
1308unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1309 size_type __n, const hasher& __hf, const key_equal& __eql)
1310 : __table_(__hf, __eql)
1311{
Howard Hinnant39213642013-07-23 22:01:58 +00001312#if _LIBCPP_DEBUG_LEVEL >= 2
1313 __get_db()->__insert_c(this);
1314#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315 __table_.rehash(__n);
1316}
1317
1318template <class _Value, class _Hash, class _Pred, class _Alloc>
1319unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1320 size_type __n, const hasher& __hf, const key_equal& __eql,
1321 const allocator_type& __a)
1322 : __table_(__hf, __eql, __a)
1323{
Howard Hinnant39213642013-07-23 22:01:58 +00001324#if _LIBCPP_DEBUG_LEVEL >= 2
1325 __get_db()->__insert_c(this);
1326#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327 __table_.rehash(__n);
1328}
1329
1330template <class _Value, class _Hash, class _Pred, class _Alloc>
1331template <class _InputIterator>
1332unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1333 _InputIterator __first, _InputIterator __last)
1334{
Howard Hinnant39213642013-07-23 22:01:58 +00001335#if _LIBCPP_DEBUG_LEVEL >= 2
1336 __get_db()->__insert_c(this);
1337#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 insert(__first, __last);
1339}
1340
1341template <class _Value, class _Hash, class _Pred, class _Alloc>
1342template <class _InputIterator>
1343unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1344 _InputIterator __first, _InputIterator __last, size_type __n,
1345 const hasher& __hf, const key_equal& __eql)
1346 : __table_(__hf, __eql)
1347{
Howard Hinnant39213642013-07-23 22:01:58 +00001348#if _LIBCPP_DEBUG_LEVEL >= 2
1349 __get_db()->__insert_c(this);
1350#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001351 __table_.rehash(__n);
1352 insert(__first, __last);
1353}
1354
1355template <class _Value, class _Hash, class _Pred, class _Alloc>
1356template <class _InputIterator>
1357unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1358 _InputIterator __first, _InputIterator __last, size_type __n,
1359 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1360 : __table_(__hf, __eql, __a)
1361{
Howard Hinnant39213642013-07-23 22:01:58 +00001362#if _LIBCPP_DEBUG_LEVEL >= 2
1363 __get_db()->__insert_c(this);
1364#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365 __table_.rehash(__n);
1366 insert(__first, __last);
1367}
1368
1369template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001370inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1372 const allocator_type& __a)
1373 : __table_(__a)
1374{
Howard Hinnant39213642013-07-23 22:01:58 +00001375#if _LIBCPP_DEBUG_LEVEL >= 2
1376 __get_db()->__insert_c(this);
1377#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378}
1379
1380template <class _Value, class _Hash, class _Pred, class _Alloc>
1381unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1382 const unordered_multiset& __u)
1383 : __table_(__u.__table_)
1384{
Howard Hinnant39213642013-07-23 22:01:58 +00001385#if _LIBCPP_DEBUG_LEVEL >= 2
1386 __get_db()->__insert_c(this);
1387#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388 __table_.rehash(__u.bucket_count());
1389 insert(__u.begin(), __u.end());
1390}
1391
1392template <class _Value, class _Hash, class _Pred, class _Alloc>
1393unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1394 const unordered_multiset& __u, const allocator_type& __a)
1395 : __table_(__u.__table_, __a)
1396{
Howard Hinnant39213642013-07-23 22:01:58 +00001397#if _LIBCPP_DEBUG_LEVEL >= 2
1398 __get_db()->__insert_c(this);
1399#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400 __table_.rehash(__u.bucket_count());
1401 insert(__u.begin(), __u.end());
1402}
1403
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001404#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001405
1406template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001407inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1409 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001410 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001411 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412{
Howard Hinnant39213642013-07-23 22:01:58 +00001413#if _LIBCPP_DEBUG_LEVEL >= 2
1414 __get_db()->__insert_c(this);
1415 __get_db()->swap(this, &__u);
1416#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417}
1418
1419template <class _Value, class _Hash, class _Pred, class _Alloc>
1420unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1421 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001422 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423{
Howard Hinnant39213642013-07-23 22:01:58 +00001424#if _LIBCPP_DEBUG_LEVEL >= 2
1425 __get_db()->__insert_c(this);
1426#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 if (__a != __u.get_allocator())
1428 {
1429 iterator __i = __u.begin();
1430 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001431 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 }
Howard Hinnant39213642013-07-23 22:01:58 +00001433#if _LIBCPP_DEBUG_LEVEL >= 2
1434 else
1435 __get_db()->swap(this, &__u);
1436#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437}
1438
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439template <class _Value, class _Hash, class _Pred, class _Alloc>
1440unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1441 initializer_list<value_type> __il)
1442{
Howard Hinnant39213642013-07-23 22:01:58 +00001443#if _LIBCPP_DEBUG_LEVEL >= 2
1444 __get_db()->__insert_c(this);
1445#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001446 insert(__il.begin(), __il.end());
1447}
1448
1449template <class _Value, class _Hash, class _Pred, class _Alloc>
1450unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1451 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1452 const key_equal& __eql)
1453 : __table_(__hf, __eql)
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 __table_.rehash(__n);
1459 insert(__il.begin(), __il.end());
1460}
1461
1462template <class _Value, class _Hash, class _Pred, class _Alloc>
1463unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1464 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1465 const key_equal& __eql, const allocator_type& __a)
1466 : __table_(__hf, __eql, __a)
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(__il.begin(), __il.end());
1473}
1474
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475template <class _Value, class _Hash, class _Pred, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001476inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1478unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1479 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001480 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001482 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 return *this;
1484}
1485
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486template <class _Value, class _Hash, class _Pred, class _Alloc>
1487inline
1488unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1489unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1490 initializer_list<value_type> __il)
1491{
1492 __table_.__assign_multi(__il.begin(), __il.end());
1493 return *this;
1494}
1495
Eric Fiselier6cdc0492017-04-18 22:37:32 +00001496#endif // _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:02 +00001497
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498template <class _Value, class _Hash, class _Pred, class _Alloc>
1499template <class _InputIterator>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +00001500inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501void
1502unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1503 _InputIterator __last)
1504{
1505 for (; __first != __last; ++__first)
1506 __table_.__insert_multi(*__first);
1507}
1508
1509template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511void
1512swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1513 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001514 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515{
1516 __x.swap(__y);
1517}
1518
Marshall Clowf9276352018-12-14 18:49:35 +00001519#if _LIBCPP_STD_VER > 17
1520template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
1521inline _LIBCPP_INLINE_VISIBILITY
1522void erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
1523{ __libcpp_erase_if_container(__c, __pred); }
1524#endif
1525
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526template <class _Value, class _Hash, class _Pred, class _Alloc>
1527bool
1528operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1529 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1530{
1531 if (__x.size() != __y.size())
1532 return false;
1533 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1534 const_iterator;
1535 typedef pair<const_iterator, const_iterator> _EqRng;
1536 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1537 {
1538 _EqRng __xeq = __x.equal_range(*__i);
1539 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001540 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1541 _VSTD::distance(__yeq.first, __yeq.second) ||
1542 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 return false;
1544 __i = __xeq.second;
1545 }
1546 return true;
1547}
1548
1549template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551bool
1552operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1553 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1554{
1555 return !(__x == __y);
1556}
1557
1558_LIBCPP_END_NAMESPACE_STD
1559
1560#endif // _LIBCPP_UNORDERED_SET