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 <__algorithm/is_permutation.h>
463#include <__assert> // all public C++ headers provide the assertion handler
464#include <__config>
465#include <__debug>
466#include <__functional/is_transparent.h>
467#include <__functional/operations.h>
468#include <__hash_table>
469#include <__iterator/distance.h>
470#include <__iterator/erase_if_container.h>
471#include <__iterator/iterator_traits.h>
472#include <__memory/addressof.h>
473#include <__node_handle>
474#include <__utility/forward.h>
475#include <compare>
476#include <iterator> // TODO: Remove this include
477#include <version>
478
479#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
480#  pragma GCC system_header
481#endif
482
483_LIBCPP_BEGIN_NAMESPACE_STD
484
485template <class _Value, class _Hash, class _Pred, class _Alloc>
486class unordered_multiset;
487
488template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
489          class _Alloc = allocator<_Value> >
490class _LIBCPP_TEMPLATE_VIS unordered_set
491{
492public:
493    // types
494    typedef _Value                                                     key_type;
495    typedef key_type                                                   value_type;
496    typedef __type_identity_t<_Hash>                                   hasher;
497    typedef __type_identity_t<_Pred>                                   key_equal;
498    typedef __type_identity_t<_Alloc>                                  allocator_type;
499    typedef value_type&                                                reference;
500    typedef const value_type&                                          const_reference;
501    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
502                  "Invalid allocator::value_type");
503
504private:
505    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
506
507    __table __table_;
508
509public:
510    typedef typename __table::pointer         pointer;
511    typedef typename __table::const_pointer   const_pointer;
512    typedef typename __table::size_type       size_type;
513    typedef typename __table::difference_type difference_type;
514
515    typedef typename __table::const_iterator       iterator;
516    typedef typename __table::const_iterator       const_iterator;
517    typedef typename __table::const_local_iterator local_iterator;
518    typedef typename __table::const_local_iterator const_local_iterator;
519
520#if _LIBCPP_STD_VER > 14
521    typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
522    typedef __insert_return_type<iterator, node_type> insert_return_type;
523#endif
524
525    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
526        friend class _LIBCPP_TEMPLATE_VIS unordered_set;
527    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
528        friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
529
530    _LIBCPP_INLINE_VISIBILITY
531    unordered_set()
532        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
533    {
534        _VSTD::__debug_db_insert_c(this);
535    }
536    explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
537                           const key_equal& __eql = key_equal());
538#if _LIBCPP_STD_VER > 11
539    inline _LIBCPP_INLINE_VISIBILITY
540    unordered_set(size_type __n, const allocator_type& __a)
541        : unordered_set(__n, hasher(), key_equal(), __a) {}
542    inline _LIBCPP_INLINE_VISIBILITY
543    unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
544        : unordered_set(__n, __hf, key_equal(), __a) {}
545#endif
546    unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
547                  const allocator_type& __a);
548    template <class _InputIterator>
549        unordered_set(_InputIterator __first, _InputIterator __last);
550    template <class _InputIterator>
551        unordered_set(_InputIterator __first, _InputIterator __last,
552                      size_type __n, const hasher& __hf = hasher(),
553                      const key_equal& __eql = key_equal());
554    template <class _InputIterator>
555        unordered_set(_InputIterator __first, _InputIterator __last,
556                      size_type __n, const hasher& __hf, const key_equal& __eql,
557                      const allocator_type& __a);
558#if _LIBCPP_STD_VER > 11
559    template <class _InputIterator>
560    inline _LIBCPP_INLINE_VISIBILITY
561        unordered_set(_InputIterator __first, _InputIterator __last,
562                    size_type __n, const allocator_type& __a)
563            : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
564    template <class _InputIterator>
565        unordered_set(_InputIterator __first, _InputIterator __last,
566                      size_type __n, const hasher& __hf, const allocator_type& __a)
567            : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
568#endif
569    _LIBCPP_INLINE_VISIBILITY
570    explicit unordered_set(const allocator_type& __a);
571    unordered_set(const unordered_set& __u);
572    unordered_set(const unordered_set& __u, const allocator_type& __a);
573#ifndef _LIBCPP_CXX03_LANG
574    _LIBCPP_INLINE_VISIBILITY
575    unordered_set(unordered_set&& __u)
576        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
577    unordered_set(unordered_set&& __u, const allocator_type& __a);
578    unordered_set(initializer_list<value_type> __il);
579    unordered_set(initializer_list<value_type> __il, size_type __n,
580                  const hasher& __hf = hasher(),
581                  const key_equal& __eql = key_equal());
582    unordered_set(initializer_list<value_type> __il, size_type __n,
583                  const hasher& __hf, const key_equal& __eql,
584                  const allocator_type& __a);
585#if _LIBCPP_STD_VER > 11
586    inline _LIBCPP_INLINE_VISIBILITY
587    unordered_set(initializer_list<value_type> __il, size_type __n,
588                                                      const allocator_type& __a)
589        : unordered_set(__il, __n, hasher(), key_equal(), __a) {}
590    inline _LIBCPP_INLINE_VISIBILITY
591    unordered_set(initializer_list<value_type> __il, size_type __n,
592                                  const hasher& __hf, const allocator_type& __a)
593        : unordered_set(__il, __n, __hf, key_equal(), __a) {}
594#endif
595#endif // _LIBCPP_CXX03_LANG
596    _LIBCPP_INLINE_VISIBILITY
597    ~unordered_set() {
598        static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
599    }
600
601    _LIBCPP_INLINE_VISIBILITY
602    unordered_set& operator=(const unordered_set& __u)
603    {
604        __table_ = __u.__table_;
605        return *this;
606    }
607#ifndef _LIBCPP_CXX03_LANG
608    _LIBCPP_INLINE_VISIBILITY
609    unordered_set& operator=(unordered_set&& __u)
610        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
611    _LIBCPP_INLINE_VISIBILITY
612    unordered_set& operator=(initializer_list<value_type> __il);
613#endif // _LIBCPP_CXX03_LANG
614
615    _LIBCPP_INLINE_VISIBILITY
616    allocator_type get_allocator() const _NOEXCEPT
617        {return allocator_type(__table_.__node_alloc());}
618
619    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
620    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
621    _LIBCPP_INLINE_VISIBILITY
622    size_type size() const _NOEXCEPT  {return __table_.size();}
623    _LIBCPP_INLINE_VISIBILITY
624    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
625
626    _LIBCPP_INLINE_VISIBILITY
627    iterator       begin() _NOEXCEPT        {return __table_.begin();}
628    _LIBCPP_INLINE_VISIBILITY
629    iterator       end() _NOEXCEPT          {return __table_.end();}
630    _LIBCPP_INLINE_VISIBILITY
631    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
632    _LIBCPP_INLINE_VISIBILITY
633    const_iterator end()    const _NOEXCEPT {return __table_.end();}
634    _LIBCPP_INLINE_VISIBILITY
635    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
636    _LIBCPP_INLINE_VISIBILITY
637    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
638
639#ifndef _LIBCPP_CXX03_LANG
640    template <class... _Args>
641        _LIBCPP_INLINE_VISIBILITY
642        pair<iterator, bool> emplace(_Args&&... __args)
643            {return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
644    template <class... _Args>
645    _LIBCPP_INLINE_VISIBILITY
646    iterator emplace_hint(const_iterator __p, _Args&&... __args) {
647        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
648            "unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
649            " referring to this unordered_set");
650        (void)__p;
651        return __table_.__emplace_unique(std::forward<_Args>(__args)...).first;
652    }
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    iterator insert(const_iterator __p, value_type&& __x) {
659        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
660            "unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
661            " referring to this unordered_set");
662        (void)__p;
663        return insert(std::move(__x)).first;
664    }
665
666    _LIBCPP_INLINE_VISIBILITY
667    void insert(initializer_list<value_type> __il)
668        {insert(__il.begin(), __il.end());}
669#endif // _LIBCPP_CXX03_LANG
670    _LIBCPP_INLINE_VISIBILITY
671    pair<iterator, bool> insert(const value_type& __x)
672        {return __table_.__insert_unique(__x);}
673
674    _LIBCPP_INLINE_VISIBILITY
675    iterator insert(const_iterator __p, const value_type& __x) {
676        _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(std::addressof(__p)) == this,
677            "unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
678            " referring to this unordered_set");
679        (void)__p;
680        return insert(__x).first;
681    }
682    template <class _InputIterator>
683        _LIBCPP_INLINE_VISIBILITY
684        void insert(_InputIterator __first, _InputIterator __last);
685
686    _LIBCPP_INLINE_VISIBILITY
687    iterator erase(const_iterator __p) {return __table_.erase(__p);}
688    _LIBCPP_INLINE_VISIBILITY
689    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
690    _LIBCPP_INLINE_VISIBILITY
691    iterator erase(const_iterator __first, const_iterator __last)
692        {return __table_.erase(__first, __last);}
693    _LIBCPP_INLINE_VISIBILITY
694    void clear() _NOEXCEPT {__table_.clear();}
695
696#if _LIBCPP_STD_VER > 14
697    _LIBCPP_INLINE_VISIBILITY
698    insert_return_type insert(node_type&& __nh)
699    {
700        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
701            "node_type with incompatible allocator passed to unordered_set::insert()");
702        return __table_.template __node_handle_insert_unique<
703            node_type, insert_return_type>(_VSTD::move(__nh));
704    }
705    _LIBCPP_INLINE_VISIBILITY
706    iterator insert(const_iterator __h, node_type&& __nh)
707    {
708        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
709            "node_type with incompatible allocator passed to unordered_set::insert()");
710        return __table_.template __node_handle_insert_unique<node_type>(
711            __h, _VSTD::move(__nh));
712    }
713    _LIBCPP_INLINE_VISIBILITY
714    node_type extract(key_type const& __key)
715    {
716        return __table_.template __node_handle_extract<node_type>(__key);
717    }
718    _LIBCPP_INLINE_VISIBILITY
719    node_type extract(const_iterator __it)
720    {
721        return __table_.template __node_handle_extract<node_type>(__it);
722    }
723
724    template<class _H2, class _P2>
725    _LIBCPP_INLINE_VISIBILITY
726    void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
727    {
728        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
729                       "merging container with incompatible allocator");
730        __table_.__node_handle_merge_unique(__source.__table_);
731    }
732    template<class _H2, class _P2>
733    _LIBCPP_INLINE_VISIBILITY
734    void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
735    {
736        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
737                       "merging container with incompatible allocator");
738        __table_.__node_handle_merge_unique(__source.__table_);
739    }
740    template<class _H2, class _P2>
741    _LIBCPP_INLINE_VISIBILITY
742    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
743    {
744        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
745                       "merging container with incompatible allocator");
746        __table_.__node_handle_merge_unique(__source.__table_);
747    }
748    template<class _H2, class _P2>
749    _LIBCPP_INLINE_VISIBILITY
750    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
751    {
752        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
753                       "merging container with incompatible allocator");
754        __table_.__node_handle_merge_unique(__source.__table_);
755    }
756#endif
757
758    _LIBCPP_INLINE_VISIBILITY
759    void swap(unordered_set& __u)
760        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
761        {__table_.swap(__u.__table_);}
762
763    _LIBCPP_INLINE_VISIBILITY
764    hasher hash_function() const {return __table_.hash_function();}
765    _LIBCPP_INLINE_VISIBILITY
766    key_equal key_eq() const {return __table_.key_eq();}
767
768    _LIBCPP_INLINE_VISIBILITY
769    iterator       find(const key_type& __k)       {return __table_.find(__k);}
770    _LIBCPP_INLINE_VISIBILITY
771    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
772#if _LIBCPP_STD_VER > 17
773    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
774    _LIBCPP_INLINE_VISIBILITY
775    iterator       find(const _K2& __k)            {return __table_.find(__k);}
776    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
777    _LIBCPP_INLINE_VISIBILITY
778    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
779#endif // _LIBCPP_STD_VER > 17
780
781    _LIBCPP_INLINE_VISIBILITY
782    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
783#if _LIBCPP_STD_VER > 17
784    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
785    _LIBCPP_INLINE_VISIBILITY
786    size_type count(const _K2& __k) const      {return __table_.__count_unique(__k);}
787#endif // _LIBCPP_STD_VER > 17
788
789#if _LIBCPP_STD_VER > 17
790    _LIBCPP_INLINE_VISIBILITY
791    bool contains(const key_type& __k) const {return find(__k) != end();}
792
793    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
794    _LIBCPP_INLINE_VISIBILITY
795    bool contains(const _K2& __k) const      {return find(__k) != end();}
796#endif // _LIBCPP_STD_VER > 17
797
798    _LIBCPP_INLINE_VISIBILITY
799    pair<iterator, iterator>             equal_range(const key_type& __k)
800        {return __table_.__equal_range_unique(__k);}
801    _LIBCPP_INLINE_VISIBILITY
802    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
803        {return __table_.__equal_range_unique(__k);}
804#if _LIBCPP_STD_VER > 17
805    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
806    _LIBCPP_INLINE_VISIBILITY
807    pair<iterator, iterator>             equal_range(const _K2& __k)
808        {return __table_.__equal_range_unique(__k);}
809    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
810    _LIBCPP_INLINE_VISIBILITY
811    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
812        {return __table_.__equal_range_unique(__k);}
813#endif // _LIBCPP_STD_VER > 17
814
815    _LIBCPP_INLINE_VISIBILITY
816    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
817    _LIBCPP_INLINE_VISIBILITY
818    size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
819
820    _LIBCPP_INLINE_VISIBILITY
821    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
822    _LIBCPP_INLINE_VISIBILITY
823    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
824
825    _LIBCPP_INLINE_VISIBILITY
826    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
827    _LIBCPP_INLINE_VISIBILITY
828    local_iterator       end(size_type __n)          {return __table_.end(__n);}
829    _LIBCPP_INLINE_VISIBILITY
830    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
831    _LIBCPP_INLINE_VISIBILITY
832    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
833    _LIBCPP_INLINE_VISIBILITY
834    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
835    _LIBCPP_INLINE_VISIBILITY
836    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
837
838    _LIBCPP_INLINE_VISIBILITY
839    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
840    _LIBCPP_INLINE_VISIBILITY
841    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
842    _LIBCPP_INLINE_VISIBILITY
843    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
844    _LIBCPP_INLINE_VISIBILITY
845    void rehash(size_type __n) {__table_.rehash(__n);}
846    _LIBCPP_INLINE_VISIBILITY
847    void reserve(size_type __n) {__table_.reserve(__n);}
848
849#ifdef _LIBCPP_ENABLE_DEBUG_MODE
850
851    bool __dereferenceable(const const_iterator* __i) const
852        {return __table_.__dereferenceable(__i);}
853    bool __decrementable(const const_iterator* __i) const
854        {return __table_.__decrementable(__i);}
855    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
856        {return __table_.__addable(__i, __n);}
857    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
858        {return __table_.__addable(__i, __n);}
859
860#endif // _LIBCPP_ENABLE_DEBUG_MODE
861
862};
863
864#if _LIBCPP_STD_VER >= 17
865template<class _InputIterator,
866         class _Hash = hash<__iter_value_type<_InputIterator>>,
867         class _Pred = equal_to<__iter_value_type<_InputIterator>>,
868         class _Allocator = allocator<__iter_value_type<_InputIterator>>,
869         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
870         class = enable_if_t<!__is_allocator<_Hash>::value>,
871         class = enable_if_t<!is_integral<_Hash>::value>,
872         class = enable_if_t<!__is_allocator<_Pred>::value>,
873         class = enable_if_t<__is_allocator<_Allocator>::value>>
874unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
875              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
876  -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
877
878template<class _Tp, class _Hash = hash<_Tp>,
879         class _Pred = equal_to<_Tp>,
880         class _Allocator = allocator<_Tp>,
881         class = enable_if_t<!__is_allocator<_Hash>::value>,
882         class = enable_if_t<!is_integral<_Hash>::value>,
883         class = enable_if_t<!__is_allocator<_Pred>::value>,
884         class = enable_if_t<__is_allocator<_Allocator>::value>>
885unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
886              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
887  -> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
888
889template<class _InputIterator, class _Allocator,
890         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
891         class = enable_if_t<__is_allocator<_Allocator>::value>>
892unordered_set(_InputIterator, _InputIterator,
893              typename allocator_traits<_Allocator>::size_type, _Allocator)
894  -> unordered_set<__iter_value_type<_InputIterator>,
895                   hash<__iter_value_type<_InputIterator>>,
896                   equal_to<__iter_value_type<_InputIterator>>,
897                   _Allocator>;
898
899template<class _InputIterator, class _Hash, class _Allocator,
900         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
901         class = enable_if_t<!__is_allocator<_Hash>::value>,
902         class = enable_if_t<!is_integral<_Hash>::value>,
903         class = enable_if_t<__is_allocator<_Allocator>::value>>
904unordered_set(_InputIterator, _InputIterator,
905              typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
906  -> unordered_set<__iter_value_type<_InputIterator>, _Hash,
907                   equal_to<__iter_value_type<_InputIterator>>,
908                   _Allocator>;
909
910template<class _Tp, class _Allocator,
911         class = enable_if_t<__is_allocator<_Allocator>::value>>
912unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
913  -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
914
915template<class _Tp, class _Hash, class _Allocator,
916         class = enable_if_t<!__is_allocator<_Hash>::value>,
917         class = enable_if_t<!is_integral<_Hash>::value>,
918         class = enable_if_t<__is_allocator<_Allocator>::value>>
919unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
920  -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
921#endif
922
923template <class _Value, class _Hash, class _Pred, class _Alloc>
924unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
925        const hasher& __hf, const key_equal& __eql)
926    : __table_(__hf, __eql)
927{
928    _VSTD::__debug_db_insert_c(this);
929    __table_.rehash(__n);
930}
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, const allocator_type& __a)
935    : __table_(__hf, __eql, __a)
936{
937    _VSTD::__debug_db_insert_c(this);
938    __table_.rehash(__n);
939}
940
941template <class _Value, class _Hash, class _Pred, class _Alloc>
942template <class _InputIterator>
943unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
944        _InputIterator __first, _InputIterator __last)
945{
946    _VSTD::__debug_db_insert_c(this);
947    insert(__first, __last);
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, size_type __n,
954        const hasher& __hf, const key_equal& __eql)
955    : __table_(__hf, __eql)
956{
957    _VSTD::__debug_db_insert_c(this);
958    __table_.rehash(__n);
959    insert(__first, __last);
960}
961
962template <class _Value, class _Hash, class _Pred, class _Alloc>
963template <class _InputIterator>
964unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
965        _InputIterator __first, _InputIterator __last, size_type __n,
966        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
967    : __table_(__hf, __eql, __a)
968{
969    _VSTD::__debug_db_insert_c(this);
970    __table_.rehash(__n);
971    insert(__first, __last);
972}
973
974template <class _Value, class _Hash, class _Pred, class _Alloc>
975inline
976unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
977        const allocator_type& __a)
978    : __table_(__a)
979{
980    _VSTD::__debug_db_insert_c(this);
981}
982
983template <class _Value, class _Hash, class _Pred, class _Alloc>
984unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
985        const unordered_set& __u)
986    : __table_(__u.__table_)
987{
988    _VSTD::__debug_db_insert_c(this);
989    __table_.rehash(__u.bucket_count());
990    insert(__u.begin(), __u.end());
991}
992
993template <class _Value, class _Hash, class _Pred, class _Alloc>
994unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
995        const unordered_set& __u, const allocator_type& __a)
996    : __table_(__u.__table_, __a)
997{
998    _VSTD::__debug_db_insert_c(this);
999    __table_.rehash(__u.bucket_count());
1000    insert(__u.begin(), __u.end());
1001}
1002
1003#ifndef _LIBCPP_CXX03_LANG
1004
1005template <class _Value, class _Hash, class _Pred, class _Alloc>
1006inline
1007unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1008        unordered_set&& __u)
1009    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1010    : __table_(_VSTD::move(__u.__table_))
1011{
1012    _VSTD::__debug_db_insert_c(this);
1013    std::__debug_db_swap(this, std::addressof(__u));
1014}
1015
1016template <class _Value, class _Hash, class _Pred, class _Alloc>
1017unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1018        unordered_set&& __u, const allocator_type& __a)
1019    : __table_(_VSTD::move(__u.__table_), __a)
1020{
1021    _VSTD::__debug_db_insert_c(this);
1022    if (__a != __u.get_allocator())
1023    {
1024        iterator __i = __u.begin();
1025        while (__u.size() != 0)
1026            __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
1027    }
1028    else
1029        std::__debug_db_swap(this, std::addressof(__u));
1030}
1031
1032template <class _Value, class _Hash, class _Pred, class _Alloc>
1033unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1034        initializer_list<value_type> __il)
1035{
1036    _VSTD::__debug_db_insert_c(this);
1037    insert(__il.begin(), __il.end());
1038}
1039
1040template <class _Value, class _Hash, class _Pred, class _Alloc>
1041unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1042        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1043        const key_equal& __eql)
1044    : __table_(__hf, __eql)
1045{
1046    _VSTD::__debug_db_insert_c(this);
1047    __table_.rehash(__n);
1048    insert(__il.begin(), __il.end());
1049}
1050
1051template <class _Value, class _Hash, class _Pred, class _Alloc>
1052unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
1053        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1054        const key_equal& __eql, const allocator_type& __a)
1055    : __table_(__hf, __eql, __a)
1056{
1057    _VSTD::__debug_db_insert_c(this);
1058    __table_.rehash(__n);
1059    insert(__il.begin(), __il.end());
1060}
1061
1062template <class _Value, class _Hash, class _Pred, class _Alloc>
1063inline
1064unordered_set<_Value, _Hash, _Pred, _Alloc>&
1065unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
1066    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1067{
1068    __table_ = _VSTD::move(__u.__table_);
1069    return *this;
1070}
1071
1072template <class _Value, class _Hash, class _Pred, class _Alloc>
1073inline
1074unordered_set<_Value, _Hash, _Pred, _Alloc>&
1075unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
1076        initializer_list<value_type> __il)
1077{
1078    __table_.__assign_unique(__il.begin(), __il.end());
1079    return *this;
1080}
1081
1082#endif // _LIBCPP_CXX03_LANG
1083
1084template <class _Value, class _Hash, class _Pred, class _Alloc>
1085template <class _InputIterator>
1086inline
1087void
1088unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1089                                                    _InputIterator __last)
1090{
1091    for (; __first != __last; ++__first)
1092        __table_.__insert_unique(*__first);
1093}
1094
1095template <class _Value, class _Hash, class _Pred, class _Alloc>
1096inline _LIBCPP_INLINE_VISIBILITY
1097void
1098swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1099     unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1100    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1101{
1102    __x.swap(__y);
1103}
1104
1105#if _LIBCPP_STD_VER > 17
1106template <class _Value, class _Hash, class _Pred, class _Alloc,
1107          class _Predicate>
1108inline _LIBCPP_INLINE_VISIBILITY
1109    typename unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type
1110    erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c,
1111             _Predicate __pred) {
1112  return _VSTD::__libcpp_erase_if_container(__c, __pred);
1113}
1114#endif
1115
1116template <class _Value, class _Hash, class _Pred, class _Alloc>
1117bool
1118operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1119           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1120{
1121    if (__x.size() != __y.size())
1122        return false;
1123    typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
1124                                                                 const_iterator;
1125    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1126            __i != __ex; ++__i)
1127    {
1128        const_iterator __j = __y.find(*__i);
1129        if (__j == __ey || !(*__i == *__j))
1130            return false;
1131    }
1132    return true;
1133}
1134
1135template <class _Value, class _Hash, class _Pred, class _Alloc>
1136inline _LIBCPP_INLINE_VISIBILITY
1137bool
1138operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
1139           const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
1140{
1141    return !(__x == __y);
1142}
1143
1144template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
1145          class _Alloc = allocator<_Value> >
1146class _LIBCPP_TEMPLATE_VIS unordered_multiset
1147{
1148public:
1149    // types
1150    typedef _Value                                                     key_type;
1151    typedef key_type                                                   value_type;
1152    typedef __type_identity_t<_Hash>                                   hasher;
1153    typedef __type_identity_t<_Pred>                                   key_equal;
1154    typedef __type_identity_t<_Alloc>                                  allocator_type;
1155    typedef value_type&                                                reference;
1156    typedef const value_type&                                          const_reference;
1157    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1158                  "Invalid allocator::value_type");
1159
1160private:
1161    typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
1162
1163    __table __table_;
1164
1165public:
1166    typedef typename __table::pointer         pointer;
1167    typedef typename __table::const_pointer   const_pointer;
1168    typedef typename __table::size_type       size_type;
1169    typedef typename __table::difference_type difference_type;
1170
1171    typedef typename __table::const_iterator       iterator;
1172    typedef typename __table::const_iterator       const_iterator;
1173    typedef typename __table::const_local_iterator local_iterator;
1174    typedef typename __table::const_local_iterator const_local_iterator;
1175
1176#if _LIBCPP_STD_VER > 14
1177    typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
1178#endif
1179
1180    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1181        friend class _LIBCPP_TEMPLATE_VIS unordered_set;
1182    template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
1183        friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
1184
1185    _LIBCPP_INLINE_VISIBILITY
1186    unordered_multiset()
1187        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1188    {
1189        _VSTD::__debug_db_insert_c(this);
1190    }
1191    explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
1192                                const key_equal& __eql = key_equal());
1193    unordered_multiset(size_type __n, const hasher& __hf,
1194                       const key_equal& __eql, const allocator_type& __a);
1195#if _LIBCPP_STD_VER > 11
1196    inline _LIBCPP_INLINE_VISIBILITY
1197    unordered_multiset(size_type __n, const allocator_type& __a)
1198        : unordered_multiset(__n, hasher(), key_equal(), __a) {}
1199    inline _LIBCPP_INLINE_VISIBILITY
1200    unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
1201        : unordered_multiset(__n, __hf, key_equal(), __a) {}
1202#endif
1203    template <class _InputIterator>
1204        unordered_multiset(_InputIterator __first, _InputIterator __last);
1205    template <class _InputIterator>
1206        unordered_multiset(_InputIterator __first, _InputIterator __last,
1207                      size_type __n, const hasher& __hf = hasher(),
1208                      const key_equal& __eql = key_equal());
1209    template <class _InputIterator>
1210        unordered_multiset(_InputIterator __first, _InputIterator __last,
1211                      size_type __n , const hasher& __hf,
1212                      const key_equal& __eql, const allocator_type& __a);
1213#if _LIBCPP_STD_VER > 11
1214    template <class _InputIterator>
1215    inline _LIBCPP_INLINE_VISIBILITY
1216    unordered_multiset(_InputIterator __first, _InputIterator __last,
1217                       size_type __n, const allocator_type& __a)
1218        : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
1219    template <class _InputIterator>
1220    inline _LIBCPP_INLINE_VISIBILITY
1221    unordered_multiset(_InputIterator __first, _InputIterator __last,
1222                       size_type __n, const hasher& __hf, const allocator_type& __a)
1223        : unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
1224#endif
1225    _LIBCPP_INLINE_VISIBILITY
1226    explicit unordered_multiset(const allocator_type& __a);
1227    unordered_multiset(const unordered_multiset& __u);
1228    unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
1229#ifndef _LIBCPP_CXX03_LANG
1230    _LIBCPP_INLINE_VISIBILITY
1231    unordered_multiset(unordered_multiset&& __u)
1232        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
1233    unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
1234    unordered_multiset(initializer_list<value_type> __il);
1235    unordered_multiset(initializer_list<value_type> __il, size_type __n,
1236                       const hasher& __hf = hasher(),
1237                       const key_equal& __eql = key_equal());
1238    unordered_multiset(initializer_list<value_type> __il, size_type __n,
1239                       const hasher& __hf, const key_equal& __eql,
1240                       const allocator_type& __a);
1241#if _LIBCPP_STD_VER > 11
1242    inline _LIBCPP_INLINE_VISIBILITY
1243    unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1244      : unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
1245    inline _LIBCPP_INLINE_VISIBILITY
1246    unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
1247      : unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
1248#endif
1249#endif // _LIBCPP_CXX03_LANG
1250    _LIBCPP_INLINE_VISIBILITY
1251    ~unordered_multiset() {
1252        static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
1253    }
1254
1255    _LIBCPP_INLINE_VISIBILITY
1256    unordered_multiset& operator=(const unordered_multiset& __u)
1257    {
1258        __table_ = __u.__table_;
1259        return *this;
1260    }
1261#ifndef _LIBCPP_CXX03_LANG
1262    _LIBCPP_INLINE_VISIBILITY
1263    unordered_multiset& operator=(unordered_multiset&& __u)
1264        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
1265    unordered_multiset& operator=(initializer_list<value_type> __il);
1266#endif // _LIBCPP_CXX03_LANG
1267
1268    _LIBCPP_INLINE_VISIBILITY
1269    allocator_type get_allocator() const _NOEXCEPT
1270        {return allocator_type(__table_.__node_alloc());}
1271
1272    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1273    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
1274    _LIBCPP_INLINE_VISIBILITY
1275    size_type size() const _NOEXCEPT  {return __table_.size();}
1276    _LIBCPP_INLINE_VISIBILITY
1277    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1278
1279    _LIBCPP_INLINE_VISIBILITY
1280    iterator       begin() _NOEXCEPT        {return __table_.begin();}
1281    _LIBCPP_INLINE_VISIBILITY
1282    iterator       end() _NOEXCEPT          {return __table_.end();}
1283    _LIBCPP_INLINE_VISIBILITY
1284    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
1285    _LIBCPP_INLINE_VISIBILITY
1286    const_iterator end()    const _NOEXCEPT {return __table_.end();}
1287    _LIBCPP_INLINE_VISIBILITY
1288    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1289    _LIBCPP_INLINE_VISIBILITY
1290    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
1291
1292#ifndef _LIBCPP_CXX03_LANG
1293    template <class... _Args>
1294        _LIBCPP_INLINE_VISIBILITY
1295        iterator emplace(_Args&&... __args)
1296            {return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
1297    template <class... _Args>
1298        _LIBCPP_INLINE_VISIBILITY
1299        iterator emplace_hint(const_iterator __p, _Args&&... __args)
1300            {return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
1301
1302    _LIBCPP_INLINE_VISIBILITY
1303    iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
1304    _LIBCPP_INLINE_VISIBILITY
1305    iterator insert(const_iterator __p, value_type&& __x)
1306        {return __table_.__insert_multi(__p, _VSTD::move(__x));}
1307    _LIBCPP_INLINE_VISIBILITY
1308    void insert(initializer_list<value_type> __il)
1309        {insert(__il.begin(), __il.end());}
1310#endif // _LIBCPP_CXX03_LANG
1311
1312    _LIBCPP_INLINE_VISIBILITY
1313    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
1314
1315    _LIBCPP_INLINE_VISIBILITY
1316    iterator insert(const_iterator __p, const value_type& __x)
1317        {return __table_.__insert_multi(__p, __x);}
1318
1319    template <class _InputIterator>
1320        _LIBCPP_INLINE_VISIBILITY
1321        void insert(_InputIterator __first, _InputIterator __last);
1322
1323#if _LIBCPP_STD_VER > 14
1324    _LIBCPP_INLINE_VISIBILITY
1325    iterator insert(node_type&& __nh)
1326    {
1327        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1328            "node_type with incompatible allocator passed to unordered_multiset::insert()");
1329        return __table_.template __node_handle_insert_multi<node_type>(
1330            _VSTD::move(__nh));
1331    }
1332    _LIBCPP_INLINE_VISIBILITY
1333    iterator insert(const_iterator __hint, node_type&& __nh)
1334    {
1335        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1336            "node_type with incompatible allocator passed to unordered_multiset::insert()");
1337        return __table_.template __node_handle_insert_multi<node_type>(
1338            __hint, _VSTD::move(__nh));
1339    }
1340    _LIBCPP_INLINE_VISIBILITY
1341    node_type extract(const_iterator __position)
1342    {
1343        return __table_.template __node_handle_extract<node_type>(
1344            __position);
1345    }
1346    _LIBCPP_INLINE_VISIBILITY
1347    node_type extract(key_type const& __key)
1348    {
1349        return __table_.template __node_handle_extract<node_type>(__key);
1350    }
1351
1352    template <class _H2, class _P2>
1353    _LIBCPP_INLINE_VISIBILITY
1354    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
1355    {
1356        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1357                       "merging container with incompatible allocator");
1358        return __table_.__node_handle_merge_multi(__source.__table_);
1359    }
1360    template <class _H2, class _P2>
1361    _LIBCPP_INLINE_VISIBILITY
1362    void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
1363    {
1364        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1365                       "merging container with incompatible allocator");
1366        return __table_.__node_handle_merge_multi(__source.__table_);
1367    }
1368    template <class _H2, class _P2>
1369    _LIBCPP_INLINE_VISIBILITY
1370    void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
1371    {
1372        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1373                       "merging container with incompatible allocator");
1374        return __table_.__node_handle_merge_multi(__source.__table_);
1375    }
1376    template <class _H2, class _P2>
1377    _LIBCPP_INLINE_VISIBILITY
1378    void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
1379    {
1380        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1381                       "merging container with incompatible allocator");
1382        return __table_.__node_handle_merge_multi(__source.__table_);
1383    }
1384#endif
1385
1386    _LIBCPP_INLINE_VISIBILITY
1387    iterator erase(const_iterator __p) {return __table_.erase(__p);}
1388    _LIBCPP_INLINE_VISIBILITY
1389    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
1390    _LIBCPP_INLINE_VISIBILITY
1391    iterator erase(const_iterator __first, const_iterator __last)
1392        {return __table_.erase(__first, __last);}
1393    _LIBCPP_INLINE_VISIBILITY
1394    void clear() _NOEXCEPT {__table_.clear();}
1395
1396    _LIBCPP_INLINE_VISIBILITY
1397    void swap(unordered_multiset& __u)
1398        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1399        {__table_.swap(__u.__table_);}
1400
1401    _LIBCPP_INLINE_VISIBILITY
1402    hasher hash_function() const {return __table_.hash_function();}
1403    _LIBCPP_INLINE_VISIBILITY
1404    key_equal key_eq() const {return __table_.key_eq();}
1405
1406    _LIBCPP_INLINE_VISIBILITY
1407    iterator       find(const key_type& __k)       {return __table_.find(__k);}
1408    _LIBCPP_INLINE_VISIBILITY
1409    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1410#if _LIBCPP_STD_VER > 17
1411    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1412    _LIBCPP_INLINE_VISIBILITY
1413    iterator       find(const _K2& __k)            {return __table_.find(__k);}
1414    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1415    _LIBCPP_INLINE_VISIBILITY
1416    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
1417#endif // _LIBCPP_STD_VER > 17
1418
1419    _LIBCPP_INLINE_VISIBILITY
1420    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
1421#if _LIBCPP_STD_VER > 17
1422    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1423    _LIBCPP_INLINE_VISIBILITY
1424    size_type count(const _K2& __k) const      {return __table_.__count_multi(__k);}
1425#endif // _LIBCPP_STD_VER > 17
1426
1427#if _LIBCPP_STD_VER > 17
1428    _LIBCPP_INLINE_VISIBILITY
1429    bool contains(const key_type& __k) const {return find(__k) != end();}
1430
1431    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1432    _LIBCPP_INLINE_VISIBILITY
1433    bool contains(const _K2& __k) const      {return find(__k) != end();}
1434#endif // _LIBCPP_STD_VER > 17
1435
1436    _LIBCPP_INLINE_VISIBILITY
1437    pair<iterator, iterator>             equal_range(const key_type& __k)
1438        {return __table_.__equal_range_multi(__k);}
1439    _LIBCPP_INLINE_VISIBILITY
1440    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1441        {return __table_.__equal_range_multi(__k);}
1442#if _LIBCPP_STD_VER > 17
1443    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1444    _LIBCPP_INLINE_VISIBILITY
1445    pair<iterator, iterator>             equal_range(const _K2& __k)
1446        {return __table_.__equal_range_multi(__k);}
1447    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1448    _LIBCPP_INLINE_VISIBILITY
1449    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
1450        {return __table_.__equal_range_multi(__k);}
1451#endif // _LIBCPP_STD_VER > 17
1452
1453    _LIBCPP_INLINE_VISIBILITY
1454    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1455    _LIBCPP_INLINE_VISIBILITY
1456    size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
1457
1458    _LIBCPP_INLINE_VISIBILITY
1459    size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
1460    _LIBCPP_INLINE_VISIBILITY
1461    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1462
1463    _LIBCPP_INLINE_VISIBILITY
1464    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
1465    _LIBCPP_INLINE_VISIBILITY
1466    local_iterator       end(size_type __n)          {return __table_.end(__n);}
1467    _LIBCPP_INLINE_VISIBILITY
1468    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
1469    _LIBCPP_INLINE_VISIBILITY
1470    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
1471    _LIBCPP_INLINE_VISIBILITY
1472    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1473    _LIBCPP_INLINE_VISIBILITY
1474    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
1475
1476    _LIBCPP_INLINE_VISIBILITY
1477    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1478    _LIBCPP_INLINE_VISIBILITY
1479    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1480    _LIBCPP_INLINE_VISIBILITY
1481    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1482    _LIBCPP_INLINE_VISIBILITY
1483    void rehash(size_type __n) {__table_.rehash(__n);}
1484    _LIBCPP_INLINE_VISIBILITY
1485    void reserve(size_type __n) {__table_.reserve(__n);}
1486
1487#ifdef _LIBCPP_ENABLE_DEBUG_MODE
1488
1489    bool __dereferenceable(const const_iterator* __i) const
1490        {return __table_.__dereferenceable(__i);}
1491    bool __decrementable(const const_iterator* __i) const
1492        {return __table_.__decrementable(__i);}
1493    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1494        {return __table_.__addable(__i, __n);}
1495    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1496        {return __table_.__addable(__i, __n);}
1497
1498#endif // _LIBCPP_ENABLE_DEBUG_MODE
1499
1500};
1501
1502#if _LIBCPP_STD_VER >= 17
1503template<class _InputIterator,
1504         class _Hash = hash<__iter_value_type<_InputIterator>>,
1505         class _Pred = equal_to<__iter_value_type<_InputIterator>>,
1506         class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1507         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1508         class = enable_if_t<!__is_allocator<_Hash>::value>,
1509         class = enable_if_t<!is_integral<_Hash>::value>,
1510         class = enable_if_t<!__is_allocator<_Pred>::value>,
1511         class = enable_if_t<__is_allocator<_Allocator>::value>>
1512unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
1513              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1514  -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
1515
1516template<class _Tp, class _Hash = hash<_Tp>,
1517         class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
1518         class = enable_if_t<!__is_allocator<_Hash>::value>,
1519         class = enable_if_t<!is_integral<_Hash>::value>,
1520         class = enable_if_t<!__is_allocator<_Pred>::value>,
1521         class = enable_if_t<__is_allocator<_Allocator>::value>>
1522unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
1523              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1524  -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
1525
1526template<class _InputIterator, class _Allocator,
1527         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1528         class = enable_if_t<__is_allocator<_Allocator>::value>>
1529unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
1530  -> unordered_multiset<__iter_value_type<_InputIterator>,
1531                   hash<__iter_value_type<_InputIterator>>,
1532                   equal_to<__iter_value_type<_InputIterator>>,
1533                   _Allocator>;
1534
1535template<class _InputIterator, class _Hash, class _Allocator,
1536         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1537         class = enable_if_t<!__is_allocator<_Hash>::value>,
1538         class = enable_if_t<!is_integral<_Hash>::value>,
1539         class = enable_if_t<__is_allocator<_Allocator>::value>>
1540unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
1541              _Hash, _Allocator)
1542  -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
1543                   equal_to<__iter_value_type<_InputIterator>>,
1544                   _Allocator>;
1545
1546template<class _Tp, class _Allocator,
1547         class = enable_if_t<__is_allocator<_Allocator>::value>>
1548unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
1549  -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
1550
1551template<class _Tp, class _Hash, class _Allocator,
1552         class = enable_if_t<!__is_allocator<_Hash>::value>,
1553         class = enable_if_t<!is_integral<_Hash>::value>,
1554         class = enable_if_t<__is_allocator<_Allocator>::value>>
1555unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1556  -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
1557#endif
1558
1559template <class _Value, class _Hash, class _Pred, class _Alloc>
1560unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1561        size_type __n, const hasher& __hf, const key_equal& __eql)
1562    : __table_(__hf, __eql)
1563{
1564    _VSTD::__debug_db_insert_c(this);
1565    __table_.rehash(__n);
1566}
1567
1568template <class _Value, class _Hash, class _Pred, class _Alloc>
1569unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1570        size_type __n, const hasher& __hf, const key_equal& __eql,
1571        const allocator_type& __a)
1572    : __table_(__hf, __eql, __a)
1573{
1574    _VSTD::__debug_db_insert_c(this);
1575    __table_.rehash(__n);
1576}
1577
1578template <class _Value, class _Hash, class _Pred, class _Alloc>
1579template <class _InputIterator>
1580unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1581        _InputIterator __first, _InputIterator __last)
1582{
1583    _VSTD::__debug_db_insert_c(this);
1584    insert(__first, __last);
1585}
1586
1587template <class _Value, class _Hash, class _Pred, class _Alloc>
1588template <class _InputIterator>
1589unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1590        _InputIterator __first, _InputIterator __last, size_type __n,
1591        const hasher& __hf, const key_equal& __eql)
1592    : __table_(__hf, __eql)
1593{
1594    _VSTD::__debug_db_insert_c(this);
1595    __table_.rehash(__n);
1596    insert(__first, __last);
1597}
1598
1599template <class _Value, class _Hash, class _Pred, class _Alloc>
1600template <class _InputIterator>
1601unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1602        _InputIterator __first, _InputIterator __last, size_type __n,
1603        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1604    : __table_(__hf, __eql, __a)
1605{
1606    _VSTD::__debug_db_insert_c(this);
1607    __table_.rehash(__n);
1608    insert(__first, __last);
1609}
1610
1611template <class _Value, class _Hash, class _Pred, class _Alloc>
1612inline
1613unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1614        const allocator_type& __a)
1615    : __table_(__a)
1616{
1617    _VSTD::__debug_db_insert_c(this);
1618}
1619
1620template <class _Value, class _Hash, class _Pred, class _Alloc>
1621unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1622        const unordered_multiset& __u)
1623    : __table_(__u.__table_)
1624{
1625    _VSTD::__debug_db_insert_c(this);
1626    __table_.rehash(__u.bucket_count());
1627    insert(__u.begin(), __u.end());
1628}
1629
1630template <class _Value, class _Hash, class _Pred, class _Alloc>
1631unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1632        const unordered_multiset& __u, const allocator_type& __a)
1633    : __table_(__u.__table_, __a)
1634{
1635    _VSTD::__debug_db_insert_c(this);
1636    __table_.rehash(__u.bucket_count());
1637    insert(__u.begin(), __u.end());
1638}
1639
1640#ifndef _LIBCPP_CXX03_LANG
1641
1642template <class _Value, class _Hash, class _Pred, class _Alloc>
1643inline
1644unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1645        unordered_multiset&& __u)
1646    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1647    : __table_(_VSTD::move(__u.__table_))
1648{
1649    _VSTD::__debug_db_insert_c(this);
1650    std::__debug_db_swap(this, std::addressof(__u));
1651}
1652
1653template <class _Value, class _Hash, class _Pred, class _Alloc>
1654unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1655        unordered_multiset&& __u, const allocator_type& __a)
1656    : __table_(_VSTD::move(__u.__table_), __a)
1657{
1658    _VSTD::__debug_db_insert_c(this);
1659    if (__a != __u.get_allocator())
1660    {
1661        iterator __i = __u.begin();
1662        while (__u.size() != 0)
1663            __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
1664    }
1665    else
1666        std::__debug_db_swap(this, std::addressof(__u));
1667}
1668
1669template <class _Value, class _Hash, class _Pred, class _Alloc>
1670unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1671        initializer_list<value_type> __il)
1672{
1673    _VSTD::__debug_db_insert_c(this);
1674    insert(__il.begin(), __il.end());
1675}
1676
1677template <class _Value, class _Hash, class _Pred, class _Alloc>
1678unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1679        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1680        const key_equal& __eql)
1681    : __table_(__hf, __eql)
1682{
1683    _VSTD::__debug_db_insert_c(this);
1684    __table_.rehash(__n);
1685    insert(__il.begin(), __il.end());
1686}
1687
1688template <class _Value, class _Hash, class _Pred, class _Alloc>
1689unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
1690        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1691        const key_equal& __eql, const allocator_type& __a)
1692    : __table_(__hf, __eql, __a)
1693{
1694    _VSTD::__debug_db_insert_c(this);
1695    __table_.rehash(__n);
1696    insert(__il.begin(), __il.end());
1697}
1698
1699template <class _Value, class _Hash, class _Pred, class _Alloc>
1700inline
1701unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1702unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1703        unordered_multiset&& __u)
1704    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1705{
1706    __table_ = _VSTD::move(__u.__table_);
1707    return *this;
1708}
1709
1710template <class _Value, class _Hash, class _Pred, class _Alloc>
1711inline
1712unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
1713unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
1714        initializer_list<value_type> __il)
1715{
1716    __table_.__assign_multi(__il.begin(), __il.end());
1717    return *this;
1718}
1719
1720#endif // _LIBCPP_CXX03_LANG
1721
1722template <class _Value, class _Hash, class _Pred, class _Alloc>
1723template <class _InputIterator>
1724inline
1725void
1726unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1727                                                         _InputIterator __last)
1728{
1729    for (; __first != __last; ++__first)
1730        __table_.__insert_multi(*__first);
1731}
1732
1733template <class _Value, class _Hash, class _Pred, class _Alloc>
1734inline _LIBCPP_INLINE_VISIBILITY
1735void
1736swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1737     unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1738    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1739{
1740    __x.swap(__y);
1741}
1742
1743#if _LIBCPP_STD_VER > 17
1744template <class _Value, class _Hash, class _Pred, class _Alloc,
1745          class _Predicate>
1746inline _LIBCPP_INLINE_VISIBILITY
1747    typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::size_type
1748    erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c,
1749             _Predicate __pred) {
1750  return _VSTD::__libcpp_erase_if_container(__c, __pred);
1751}
1752#endif
1753
1754template <class _Value, class _Hash, class _Pred, class _Alloc>
1755bool
1756operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1757           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1758{
1759    if (__x.size() != __y.size())
1760        return false;
1761    typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
1762                                                                 const_iterator;
1763    typedef pair<const_iterator, const_iterator> _EqRng;
1764    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
1765    {
1766        _EqRng __xeq = __x.equal_range(*__i);
1767        _EqRng __yeq = __y.equal_range(*__i);
1768        if (_VSTD::distance(__xeq.first, __xeq.second) !=
1769            _VSTD::distance(__yeq.first, __yeq.second) ||
1770                  !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
1771            return false;
1772        __i = __xeq.second;
1773    }
1774    return true;
1775}
1776
1777template <class _Value, class _Hash, class _Pred, class _Alloc>
1778inline _LIBCPP_INLINE_VISIBILITY
1779bool
1780operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
1781           const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
1782{
1783    return !(__x == __y);
1784}
1785
1786_LIBCPP_END_NAMESPACE_STD
1787
1788#endif // _LIBCPP_UNORDERED_SET
1789