blob: b5b734784b4257489eff146bf11dd1452a0ef6f8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- unordered_set -----------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:3746 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:1652 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:3762 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:1667 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:3773 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:1679 unordered_set& operator=(initializer_list<value_type>);
80
Howard Hinnant04dae1d2011-06-04 20:18:3781 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1682
Howard Hinnant04dae1d2011-06-04 20:18:3783 bool empty() const noexcept;
84 size_type size() const noexcept;
85 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1686
Howard Hinnant04dae1d2011-06-04 20:18:3787 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:1693
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:37109 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16110
Howard Hinnant04dae1d2011-06-04 20:18:37111 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:16117
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:37127 size_type bucket_count() const noexcept;
128 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16129
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:37140 float load_factor() const noexcept;
141 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16142 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:37149 unordered_set<Value, Hash, Pred, Alloc>& y)
150 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16151
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:37185 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:16191 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:37201 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:16206 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:37212 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:16218 unordered_multiset& operator=(initializer_list<value_type>);
219
Howard Hinnant04dae1d2011-06-04 20:18:37220 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16221
Howard Hinnant04dae1d2011-06-04 20:18:37222 bool empty() const noexcept;
223 size_type size() const noexcept;
224 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16225
Howard Hinnant04dae1d2011-06-04 20:18:37226 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:16232
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:37248 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16249
Howard Hinnant04dae1d2011-06-04 20:18:37250 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:16256
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:37266 size_type bucket_count() const noexcept;
267 size_type max_bucket_count() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16268
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:37279 float load_factor() const noexcept;
280 float max_load_factor() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16281 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:37288 unordered_multiset<Value, Hash, Pred, Alloc>& y)
289 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16290
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:10308#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16309#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10310#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16311
312_LIBCPP_BEGIN_NAMESPACE_STD
313
314template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
315 class _Alloc = allocator<_Value> >
Howard Hinnant0f678bd2013-08-12 18:38:34316class _LIBCPP_TYPE_VIS_ONLY unordered_set
Howard Hinnantbc8d3f92010-05-11 19:42:16317{
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:58327 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
328 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16329
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:28346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37347 unordered_set()
348 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58349 {
350#if _LIBCPP_DEBUG_LEVEL >= 2
351 __get_db()->__insert_c(this);
352#endif
353 }
Howard Hinnantbc8d3f92010-05-11 19:42:16354 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:19371#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37372 unordered_set(unordered_set&& __u)
373 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16374 unordered_set(unordered_set&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19375#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02376#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16377 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:02384#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16385 // ~unordered_set() = default;
Howard Hinnant61aa6012011-07-01 19:24:36386 _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:19392#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37393 unordered_set& operator=(unordered_set&& __u)
394 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16395#endif
Howard Hinnante3e32912011-08-12 21:56:02396#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16397 unordered_set& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02398#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16399
Howard Hinnantee6ccd02010-09-23 18:58:28400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37401 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16402 {return allocator_type(__table_.__node_alloc());}
403
Howard Hinnantee6ccd02010-09-23 18:58:28404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37405 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37407 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37409 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16410
Howard Hinnantee6ccd02010-09-23 18:58:28411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37412 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37414 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37416 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37418 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37420 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37422 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16423
Howard Hinnant73d21a42010-09-04 23:28:19424#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16425 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16427 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19428 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16429 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58431#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:16440 iterator emplace_hint(const_iterator, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19441 {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
Howard Hinnant39213642013-07-23 22:01:58442#endif
Howard Hinnant73d21a42010-09-04 23:28:19443#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16445 pair<iterator, bool> insert(const value_type& __x)
446 {return __table_.__insert_unique(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19447#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16449 pair<iterator, bool> insert(value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19450 {return __table_.__insert_unique(_VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19451#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58453#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:16462 iterator insert(const_iterator, const value_type& __x)
463 {return insert(__x).first;}
Howard Hinnant39213642013-07-23 22:01:58464#endif
Howard Hinnant73d21a42010-09-04 23:28:19465#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant39213642013-07-23 22:01:58467#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:16476 iterator insert(const_iterator, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19477 {return insert(_VSTD::move(__x)).first;}
Howard Hinnant39213642013-07-23 22:01:58478#endif
Howard Hinnant73d21a42010-09-04 23:28:19479#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16480 template <class _InputIterator>
481 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02482#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16484 void insert(initializer_list<value_type> __il)
485 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02486#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16487
Howard Hinnantee6ccd02010-09-23 18:58:28488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16489 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16491 size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16493 iterator erase(const_iterator __first, const_iterator __last)
494 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37496 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16497
Howard Hinnantee6ccd02010-09-23 18:58:28498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37499 void swap(unordered_set& __u)
500 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
501 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16502
Howard Hinnantee6ccd02010-09-23 18:58:28503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16504 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16506 key_equal key_eq() const {return __table_.key_eq();}
507
Howard Hinnantee6ccd02010-09-23 18:58:28508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16509 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16511 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16513 size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16515 pair<iterator, iterator> equal_range(const key_type& __k)
516 {return __table_.__equal_range_unique(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16518 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:28521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37522 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37524 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16525
Howard Hinnantee6ccd02010-09-23 18:58:28526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16527 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16529 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
530
Howard Hinnantee6ccd02010-09-23 18:58:28531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16532 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16534 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16536 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16538 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16540 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16542 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
543
Howard Hinnantee6ccd02010-09-23 18:58:28544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37545 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37547 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:28548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16549 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:28550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16551 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:28552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16553 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:58554
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:16568};
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:58575#if _LIBCPP_DEBUG_LEVEL >= 2
576 __get_db()->__insert_c(this);
577#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16578 __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:58586#if _LIBCPP_DEBUG_LEVEL >= 2
587 __get_db()->__insert_c(this);
588#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16589 __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:58597#if _LIBCPP_DEBUG_LEVEL >= 2
598 __get_db()->__insert_c(this);
599#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16600 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:58610#if _LIBCPP_DEBUG_LEVEL >= 2
611 __get_db()->__insert_c(this);
612#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16613 __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:58624#if _LIBCPP_DEBUG_LEVEL >= 2
625 __get_db()->__insert_c(this);
626#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16627 __table_.rehash(__n);
628 insert(__first, __last);
629}
630
631template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16633unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
634 const allocator_type& __a)
635 : __table_(__a)
636{
Howard Hinnant39213642013-07-23 22:01:58637#if _LIBCPP_DEBUG_LEVEL >= 2
638 __get_db()->__insert_c(this);
639#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16640}
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:58647#if _LIBCPP_DEBUG_LEVEL >= 2
648 __get_db()->__insert_c(this);
649#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16650 __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:58659#if _LIBCPP_DEBUG_LEVEL >= 2
660 __get_db()->__insert_c(this);
661#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16662 __table_.rehash(__u.bucket_count());
663 insert(__u.begin(), __u.end());
664}
665
Howard Hinnant73d21a42010-09-04 23:28:19666#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16667
668template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16670unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
671 unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37672 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:19673 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:16674{
Howard Hinnant39213642013-07-23 22:01:58675#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:16679}
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:19684 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16685{
Howard Hinnant39213642013-07-23 22:01:58686#if _LIBCPP_DEBUG_LEVEL >= 2
687 __get_db()->__insert_c(this);
688#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16689 if (__a != __u.get_allocator())
690 {
691 iterator __i = __u.begin();
692 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:19693 __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16694 }
Howard Hinnant39213642013-07-23 22:01:58695#if _LIBCPP_DEBUG_LEVEL >= 2
696 else
697 __get_db()->swap(this, &__u);
698#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16699}
700
Howard Hinnant73d21a42010-09-04 23:28:19701#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16702
Howard Hinnante3e32912011-08-12 21:56:02703#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
704
Howard Hinnantbc8d3f92010-05-11 19:42:16705template <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:58709#if _LIBCPP_DEBUG_LEVEL >= 2
710 __get_db()->__insert_c(this);
711#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16712 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:58721#if _LIBCPP_DEBUG_LEVEL >= 2
722 __get_db()->__insert_c(this);
723#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16724 __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:58734#if _LIBCPP_DEBUG_LEVEL >= 2
735 __get_db()->__insert_c(this);
736#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16737 __table_.rehash(__n);
738 insert(__il.begin(), __il.end());
739}
740
Howard Hinnante3e32912011-08-12 21:56:02741#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
742
Howard Hinnant73d21a42010-09-04 23:28:19743#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16744
745template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28746inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16747unordered_set<_Value, _Hash, _Pred, _Alloc>&
748unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:37749 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16750{
Howard Hinnant0949eed2011-06-30 21:18:19751 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:16752 return *this;
753}
754
Howard Hinnant73d21a42010-09-04 23:28:19755#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16756
Howard Hinnante3e32912011-08-12 21:56:02757#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
758
Howard Hinnantbc8d3f92010-05-11 19:42:16759template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:28760inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16761unordered_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:02769#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
770
Howard Hinnantbc8d3f92010-05-11 19:42:16771template <class _Value, class _Hash, class _Pred, class _Alloc>
772template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:28773inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16774void
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:28783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16784void
785swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
786 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:37787 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16788{
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:28812inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16813bool
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 Hinnant0f678bd2013-08-12 18:38:34822class _LIBCPP_TYPE_VIS_ONLY unordered_multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16823{
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:58833 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
834 "Invalid allocator::value_type");
Howard Hinnantbc8d3f92010-05-11 19:42:16835
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:28852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37853 unordered_multiset()
854 _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
Howard Hinnant39213642013-07-23 22:01:58855 {
856#if _LIBCPP_DEBUG_LEVEL >= 2
857 __get_db()->__insert_c(this);
858#endif
859 }
Howard Hinnantbc8d3f92010-05-11 19:42:16860 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:19877#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37878 unordered_multiset(unordered_multiset&& __u)
879 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16880 unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19881#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02882#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16883 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:02890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16891 // ~unordered_multiset() = default;
Howard Hinnant61aa6012011-07-01 19:24:36892 _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:19898#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant04dae1d2011-06-04 20:18:37899 unordered_multiset& operator=(unordered_multiset&& __u)
900 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16901#endif
Howard Hinnante3e32912011-08-12 21:56:02902#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16903 unordered_multiset& operator=(initializer_list<value_type> __il);
Howard Hinnante3e32912011-08-12 21:56:02904#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16905
Howard Hinnantee6ccd02010-09-23 18:58:28906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37907 allocator_type get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16908 {return allocator_type(__table_.__node_alloc());}
909
Howard Hinnantee6ccd02010-09-23 18:58:28910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37911 bool empty() const _NOEXCEPT {return __table_.size() == 0;}
Howard Hinnantee6ccd02010-09-23 18:58:28912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37913 size_type size() const _NOEXCEPT {return __table_.size();}
Howard Hinnantee6ccd02010-09-23 18:58:28914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37915 size_type max_size() const _NOEXCEPT {return __table_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16916
Howard Hinnantee6ccd02010-09-23 18:58:28917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37918 iterator begin() _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37920 iterator end() _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37922 const_iterator begin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37924 const_iterator end() const _NOEXCEPT {return __table_.end();}
Howard Hinnantee6ccd02010-09-23 18:58:28925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37926 const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
Howard Hinnantee6ccd02010-09-23 18:58:28927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37928 const_iterator cend() const _NOEXCEPT {return __table_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16929
Howard Hinnant73d21a42010-09-04 23:28:19930#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16931 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16933 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19934 {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16935 template <class... _Args>
Howard Hinnantee6ccd02010-09-23 18:58:28936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16937 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19938 {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19939#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantee6ccd02010-09-23 18:58:28940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16941 iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
Howard Hinnant73d21a42010-09-04 23:28:19942#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19944 iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
Howard Hinnantbc8d3f92010-05-11 19:42:16945#endif
Howard Hinnantee6ccd02010-09-23 18:58:28946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16947 iterator insert(const_iterator __p, const value_type& __x)
948 {return __table_.__insert_multi(__p, __x);}
Howard Hinnant73d21a42010-09-04 23:28:19949#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantee6ccd02010-09-23 18:58:28950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16951 iterator insert(const_iterator __p, value_type&& __x)
Howard Hinnant0949eed2011-06-30 21:18:19952 {return __table_.__insert_multi(__p, _VSTD::move(__x));}
Howard Hinnant73d21a42010-09-04 23:28:19953#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16954 template <class _InputIterator>
955 void insert(_InputIterator __first, _InputIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02956#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantee6ccd02010-09-23 18:58:28957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16958 void insert(initializer_list<value_type> __il)
959 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02960#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16961
Howard Hinnantee6ccd02010-09-23 18:58:28962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16963 iterator erase(const_iterator __p) {return __table_.erase(__p);}
Howard Hinnantee6ccd02010-09-23 18:58:28964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16965 size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16967 iterator erase(const_iterator __first, const_iterator __last)
968 {return __table_.erase(__first, __last);}
Howard Hinnantee6ccd02010-09-23 18:58:28969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37970 void clear() _NOEXCEPT {__table_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16971
Howard Hinnantee6ccd02010-09-23 18:58:28972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37973 void swap(unordered_multiset& __u)
974 _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
975 {__table_.swap(__u.__table_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16976
Howard Hinnantee6ccd02010-09-23 18:58:28977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16978 hasher hash_function() const {return __table_.hash_function();}
Howard Hinnantee6ccd02010-09-23 18:58:28979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16980 key_equal key_eq() const {return __table_.key_eq();}
981
Howard Hinnantee6ccd02010-09-23 18:58:28982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16983 iterator find(const key_type& __k) {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16985 const_iterator find(const key_type& __k) const {return __table_.find(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16987 size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16989 pair<iterator, iterator> equal_range(const key_type& __k)
990 {return __table_.__equal_range_multi(__k);}
Howard Hinnantee6ccd02010-09-23 18:58:28991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16992 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:28995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37996 size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
Howard Hinnantee6ccd02010-09-23 18:58:28997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:37998 size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
Howard Hinnantbc8d3f92010-05-11 19:42:16999
Howard Hinnantee6ccd02010-09-23 18:58:281000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161001 size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161003 size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1004
Howard Hinnantee6ccd02010-09-23 18:58:281005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161006 local_iterator begin(size_type __n) {return __table_.begin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161008 local_iterator end(size_type __n) {return __table_.end(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161010 const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161012 const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161014 const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161016 const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
1017
Howard Hinnantee6ccd02010-09-23 18:58:281018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:371019 float load_factor() const _NOEXCEPT {return __table_.load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant04dae1d2011-06-04 20:18:371021 float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
Howard Hinnantee6ccd02010-09-23 18:58:281022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161023 void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
Howard Hinnantee6ccd02010-09-23 18:58:281024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161025 void rehash(size_type __n) {__table_.rehash(__n);}
Howard Hinnantee6ccd02010-09-23 18:58:281026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161027 void reserve(size_type __n) {__table_.reserve(__n);}
Howard Hinnant39213642013-07-23 22:01:581028
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:161042};
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:581049#if _LIBCPP_DEBUG_LEVEL >= 2
1050 __get_db()->__insert_c(this);
1051#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161052 __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:581061#if _LIBCPP_DEBUG_LEVEL >= 2
1062 __get_db()->__insert_c(this);
1063#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161064 __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:581072#if _LIBCPP_DEBUG_LEVEL >= 2
1073 __get_db()->__insert_c(this);
1074#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161075 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:581085#if _LIBCPP_DEBUG_LEVEL >= 2
1086 __get_db()->__insert_c(this);
1087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161088 __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:581099#if _LIBCPP_DEBUG_LEVEL >= 2
1100 __get_db()->__insert_c(this);
1101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161102 __table_.rehash(__n);
1103 insert(__first, __last);
1104}
1105
1106template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:281107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161108unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1109 const allocator_type& __a)
1110 : __table_(__a)
1111{
Howard Hinnant39213642013-07-23 22:01:581112#if _LIBCPP_DEBUG_LEVEL >= 2
1113 __get_db()->__insert_c(this);
1114#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161115}
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:581122#if _LIBCPP_DEBUG_LEVEL >= 2
1123 __get_db()->__insert_c(this);
1124#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161125 __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:581134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
1136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161137 __table_.rehash(__u.bucket_count());
1138 insert(__u.begin(), __u.end());
1139}
1140
Howard Hinnant73d21a42010-09-04 23:28:191141#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161142
1143template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:281144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161145unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1146 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:371147 _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
Howard Hinnant0949eed2011-06-30 21:18:191148 : __table_(_VSTD::move(__u.__table_))
Howard Hinnantbc8d3f92010-05-11 19:42:161149{
Howard Hinnant39213642013-07-23 22:01:581150#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:161154}
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:191159 : __table_(_VSTD::move(__u.__table_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:161160{
Howard Hinnant39213642013-07-23 22:01:581161#if _LIBCPP_DEBUG_LEVEL >= 2
1162 __get_db()->__insert_c(this);
1163#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161164 if (__a != __u.get_allocator())
1165 {
1166 iterator __i = __u.begin();
1167 while (__u.size() != 0)
Howard Hinnant0949eed2011-06-30 21:18:191168 __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161169 }
Howard Hinnant39213642013-07-23 22:01:581170#if _LIBCPP_DEBUG_LEVEL >= 2
1171 else
1172 __get_db()->swap(this, &__u);
1173#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161174}
1175
Howard Hinnant73d21a42010-09-04 23:28:191176#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161177
Howard Hinnante3e32912011-08-12 21:56:021178#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1179
Howard Hinnantbc8d3f92010-05-11 19:42:161180template <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:581184#if _LIBCPP_DEBUG_LEVEL >= 2
1185 __get_db()->__insert_c(this);
1186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161187 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:581196#if _LIBCPP_DEBUG_LEVEL >= 2
1197 __get_db()->__insert_c(this);
1198#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161199 __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:581209#if _LIBCPP_DEBUG_LEVEL >= 2
1210 __get_db()->__insert_c(this);
1211#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161212 __table_.rehash(__n);
1213 insert(__il.begin(), __il.end());
1214}
1215
Howard Hinnante3e32912011-08-12 21:56:021216#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1217
Howard Hinnant73d21a42010-09-04 23:28:191218#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161219
1220template <class _Value, class _Hash, class _Pred, class _Alloc>
Howard Hinnantee6ccd02010-09-23 18:58:281221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161222unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1223unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1224 unordered_multiset&& __u)
Howard Hinnant04dae1d2011-06-04 20:18:371225 _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161226{
Howard Hinnant0949eed2011-06-30 21:18:191227 __table_ = _VSTD::move(__u.__table_);
Howard Hinnantbc8d3f92010-05-11 19:42:161228 return *this;
1229}
1230
Howard Hinnant73d21a42010-09-04 23:28:191231#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161232
Howard Hinnante3e32912011-08-12 21:56:021233#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1234
Howard Hinnantbc8d3f92010-05-11 19:42:161235template <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:021245#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1246
Howard Hinnantbc8d3f92010-05-11 19:42:161247template <class _Value, class _Hash, class _Pred, class _Alloc>
1248template <class _InputIterator>
Howard Hinnantee6ccd02010-09-23 18:58:281249inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161250void
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:281259inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161260void
1261swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1262 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
Howard Hinnant04dae1d2011-06-04 20:18:371263 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:161264{
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:191282 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:161285 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:281292inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161293bool
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