1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_UNORDERED_SET
11#define _LIBCPP_UNORDERED_SET
12
13/*
14
15    unordered_set synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
23          class Alloc = allocator<Value>>
24class unordered_set
25{
26public:
27    // types
28    typedef Value                                                      key_type;
29    typedef key_type                                                   value_type;
30    typedef Hash                                                       hasher;
31    typedef Pred                                                       key_equal;
32    typedef Alloc                                                      allocator_type;
33    typedef value_type&                                                reference;
34    typedef const value_type&                                          const_reference;
35    typedef typename allocator_traits<allocator_type>::pointer         pointer;
36    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
37    typedef typename allocator_traits<allocator_type>::size_type       size_type;
38    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
39
40    typedef /unspecified/ iterator;
41    typedef /unspecified/ const_iterator;
42    typedef /unspecified/ local_iterator;
43    typedef /unspecified/ const_local_iterator;
44
45    typedef unspecified node_type unspecified;                            // C++17
46    typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type;   // C++17
47
48    unordered_set()
49        noexcept(
50            is_nothrow_default_constructible<hasher>::value &&
51            is_nothrow_default_constructible<key_equal>::value &&
52            is_nothrow_default_constructible<allocator_type>::value);
53    explicit unordered_set(size_type n, const hasher& hf = hasher(),
54                           const key_equal& eql = key_equal(),
55                           const allocator_type& a = allocator_type());
56    template <class InputIterator>
57        unordered_set(InputIterator f, InputIterator l,
58                      size_type n = 0, const hasher& hf = hasher(),
59                      const key_equal& eql = key_equal(),
60                      const allocator_type& a = allocator_type());
61    explicit unordered_set(const allocator_type&);
62    unordered_set(const unordered_set&);
63    unordered_set(const unordered_set&, const Allocator&);
64    unordered_set(unordered_set&&)
65        noexcept(
66            is_nothrow_move_constructible<hasher>::value &&
67            is_nothrow_move_constructible<key_equal>::value &&
68            is_nothrow_move_constructible<allocator_type>::value);
69    unordered_set(unordered_set&&, const Allocator&);
70    unordered_set(initializer_list<value_type>, size_type n = 0,
71                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
72                  const allocator_type& a = allocator_type());
73    unordered_set(size_type n, const allocator_type& a); // C++14
74    unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
75    template <class InputIterator>
76      unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
77    template <class InputIterator>
78      unordered_set(InputIterator f, InputIterator l, size_type n,
79                    const hasher& hf,  const allocator_type& a); // C++14
80    unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
81    unordered_set(initializer_list<value_type> il, size_type n,
82                  const hasher& hf,  const allocator_type& a); // C++14
83    ~unordered_set();
84    unordered_set& operator=(const unordered_set&);
85    unordered_set& operator=(unordered_set&&)
86        noexcept(
87            allocator_type::propagate_on_container_move_assignment::value &&
88            is_nothrow_move_assignable<allocator_type>::value &&
89            is_nothrow_move_assignable<hasher>::value &&
90            is_nothrow_move_assignable<key_equal>::value);
91    unordered_set& operator=(initializer_list<value_type>);
92
93    allocator_type get_allocator() const noexcept;
94
95    bool      empty() const noexcept;
96    size_type size() const noexcept;
97    size_type max_size() const noexcept;
98
99    iterator       begin() noexcept;
100    iterator       end() noexcept;
101    const_iterator begin()  const noexcept;
102    const_iterator end()    const noexcept;
103    const_iterator cbegin() const noexcept;
104    const_iterator cend()   const noexcept;
105
106    template <class... Args>
107        pair<iterator, bool> emplace(Args&&... args);
108    template <class... Args>
109        iterator emplace_hint(const_iterator position, Args&&... args);
110    pair<iterator, bool> insert(const value_type& obj);
111    pair<iterator, bool> insert(value_type&& obj);
112    iterator insert(const_iterator hint, const value_type& obj);
113    iterator insert(const_iterator hint, value_type&& obj);
114    template <class InputIterator>
115        void insert(InputIterator first, InputIterator last);
116    void insert(initializer_list<value_type>);
117
118    node_type extract(const_iterator position);                       // C++17
119    node_type extract(const key_type& x);                             // C++17
120    insert_return_type insert(node_type&& nh);                        // C++17
121    iterator           insert(const_iterator hint, node_type&& nh);   // C++17
122
123    iterator erase(const_iterator position);
124    iterator erase(iterator position);  // C++14
125    size_type erase(const key_type& k);
126    iterator erase(const_iterator first, const_iterator last);
127    void clear() noexcept;
128
129    template<class H2, class P2>
130      void merge(unordered_set<Key, H2, P2, Allocator>& source);         // C++17
131    template<class H2, class P2>
132      void merge(unordered_set<Key, H2, P2, Allocator>&& source);        // C++17
133    template<class H2, class P2>
134      void merge(unordered_multiset<Key, H2, P2, Allocator>& source);    // C++17
135    template<class H2, class P2>
136      void merge(unordered_multiset<Key, H2, P2, Allocator>&& source);   // C++17
137
138    void swap(unordered_set&)
139       noexcept(allocator_traits<Allocator>::is_always_equal::value &&
140                 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
141                 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
142
143    hasher hash_function() const;
144    key_equal key_eq() const;
145
146    iterator       find(const key_type& k);
147    const_iterator find(const key_type& k) const;
148    template<typename K>
149        iterator find(const K& x);              // C++20
150    template<typename K>
151        const_iterator find(const K& x) const;  // C++20
152    size_type count(const key_type& k) const;
153    template<typename K>
154        size_type count(const K& k) const; // C++20
155    bool contains(const key_type& k) const; // C++20
156    template<typename K>
157        bool contains(const K& k) const; // C++20
158    pair<iterator, iterator>             equal_range(const key_type& k);
159    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
160    template<typename K>
161        pair<iterator, iterator>             equal_range(const K& k); // C++20
162    template<typename K>
163        pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
164
165    size_type bucket_count() const noexcept;
166    size_type max_bucket_count() const noexcept;
167
168    size_type bucket_size(size_type n) const;
169    size_type bucket(const key_type& k) const;
170
171    local_iterator       begin(size_type n);
172    local_iterator       end(size_type n);
173    const_local_iterator begin(size_type n) const;
174    const_local_iterator end(size_type n) const;
175    const_local_iterator cbegin(size_type n) const;
176    const_local_iterator cend(size_type n) const;
177
178    float load_factor() const noexcept;
179    float max_load_factor() const noexcept;
180    void max_load_factor(float z);
181    void rehash(size_type n);
182    void reserve(size_type n);
183};
184
185template<class InputIterator,
186    class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
187    class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
188    class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
189unordered_set(InputIterator, InputIterator, typename see below::size_type = see below,
190    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
191  -> unordered_set<typename iterator_traits<InputIterator>::value_type,
192        Hash, Pred, Allocator>; // C++17
193
194template<class T, class Hash = hash<T>,
195          class Pred = equal_to<T>, class Allocator = allocator<T>>
196unordered_set(initializer_list<T>, typename see below::size_type = see below,
197    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
198  -> unordered_set<T, Hash, Pred, Allocator>; // C++17
199
200template<class InputIterator,  class Allocator>
201unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator)
202  -> unordered_set<typename iterator_traits<InputIterator>::value_type,
203        hash<typename iterator_traits<InputIterator>::value_type>,
204        equal_to<typename iterator_traits<InputIterator>::value_type>,
205        Allocator>; // C++17
206
207template<class InputIterator, class Hash, class Allocator>
208unordered_set(InputIterator, InputIterator, typename see below::size_type,
209    Hash, Allocator)
210  -> unordered_set<typename iterator_traits<InputIterator>::value_type, Hash,
211        equal_to<typename iterator_traits<InputIterator>::value_type>,
212        Allocator>; // C++17
213
214template<class T, class Allocator>
215unordered_set(initializer_list<T>, typename see below::size_type, Allocator)
216  -> unordered_set<T, hash<T>, equal_to<T>, Allocator>; // C++17
217
218template<class T, class Hash, class Allocator>
219unordered_set(initializer_list<T>, typename see below::size_type, Hash, Allocator)
220  -> unordered_set<T, Hash, equal_to<T>, Allocator>; // C++17
221
222template <class Value, class Hash, class Pred, class Alloc>
223    void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
224              unordered_set<Value, Hash, Pred, Alloc>& y)
225              noexcept(noexcept(x.swap(y)));
226
227template <class Value, class Hash, class Pred, class Alloc>
228    bool
229    operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
230               const unordered_set<Value, Hash, Pred, Alloc>& y);
231
232template <class Value, class Hash, class Pred, class Alloc>
233    bool
234    operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
235               const unordered_set<Value, Hash, Pred, Alloc>& y);
236
237template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
238          class Alloc = allocator<Value>>
239class unordered_multiset
240{
241public:
242    // types
243    typedef Value                                                      key_type;
244    typedef key_type                                                   value_type;
245    typedef Hash                                                       hasher;
246    typedef Pred                                                       key_equal;
247    typedef Alloc                                                      allocator_type;
248    typedef value_type&                                                reference;
249    typedef const value_type&                                          const_reference;
250    typedef typename allocator_traits<allocator_type>::pointer         pointer;
251    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
252    typedef typename allocator_traits<allocator_type>::size_type       size_type;
253    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
254
255    typedef /unspecified/ iterator;
256    typedef /unspecified/ const_iterator;
257    typedef /unspecified/ local_iterator;
258    typedef /unspecified/ const_local_iterator;
259
260    typedef unspecified node_type unspecified;   // C++17
261
262    unordered_multiset()
263        noexcept(
264            is_nothrow_default_constructible<hasher>::value &&
265            is_nothrow_default_constructible<key_equal>::value &&
266            is_nothrow_default_constructible<allocator_type>::value);
267    explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
268                           const key_equal& eql = key_equal(),
269                           const allocator_type& a = allocator_type());
270    template <class InputIterator>
271        unordered_multiset(InputIterator f, InputIterator l,
272                      size_type n = 0, const hasher& hf = hasher(),
273                      const key_equal& eql = key_equal(),
274                      const allocator_type& a = allocator_type());
275    explicit unordered_multiset(const allocator_type&);
276    unordered_multiset(const unordered_multiset&);
277    unordered_multiset(const unordered_multiset&, const Allocator&);
278    unordered_multiset(unordered_multiset&&)
279        noexcept(
280            is_nothrow_move_constructible<hasher>::value &&
281            is_nothrow_move_constructible<key_equal>::value &&
282            is_nothrow_move_constructible<allocator_type>::value);
283    unordered_multiset(unordered_multiset&&, const Allocator&);
284    unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
285                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
286                  const allocator_type& a = allocator_type());
287    unordered_multiset(size_type n, const allocator_type& a); // C++14
288    unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
289    template <class InputIterator>
290      unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
291    template <class InputIterator>
292      unordered_multiset(InputIterator f, InputIterator l, size_type n,
293                         const hasher& hf, const allocator_type& a); // C++14
294    unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
295    unordered_multiset(initializer_list<value_type> il, size_type n,
296                       const hasher& hf,  const allocator_type& a); // C++14
297    ~unordered_multiset();
298    unordered_multiset& operator=(const unordered_multiset&);
299    unordered_multiset& operator=(unordered_multiset&&)
300        noexcept(
301            allocator_type::propagate_on_container_move_assignment::value &&
302            is_nothrow_move_assignable<allocator_type>::value &&
303            is_nothrow_move_assignable<hasher>::value &&
304            is_nothrow_move_assignable<key_equal>::value);
305    unordered_multiset& operator=(initializer_list<value_type>);
306
307    allocator_type get_allocator() const noexcept;
308
309    bool      empty() const noexcept;
310    size_type size() const noexcept;
311    size_type max_size() const noexcept;
312
313    iterator       begin() noexcept;
314    iterator       end() noexcept;
315    const_iterator begin()  const noexcept;
316    const_iterator end()    const noexcept;
317    const_iterator cbegin() const noexcept;
318    const_iterator cend()   const noexcept;
319
320    template <class... Args>
321        iterator emplace(Args&&... args);
322    template <class... Args>
323        iterator emplace_hint(const_iterator position, Args&&... args);
324    iterator insert(const value_type& obj);
325    iterator insert(value_type&& obj);
326    iterator insert(const_iterator hint, const value_type& obj);
327    iterator insert(const_iterator hint, value_type&& obj);
328    template <class InputIterator>
329        void insert(InputIterator first, InputIterator last);
330    void insert(initializer_list<value_type>);
331
332    node_type extract(const_iterator position);             // C++17
333    node_type extract(const key_type& x);                   // C++17
334    iterator insert(node_type&& nh);                        // C++17
335    iterator insert(const_iterator hint, node_type&& nh);   // C++17
336
337    iterator erase(const_iterator position);
338    iterator erase(iterator position);  // C++14
339    size_type erase(const key_type& k);
340    iterator erase(const_iterator first, const_iterator last);
341    void clear() noexcept;
342
343    template<class H2, class P2>
344      void merge(unordered_multiset<Key, H2, P2, Allocator>& source);    // C++17
345    template<class H2, class P2>
346      void merge(unordered_multiset<Key, H2, P2, Allocator>&& source);   // C++17
347    template<class H2, class P2>
348      void merge(unordered_set<Key, H2, P2, Allocator>& source);         // C++17
349    template<class H2, class P2>
350      void merge(unordered_set<Key, H2, P2, Allocator>&& source);        // C++17
351
352    void swap(unordered_multiset&)
353       noexcept(allocator_traits<Allocator>::is_always_equal::value &&
354                 noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
355                 noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
356
357    hasher hash_function() const;
358    key_equal key_eq() const;
359
360    iterator       find(const key_type& k);
361    const_iterator find(const key_type& k) const;
362    template<typename K>
363        iterator find(const K& x);              // C++20
364    template<typename K>
365        const_iterator find(const K& x) const;  // C++20
366    size_type count(const key_type& k) const;
367    template<typename K>
368        size_type count(const K& k) const; // C++20
369    bool contains(const key_type& k) const; // C++20
370    template<typename K>
371        bool contains(const K& k) const; // C++20
372    pair<iterator, iterator>             equal_range(const key_type& k);
373    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
374    template<typename K>
375        pair<iterator, iterator>             equal_range(const K& k); // C++20
376    template<typename K>
377        pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
378
379    size_type bucket_count() const noexcept;
380    size_type max_bucket_count() const noexcept;
381
382    size_type bucket_size(size_type n) const;
383    size_type bucket(const key_type& k) const;
384
385    local_iterator       begin(size_type n);
386    local_iterator       end(size_type n);
387    const_local_iterator begin(size_type n) const;
388    const_local_iterator end(size_type n) const;
389    const_local_iterator cbegin(size_type n) const;
390    const_local_iterator cend(size_type n) const;
391
392    float load_factor() const noexcept;
393    float max_load_factor() const noexcept;
394    void max_load_factor(float z);
395    void rehash(size_type n);
396    void reserve(size_type n);
397};
398
399template<class InputIterator,
400    class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
401    class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
402    class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
403unordered_multiset(InputIterator, InputIterator, see below::size_type = see below,
404    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
405  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
406        Hash, Pred, Allocator>; // C++17
407
408template<class T, class Hash = hash<T>,
409          class Pred = equal_to<T>, class Allocator = allocator<T>>
410unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
411    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
412  -> unordered_multiset<T, Hash, Pred, Allocator>; // C++17
413
414template<class InputIterator,  class Allocator>
415unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
416  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
417        hash<typename iterator_traits<InputIterator>::value_type>,
418        equal_to<typename iterator_traits<InputIterator>::value_type>,
419        Allocator>; // C++17
420
421template<class InputIterator,  class Hash, class Allocator>
422unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
423    Hash, Allocator)
424  -> unordered_multiset<typename iterator_traits<InputIterator>::value_type, Hash,
425        equal_to<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
426
427template<class T, class Allocator>
428unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
429  -> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>; // C++17
430
431template<class T, class Hash, class Allocator>
432unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
433  -> unordered_multiset<T, Hash, equal_to<T>, Allocator>; // C++17
434
435template <class Value, class Hash, class Pred, class Alloc>
436    void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
437              unordered_multiset<Value, Hash, Pred, Alloc>& y)
438              noexcept(noexcept(x.swap(y)));
439
440template <class K, class T, class H, class P, class A, class Predicate>
441    typename unordered_set<K, T, H, P, A>::size_type
442    erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred);       // C++20
443
444template <class K, class T, class H, class P, class A, class Predicate>
445    typename unordered_multiset<K, T, H, P, A>::size_type
446    erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred);  // C++20
447
448
449template <class Value, class Hash, class Pred, class Alloc>
450    bool
451    operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
452               const unordered_multiset<Value, Hash, Pred, Alloc>& y);
453
454template <class Value, class Hash, class Pred, class Alloc>
455    bool
456    operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
457               const unordered_multiset<Value, Hash, Pred, Alloc>& y);
458}  // std
459
460*/
461
462#include <__config>
463#include <__debug>
464#include <__functional/is_transparent.h>
465#include <__hash_table>
466#include <__memory/addressof.h>
467#include <__node_handle>
468#include <__utility/forward.h>
469#include <compare>
470#include <functional>
471#include <iterator> // __libcpp_erase_if_container
472#include <version>
473
474#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
475#pragma GCC system_header
476#endif
477
478_LIBCPP_BEGIN_NAMESPACE_STD
479
480template <class _Value, class _Hash, class _Pred, class _Alloc>
481class unordered_multiset;
482
483template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
484          class _Alloc = allocator<_Value> >
485class _LIBCPP_TEMPLATE_VIS unordered_set
486{
487public:
488    // types
489    typedef _Value                                                     key_type;
490    typedef key_type                                                   value_type;
491    typedef __identity_t<_Hash>                                        hasher;
492    typedef __identity_t<_Pred>                                        key_equal;
493    typedef __identity_t<_Alloc>                                       allocator_type;
494    typedef value_type&                                                reference;
495    typedef const value_type&                                          const_reference;
496    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
497                  "Invalid allocator::value_type");
498
499private:
500    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
501
502    __table __table_;
503
504public:
505    typedef typename __table::pointer         pointer;
506    typedef typename __table::const_pointer   const_pointer;
507    typedef typename __table::size_type       size_type;
508    typedef typename __table::difference_type difference_type;
509
510    typedef typename __table::const_iterator       iterator;
511    typedef typename __table::const_iterator       const_iterator;
512    typedef typename __table::const_local_iterator local_iterator;
513    typedef typename __table::const_local_iterator const_local_iterator;
514
515#if _LIBCPP_STD_VER > 14
516    typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
517    typedef __insert_return_type<iterator, node_type> insert_return_type;
518#endif
519
520    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
521        friend class _LIBCPP_TEMPLATE_VIS unordered_set;
522    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
523        friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
524
525    _LIBCPP_INLINE_VISIBILITY
526    unordered_set()
527        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
528    {
529        _VSTD::__debug_db_insert_c(this);
530    }
531    explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
532                           const key_equal& __eql = key_equal());
533#if _LIBCPP_STD_VER > 11
534    inline _LIBCPP_INLINE_VISIBILITY
535    unordered_set(size_type __n, const allocator_type& __a)
536        : unordered_set(__n, hasher(), key_equal(), __a) {}
537    inline _LIBCPP_INLINE_VISIBILITY
538    unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
539        : unordered_set(__n, __hf, key_equal(), __a) {}
540#endif
541    unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
542                  const allocator_type& __a);
543    template <class _InputIterator>
544        unordered_set(_InputIterator __first, _InputIterator __last);
545    template <class _InputIterator>
546        unordered_set(_InputIterator __first, _InputIterator __last,
547                      size_type __n, const hasher& __hf = hasher(),
548                      const key_equal& __eql = key_equal());
549    template <class _InputIterator>
550        unordered_set(_InputIterator __first, _InputIterator __last,
551                      size_type __n, const hasher& __hf, const key_equal& __eql,
552                      const allocator_type& __a);
553#if _LIBCPP_STD_VER > 11
554    template <class _InputIterator>
555    inline _LIBCPP_INLINE_VISIBILITY
556        unordered_set(_InputIterator __first, _InputIterator __last,
557                    size_type __n, const allocator_type& __a)
558            : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
559    template <class _InputIterator>
560        unordered_set(_InputIterator __first, _InputIterator __last,
561                      size_type __n, const hasher& __hf, const allocator_type& __a)
562            : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
563#endif
564    _LIBCPP_INLINE_VISIBILITY
565    explicit unordered_set(const allocator_type& __a);
566    unordered_set(const unordered_set& __u);
567    unordered_set(const unordered_set& __u, const allocator_type& __a);
568#ifndef _LIBCPP_CXX03_LANG
569    _LIBCPP_INLINE_VISIBILITY
570    unordered_set(unordered_set&& __u)
571        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
572    unordered_set(unordered_set&& __u, const allocator_type& __a);
573    unordered_set(initializer_list<value_type> __il);
574    unordered_set(initializer_list<value_type> __il, size_type __n,
575                  const hasher& __hf = hasher(),
576                  const key_equal& __eql = key_equal());
577    unordered_set(initializer_list<value_type> __il, size_type __n,
578                  const hasher& __hf, const key_equal& __eql,
579                  const allocator_type& __a);
580#if _LIBCPP_STD_VER > 11
581    inline _LIBCPP_INLINE_VISIBILITY
582    unordered_set(initializer_list<value_type> __il, size_type __n,
583                                                      const allocator_type& __a)
584        : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
585    inline _LIBCPP_INLINE_VISIBILITY
586    unordered_set(initializer_list<value_type> __il, size_type __n,
587                                  const hasher& __hf, const allocator_type& __a)
588        : unordered_set(__il, __n, __hf, key_equal(), __a) {}
589#endif
590#endif // _LIBCPP_CXX03_LANG
591    _LIBCPP_INLINE_VISIBILITY
592    ~unordered_set() {
593        static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
594    }
595
596    _LIBCPP_INLINE_VISIBILITY
597    unordered_set& operator=(const unordered_set& __u)
598    {
599        __table_ = __u.__table_;
600        return *this;
601    }
602#ifndef _LIBCPP_CXX03_LANG
603    _LIBCPP_INLINE_VISIBILITY
604    unordered_set& operator=(unordered_set&& __u)
605        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
606    _LIBCPP_INLINE_VISIBILITY
607    unordered_set& operator=(initializer_list<value_type> __il);
608#endif // _LIBCPP_CXX03_LANG
609
610    _LIBCPP_INLINE_VISIBILITY
611    allocator_type get_allocator() const _NOEXCEPT
612        {return allocator_type(__table_.__node_alloc());}
613
614    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
615    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
616    _LIBCPP_INLINE_VISIBILITY
617    size_type size() const _NOEXCEPT  {return __table_.size();}
618    _LIBCPP_INLINE_VISIBILITY
619    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
620
621    _LIBCPP_INLINE_VISIBILITY
622    iterator       begin() _NOEXCEPT        {return __table_.begin();}
623    _LIBCPP_INLINE_VISIBILITY
624    iterator       end() _NOEXCEPT          {return __table_.end();}
625    _LIBCPP_INLINE_VISIBILITY
626    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
627    _LIBCPP_INLINE_VISIBILITY
628    const_iterator end()    const _NOEXCEPT {return __table_.end();}
629    _LIBCPP_INLINE_VISIBILITY
630    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
631    _LIBCPP_INLINE_VISIBILITY
632    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
633
634#ifndef _LIBCPP_CXX03_LANG
635    template <class... _Args>
636        _LIBCPP_INLINE_VISIBILITY
637        pair<iterator, bool> emplace(_Args&&... __args)
638            {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
639    template <class... _Args>
640        _LIBCPP_INLINE_VISIBILITY
641#if _LIBCPP_DEBUG_LEVEL == 2
642        iterator emplace_hint(const_iterator __p, _Args&&... __args)
643        {
644            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
645                "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
646                " referring to this unordered_set");
647            return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
648        }
649#else
650        iterator emplace_hint(const_iterator, _Args&&... __args)
651            {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
652#endif
653
654    _LIBCPP_INLINE_VISIBILITY
655    pair<iterator, bool> insert(value_type&& __x)
656        {return __table_.__insert_unique(_VSTD::move(__x));}
657    _LIBCPP_INLINE_VISIBILITY
658#if _LIBCPP_DEBUG_LEVEL == 2
659    iterator insert(const_iterator __p, value_type&& __x)
660        {
661            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
662                "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
663                " referring to this unordered_set");
664            return insert(_VSTD::move(__x)).first;
665        }
666#else
667    iterator insert(const_iterator, value_type&& __x)
668        {return insert(_VSTD::move(__x)).first;}
669#endif
670    _LIBCPP_INLINE_VISIBILITY
671    void insert(initializer_list<value_type> __il)
672        {insert(__il.begin(), __il.end());}
673#endif // _LIBCPP_CXX03_LANG
674    _LIBCPP_INLINE_VISIBILITY
675    pair<iterator, bool> insert(const value_type& __x)
676        {return __table_.__insert_unique(__x);}
677
678    _LIBCPP_INLINE_VISIBILITY
679#if _LIBCPP_DEBUG_LEVEL == 2
680    iterator insert(const_iterator __p, const value_type& __x)
681        {
682            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
683                "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
684                " referring to this unordered_set");
685            return insert(__x).first;
686        }
687#else
688    iterator insert(const_iterator, const value_type& __x)
689        {return insert(__x).first;}
690#endif
691    template <class _InputIterator>
692        _LIBCPP_INLINE_VISIBILITY
693        void insert(_InputIterator __first, _InputIterator __last);
694
695    _LIBCPP_INLINE_VISIBILITY
696    iterator erase(const_iterator __p) {return __table_.erase(__p);}
697    _LIBCPP_INLINE_VISIBILITY
698    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
699    _LIBCPP_INLINE_VISIBILITY
700    iterator erase(const_iterator __first, const_iterator __last)
701        {return __table_.erase(__first, __last);}
702    _LIBCPP_INLINE_VISIBILITY
703    void clear() _NOEXCEPT {__table_.clear();}
704
705#if _LIBCPP_STD_VER > 14
706    _LIBCPP_INLINE_VISIBILITY
707    insert_return_type insert(node_type&& __nh)
708    {
709        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
710            "node_type with incompatible allocator passed to unordered_set::insert()");
711        return __table_.template __node_handle_insert_unique<
712            node_type, insert_return_type>(_VSTD::move(__nh));
713    }
714    _LIBCPP_INLINE_VISIBILITY
715    iterator insert(const_iterator __h, node_type&& __nh)
716    {
717        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
718            "node_type with incompatible allocator passed to unordered_set::insert()");
719        return __table_.template __node_handle_insert_unique<node_type>(
720            __h, _VSTD::move(__nh));
721    }
722    _LIBCPP_INLINE_VISIBILITY
723    node_type extract(key_type const& __key)
724    {
725        return __table_.template __node_handle_extract<node_type>(__key);
726    }
727    _LIBCPP_INLINE_VISIBILITY
728    node_type extract(const_iterator __it)
729    {
730        return __table_.template __node_handle_extract<node_type>(__it);
731    }
732
733    template<class _H2, class _P2>
734    _LIBCPP_INLINE_VISIBILITY
735    void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
736    {
737        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
738                       "merging container with incompatible allocator");
739        __table_.__node_handle_merge_unique(__source.__table_);
740    }
741    template<class _H2, class _P2>
742    _LIBCPP_INLINE_VISIBILITY
743    void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
744    {
745        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
746                       "merging container with incompatible allocator");
747        __table_.__node_handle_merge_unique(__source.__table_);
748    }
749    template<class _H2, class _P2>
750    _LIBCPP_INLINE_VISIBILITY
751    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
752    {
753        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
754                       "merging container with incompatible allocator");
755        __table_.__node_handle_merge_unique(__source.__table_);
756    }
757    template<class _H2, class _P2>
758    _LIBCPP_INLINE_VISIBILITY
759    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
760    {
761        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
762                       "merging container with incompatible allocator");
763        __table_.__node_handle_merge_unique(__source.__table_);
764    }
765#endif
766
767    _LIBCPP_INLINE_VISIBILITY
768    void swap(unordered_set& __u)
769        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
770        {__table_.swap(__u.__table_);}
771
772    _LIBCPP_INLINE_VISIBILITY
773    hasher hash_function() const {return __table_.hash_function();}
774    _LIBCPP_INLINE_VISIBILITY
775    key_equal key_eq() const {return __table_.key_eq();}
776
777    _LIBCPP_INLINE_VISIBILITY
778    iterator       find(const key_type& __k)       {return __table_.find(__k);}
779    _LIBCPP_INLINE_VISIBILITY
780    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
781#if _LIBCPP_STD_VER > 17
782    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
783    _LIBCPP_INLINE_VISIBILITY
784    iterator       find(const _K2& __k)            {return __table_.find(__k);}
785    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
786    _LIBCPP_INLINE_VISIBILITY
787    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
788#endif // _LIBCPP_STD_VER > 17
789
790    _LIBCPP_INLINE_VISIBILITY
791    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
792#if _LIBCPP_STD_VER > 17
793    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
794    _LIBCPP_INLINE_VISIBILITY
795    size_type count(const _K2& __k) const      {return __table_.__count_unique(__k);}
796#endif // _LIBCPP_STD_VER > 17
797
798#if _LIBCPP_STD_VER > 17
799    _LIBCPP_INLINE_VISIBILITY
800    bool contains(const key_type& __k) const {return find(__k) != end();}
801
802    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
803    _LIBCPP_INLINE_VISIBILITY
804    bool contains(const _K2& __k) const      {return find(__k) != end();}
805#endif // _LIBCPP_STD_VER > 17
806
807    _LIBCPP_INLINE_VISIBILITY
808    pair<iterator, iterator>             equal_range(const key_type& __k)
809        {return __table_.__equal_range_unique(__k);}
810    _LIBCPP_INLINE_VISIBILITY
811    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
812        {return __table_.__equal_range_unique(__k);}
813#if _LIBCPP_STD_VER > 17
814    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
815    _LIBCPP_INLINE_VISIBILITY
816    pair<iterator, iterator>             equal_range(const _K2& __k)
817        {return __table_.__equal_range_unique(__k);}
818    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
819    _LIBCPP_INLINE_VISIBILITY
820    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
821        {return __table_.__equal_range_unique(__k);}
822#endif // _LIBCPP_STD_VER > 17
823
824    _LIBCPP_INLINE_VISIBILITY
825    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
826    _LIBCPP_INLINE_VISIBILITY
827    size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
828
829    _LIBCPP_INLINE_VISIBILITY
830    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
831    _LIBCPP_INLINE_VISIBILITY
832    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
833
834    _LIBCPP_INLINE_VISIBILITY
835    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
836    _LIBCPP_INLINE_VISIBILITY
837    local_iterator       end(size_type __n)          {return __table_.end(__n);}
838    _LIBCPP_INLINE_VISIBILITY
839    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
840    _LIBCPP_INLINE_VISIBILITY
841    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
842    _LIBCPP_INLINE_VISIBILITY
843    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
844    _LIBCPP_INLINE_VISIBILITY
845    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
846
847    _LIBCPP_INLINE_VISIBILITY
848    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
849    _LIBCPP_INLINE_VISIBILITY
850    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
851    _LIBCPP_INLINE_VISIBILITY
852    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
853    _LIBCPP_INLINE_VISIBILITY
854    void rehash(size_type __n) {__table_.rehash(__n);}
855    _LIBCPP_INLINE_VISIBILITY
856    void reserve(size_type __n) {__table_.reserve(__n);}
857
858#if _LIBCPP_DEBUG_LEVEL == 2
859
860    bool __dereferenceable(const const_iterator* __i) const
861        {return __table_.__dereferenceable(__i);}
862    bool __decrementable(const const_iterator* __i) const
863        {return __table_.__decrementable(__i);}
864    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
865        {return __table_.__addable(__i, __n);}
866    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
867        {return __table_.__addable(__i, __n);}
868
869#endif // _LIBCPP_DEBUG_LEVEL == 2
870
871};
872
873#if _LIBCPP_STD_VER >= 17
874template<class _InputIterator,
875         class _Hash = hash<__iter_value_type<_InputIterator>>,
876         class _Pred = equal_to<__iter_value_type<_InputIterator>>,
877         class _Allocator = allocator<__iter_value_type<_InputIterator>>,
878         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
879         class = enable_if_t<!__is_allocator<_Hash>::value>,
880         class = enable_if_t<!is_integral<_Hash>::value>,
881         class = enable_if_t<!__is_allocator<_Pred>::value>,
882         class = enable_if_t<__is_allocator<_Allocator>::value>>
883unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
884              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
885  -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
886
887template<class _Tp, class _Hash = hash<_Tp>,
888         class _Pred = equal_to<_Tp>,
889         class _Allocator = allocator<_Tp>,
890         class = enable_if_t<!__is_allocator<_Hash>::value>,
891         class = enable_if_t<!is_integral<_Hash>::value>,
892         class = enable_if_t<!__is_allocator<_Pred>::value>,
893         class = enable_if_t<__is_allocator<_Allocator>::value>>
894unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
895              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
896  -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
897
898template<class _InputIterator, class _Allocator,
899         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
900         class = enable_if_t<__is_allocator<_Allocator>::value>>
901unordered_set(_InputIterator, _InputIterator,
902              typename allocator_traits<_Allocator>::size_type, _Allocator)
903  -> unordered_set<__iter_value_type<_InputIterator>,
904                   hash<__iter_value_type<_InputIterator>>,
905                   equal_to<__iter_value_type<_InputIterator>>,
906                   _Allocator>;
907
908template<class _InputIterator, class _Hash, class _Allocator,
909         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
910         class = enable_if_t<!__is_allocator<_Hash>::value>,
911         class = enable_if_t<!is_integral<_Hash>::value>,
912         class = enable_if_t<__is_allocator<_Allocator>::value>>
913unordered_set(_InputIterator, _InputIterator,
914              typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
915  -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
916                   equal_to<__iter_value_type<_InputIterator>>,
917                   _Allocator>;
918
919template<class _Tp, class _Allocator,
920         class = enable_if_t<__is_allocator<_Allocator>::value>>
921unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
922  -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
923
924template<class _Tp, class _Hash, class _Allocator,
925         class = enable_if_t<!__is_allocator<_Hash>::value>,
926         class = enable_if_t<!is_integral<_Hash>::value>,
927         class = enable_if_t<__is_allocator<_Allocator>::value>>
928unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
929  -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
930#endif
931
932template <class _Value, class _Hash, class _Pred, class _Alloc>
933unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
934        const hasher& __hf, const key_equal& __eql)
935    : __table_(__hf, __eql)
936{
937    _VSTD::__debug_db_insert_c(this);
938    __table_.rehash(__n);
939}
940
941template <class _Value, class _Hash, class _Pred, class _Alloc>
942unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
943        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
944    : __table_(__hf, __eql, __a)
945{
946    _VSTD::__debug_db_insert_c(this);
947    __table_.rehash(__n);
948}
949
950template <class _Value, class _Hash, class _Pred, class _Alloc>
951template <class _InputIterator>
952unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
953        _InputIterator __first, _InputIterator __last)
954{
955    _VSTD::__debug_db_insert_c(this);
956    insert(__first, __last);
957}
958
959template <class _Value, class _Hash, class _Pred, class _Alloc>
960template <class _InputIterator>
961unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
962        _InputIterator __first, _InputIterator __last, size_type __n,
963        const hasher& __hf, const key_equal& __eql)
964    : __table_(__hf, __eql)
965{
966    _VSTD::__debug_db_insert_c(this);
967    __table_.rehash(__n);
968    insert(__first, __last);
969}
970
971template <class _Value, class _Hash, class _Pred, class _Alloc>
972template <class _InputIterator>
973unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
974        _InputIterator __first, _InputIterator __last, size_type __n,
975        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
976    : __table_(__hf, __eql, __a)
977{
978    _VSTD::__debug_db_insert_c(this);
979    __table_.rehash(__n);
980    insert(__first, __last);
981}
982
983template <class _Value, class _Hash, class _Pred, class _Alloc>
984inline
985unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
986        const allocator_type& __a)
987    : __table_(__a)
988{
989    _VSTD::__debug_db_insert_c(this);
990}
991
992template <class _Value, class _Hash, class _Pred, class _Alloc>
993unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
994        const unordered_set& __u)
995    : __table_(__u.__table_)
996{
997    _VSTD::__debug_db_insert_c(this);
998    __table_.rehash(__u.bucket_count());
999    insert(__u.begin(), __u.end());
1000}
1001
1002template <class _Value, class _Hash, class _Pred, class _Alloc>
1003unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1004        const unordered_set& __u, const allocator_type& __a)
1005    : __table_(__u.__table_, __a)
1006{
1007    _VSTD::__debug_db_insert_c(this);
1008    __table_.rehash(__u.bucket_count());
1009    insert(__u.begin(), __u.end());
1010}
1011
1012#ifndef _LIBCPP_CXX03_LANG
1013
1014template <class _Value, class _Hash, class _Pred, class _Alloc>
1015inline
1016unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1017        unordered_set&& __u)
1018    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1019    : __table_(_VSTD::move(__u.__table_))
1020{
1021    _VSTD::__debug_db_insert_c(this);
1022#if _LIBCPP_DEBUG_LEVEL == 2
1023    __get_db()->swap(this, _VSTD::addressof(__u));
1024#endif
1025}
1026
1027template <class _Value, class _Hash, class _Pred, class _Alloc>
1028unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1029        unordered_set&& __u, const allocator_type& __a)
1030    : __table_(_VSTD::move(__u.__table_), __a)
1031{
1032    _VSTD::__debug_db_insert_c(this);
1033    if (__a != __u.get_allocator())
1034    {
1035        iterator __i = __u.begin();
1036        while (__u.size() != 0)
1037            __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
1038    }
1039#if _LIBCPP_DEBUG_LEVEL == 2
1040    else
1041        __get_db()->swap(this, _VSTD::addressof(__u));
1042#endif
1043}
1044
1045template <class _Value, class _Hash, class _Pred, class _Alloc>
1046unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1047        initializer_list<value_type> __il)
1048{
1049    _VSTD::__debug_db_insert_c(this);
1050    insert(__il.begin(), __il.end());
1051}
1052
1053template <class _Value, class _Hash, class _Pred, class _Alloc>
1054unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1055        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1056        const key_equal& __eql)
1057    : __table_(__hf, __eql)
1058{
1059    _VSTD::__debug_db_insert_c(this);
1060    __table_.rehash(__n);
1061    insert(__il.begin(), __il.end());
1062}
1063
1064template <class _Value, class _Hash, class _Pred, class _Alloc>
1065unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1066        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1067        const key_equal& __eql, const allocator_type& __a)
1068    : __table_(__hf, __eql, __a)
1069{
1070    _VSTD::__debug_db_insert_c(this);
1071    __table_.rehash(__n);
1072    insert(__il.begin(), __il.end());
1073}
1074
1075template <class _Value, class _Hash, class _Pred, class _Alloc>
1076inline
1077unordered_set<_Value, _Hash, _Pred, _Alloc>&
1078unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
1079    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1080{
1081    __table_ = _VSTD::move(__u.__table_);
1082    return *this;
1083}
1084
1085template <class _Value, class _Hash, class _Pred, class _Alloc>
1086inline
1087unordered_set<_Value, _Hash, _Pred, _Alloc>&
1088unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
1089        initializer_list<value_type> __il)
1090{
1091    __table_.__assign_unique(__il.begin(), __il.end());
1092    return *this;
1093}
1094
1095#endif // _LIBCPP_CXX03_LANG
1096
1097template <class _Value, class _Hash, class _Pred, class _Alloc>
1098template <class _InputIterator>
1099inline
1100void
1101unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1102                                                    _InputIterator __last)
1103{
1104    for (; __first != __last; ++__first)
1105        __table_.__insert_unique(*__first);
1106}
1107
1108template <class _Value, class _Hash, class _Pred, class _Alloc>
1109inline _LIBCPP_INLINE_VISIBILITY
1110void
1111swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1112     unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1113    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1114{
1115    __x.swap(__y);
1116}
1117
1118#if _LIBCPP_STD_VER > 17
1119template <class _Value, class _Hash, class _Pred, class _Alloc,
1120          class _Predicate>
1121inline _LIBCPP_INLINE_VISIBILITY
1122    typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
1123    erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
1124             _Predicate __pred) {
1125  return _VSTD::__libcpp_erase_if_container(__c, __pred);
1126}
1127#endif
1128
1129template <class _Value, class _Hash, class _Pred, class _Alloc>
1130bool
1131operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1132           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1133{
1134    if (__x.size() != __y.size())
1135        return false;
1136    typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
1137                                                                 const_iterator;
1138    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1139            __i != __ex; ++__i)
1140    {
1141        const_iterator __j = __y.find(*__i);
1142        if (__j == __ey || !(*__i == *__j))
1143            return false;
1144    }
1145    return true;
1146}
1147
1148template <class _Value, class _Hash, class _Pred, class _Alloc>
1149inline _LIBCPP_INLINE_VISIBILITY
1150bool
1151operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1152           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1153{
1154    return !(__x == __y);
1155}
1156
1157template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
1158          class _Alloc = allocator<_Value> >
1159class _LIBCPP_TEMPLATE_VIS unordered_multiset
1160{
1161public:
1162    // types
1163    typedef _Value                                                     key_type;
1164    typedef key_type                                                   value_type;
1165    typedef __identity_t<_Hash>                                        hasher;
1166    typedef __identity_t<_Pred>                                        key_equal;
1167    typedef __identity_t<_Alloc>                                       allocator_type;
1168    typedef value_type&                                                reference;
1169    typedef const value_type&                                          const_reference;
1170    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1171                  "Invalid allocator::value_type");
1172
1173private:
1174    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
1175
1176    __table __table_;
1177
1178public:
1179    typedef typename __table::pointer         pointer;
1180    typedef typename __table::const_pointer   const_pointer;
1181    typedef typename __table::size_type       size_type;
1182    typedef typename __table::difference_type difference_type;
1183
1184    typedef typename __table::const_iterator       iterator;
1185    typedef typename __table::const_iterator       const_iterator;
1186    typedef typename __table::const_local_iterator local_iterator;
1187    typedef typename __table::const_local_iterator const_local_iterator;
1188
1189#if _LIBCPP_STD_VER > 14
1190    typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
1191#endif
1192
1193    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1194        friend class _LIBCPP_TEMPLATE_VIS unordered_set;
1195    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1196        friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
1197
1198    _LIBCPP_INLINE_VISIBILITY
1199    unordered_multiset()
1200        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1201    {
1202        _VSTD::__debug_db_insert_c(this);
1203    }
1204    explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
1205                                const key_equal& __eql = key_equal());
1206    unordered_multiset(size_type __n, const hasher& __hf,
1207                       const key_equal& __eql, const allocator_type& __a);
1208#if _LIBCPP_STD_VER > 11
1209    inline _LIBCPP_INLINE_VISIBILITY
1210    unordered_multiset(size_type __n, const allocator_type& __a)
1211        : unordered_multiset(__n, hasher(), key_equal(), __a) {}
1212    inline _LIBCPP_INLINE_VISIBILITY
1213    unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
1214        : unordered_multiset(__n, __hf, key_equal(), __a) {}
1215#endif
1216    template <class _InputIterator>
1217        unordered_multiset(_InputIterator __first, _InputIterator __last);
1218    template <class _InputIterator>
1219        unordered_multiset(_InputIterator __first, _InputIterator __last,
1220                      size_type __n, const hasher& __hf = hasher(),
1221                      const key_equal& __eql = key_equal());
1222    template <class _InputIterator>
1223        unordered_multiset(_InputIterator __first, _InputIterator __last,
1224                      size_type __n , const hasher& __hf,
1225                      const key_equal& __eql, const allocator_type& __a);
1226#if _LIBCPP_STD_VER > 11
1227    template <class _InputIterator>
1228    inline _LIBCPP_INLINE_VISIBILITY
1229    unordered_multiset(_InputIterator __first, _InputIterator __last,
1230                       size_type __n, const allocator_type& __a)
1231        : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
1232    template <class _InputIterator>
1233    inline _LIBCPP_INLINE_VISIBILITY
1234    unordered_multiset(_InputIterator __first, _InputIterator __last,
1235                       size_type __n, const hasher& __hf, const allocator_type& __a)
1236        : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
1237#endif
1238    _LIBCPP_INLINE_VISIBILITY
1239    explicit unordered_multiset(const allocator_type& __a);
1240    unordered_multiset(const unordered_multiset& __u);
1241    unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
1242#ifndef _LIBCPP_CXX03_LANG
1243    _LIBCPP_INLINE_VISIBILITY
1244    unordered_multiset(unordered_multiset&& __u)
1245        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
1246    unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
1247    unordered_multiset(initializer_list<value_type> __il);
1248    unordered_multiset(initializer_list<value_type> __il, size_type __n,
1249                       const hasher& __hf = hasher(),
1250                       const key_equal& __eql = key_equal());
1251    unordered_multiset(initializer_list<value_type> __il, size_type __n,
1252                       const hasher& __hf, const key_equal& __eql,
1253                       const allocator_type& __a);
1254#if _LIBCPP_STD_VER > 11
1255    inline _LIBCPP_INLINE_VISIBILITY
1256    unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1257      : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
1258    inline _LIBCPP_INLINE_VISIBILITY
1259    unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
1260      : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1261#endif
1262#endif // _LIBCPP_CXX03_LANG
1263    _LIBCPP_INLINE_VISIBILITY
1264    ~unordered_multiset() {
1265        static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
1266    }
1267
1268    _LIBCPP_INLINE_VISIBILITY
1269    unordered_multiset& operator=(const unordered_multiset& __u)
1270    {
1271        __table_ = __u.__table_;
1272        return *this;
1273    }
1274#ifndef _LIBCPP_CXX03_LANG
1275    _LIBCPP_INLINE_VISIBILITY
1276    unordered_multiset& operator=(unordered_multiset&& __u)
1277        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
1278    unordered_multiset& operator=(initializer_list<value_type> __il);
1279#endif // _LIBCPP_CXX03_LANG
1280
1281    _LIBCPP_INLINE_VISIBILITY
1282    allocator_type get_allocator() const _NOEXCEPT
1283        {return allocator_type(__table_.__node_alloc());}
1284
1285    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1286    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
1287    _LIBCPP_INLINE_VISIBILITY
1288    size_type size() const _NOEXCEPT  {return __table_.size();}
1289    _LIBCPP_INLINE_VISIBILITY
1290    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1291
1292    _LIBCPP_INLINE_VISIBILITY
1293    iterator       begin() _NOEXCEPT        {return __table_.begin();}
1294    _LIBCPP_INLINE_VISIBILITY
1295    iterator       end() _NOEXCEPT          {return __table_.end();}
1296    _LIBCPP_INLINE_VISIBILITY
1297    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
1298    _LIBCPP_INLINE_VISIBILITY
1299    const_iterator end()    const _NOEXCEPT {return __table_.end();}
1300    _LIBCPP_INLINE_VISIBILITY
1301    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1302    _LIBCPP_INLINE_VISIBILITY
1303    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
1304
1305#ifndef _LIBCPP_CXX03_LANG
1306    template <class... _Args>
1307        _LIBCPP_INLINE_VISIBILITY
1308        iterator emplace(_Args&&... __args)
1309            {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
1310    template <class... _Args>
1311        _LIBCPP_INLINE_VISIBILITY
1312        iterator emplace_hint(const_iterator __p, _Args&&... __args)
1313            {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
1314
1315    _LIBCPP_INLINE_VISIBILITY
1316    iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1317    _LIBCPP_INLINE_VISIBILITY
1318    iterator insert(const_iterator __p, value_type&& __x)
1319        {return __table_.__insert_multi(__p, _VSTD::move(__x));}
1320    _LIBCPP_INLINE_VISIBILITY
1321    void insert(initializer_list<value_type> __il)
1322        {insert(__il.begin(), __il.end());}
1323#endif // _LIBCPP_CXX03_LANG
1324
1325    _LIBCPP_INLINE_VISIBILITY
1326    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1327
1328    _LIBCPP_INLINE_VISIBILITY
1329    iterator insert(const_iterator __p, const value_type& __x)
1330        {return __table_.__insert_multi(__p, __x);}
1331
1332    template <class _InputIterator>
1333        _LIBCPP_INLINE_VISIBILITY
1334        void insert(_InputIterator __first, _InputIterator __last);
1335
1336#if _LIBCPP_STD_VER > 14
1337    _LIBCPP_INLINE_VISIBILITY
1338    iterator insert(node_type&& __nh)
1339    {
1340        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1341            "node_type with incompatible allocator passed to unordered_multiset::insert()");
1342        return __table_.template __node_handle_insert_multi<node_type>(
1343            _VSTD::move(__nh));
1344    }
1345    _LIBCPP_INLINE_VISIBILITY
1346    iterator insert(const_iterator __hint, node_type&& __nh)
1347    {
1348        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1349            "node_type with incompatible allocator passed to unordered_multiset::insert()");
1350        return __table_.template __node_handle_insert_multi<node_type>(
1351            __hint, _VSTD::move(__nh));
1352    }
1353    _LIBCPP_INLINE_VISIBILITY
1354    node_type extract(const_iterator __position)
1355    {
1356        return __table_.template __node_handle_extract<node_type>(
1357            __position);
1358    }
1359    _LIBCPP_INLINE_VISIBILITY
1360    node_type extract(key_type const& __key)
1361    {
1362        return __table_.template __node_handle_extract<node_type>(__key);
1363    }
1364
1365    template <class _H2, class _P2>
1366    _LIBCPP_INLINE_VISIBILITY
1367    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
1368    {
1369        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1370                       "merging container with incompatible allocator");
1371        return __table_.__node_handle_merge_multi(__source.__table_);
1372    }
1373    template <class _H2, class _P2>
1374    _LIBCPP_INLINE_VISIBILITY
1375    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
1376    {
1377        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1378                       "merging container with incompatible allocator");
1379        return __table_.__node_handle_merge_multi(__source.__table_);
1380    }
1381    template <class _H2, class _P2>
1382    _LIBCPP_INLINE_VISIBILITY
1383    void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
1384    {
1385        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1386                       "merging container with incompatible allocator");
1387        return __table_.__node_handle_merge_multi(__source.__table_);
1388    }
1389    template <class _H2, class _P2>
1390    _LIBCPP_INLINE_VISIBILITY
1391    void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
1392    {
1393        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1394                       "merging container with incompatible allocator");
1395        return __table_.__node_handle_merge_multi(__source.__table_);
1396    }
1397#endif
1398
1399    _LIBCPP_INLINE_VISIBILITY
1400    iterator erase(const_iterator __p) {return __table_.erase(__p);}
1401    _LIBCPP_INLINE_VISIBILITY
1402    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
1403    _LIBCPP_INLINE_VISIBILITY
1404    iterator erase(const_iterator __first, const_iterator __last)
1405        {return __table_.erase(__first, __last);}
1406    _LIBCPP_INLINE_VISIBILITY
1407    void clear() _NOEXCEPT {__table_.clear();}
1408
1409    _LIBCPP_INLINE_VISIBILITY
1410    void swap(unordered_multiset& __u)
1411        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1412        {__table_.swap(__u.__table_);}
1413
1414    _LIBCPP_INLINE_VISIBILITY
1415    hasher hash_function() const {return __table_.hash_function();}
1416    _LIBCPP_INLINE_VISIBILITY
1417    key_equal key_eq() const {return __table_.key_eq();}
1418
1419    _LIBCPP_INLINE_VISIBILITY
1420    iterator       find(const key_type& __k)       {return __table_.find(__k);}
1421    _LIBCPP_INLINE_VISIBILITY
1422    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1423#if _LIBCPP_STD_VER > 17
1424    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1425    _LIBCPP_INLINE_VISIBILITY
1426    iterator       find(const _K2& __k)            {return __table_.find(__k);}
1427    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1428    _LIBCPP_INLINE_VISIBILITY
1429    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
1430#endif // _LIBCPP_STD_VER > 17
1431
1432    _LIBCPP_INLINE_VISIBILITY
1433    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
1434#if _LIBCPP_STD_VER > 17
1435    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1436    _LIBCPP_INLINE_VISIBILITY
1437    size_type count(const _K2& __k) const      {return __table_.__count_multi(__k);}
1438#endif // _LIBCPP_STD_VER > 17
1439
1440#if _LIBCPP_STD_VER > 17
1441    _LIBCPP_INLINE_VISIBILITY
1442    bool contains(const key_type& __k) const {return find(__k) != end();}
1443
1444    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1445    _LIBCPP_INLINE_VISIBILITY
1446    bool contains(const _K2& __k) const      {return find(__k) != end();}
1447#endif // _LIBCPP_STD_VER > 17
1448
1449    _LIBCPP_INLINE_VISIBILITY
1450    pair<iterator, iterator>             equal_range(const key_type& __k)
1451        {return __table_.__equal_range_multi(__k);}
1452    _LIBCPP_INLINE_VISIBILITY
1453    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1454        {return __table_.__equal_range_multi(__k);}
1455#if _LIBCPP_STD_VER > 17
1456    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1457    _LIBCPP_INLINE_VISIBILITY
1458    pair<iterator, iterator>             equal_range(const _K2& __k)
1459        {return __table_.__equal_range_multi(__k);}
1460    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1461    _LIBCPP_INLINE_VISIBILITY
1462    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
1463        {return __table_.__equal_range_multi(__k);}
1464#endif // _LIBCPP_STD_VER > 17
1465
1466    _LIBCPP_INLINE_VISIBILITY
1467    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1468    _LIBCPP_INLINE_VISIBILITY
1469    size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
1470
1471    _LIBCPP_INLINE_VISIBILITY
1472    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
1473    _LIBCPP_INLINE_VISIBILITY
1474    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1475
1476    _LIBCPP_INLINE_VISIBILITY
1477    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
1478    _LIBCPP_INLINE_VISIBILITY
1479    local_iterator       end(size_type __n)          {return __table_.end(__n);}
1480    _LIBCPP_INLINE_VISIBILITY
1481    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
1482    _LIBCPP_INLINE_VISIBILITY
1483    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
1484    _LIBCPP_INLINE_VISIBILITY
1485    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1486    _LIBCPP_INLINE_VISIBILITY
1487    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
1488
1489    _LIBCPP_INLINE_VISIBILITY
1490    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1491    _LIBCPP_INLINE_VISIBILITY
1492    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1493    _LIBCPP_INLINE_VISIBILITY
1494    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1495    _LIBCPP_INLINE_VISIBILITY
1496    void rehash(size_type __n) {__table_.rehash(__n);}
1497    _LIBCPP_INLINE_VISIBILITY
1498    void reserve(size_type __n) {__table_.reserve(__n);}
1499
1500#if _LIBCPP_DEBUG_LEVEL == 2
1501
1502    bool __dereferenceable(const const_iterator* __i) const
1503        {return __table_.__dereferenceable(__i);}
1504    bool __decrementable(const const_iterator* __i) const
1505        {return __table_.__decrementable(__i);}
1506    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1507        {return __table_.__addable(__i, __n);}
1508    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1509        {return __table_.__addable(__i, __n);}
1510
1511#endif // _LIBCPP_DEBUG_LEVEL == 2
1512
1513};
1514
1515#if _LIBCPP_STD_VER >= 17
1516template<class _InputIterator,
1517         class _Hash = hash<__iter_value_type<_InputIterator>>,
1518         class _Pred = equal_to<__iter_value_type<_InputIterator>>,
1519         class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1520         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1521         class = enable_if_t<!__is_allocator<_Hash>::value>,
1522         class = enable_if_t<!is_integral<_Hash>::value>,
1523         class = enable_if_t<!__is_allocator<_Pred>::value>,
1524         class = enable_if_t<__is_allocator<_Allocator>::value>>
1525unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
1526              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1527  -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
1528
1529template<class _Tp, class _Hash = hash<_Tp>,
1530         class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
1531         class = enable_if_t<!__is_allocator<_Hash>::value>,
1532         class = enable_if_t<!is_integral<_Hash>::value>,
1533         class = enable_if_t<!__is_allocator<_Pred>::value>,
1534         class = enable_if_t<__is_allocator<_Allocator>::value>>
1535unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
1536              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1537  -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
1538
1539template<class _InputIterator, class _Allocator,
1540         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1541         class = enable_if_t<__is_allocator<_Allocator>::value>>
1542unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
1543  -> unordered_multiset<__iter_value_type<_InputIterator>,
1544                   hash<__iter_value_type<_InputIterator>>,
1545                   equal_to<__iter_value_type<_InputIterator>>,
1546                   _Allocator>;
1547
1548template<class _InputIterator, class _Hash, class _Allocator,
1549         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1550         class = enable_if_t<!__is_allocator<_Hash>::value>,
1551         class = enable_if_t<!is_integral<_Hash>::value>,
1552         class = enable_if_t<__is_allocator<_Allocator>::value>>
1553unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
1554              _Hash, _Allocator)
1555  -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
1556                   equal_to<__iter_value_type<_InputIterator>>,
1557                   _Allocator>;
1558
1559template<class _Tp, class _Allocator,
1560         class = enable_if_t<__is_allocator<_Allocator>::value>>
1561unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
1562  -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
1563
1564template<class _Tp, class _Hash, class _Allocator,
1565         class = enable_if_t<!__is_allocator<_Hash>::value>,
1566         class = enable_if_t<!is_integral<_Hash>::value>,
1567         class = enable_if_t<__is_allocator<_Allocator>::value>>
1568unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1569  -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1570#endif
1571
1572template <class _Value, class _Hash, class _Pred, class _Alloc>
1573unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1574        size_type __n, const hasher& __hf, const key_equal& __eql)
1575    : __table_(__hf, __eql)
1576{
1577    _VSTD::__debug_db_insert_c(this);
1578    __table_.rehash(__n);
1579}
1580
1581template <class _Value, class _Hash, class _Pred, class _Alloc>
1582unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1583        size_type __n, const hasher& __hf, const key_equal& __eql,
1584        const allocator_type& __a)
1585    : __table_(__hf, __eql, __a)
1586{
1587    _VSTD::__debug_db_insert_c(this);
1588    __table_.rehash(__n);
1589}
1590
1591template <class _Value, class _Hash, class _Pred, class _Alloc>
1592template <class _InputIterator>
1593unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1594        _InputIterator __first, _InputIterator __last)
1595{
1596    _VSTD::__debug_db_insert_c(this);
1597    insert(__first, __last);
1598}
1599
1600template <class _Value, class _Hash, class _Pred, class _Alloc>
1601template <class _InputIterator>
1602unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1603        _InputIterator __first, _InputIterator __last, size_type __n,
1604        const hasher& __hf, const key_equal& __eql)
1605    : __table_(__hf, __eql)
1606{
1607    _VSTD::__debug_db_insert_c(this);
1608    __table_.rehash(__n);
1609    insert(__first, __last);
1610}
1611
1612template <class _Value, class _Hash, class _Pred, class _Alloc>
1613template <class _InputIterator>
1614unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1615        _InputIterator __first, _InputIterator __last, size_type __n,
1616        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1617    : __table_(__hf, __eql, __a)
1618{
1619    _VSTD::__debug_db_insert_c(this);
1620    __table_.rehash(__n);
1621    insert(__first, __last);
1622}
1623
1624template <class _Value, class _Hash, class _Pred, class _Alloc>
1625inline
1626unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1627        const allocator_type& __a)
1628    : __table_(__a)
1629{
1630    _VSTD::__debug_db_insert_c(this);
1631}
1632
1633template <class _Value, class _Hash, class _Pred, class _Alloc>
1634unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1635        const unordered_multiset& __u)
1636    : __table_(__u.__table_)
1637{
1638    _VSTD::__debug_db_insert_c(this);
1639    __table_.rehash(__u.bucket_count());
1640    insert(__u.begin(), __u.end());
1641}
1642
1643template <class _Value, class _Hash, class _Pred, class _Alloc>
1644unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1645        const unordered_multiset& __u, const allocator_type& __a)
1646    : __table_(__u.__table_, __a)
1647{
1648    _VSTD::__debug_db_insert_c(this);
1649    __table_.rehash(__u.bucket_count());
1650    insert(__u.begin(), __u.end());
1651}
1652
1653#ifndef _LIBCPP_CXX03_LANG
1654
1655template <class _Value, class _Hash, class _Pred, class _Alloc>
1656inline
1657unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1658        unordered_multiset&& __u)
1659    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1660    : __table_(_VSTD::move(__u.__table_))
1661{
1662    _VSTD::__debug_db_insert_c(this);
1663#if _LIBCPP_DEBUG_LEVEL == 2
1664    __get_db()->swap(this, _VSTD::addressof(__u));
1665#endif
1666}
1667
1668template <class _Value, class _Hash, class _Pred, class _Alloc>
1669unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1670        unordered_multiset&& __u, const allocator_type& __a)
1671    : __table_(_VSTD::move(__u.__table_), __a)
1672{
1673    _VSTD::__debug_db_insert_c(this);
1674    if (__a != __u.get_allocator())
1675    {
1676        iterator __i = __u.begin();
1677        while (__u.size() != 0)
1678            __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
1679    }
1680#if _LIBCPP_DEBUG_LEVEL == 2
1681    else
1682        __get_db()->swap(this, _VSTD::addressof(__u));
1683#endif
1684}
1685
1686template <class _Value, class _Hash, class _Pred, class _Alloc>
1687unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1688        initializer_list<value_type> __il)
1689{
1690    _VSTD::__debug_db_insert_c(this);
1691    insert(__il.begin(), __il.end());
1692}
1693
1694template <class _Value, class _Hash, class _Pred, class _Alloc>
1695unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1696        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1697        const key_equal& __eql)
1698    : __table_(__hf, __eql)
1699{
1700    _VSTD::__debug_db_insert_c(this);
1701    __table_.rehash(__n);
1702    insert(__il.begin(), __il.end());
1703}
1704
1705template <class _Value, class _Hash, class _Pred, class _Alloc>
1706unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1707        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1708        const key_equal& __eql, const allocator_type& __a)
1709    : __table_(__hf, __eql, __a)
1710{
1711    _VSTD::__debug_db_insert_c(this);
1712    __table_.rehash(__n);
1713    insert(__il.begin(), __il.end());
1714}
1715
1716template <class _Value, class _Hash, class _Pred, class _Alloc>
1717inline
1718unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1719unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1720        unordered_multiset&& __u)
1721    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1722{
1723    __table_ = _VSTD::move(__u.__table_);
1724    return *this;
1725}
1726
1727template <class _Value, class _Hash, class _Pred, class _Alloc>
1728inline
1729unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1730unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1731        initializer_list<value_type> __il)
1732{
1733    __table_.__assign_multi(__il.begin(), __il.end());
1734    return *this;
1735}
1736
1737#endif // _LIBCPP_CXX03_LANG
1738
1739template <class _Value, class _Hash, class _Pred, class _Alloc>
1740template <class _InputIterator>
1741inline
1742void
1743unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1744                                                         _InputIterator __last)
1745{
1746    for (; __first != __last; ++__first)
1747        __table_.__insert_multi(*__first);
1748}
1749
1750template <class _Value, class _Hash, class _Pred, class _Alloc>
1751inline _LIBCPP_INLINE_VISIBILITY
1752void
1753swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1754     unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1755    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1756{
1757    __x.swap(__y);
1758}
1759
1760#if _LIBCPP_STD_VER > 17
1761template <class _Value, class _Hash, class _Pred, class _Alloc,
1762          class _Predicate>
1763inline _LIBCPP_INLINE_VISIBILITY
1764    typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
1765    erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
1766             _Predicate __pred) {
1767  return _VSTD::__libcpp_erase_if_container(__c, __pred);
1768}
1769#endif
1770
1771template <class _Value, class _Hash, class _Pred, class _Alloc>
1772bool
1773operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1774           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1775{
1776    if (__x.size() != __y.size())
1777        return false;
1778    typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1779                                                                 const_iterator;
1780    typedef pair<const_iterator, const_iterator> _EqRng;
1781    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1782    {
1783        _EqRng __xeq = __x.equal_range(*__i);
1784        _EqRng __yeq = __y.equal_range(*__i);
1785        if (_VSTD::distance(__xeq.first, __xeq.second) !=
1786            _VSTD::distance(__yeq.first, __yeq.second) ||
1787                  !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
1788            return false;
1789        __i = __xeq.second;
1790    }
1791    return true;
1792}
1793
1794template <class _Value, class _Hash, class _Pred, class _Alloc>
1795inline _LIBCPP_INLINE_VISIBILITY
1796bool
1797operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1798           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1799{
1800    return !(__x == __y);
1801}
1802
1803_LIBCPP_END_NAMESPACE_STD
1804
1805#endif // _LIBCPP_UNORDERED_SET
1806