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