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