blob: 8be36df6d23d976785449a25f75ad98fb2287239 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_UNORDERED_SET
12#define _LIBCPP_UNORDERED_SET
13
14/*
15
16 unordered_set synopsis
17
18#include <initializer_list>
19
20namespace std
21{
22
23template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
24 class Alloc = allocator<Value>>
25class unordered_set
26{
27public:
28 // types
29 typedef Value key_type;
30 typedef key_type value_type;
31 typedef Hash hasher;
32 typedef Pred key_equal;
33 typedef Alloc allocator_type;
34 typedef value_type& reference;
35 typedef const value_type& const_reference;
36 typedef typename allocator_traits<allocator_type>::pointer pointer;
37 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
38 typedef typename allocator_traits<allocator_type>::size_type size_type;
39 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
40
41 typedef /unspecified/ iterator;
42 typedef /unspecified/ const_iterator;
43 typedef /unspecified/ local_iterator;
44 typedef /unspecified/ const_local_iterator;
45
Howard Hinnant04dae1d2011-06-04 20:18:37 +000046 unordered_set()
47 noexcept(
48 is_nothrow_default_constructible<hasher>::value &&
49 is_nothrow_default_constructible<key_equal>::value &&
50 is_nothrow_default_constructible<allocator_type>::value);
51 explicit unordered_set(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052 const key_equal& eql = key_equal(),
53 const allocator_type& a = allocator_type());
54 template <class InputIterator>
55 unordered_set(InputIterator f, InputIterator l,
56 size_type n = 0, const hasher& hf = hasher(),
57 const key_equal& eql = key_equal(),
58 const allocator_type& a = allocator_type());
59 explicit unordered_set(const allocator_type&);
60 unordered_set(const unordered_set&);
61 unordered_set(const unordered_set&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000062 unordered_set(unordered_set&&)
63 noexcept(
64 is_nothrow_move_constructible<hasher>::value &&
65 is_nothrow_move_constructible<key_equal>::value &&
66 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 unordered_set(unordered_set&&, const Allocator&);
68 unordered_set(initializer_list<value_type>, size_type n = 0,
69 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
70 const allocator_type& a = allocator_type());
71 ~unordered_set();
72 unordered_set& operator=(const unordered_set&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +000073 unordered_set& operator=(unordered_set&&)
74 noexcept(
75 allocator_type::propagate_on_container_move_assignment::value &&
76 is_nothrow_move_assignable<allocator_type>::value &&
77 is_nothrow_move_assignable<hasher>::value &&
78 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 unordered_set& operator=(initializer_list<value_type>);
80
Howard Hinnant04dae1d2011-06-04 20:18:37 +000081 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000082
Howard Hinnant04dae1d2011-06-04 20:18:37 +000083 bool empty() const noexcept;
84 size_type size() const noexcept;
85 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086
Howard Hinnant04dae1d2011-06-04 20:18:37 +000087 iterator begin() noexcept;
88 iterator end() noexcept;
89 const_iterator begin() const noexcept;
90 const_iterator end() const noexcept;
91 const_iterator cbegin() const noexcept;
92 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093
94 template <class... Args>
95 pair<iterator, bool> emplace(Args&&... args);
96 template <class... Args>
97 iterator emplace_hint(const_iterator position, Args&&... args);
98 pair<iterator, bool> insert(const value_type& obj);
99 pair<iterator, bool> insert(value_type&& obj);
100 iterator insert(const_iterator hint, const value_type& obj);
101 iterator insert(const_iterator hint, value_type&& obj);
102 template <class InputIterator>
103 void insert(InputIterator first, InputIterator last);
104 void insert(initializer_list<value_type>);
105
106 iterator erase(const_iterator position);
107 size_type erase(const key_type& k);
108 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000109 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000111 void swap(unordered_set&)
112 noexcept(
113 (!allocator_type::propagate_on_container_swap::value ||
114 __is_nothrow_swappable<allocator_type>::value) &&
115 __is_nothrow_swappable<hasher>::value &&
116 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117
118 hasher hash_function() const;
119 key_equal key_eq() const;
120
121 iterator find(const key_type& k);
122 const_iterator find(const key_type& k) const;
123 size_type count(const key_type& k) const;
124 pair<iterator, iterator> equal_range(const key_type& k);
125 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
126
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000127 size_type bucket_count() const noexcept;
128 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129
130 size_type bucket_size(size_type n) const;
131 size_type bucket(const key_type& k) const;
132
133 local_iterator begin(size_type n);
134 local_iterator end(size_type n);
135 const_local_iterator begin(size_type n) const;
136 const_local_iterator end(size_type n) const;
137 const_local_iterator cbegin(size_type n) const;
138 const_local_iterator cend(size_type n) const;
139
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000140 float load_factor() const noexcept;
141 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000142 void max_load_factor(float z);
143 void rehash(size_type n);
144 void reserve(size_type n);
145};
146
147template <class Value, class Hash, class Pred, class Alloc>
148 void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000149 unordered_set<Value, Hash, Pred, Alloc>& y)
150 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151
152template <class Value, class Hash, class Pred, class Alloc>
153 bool
154 operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
155 const unordered_set<Value, Hash, Pred, Alloc>& y);
156
157template <class Value, class Hash, class Pred, class Alloc>
158 bool
159 operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
160 const unordered_set<Value, Hash, Pred, Alloc>& y);
161
162template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
163 class Alloc = allocator<Value>>
164class unordered_multiset
165{
166public:
167 // types
168 typedef Value key_type;
169 typedef key_type value_type;
170 typedef Hash hasher;
171 typedef Pred key_equal;
172 typedef Alloc allocator_type;
173 typedef value_type& reference;
174 typedef const value_type& const_reference;
175 typedef typename allocator_traits<allocator_type>::pointer pointer;
176 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
177 typedef typename allocator_traits<allocator_type>::size_type size_type;
178 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
179
180 typedef /unspecified/ iterator;
181 typedef /unspecified/ const_iterator;
182 typedef /unspecified/ local_iterator;
183 typedef /unspecified/ const_local_iterator;
184
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000185 unordered_multiset()
186 noexcept(
187 is_nothrow_default_constructible<hasher>::value &&
188 is_nothrow_default_constructible<key_equal>::value &&
189 is_nothrow_default_constructible<allocator_type>::value);
190 explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191 const key_equal& eql = key_equal(),
192 const allocator_type& a = allocator_type());
193 template <class InputIterator>
194 unordered_multiset(InputIterator f, InputIterator l,
195 size_type n = 0, const hasher& hf = hasher(),
196 const key_equal& eql = key_equal(),
197 const allocator_type& a = allocator_type());
198 explicit unordered_multiset(const allocator_type&);
199 unordered_multiset(const unordered_multiset&);
200 unordered_multiset(const unordered_multiset&, const Allocator&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000201 unordered_multiset(unordered_multiset&&)
202 noexcept(
203 is_nothrow_move_constructible<hasher>::value &&
204 is_nothrow_move_constructible<key_equal>::value &&
205 is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000206 unordered_multiset(unordered_multiset&&, const Allocator&);
207 unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
208 const hasher& hf = hasher(), const key_equal& eql = key_equal(),
209 const allocator_type& a = allocator_type());
210 ~unordered_multiset();
211 unordered_multiset& operator=(const unordered_multiset&);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000212 unordered_multiset& operator=(unordered_multiset&&)
213 noexcept(
214 allocator_type::propagate_on_container_move_assignment::value &&
215 is_nothrow_move_assignable<allocator_type>::value &&
216 is_nothrow_move_assignable<hasher>::value &&
217 is_nothrow_move_assignable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000218 unordered_multiset& operator=(initializer_list<value_type>);
219
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000220 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000221
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000222 bool empty() const noexcept;
223 size_type size() const noexcept;
224 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000225
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000226 iterator begin() noexcept;
227 iterator end() noexcept;
228 const_iterator begin() const noexcept;
229 const_iterator end() const noexcept;
230 const_iterator cbegin() const noexcept;
231 const_iterator cend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232
233 template <class... Args>
234 iterator emplace(Args&&... args);
235 template <class... Args>
236 iterator emplace_hint(const_iterator position, Args&&... args);
237 iterator insert(const value_type& obj);
238 iterator insert(value_type&& obj);
239 iterator insert(const_iterator hint, const value_type& obj);
240 iterator insert(const_iterator hint, value_type&& obj);
241 template <class InputIterator>
242 void insert(InputIterator first, InputIterator last);
243 void insert(initializer_list<value_type>);
244
245 iterator erase(const_iterator position);
246 size_type erase(const key_type& k);
247 iterator erase(const_iterator first, const_iterator last);
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000248 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000250 void swap(unordered_multiset&)
251 noexcept(
252 (!allocator_type::propagate_on_container_swap::value ||
253 __is_nothrow_swappable<allocator_type>::value) &&
254 __is_nothrow_swappable<hasher>::value &&
255 __is_nothrow_swappable<key_equal>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
257 hasher hash_function() const;
258 key_equal key_eq() const;
259
260 iterator find(const key_type& k);
261 const_iterator find(const key_type& k) const;
262 size_type count(const key_type& k) const;
263 pair<iterator, iterator> equal_range(const key_type& k);
264 pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
265
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000266 size_type bucket_count() const noexcept;
267 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
269 size_type bucket_size(size_type n) const;
270 size_type bucket(const key_type& k) const;
271
272 local_iterator begin(size_type n);
273 local_iterator end(size_type n);
274 const_local_iterator begin(size_type n) const;
275 const_local_iterator end(size_type n) const;
276 const_local_iterator cbegin(size_type n) const;
277 const_local_iterator cend(size_type n) const;
278
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000279 float load_factor() const noexcept;
280 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 void max_load_factor(float z);
282 void rehash(size_type n);
283 void reserve(size_type n);
284};
285
286template <class Value, class Hash, class Pred, class Alloc>
287 void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000288 unordered_multiset<Value, Hash, Pred, Alloc>& y)
289 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
291template <class Value, class Hash, class Pred, class Alloc>
292 bool
293 operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
294 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
295
296template <class Value, class Hash, class Pred, class Alloc>
297 bool
298 operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
299 const unordered_multiset<Value, Hash, Pred, Alloc>& y);
300} // std
301
302*/
303
304#include <__config>
305#include <__hash_table>
306#include <functional>
307
Howard Hinnant08e17472011-10-17 20:05:10 +0000308#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000310#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000311
312_LIBCPP_BEGIN_NAMESPACE_STD
313
314template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
315 class _Alloc = allocator<_Value> >
Howard Hinnant83eade62013-03-06 23:30:19 +0000316class _LIBCPP_TYPE_VIS unordered_set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317{
318public:
319 // types
320 typedef _Value key_type;
321 typedef key_type value_type;
322 typedef _Hash hasher;
323 typedef _Pred key_equal;
324 typedef _Alloc allocator_type;
325 typedef value_type& reference;
326 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000327 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
328 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330private:
331 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
332
333 __table __table_;
334
335public:
336 typedef typename __table::pointer pointer;
337 typedef typename __table::const_pointer const_pointer;
338 typedef typename __table::size_type size_type;
339 typedef typename __table::difference_type difference_type;
340
341 typedef typename __table::const_iterator iterator;
342 typedef typename __table::const_iterator const_iterator;
343 typedef typename __table::const_local_iterator local_iterator;
344 typedef typename __table::const_local_iterator const_local_iterator;
345
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000347 unordered_set()
348 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000349 {
350#if _LIBCPP_DEBUG_LEVEL >= 2
351 __get_db()->__insert_c(this);
352#endif
353 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
355 const key_equal& __eql = key_equal());
356 unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
357 const allocator_type& __a);
358 template <class _InputIterator>
359 unordered_set(_InputIterator __first, _InputIterator __last);
360 template <class _InputIterator>
361 unordered_set(_InputIterator __first, _InputIterator __last,
362 size_type __n, const hasher& __hf = hasher(),
363 const key_equal& __eql = key_equal());
364 template <class _InputIterator>
365 unordered_set(_InputIterator __first, _InputIterator __last,
366 size_type __n, const hasher& __hf, const key_equal& __eql,
367 const allocator_type& __a);
368 explicit unordered_set(const allocator_type& __a);
369 unordered_set(const unordered_set& __u);
370 unordered_set(const unordered_set& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000371#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000372 unordered_set(unordered_set&& __u)
373 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000375#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000376#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 unordered_set(initializer_list<value_type> __il);
378 unordered_set(initializer_list<value_type> __il, size_type __n,
379 const hasher& __hf = hasher(),
380 const key_equal& __eql = key_equal());
381 unordered_set(initializer_list<value_type> __il, size_type __n,
382 const hasher& __hf, const key_equal& __eql,
383 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000384#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 // ~unordered_set() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000386 _LIBCPP_INLINE_VISIBILITY
387 unordered_set& operator=(const unordered_set& __u)
388 {
389 __table_ = __u.__table_;
390 return *this;
391 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000392#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000393 unordered_set& operator=(unordered_set&& __u)
394 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000396#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 unordered_set& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000398#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000401 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 {return allocator_type(__table_.__node_alloc());}
403
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000405 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000407 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000409 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000412 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000414 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000416 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000418 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000420 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000422 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423
Howard Hinnant73d21a42010-09-04 23:28:19 +0000424#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000428 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000431#if _LIBCPP_DEBUG_LEVEL >= 2
432 iterator emplace_hint(const_iterator __p, _Args&&... __args)
433 {
434 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
435 "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
436 " referring to this unordered_set");
437 return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
438 }
439#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000441 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000442#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000443#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 pair<iterator, bool> insert(const value_type& __x)
446 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000447#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000450 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000451#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000453#if _LIBCPP_DEBUG_LEVEL >= 2
454 iterator insert(const_iterator __p, const value_type& __x)
455 {
456 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
457 "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
458 " referring to this unordered_set");
459 return insert(__x).first;
460 }
461#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 iterator insert(const_iterator, const value_type& __x)
463 {return insert(__x).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000464#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000465#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58 +0000467#if _LIBCPP_DEBUG_LEVEL >= 2
468 iterator insert(const_iterator __p, value_type&& __x)
469 {
470 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
471 "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
472 " referring to this unordered_set");
473 return insert(_VSTD::move(__x)).first;
474 }
475#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 iterator insert(const_iterator, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000477 {return insert(_VSTD::move(__x)).first;}
Howard Hinnant39213642013-07-23 22:01:58 +0000478#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +0000479#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 template <class _InputIterator>
481 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000482#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484 void insert(initializer_list<value_type> __il)
485 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000486#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 iterator erase(const_iterator __first, const_iterator __last)
494 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000496 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000499 void swap(unordered_set& __u)
500 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
501 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506 key_equal key_eq() const {return __table_.key_eq();}
507
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 pair<iterator, iterator> equal_range(const key_type& __k)
516 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
519 {return __table_.__equal_range_unique(__k);}
520
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000522 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000524 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
530
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
543
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000545 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000547 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +0000554
555#if _LIBCPP_DEBUG_LEVEL >= 2
556
557 bool __dereferenceable(const const_iterator* __i) const
558 {return __table_.__dereferenceable(__i);}
559 bool __decrementable(const const_iterator* __i) const
560 {return __table_.__decrementable(__i);}
561 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
562 {return __table_.__addable(__i, __n);}
563 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
564 {return __table_.__addable(__i, __n);}
565
566#endif // _LIBCPP_DEBUG_LEVEL >= 2
567
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568};
569
570template <class _Value, class _Hash, class _Pred, class _Alloc>
571unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
572 const hasher& __hf, const key_equal& __eql)
573 : __table_(__hf, __eql)
574{
Howard Hinnant39213642013-07-23 22:01:58 +0000575#if _LIBCPP_DEBUG_LEVEL >= 2
576 __get_db()->__insert_c(this);
577#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578 __table_.rehash(__n);
579}
580
581template <class _Value, class _Hash, class _Pred, class _Alloc>
582unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
583 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
584 : __table_(__hf, __eql, __a)
585{
Howard Hinnant39213642013-07-23 22:01:58 +0000586#if _LIBCPP_DEBUG_LEVEL >= 2
587 __get_db()->__insert_c(this);
588#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000589 __table_.rehash(__n);
590}
591
592template <class _Value, class _Hash, class _Pred, class _Alloc>
593template <class _InputIterator>
594unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
595 _InputIterator __first, _InputIterator __last)
596{
Howard Hinnant39213642013-07-23 22:01:58 +0000597#if _LIBCPP_DEBUG_LEVEL >= 2
598 __get_db()->__insert_c(this);
599#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 insert(__first, __last);
601}
602
603template <class _Value, class _Hash, class _Pred, class _Alloc>
604template <class _InputIterator>
605unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
606 _InputIterator __first, _InputIterator __last, size_type __n,
607 const hasher& __hf, const key_equal& __eql)
608 : __table_(__hf, __eql)
609{
Howard Hinnant39213642013-07-23 22:01:58 +0000610#if _LIBCPP_DEBUG_LEVEL >= 2
611 __get_db()->__insert_c(this);
612#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613 __table_.rehash(__n);
614 insert(__first, __last);
615}
616
617template <class _Value, class _Hash, class _Pred, class _Alloc>
618template <class _InputIterator>
619unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
620 _InputIterator __first, _InputIterator __last, size_type __n,
621 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
622 : __table_(__hf, __eql, __a)
623{
Howard Hinnant39213642013-07-23 22:01:58 +0000624#if _LIBCPP_DEBUG_LEVEL >= 2
625 __get_db()->__insert_c(this);
626#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627 __table_.rehash(__n);
628 insert(__first, __last);
629}
630
631template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
634 const allocator_type& __a)
635 : __table_(__a)
636{
Howard Hinnant39213642013-07-23 22:01:58 +0000637#if _LIBCPP_DEBUG_LEVEL >= 2
638 __get_db()->__insert_c(this);
639#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640}
641
642template <class _Value, class _Hash, class _Pred, class _Alloc>
643unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
644 const unordered_set& __u)
645 : __table_(__u.__table_)
646{
Howard Hinnant39213642013-07-23 22:01:58 +0000647#if _LIBCPP_DEBUG_LEVEL >= 2
648 __get_db()->__insert_c(this);
649#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650 __table_.rehash(__u.bucket_count());
651 insert(__u.begin(), __u.end());
652}
653
654template <class _Value, class _Hash, class _Pred, class _Alloc>
655unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
656 const unordered_set& __u, const allocator_type& __a)
657 : __table_(__u.__table_, __a)
658{
Howard Hinnant39213642013-07-23 22:01:58 +0000659#if _LIBCPP_DEBUG_LEVEL >= 2
660 __get_db()->__insert_c(this);
661#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 __table_.rehash(__u.bucket_count());
663 insert(__u.begin(), __u.end());
664}
665
Howard Hinnant73d21a42010-09-04 23:28:19 +0000666#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667
668template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
671 unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000672 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000673 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674{
Howard Hinnant39213642013-07-23 22:01:58 +0000675#if _LIBCPP_DEBUG_LEVEL >= 2
676 __get_db()->__insert_c(this);
677 __get_db()->swap(this, &__u);
678#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679}
680
681template <class _Value, class _Hash, class _Pred, class _Alloc>
682unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
683 unordered_set&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000684 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685{
Howard Hinnant39213642013-07-23 22:01:58 +0000686#if _LIBCPP_DEBUG_LEVEL >= 2
687 __get_db()->__insert_c(this);
688#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689 if (__a != __u.get_allocator())
690 {
691 iterator __i = __u.begin();
692 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000693 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 }
Howard Hinnant39213642013-07-23 22:01:58 +0000695#if _LIBCPP_DEBUG_LEVEL >= 2
696 else
697 __get_db()->swap(this, &__u);
698#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699}
700
Howard Hinnant73d21a42010-09-04 23:28:19 +0000701#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702
Howard Hinnante3e32912011-08-12 21:56:02 +0000703#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
704
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705template <class _Value, class _Hash, class _Pred, class _Alloc>
706unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
707 initializer_list<value_type> __il)
708{
Howard Hinnant39213642013-07-23 22:01:58 +0000709#if _LIBCPP_DEBUG_LEVEL >= 2
710 __get_db()->__insert_c(this);
711#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 insert(__il.begin(), __il.end());
713}
714
715template <class _Value, class _Hash, class _Pred, class _Alloc>
716unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
717 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
718 const key_equal& __eql)
719 : __table_(__hf, __eql)
720{
Howard Hinnant39213642013-07-23 22:01:58 +0000721#if _LIBCPP_DEBUG_LEVEL >= 2
722 __get_db()->__insert_c(this);
723#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 __table_.rehash(__n);
725 insert(__il.begin(), __il.end());
726}
727
728template <class _Value, class _Hash, class _Pred, class _Alloc>
729unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
730 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
731 const key_equal& __eql, const allocator_type& __a)
732 : __table_(__hf, __eql, __a)
733{
Howard Hinnant39213642013-07-23 22:01:58 +0000734#if _LIBCPP_DEBUG_LEVEL >= 2
735 __get_db()->__insert_c(this);
736#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 __table_.rehash(__n);
738 insert(__il.begin(), __il.end());
739}
740
Howard Hinnante3e32912011-08-12 21:56:02 +0000741#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
742
Howard Hinnant73d21a42010-09-04 23:28:19 +0000743#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744
745template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000746inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747unordered_set<_Value, _Hash, _Pred, _Alloc>&
748unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000749 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000751 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752 return *this;
753}
754
Howard Hinnant73d21a42010-09-04 23:28:19 +0000755#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756
Howard Hinnante3e32912011-08-12 21:56:02 +0000757#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
758
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761unordered_set<_Value, _Hash, _Pred, _Alloc>&
762unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
763 initializer_list<value_type> __il)
764{
765 __table_.__assign_unique(__il.begin(), __il.end());
766 return *this;
767}
768
Howard Hinnante3e32912011-08-12 21:56:02 +0000769#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
770
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771template <class _Value, class _Hash, class _Pred, class _Alloc>
772template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774void
775unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
776 _InputIterator __last)
777{
778 for (; __first != __last; ++__first)
779 __table_.__insert_unique(*__first);
780}
781
782template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784void
785swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
786 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000787 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788{
789 __x.swap(__y);
790}
791
792template <class _Value, class _Hash, class _Pred, class _Alloc>
793bool
794operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
795 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
796{
797 if (__x.size() != __y.size())
798 return false;
799 typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
800 const_iterator;
801 for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
802 __i != __ex; ++__i)
803 {
804 const_iterator __j = __y.find(*__i);
805 if (__j == __ey || !(*__i == *__j))
806 return false;
807 }
808 return true;
809}
810
811template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000812inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813bool
814operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
815 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
816{
817 return !(__x == __y);
818}
819
820template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
821 class _Alloc = allocator<_Value> >
Howard Hinnant83eade62013-03-06 23:30:19 +0000822class _LIBCPP_TYPE_VIS unordered_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823{
824public:
825 // types
826 typedef _Value key_type;
827 typedef key_type value_type;
828 typedef _Hash hasher;
829 typedef _Pred key_equal;
830 typedef _Alloc allocator_type;
831 typedef value_type& reference;
832 typedef const value_type& const_reference;
Howard Hinnant39213642013-07-23 22:01:58 +0000833 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
834 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835
836private:
837 typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
838
839 __table __table_;
840
841public:
842 typedef typename __table::pointer pointer;
843 typedef typename __table::const_pointer const_pointer;
844 typedef typename __table::size_type size_type;
845 typedef typename __table::difference_type difference_type;
846
847 typedef typename __table::const_iterator iterator;
848 typedef typename __table::const_iterator const_iterator;
849 typedef typename __table::const_local_iterator local_iterator;
850 typedef typename __table::const_local_iterator const_local_iterator;
851
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000853 unordered_multiset()
854 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58 +0000855 {
856#if _LIBCPP_DEBUG_LEVEL >= 2
857 __get_db()->__insert_c(this);
858#endif
859 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
861 const key_equal& __eql = key_equal());
862 unordered_multiset(size_type __n, const hasher& __hf,
863 const key_equal& __eql, const allocator_type& __a);
864 template <class _InputIterator>
865 unordered_multiset(_InputIterator __first, _InputIterator __last);
866 template <class _InputIterator>
867 unordered_multiset(_InputIterator __first, _InputIterator __last,
868 size_type __n, const hasher& __hf = hasher(),
869 const key_equal& __eql = key_equal());
870 template <class _InputIterator>
871 unordered_multiset(_InputIterator __first, _InputIterator __last,
872 size_type __n , const hasher& __hf,
873 const key_equal& __eql, const allocator_type& __a);
874 explicit unordered_multiset(const allocator_type& __a);
875 unordered_multiset(const unordered_multiset& __u);
876 unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000877#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000878 unordered_multiset(unordered_multiset&& __u)
879 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000881#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000882#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 unordered_multiset(initializer_list<value_type> __il);
884 unordered_multiset(initializer_list<value_type> __il, size_type __n,
885 const hasher& __hf = hasher(),
886 const key_equal& __eql = key_equal());
887 unordered_multiset(initializer_list<value_type> __il, size_type __n,
888 const hasher& __hf, const key_equal& __eql,
889 const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891 // ~unordered_multiset() = default;
Howard Hinnant61aa6012011-07-01 19:24:36 +0000892 _LIBCPP_INLINE_VISIBILITY
893 unordered_multiset& operator=(const unordered_multiset& __u)
894 {
895 __table_ = __u.__table_;
896 return *this;
897 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000898#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000899 unordered_multiset& operator=(unordered_multiset&& __u)
900 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901#endif
Howard Hinnante3e32912011-08-12 21:56:02 +0000902#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 unordered_multiset& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02 +0000904#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000907 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908 {return allocator_type(__table_.__node_alloc());}
909
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000911 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000913 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000915 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000918 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000920 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000922 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000924 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000926 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000928 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000929
Howard Hinnant73d21a42010-09-04 23:28:19 +0000930#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000934 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000938 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000939#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000941 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000942#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000944 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945#endif
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 iterator insert(const_iterator __p, const value_type& __x)
948 {return __table_.__insert_multi(__p, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000949#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000952 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000953#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000954 template <class _InputIterator>
955 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000956#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 void insert(initializer_list<value_type> __il)
959 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000960#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 iterator erase(const_iterator __first, const_iterator __last)
968 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000970 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000973 void swap(unordered_multiset& __u)
974 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
975 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980 key_equal key_eq() const {return __table_.key_eq();}
981
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989 pair<iterator, iterator> equal_range(const key_type& __k)
990 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992 pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
993 {return __table_.__equal_range_multi(__k);}
994
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000996 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +0000998 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001001 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1004
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001006 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001008 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1017
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001019 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001021 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001025 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58 +00001028
1029#if _LIBCPP_DEBUG_LEVEL >= 2
1030
1031 bool __dereferenceable(const const_iterator* __i) const
1032 {return __table_.__dereferenceable(__i);}
1033 bool __decrementable(const const_iterator* __i) const
1034 {return __table_.__decrementable(__i);}
1035 bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1036 {return __table_.__addable(__i, __n);}
1037 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1038 {return __table_.__addable(__i, __n);}
1039
1040#endif // _LIBCPP_DEBUG_LEVEL >= 2
1041
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042};
1043
1044template <class _Value, class _Hash, class _Pred, class _Alloc>
1045unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1046 size_type __n, const hasher& __hf, const key_equal& __eql)
1047 : __table_(__hf, __eql)
1048{
Howard Hinnant39213642013-07-23 22:01:58 +00001049#if _LIBCPP_DEBUG_LEVEL >= 2
1050 __get_db()->__insert_c(this);
1051#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 __table_.rehash(__n);
1053}
1054
1055template <class _Value, class _Hash, class _Pred, class _Alloc>
1056unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1057 size_type __n, const hasher& __hf, const key_equal& __eql,
1058 const allocator_type& __a)
1059 : __table_(__hf, __eql, __a)
1060{
Howard Hinnant39213642013-07-23 22:01:58 +00001061#if _LIBCPP_DEBUG_LEVEL >= 2
1062 __get_db()->__insert_c(this);
1063#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 __table_.rehash(__n);
1065}
1066
1067template <class _Value, class _Hash, class _Pred, class _Alloc>
1068template <class _InputIterator>
1069unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1070 _InputIterator __first, _InputIterator __last)
1071{
Howard Hinnant39213642013-07-23 22:01:58 +00001072#if _LIBCPP_DEBUG_LEVEL >= 2
1073 __get_db()->__insert_c(this);
1074#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001075 insert(__first, __last);
1076}
1077
1078template <class _Value, class _Hash, class _Pred, class _Alloc>
1079template <class _InputIterator>
1080unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1081 _InputIterator __first, _InputIterator __last, size_type __n,
1082 const hasher& __hf, const key_equal& __eql)
1083 : __table_(__hf, __eql)
1084{
Howard Hinnant39213642013-07-23 22:01:58 +00001085#if _LIBCPP_DEBUG_LEVEL >= 2
1086 __get_db()->__insert_c(this);
1087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088 __table_.rehash(__n);
1089 insert(__first, __last);
1090}
1091
1092template <class _Value, class _Hash, class _Pred, class _Alloc>
1093template <class _InputIterator>
1094unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1095 _InputIterator __first, _InputIterator __last, size_type __n,
1096 const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1097 : __table_(__hf, __eql, __a)
1098{
Howard Hinnant39213642013-07-23 22:01:58 +00001099#if _LIBCPP_DEBUG_LEVEL >= 2
1100 __get_db()->__insert_c(this);
1101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 __table_.rehash(__n);
1103 insert(__first, __last);
1104}
1105
1106template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1109 const allocator_type& __a)
1110 : __table_(__a)
1111{
Howard Hinnant39213642013-07-23 22:01:58 +00001112#if _LIBCPP_DEBUG_LEVEL >= 2
1113 __get_db()->__insert_c(this);
1114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115}
1116
1117template <class _Value, class _Hash, class _Pred, class _Alloc>
1118unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1119 const unordered_multiset& __u)
1120 : __table_(__u.__table_)
1121{
Howard Hinnant39213642013-07-23 22:01:58 +00001122#if _LIBCPP_DEBUG_LEVEL >= 2
1123 __get_db()->__insert_c(this);
1124#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001125 __table_.rehash(__u.bucket_count());
1126 insert(__u.begin(), __u.end());
1127}
1128
1129template <class _Value, class _Hash, class _Pred, class _Alloc>
1130unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1131 const unordered_multiset& __u, const allocator_type& __a)
1132 : __table_(__u.__table_, __a)
1133{
Howard Hinnant39213642013-07-23 22:01:58 +00001134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
1136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137 __table_.rehash(__u.bucket_count());
1138 insert(__u.begin(), __u.end());
1139}
1140
Howard Hinnant73d21a42010-09-04 23:28:19 +00001141#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142
1143template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1146 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001147 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001148 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149{
Howard Hinnant39213642013-07-23 22:01:58 +00001150#if _LIBCPP_DEBUG_LEVEL >= 2
1151 __get_db()->__insert_c(this);
1152 __get_db()->swap(this, &__u);
1153#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154}
1155
1156template <class _Value, class _Hash, class _Pred, class _Alloc>
1157unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1158 unordered_multiset&& __u, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001159 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160{
Howard Hinnant39213642013-07-23 22:01:58 +00001161#if _LIBCPP_DEBUG_LEVEL >= 2
1162 __get_db()->__insert_c(this);
1163#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164 if (__a != __u.get_allocator())
1165 {
1166 iterator __i = __u.begin();
1167 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001168 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 }
Howard Hinnant39213642013-07-23 22:01:58 +00001170#if _LIBCPP_DEBUG_LEVEL >= 2
1171 else
1172 __get_db()->swap(this, &__u);
1173#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174}
1175
Howard Hinnant73d21a42010-09-04 23:28:19 +00001176#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177
Howard Hinnante3e32912011-08-12 21:56:02 +00001178#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1179
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180template <class _Value, class _Hash, class _Pred, class _Alloc>
1181unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1182 initializer_list<value_type> __il)
1183{
Howard Hinnant39213642013-07-23 22:01:58 +00001184#if _LIBCPP_DEBUG_LEVEL >= 2
1185 __get_db()->__insert_c(this);
1186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187 insert(__il.begin(), __il.end());
1188}
1189
1190template <class _Value, class _Hash, class _Pred, class _Alloc>
1191unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1192 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1193 const key_equal& __eql)
1194 : __table_(__hf, __eql)
1195{
Howard Hinnant39213642013-07-23 22:01:58 +00001196#if _LIBCPP_DEBUG_LEVEL >= 2
1197 __get_db()->__insert_c(this);
1198#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 __table_.rehash(__n);
1200 insert(__il.begin(), __il.end());
1201}
1202
1203template <class _Value, class _Hash, class _Pred, class _Alloc>
1204unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1205 initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1206 const key_equal& __eql, const allocator_type& __a)
1207 : __table_(__hf, __eql, __a)
1208{
Howard Hinnant39213642013-07-23 22:01:58 +00001209#if _LIBCPP_DEBUG_LEVEL >= 2
1210 __get_db()->__insert_c(this);
1211#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212 __table_.rehash(__n);
1213 insert(__il.begin(), __il.end());
1214}
1215
Howard Hinnante3e32912011-08-12 21:56:02 +00001216#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1217
Howard Hinnant73d21a42010-09-04 23:28:19 +00001218#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219
1220template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1223unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1224 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001225 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001226{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001227 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228 return *this;
1229}
1230
Howard Hinnant73d21a42010-09-04 23:28:19 +00001231#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
Howard Hinnante3e32912011-08-12 21:56:02 +00001233#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1234
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235template <class _Value, class _Hash, class _Pred, class _Alloc>
1236inline
1237unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1238unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1239 initializer_list<value_type> __il)
1240{
1241 __table_.__assign_multi(__il.begin(), __il.end());
1242 return *this;
1243}
1244
Howard Hinnante3e32912011-08-12 21:56:02 +00001245#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1246
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247template <class _Value, class _Hash, class _Pred, class _Alloc>
1248template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001249inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250void
1251unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1252 _InputIterator __last)
1253{
1254 for (; __first != __last; ++__first)
1255 __table_.__insert_multi(*__first);
1256}
1257
1258template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260void
1261swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1262 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37 +00001263 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264{
1265 __x.swap(__y);
1266}
1267
1268template <class _Value, class _Hash, class _Pred, class _Alloc>
1269bool
1270operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1271 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1272{
1273 if (__x.size() != __y.size())
1274 return false;
1275 typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1276 const_iterator;
1277 typedef pair<const_iterator, const_iterator> _EqRng;
1278 for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1279 {
1280 _EqRng __xeq = __x.equal_range(*__i);
1281 _EqRng __yeq = __y.equal_range(*__i);
Howard Hinnant0949eed2011-06-30 21:18:19 +00001282 if (_VSTD::distance(__xeq.first, __xeq.second) !=
1283 _VSTD::distance(__yeq.first, __yeq.second) ||
1284 !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285 return false;
1286 __i = __xeq.second;
1287 }
1288 return true;
1289}
1290
1291template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28 +00001292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293bool
1294operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1295 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1296{
1297 return !(__x == __y);
1298}
1299
1300_LIBCPP_END_NAMESPACE_STD
1301
1302#endif // _LIBCPP_UNORDERED_SET