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_MAP
11#define _LIBCPP_UNORDERED_MAP
12
13/*
14
15    unordered_map synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
23          class Alloc = allocator<pair<const Key, T>>>
24class unordered_map
25{
26public:
27    // types
28    typedef Key                                                        key_type;
29    typedef T                                                          mapped_type;
30    typedef Hash                                                       hasher;
31    typedef Pred                                                       key_equal;
32    typedef Alloc                                                      allocator_type;
33    typedef pair<const key_type, mapped_type>                          value_type;
34    typedef value_type&                                                reference;
35    typedef const value_type&                                          const_reference;
36    typedef typename allocator_traits<allocator_type>::pointer         pointer;
37    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
38    typedef typename allocator_traits<allocator_type>::size_type       size_type;
39    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
40
41    typedef /unspecified/ iterator;
42    typedef /unspecified/ const_iterator;
43    typedef /unspecified/ local_iterator;
44    typedef /unspecified/ const_local_iterator;
45
46    typedef unspecified                             node_type;            // C++17
47    typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type;   // C++17
48
49    unordered_map()
50        noexcept(
51            is_nothrow_default_constructible<hasher>::value &&
52            is_nothrow_default_constructible<key_equal>::value &&
53            is_nothrow_default_constructible<allocator_type>::value);
54    explicit unordered_map(size_type n, const hasher& hf = hasher(),
55                           const key_equal& eql = key_equal(),
56                           const allocator_type& a = allocator_type());
57    template <class InputIterator>
58        unordered_map(InputIterator f, InputIterator l,
59                      size_type n = 0, const hasher& hf = hasher(),
60                      const key_equal& eql = key_equal(),
61                      const allocator_type& a = allocator_type());
62    explicit unordered_map(const allocator_type&);
63    unordered_map(const unordered_map&);
64    unordered_map(const unordered_map&, const Allocator&);
65    unordered_map(unordered_map&&)
66        noexcept(
67            is_nothrow_move_constructible<hasher>::value &&
68            is_nothrow_move_constructible<key_equal>::value &&
69            is_nothrow_move_constructible<allocator_type>::value);
70    unordered_map(unordered_map&&, const Allocator&);
71    unordered_map(initializer_list<value_type>, size_type n = 0,
72                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
73                  const allocator_type& a = allocator_type());
74    unordered_map(size_type n, const allocator_type& a)
75      : unordered_map(n, hasher(), key_equal(), a) {}  // C++14
76    unordered_map(size_type n, const hasher& hf, const allocator_type& a)
77      : unordered_map(n, hf, key_equal(), a) {}  // C++14
78    template <class InputIterator>
79      unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
80      : unordered_map(f, l, n, hasher(), key_equal(), a) {}  // C++14
81    template <class InputIterator>
82      unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
83        const allocator_type& a)
84      : unordered_map(f, l, n, hf, key_equal(), a) {}  // C++14
85    unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
86      : unordered_map(il, n, hasher(), key_equal(), a) {}  // C++14
87    unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
88      const allocator_type& a)
89      : unordered_map(il, n, hf, key_equal(), a) {}  // C++14
90    ~unordered_map();
91    unordered_map& operator=(const unordered_map&);
92    unordered_map& operator=(unordered_map&&)
93        noexcept(
94            allocator_type::propagate_on_container_move_assignment::value &&
95            is_nothrow_move_assignable<allocator_type>::value &&
96            is_nothrow_move_assignable<hasher>::value &&
97            is_nothrow_move_assignable<key_equal>::value);
98    unordered_map& operator=(initializer_list<value_type>);
99
100    allocator_type get_allocator() const noexcept;
101
102    bool      empty() const noexcept;
103    size_type size() const noexcept;
104    size_type max_size() const noexcept;
105
106    iterator       begin() noexcept;
107    iterator       end() noexcept;
108    const_iterator begin()  const noexcept;
109    const_iterator end()    const noexcept;
110    const_iterator cbegin() const noexcept;
111    const_iterator cend()   const noexcept;
112
113    template <class... Args>
114        pair<iterator, bool> emplace(Args&&... args);
115    template <class... Args>
116        iterator emplace_hint(const_iterator position, Args&&... args);
117    pair<iterator, bool> insert(const value_type& obj);
118    template <class P>
119        pair<iterator, bool> insert(P&& obj);
120    iterator insert(const_iterator hint, const value_type& obj);
121    template <class P>
122        iterator insert(const_iterator hint, P&& obj);
123    template <class InputIterator>
124        void insert(InputIterator first, InputIterator last);
125    void insert(initializer_list<value_type>);
126
127    node_type extract(const_iterator position);                                       // C++17
128    node_type extract(const key_type& x);                                             // C++17
129    insert_return_type insert(node_type&& nh);                                        // C++17
130    iterator           insert(const_iterator hint, node_type&& nh);                   // C++17
131
132    template <class... Args>
133        pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);          // C++17
134    template <class... Args>
135        pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);               // C++17
136    template <class... Args>
137        iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
138    template <class... Args>
139        iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);      // C++17
140    template <class M>
141        pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);            // C++17
142    template <class M>
143        pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);                 // C++17
144    template <class M>
145        iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);   // C++17
146    template <class M>
147        iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);        // C++17
148
149    iterator erase(const_iterator position);
150    iterator erase(iterator position);  // C++14
151    size_type erase(const key_type& k);
152    iterator erase(const_iterator first, const_iterator last);
153    void clear() noexcept;
154
155    template<class H2, class P2>
156      void merge(unordered_map<Key, T, H2, P2, Allocator>& source);         // C++17
157    template<class H2, class P2>
158      void merge(unordered_map<Key, T, H2, P2, Allocator>&& source);        // C++17
159    template<class H2, class P2>
160      void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);    // C++17
161    template<class H2, class P2>
162      void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);   // C++17
163
164    void swap(unordered_map&)
165        noexcept(
166            (!allocator_type::propagate_on_container_swap::value ||
167             __is_nothrow_swappable<allocator_type>::value) &&
168            __is_nothrow_swappable<hasher>::value &&
169            __is_nothrow_swappable<key_equal>::value);
170
171    hasher hash_function() const;
172    key_equal key_eq() const;
173
174    iterator       find(const key_type& k);
175    const_iterator find(const key_type& k) const;
176    template<typename K>
177        iterator find(const K& x);              // C++20
178    template<typename K>
179        const_iterator find(const K& x) const;  // C++20
180    size_type count(const key_type& k) const;
181    template<typename K>
182        size_type count(const K& k) const; // C++20
183    bool contains(const key_type& k) const; // C++20
184    template<typename K>
185        bool contains(const K& k) const; // C++20
186    pair<iterator, iterator>             equal_range(const key_type& k);
187    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
188    template<typename K>
189        pair<iterator, iterator>             equal_range(const K& k); // C++20
190    template<typename K>
191        pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
192
193    mapped_type& operator[](const key_type& k);
194    mapped_type& operator[](key_type&& k);
195
196    mapped_type&       at(const key_type& k);
197    const mapped_type& at(const key_type& k) const;
198
199    size_type bucket_count() const noexcept;
200    size_type max_bucket_count() const noexcept;
201
202    size_type bucket_size(size_type n) const;
203    size_type bucket(const key_type& k) const;
204
205    local_iterator       begin(size_type n);
206    local_iterator       end(size_type n);
207    const_local_iterator begin(size_type n) const;
208    const_local_iterator end(size_type n) const;
209    const_local_iterator cbegin(size_type n) const;
210    const_local_iterator cend(size_type n) const;
211
212    float load_factor() const noexcept;
213    float max_load_factor() const noexcept;
214    void max_load_factor(float z);
215    void rehash(size_type n);
216    void reserve(size_type n);
217};
218
219template<class InputIterator,
220    class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
221    class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
222unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
223    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
224  -> unordered_map<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
225    Allocator>; // C++17
226
227template<class Key, class T, class Hash = hash<Key>,
228    class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
229unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
230    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
231  -> unordered_map<Key, T, Hash, Pred, Allocator>; // C++17
232
233template<class InputIterator, class Allocator>
234unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
235  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
236        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
237
238template<class InputIterator, class Allocator>
239unordered_map(InputIterator, InputIterator, Allocator)
240  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
241        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
242
243template<class InputIterator, class Hash, class Allocator>
244unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
245  -> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
246          equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
247
248template<class Key, class T, typename Allocator>
249unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
250  -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
251
252template<class Key, class T, typename Allocator>
253unordered_map(initializer_list<pair<const Key, T>>, Allocator)
254  -> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
255
256template<class Key, class T, class Hash, class Allocator>
257unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash, Allocator)
258  -> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
259
260template <class Key, class T, class Hash, class Pred, class Alloc>
261    void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
262              unordered_map<Key, T, Hash, Pred, Alloc>& y)
263              noexcept(noexcept(x.swap(y)));
264
265template <class Key, class T, class Hash, class Pred, class Alloc>
266    bool
267    operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
268               const unordered_map<Key, T, Hash, Pred, Alloc>& y);
269
270template <class Key, class T, class Hash, class Pred, class Alloc>
271    bool
272    operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
273               const unordered_map<Key, T, Hash, Pred, Alloc>& y);
274
275template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
276          class Alloc = allocator<pair<const Key, T>>>
277class unordered_multimap
278{
279public:
280    // types
281    typedef Key                                                        key_type;
282    typedef T                                                          mapped_type;
283    typedef Hash                                                       hasher;
284    typedef Pred                                                       key_equal;
285    typedef Alloc                                                      allocator_type;
286    typedef pair<const key_type, mapped_type>                          value_type;
287    typedef value_type&                                                reference;
288    typedef const value_type&                                          const_reference;
289    typedef typename allocator_traits<allocator_type>::pointer         pointer;
290    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
291    typedef typename allocator_traits<allocator_type>::size_type       size_type;
292    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
293
294    typedef /unspecified/ iterator;
295    typedef /unspecified/ const_iterator;
296    typedef /unspecified/ local_iterator;
297    typedef /unspecified/ const_local_iterator;
298
299    typedef unspecified node_type;    // C++17
300
301    unordered_multimap()
302        noexcept(
303            is_nothrow_default_constructible<hasher>::value &&
304            is_nothrow_default_constructible<key_equal>::value &&
305            is_nothrow_default_constructible<allocator_type>::value);
306    explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
307                           const key_equal& eql = key_equal(),
308                           const allocator_type& a = allocator_type());
309    template <class InputIterator>
310        unordered_multimap(InputIterator f, InputIterator l,
311                      size_type n = 0, const hasher& hf = hasher(),
312                      const key_equal& eql = key_equal(),
313                      const allocator_type& a = allocator_type());
314    explicit unordered_multimap(const allocator_type&);
315    unordered_multimap(const unordered_multimap&);
316    unordered_multimap(const unordered_multimap&, const Allocator&);
317    unordered_multimap(unordered_multimap&&)
318        noexcept(
319            is_nothrow_move_constructible<hasher>::value &&
320            is_nothrow_move_constructible<key_equal>::value &&
321            is_nothrow_move_constructible<allocator_type>::value);
322    unordered_multimap(unordered_multimap&&, const Allocator&);
323    unordered_multimap(initializer_list<value_type>, size_type n = 0,
324                  const hasher& hf = hasher(), const key_equal& eql = key_equal(),
325                  const allocator_type& a = allocator_type());
326    unordered_multimap(size_type n, const allocator_type& a)
327      : unordered_multimap(n, hasher(), key_equal(), a) {}  // C++14
328    unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
329      : unordered_multimap(n, hf, key_equal(), a) {}  // C++14
330    template <class InputIterator>
331      unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
332      : unordered_multimap(f, l, n, hasher(), key_equal(), a) {}  // C++14
333    template <class InputIterator>
334      unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
335        const allocator_type& a)
336      : unordered_multimap(f, l, n, hf, key_equal(), a) {}  // C++14
337    unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
338      : unordered_multimap(il, n, hasher(), key_equal(), a) {}  // C++14
339    unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
340      const allocator_type& a)
341      : unordered_multimap(il, n, hf, key_equal(), a) {}  // C++14
342    ~unordered_multimap();
343    unordered_multimap& operator=(const unordered_multimap&);
344    unordered_multimap& operator=(unordered_multimap&&)
345        noexcept(
346            allocator_type::propagate_on_container_move_assignment::value &&
347            is_nothrow_move_assignable<allocator_type>::value &&
348            is_nothrow_move_assignable<hasher>::value &&
349            is_nothrow_move_assignable<key_equal>::value);
350    unordered_multimap& operator=(initializer_list<value_type>);
351
352    allocator_type get_allocator() const noexcept;
353
354    bool      empty() const noexcept;
355    size_type size() const noexcept;
356    size_type max_size() const noexcept;
357
358    iterator       begin() noexcept;
359    iterator       end() noexcept;
360    const_iterator begin()  const noexcept;
361    const_iterator end()    const noexcept;
362    const_iterator cbegin() const noexcept;
363    const_iterator cend()   const noexcept;
364
365    template <class... Args>
366        iterator emplace(Args&&... args);
367    template <class... Args>
368        iterator emplace_hint(const_iterator position, Args&&... args);
369    iterator insert(const value_type& obj);
370    template <class P>
371        iterator insert(P&& obj);
372    iterator insert(const_iterator hint, const value_type& obj);
373    template <class P>
374        iterator insert(const_iterator hint, P&& obj);
375    template <class InputIterator>
376        void insert(InputIterator first, InputIterator last);
377    void insert(initializer_list<value_type>);
378
379    node_type extract(const_iterator position);                // C++17
380    node_type extract(const key_type& x);                      // C++17
381    iterator insert(node_type&& nh);                           // C++17
382    iterator insert(const_iterator hint, node_type&& nh);      // C++17
383
384    iterator erase(const_iterator position);
385    iterator erase(iterator position);  // C++14
386    size_type erase(const key_type& k);
387    iterator erase(const_iterator first, const_iterator last);
388    void clear() noexcept;
389
390    template<class H2, class P2>
391      void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);    // C++17
392    template<class H2, class P2>
393      void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);   // C++17
394    template<class H2, class P2>
395      void merge(unordered_map<Key, T, H2, P2, Allocator>& source);         // C++17
396    template<class H2, class P2>
397      void merge(unordered_map<Key, T, H2, P2, Allocator>&& source);        // C++17
398
399    void swap(unordered_multimap&)
400        noexcept(
401            (!allocator_type::propagate_on_container_swap::value ||
402             __is_nothrow_swappable<allocator_type>::value) &&
403            __is_nothrow_swappable<hasher>::value &&
404            __is_nothrow_swappable<key_equal>::value);
405
406    hasher hash_function() const;
407    key_equal key_eq() const;
408
409    iterator       find(const key_type& k);
410    const_iterator find(const key_type& k) const;
411    template<typename K>
412        iterator find(const K& x);              // C++20
413    template<typename K>
414        const_iterator find(const K& x) const;  // C++20
415    size_type count(const key_type& k) const;
416    template<typename K>
417        size_type count(const K& k) const; // C++20
418    bool contains(const key_type& k) const; // C++20
419    template<typename K>
420        bool contains(const K& k) const; // C++20
421    pair<iterator, iterator>             equal_range(const key_type& k);
422    pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
423    template<typename K>
424        pair<iterator, iterator>             equal_range(const K& k); // C++20
425    template<typename K>
426        pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
427
428    size_type bucket_count() const noexcept;
429    size_type max_bucket_count() const noexcept;
430
431    size_type bucket_size(size_type n) const;
432    size_type bucket(const key_type& k) const;
433
434    local_iterator       begin(size_type n);
435    local_iterator       end(size_type n);
436    const_local_iterator begin(size_type n) const;
437    const_local_iterator end(size_type n) const;
438    const_local_iterator cbegin(size_type n) const;
439    const_local_iterator cend(size_type n) const;
440
441    float load_factor() const noexcept;
442    float max_load_factor() const noexcept;
443    void max_load_factor(float z);
444    void rehash(size_type n);
445    void reserve(size_type n);
446};
447
448template<class InputIterator,
449    class Hash = hash<iter_key_t<InputIterator>>, class Pred = equal_to<iter_key_t<InputIterator>>,
450    class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
451unordered_multimap(InputIterator, InputIterator, typename see below::size_type = see below,
452    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
453  -> unordered_multimap<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
454    Allocator>; // C++17
455
456template<class Key, class T, class Hash = hash<Key>,
457    class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
458unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type = see below,
459    Hash = Hash(), Pred = Pred(), Allocator = Allocator())
460  -> unordered_multimap<Key, T, Hash, Pred, Allocator>; // C++17
461
462template<class InputIterator, class Allocator>
463unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
464  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
465        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
466
467template<class InputIterator, class Allocator>
468unordered_multimap(InputIterator, InputIterator, Allocator)
469  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
470        hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
471
472template<class InputIterator, class Hash, class Allocator>
473unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
474  -> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
475          equal_to<iter_key_t<InputIterator>>, Allocator>; // C++17
476
477template<class Key, class T, typename Allocator>
478unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Allocator)
479  -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
480
481template<class Key, class T, typename Allocator>
482unordered_multimap(initializer_list<pair<const Key, T>>, Allocator)
483  -> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>; // C++17
484
485template<class Key, class T, class Hash, class Allocator>
486unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash,
487    Allocator)
488  -> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>; // C++17
489
490template <class Key, class T, class Hash, class Pred, class Alloc>
491    void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
492              unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
493              noexcept(noexcept(x.swap(y)));
494
495template <class K, class T, class H, class P, class A, class Predicate>
496    typename unordered_map<K, T, H, P, A>::size_type
497    erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred);       // C++20
498
499template <class K, class T, class H, class P, class A, class Predicate>
500    typename unordered_multimap<K, T, H, P, A>::size_type
501    erase_if(unordered_multimap<K, T, H, P, A>& c, Predicate pred);  // C++20
502
503template <class Key, class T, class Hash, class Pred, class Alloc>
504    bool
505    operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
506               const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
507
508template <class Key, class T, class Hash, class Pred, class Alloc>
509    bool
510    operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
511               const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
512
513}  // std
514
515*/
516
517#include <__config>
518#include <__debug>
519#include <__functional/is_transparent.h>
520#include <__hash_table>
521#include <__iterator/iterator_traits.h>
522#include <__node_handle>
523#include <__utility/forward.h>
524#include <compare>
525#include <functional>
526#include <iterator> // __libcpp_erase_if_container
527#include <stdexcept>
528#include <tuple>
529#include <version>
530
531#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
532#pragma GCC system_header
533#endif
534
535_LIBCPP_BEGIN_NAMESPACE_STD
536
537template <class _Key, class _Cp, class _Hash, class _Pred,
538          bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
539class __unordered_map_hasher
540    : private _Hash
541{
542public:
543    _LIBCPP_INLINE_VISIBILITY
544    __unordered_map_hasher()
545        _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
546        : _Hash() {}
547    _LIBCPP_INLINE_VISIBILITY
548    __unordered_map_hasher(const _Hash& __h)
549        _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
550        : _Hash(__h) {}
551    _LIBCPP_INLINE_VISIBILITY
552    const _Hash& hash_function() const _NOEXCEPT {return *this;}
553    _LIBCPP_INLINE_VISIBILITY
554    size_t operator()(const _Cp& __x) const
555        {return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
556    _LIBCPP_INLINE_VISIBILITY
557    size_t operator()(const _Key& __x) const
558        {return static_cast<const _Hash&>(*this)(__x);}
559#if _LIBCPP_STD_VER > 17
560    template <typename _K2>
561    _LIBCPP_INLINE_VISIBILITY
562    size_t operator()(const _K2& __x) const
563        {return static_cast<const _Hash&>(*this)(__x);}
564#endif
565    _LIBCPP_INLINE_VISIBILITY
566    void swap(__unordered_map_hasher& __y)
567        _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
568    {
569        using _VSTD::swap;
570        swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
571    }
572};
573
574template <class _Key, class _Cp, class _Hash, class _Pred>
575class __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, false>
576{
577    _Hash __hash_;
578public:
579    _LIBCPP_INLINE_VISIBILITY
580    __unordered_map_hasher()
581        _NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
582        : __hash_() {}
583    _LIBCPP_INLINE_VISIBILITY
584    __unordered_map_hasher(const _Hash& __h)
585        _NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
586        : __hash_(__h) {}
587    _LIBCPP_INLINE_VISIBILITY
588    const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
589    _LIBCPP_INLINE_VISIBILITY
590    size_t operator()(const _Cp& __x) const
591        {return __hash_(__x.__get_value().first);}
592    _LIBCPP_INLINE_VISIBILITY
593    size_t operator()(const _Key& __x) const
594        {return __hash_(__x);}
595#if _LIBCPP_STD_VER > 17
596    template <typename _K2>
597    _LIBCPP_INLINE_VISIBILITY
598    size_t operator()(const _K2& __x) const
599        {return __hash_(__x);}
600#endif
601    _LIBCPP_INLINE_VISIBILITY
602    void swap(__unordered_map_hasher& __y)
603        _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
604    {
605        using _VSTD::swap;
606        swap(__hash_, __y.__hash_);
607    }
608};
609
610template <class _Key, class _Cp, class _Hash, class _Pred, bool __b>
611inline _LIBCPP_INLINE_VISIBILITY
612void
613swap(__unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __x,
614     __unordered_map_hasher<_Key, _Cp, _Hash, _Pred, __b>& __y)
615    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
616{
617    __x.swap(__y);
618}
619
620template <class _Key, class _Cp, class _Pred, class _Hash,
621          bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value>
622class __unordered_map_equal
623    : private _Pred
624{
625public:
626    _LIBCPP_INLINE_VISIBILITY
627    __unordered_map_equal()
628        _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
629        : _Pred() {}
630    _LIBCPP_INLINE_VISIBILITY
631    __unordered_map_equal(const _Pred& __p)
632        _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
633        : _Pred(__p) {}
634    _LIBCPP_INLINE_VISIBILITY
635    const _Pred& key_eq() const _NOEXCEPT {return *this;}
636    _LIBCPP_INLINE_VISIBILITY
637    bool operator()(const _Cp& __x, const _Cp& __y) const
638        {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y.__get_value().first);}
639    _LIBCPP_INLINE_VISIBILITY
640    bool operator()(const _Cp& __x, const _Key& __y) const
641        {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
642    _LIBCPP_INLINE_VISIBILITY
643    bool operator()(const _Key& __x, const _Cp& __y) const
644        {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
645#if _LIBCPP_STD_VER > 17
646    template <typename _K2>
647    _LIBCPP_INLINE_VISIBILITY
648    bool operator()(const _Cp& __x, const _K2& __y) const
649        {return static_cast<const _Pred&>(*this)(__x.__get_value().first, __y);}
650    template <typename _K2>
651    _LIBCPP_INLINE_VISIBILITY
652    bool operator()(const _K2& __x, const _Cp& __y) const
653        {return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
654    template <typename _K2>
655    _LIBCPP_INLINE_VISIBILITY
656    bool operator()(const _Key& __x, const _K2& __y) const
657        {return static_cast<const _Pred&>(*this)(__x, __y);}
658    template <typename _K2>
659    _LIBCPP_INLINE_VISIBILITY
660    bool operator()(const _K2& __x, const _Key& __y) const
661        {return static_cast<const _Pred&>(*this)(__x, __y);}
662#endif
663    _LIBCPP_INLINE_VISIBILITY
664    void swap(__unordered_map_equal& __y)
665        _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
666    {
667        using _VSTD::swap;
668        swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
669    }
670};
671
672template <class _Key, class _Cp, class _Pred, class _Hash>
673class __unordered_map_equal<_Key, _Cp, _Pred, _Hash, false>
674{
675    _Pred __pred_;
676public:
677    _LIBCPP_INLINE_VISIBILITY
678    __unordered_map_equal()
679        _NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
680        : __pred_() {}
681    _LIBCPP_INLINE_VISIBILITY
682    __unordered_map_equal(const _Pred& __p)
683        _NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
684        : __pred_(__p) {}
685    _LIBCPP_INLINE_VISIBILITY
686    const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
687    _LIBCPP_INLINE_VISIBILITY
688    bool operator()(const _Cp& __x, const _Cp& __y) const
689        {return __pred_(__x.__get_value().first, __y.__get_value().first);}
690    _LIBCPP_INLINE_VISIBILITY
691    bool operator()(const _Cp& __x, const _Key& __y) const
692        {return __pred_(__x.__get_value().first, __y);}
693    _LIBCPP_INLINE_VISIBILITY
694    bool operator()(const _Key& __x, const _Cp& __y) const
695        {return __pred_(__x, __y.__get_value().first);}
696#if _LIBCPP_STD_VER > 17
697    template <typename _K2>
698    _LIBCPP_INLINE_VISIBILITY
699    bool operator()(const _Cp& __x, const _K2& __y) const
700        {return __pred_(__x.__get_value().first, __y);}
701    template <typename _K2>
702    _LIBCPP_INLINE_VISIBILITY
703    bool operator()(const _K2& __x, const _Cp& __y) const
704        {return __pred_(__x, __y.__get_value().first);}
705    template <typename _K2>
706    _LIBCPP_INLINE_VISIBILITY
707    bool operator()(const _Key& __x, const _K2& __y) const
708        {return __pred_(__x, __y);}
709    template <typename _K2>
710    _LIBCPP_INLINE_VISIBILITY
711    bool operator()(const _K2& __x, const _Key& __y) const
712        {return __pred_(__x, __y);}
713#endif
714    _LIBCPP_INLINE_VISIBILITY
715    void swap(__unordered_map_equal& __y)
716        _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
717    {
718        using _VSTD::swap;
719        swap(__pred_, __y.__pred_);
720    }
721};
722
723template <class _Key, class _Cp, class _Pred, class _Hash, bool __b>
724inline _LIBCPP_INLINE_VISIBILITY
725void
726swap(__unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __x,
727     __unordered_map_equal<_Key, _Cp, _Pred, _Hash, __b>& __y)
728    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
729{
730    __x.swap(__y);
731}
732
733template <class _Alloc>
734class __hash_map_node_destructor
735{
736    typedef _Alloc                              allocator_type;
737    typedef allocator_traits<allocator_type>    __alloc_traits;
738
739public:
740
741    typedef typename __alloc_traits::pointer       pointer;
742private:
743
744    allocator_type& __na_;
745
746    __hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
747
748public:
749    bool __first_constructed;
750    bool __second_constructed;
751
752    _LIBCPP_INLINE_VISIBILITY
753    explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
754        : __na_(__na),
755          __first_constructed(false),
756          __second_constructed(false)
757        {}
758
759#ifndef _LIBCPP_CXX03_LANG
760    _LIBCPP_INLINE_VISIBILITY
761    __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
762        _NOEXCEPT
763        : __na_(__x.__na_),
764          __first_constructed(__x.__value_constructed),
765          __second_constructed(__x.__value_constructed)
766        {
767            __x.__value_constructed = false;
768        }
769#else  // _LIBCPP_CXX03_LANG
770    _LIBCPP_INLINE_VISIBILITY
771    __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
772        : __na_(__x.__na_),
773          __first_constructed(__x.__value_constructed),
774          __second_constructed(__x.__value_constructed)
775        {
776            const_cast<bool&>(__x.__value_constructed) = false;
777        }
778#endif // _LIBCPP_CXX03_LANG
779
780    _LIBCPP_INLINE_VISIBILITY
781    void operator()(pointer __p) _NOEXCEPT
782    {
783        if (__second_constructed)
784            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
785        if (__first_constructed)
786            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
787        if (__p)
788            __alloc_traits::deallocate(__na_, __p, 1);
789    }
790};
791
792#ifndef _LIBCPP_CXX03_LANG
793template <class _Key, class _Tp>
794struct _LIBCPP_STANDALONE_DEBUG __hash_value_type
795{
796    typedef _Key                                     key_type;
797    typedef _Tp                                      mapped_type;
798    typedef pair<const key_type, mapped_type>        value_type;
799    typedef pair<key_type&, mapped_type&>            __nc_ref_pair_type;
800    typedef pair<key_type&&, mapped_type&&>          __nc_rref_pair_type;
801
802private:
803    value_type __cc;
804
805public:
806    _LIBCPP_INLINE_VISIBILITY
807    value_type& __get_value()
808    {
809#if _LIBCPP_STD_VER > 14
810        return *_VSTD::launder(_VSTD::addressof(__cc));
811#else
812        return __cc;
813#endif
814    }
815
816    _LIBCPP_INLINE_VISIBILITY
817    const value_type& __get_value() const
818    {
819#if _LIBCPP_STD_VER > 14
820        return *_VSTD::launder(_VSTD::addressof(__cc));
821#else
822        return __cc;
823#endif
824    }
825
826    _LIBCPP_INLINE_VISIBILITY
827    __nc_ref_pair_type __ref()
828    {
829        value_type& __v = __get_value();
830        return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
831    }
832
833    _LIBCPP_INLINE_VISIBILITY
834    __nc_rref_pair_type __move()
835    {
836        value_type& __v = __get_value();
837        return __nc_rref_pair_type(
838            _VSTD::move(const_cast<key_type&>(__v.first)),
839            _VSTD::move(__v.second));
840    }
841
842    _LIBCPP_INLINE_VISIBILITY
843    __hash_value_type& operator=(const __hash_value_type& __v)
844    {
845        __ref() = __v.__get_value();
846        return *this;
847    }
848
849    _LIBCPP_INLINE_VISIBILITY
850    __hash_value_type& operator=(__hash_value_type&& __v)
851    {
852        __ref() = __v.__move();
853        return *this;
854    }
855
856    template <class _ValueTp,
857              class = typename enable_if<
858                    __is_same_uncvref<_ValueTp, value_type>::value
859                 >::type
860             >
861    _LIBCPP_INLINE_VISIBILITY
862    __hash_value_type& operator=(_ValueTp&& __v)
863    {
864        __ref() = _VSTD::forward<_ValueTp>(__v);
865        return *this;
866    }
867
868private:
869    __hash_value_type(const __hash_value_type& __v) = delete;
870    __hash_value_type(__hash_value_type&& __v) = delete;
871    template <class ..._Args>
872    explicit __hash_value_type(_Args&& ...__args) = delete;
873
874    ~__hash_value_type() = delete;
875};
876
877#else
878
879template <class _Key, class _Tp>
880struct __hash_value_type
881{
882    typedef _Key                                     key_type;
883    typedef _Tp                                      mapped_type;
884    typedef pair<const key_type, mapped_type>        value_type;
885
886private:
887    value_type __cc;
888
889public:
890    _LIBCPP_INLINE_VISIBILITY
891    value_type& __get_value() { return __cc; }
892    _LIBCPP_INLINE_VISIBILITY
893    const value_type& __get_value() const { return __cc; }
894
895private:
896   ~__hash_value_type();
897};
898
899#endif
900
901template <class _HashIterator>
902class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
903{
904    _HashIterator __i_;
905
906    typedef  __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
907
908public:
909    typedef forward_iterator_tag                                 iterator_category;
910    typedef typename _NodeTypes::__map_value_type                value_type;
911    typedef typename _NodeTypes::difference_type                 difference_type;
912    typedef value_type&                                          reference;
913    typedef typename _NodeTypes::__map_value_type_pointer       pointer;
914
915    _LIBCPP_INLINE_VISIBILITY
916    __hash_map_iterator() _NOEXCEPT {}
917
918    _LIBCPP_INLINE_VISIBILITY
919    __hash_map_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
920
921    _LIBCPP_INLINE_VISIBILITY
922    reference operator*() const {return __i_->__get_value();}
923    _LIBCPP_INLINE_VISIBILITY
924    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
925
926    _LIBCPP_INLINE_VISIBILITY
927    __hash_map_iterator& operator++() {++__i_; return *this;}
928    _LIBCPP_INLINE_VISIBILITY
929    __hash_map_iterator operator++(int)
930    {
931        __hash_map_iterator __t(*this);
932        ++(*this);
933        return __t;
934    }
935
936    friend _LIBCPP_INLINE_VISIBILITY
937        bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
938        {return __x.__i_ == __y.__i_;}
939    friend _LIBCPP_INLINE_VISIBILITY
940        bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
941        {return __x.__i_ != __y.__i_;}
942
943    template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
944    template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
945    template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
946    template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
947    template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
948};
949
950template <class _HashIterator>
951class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
952{
953    _HashIterator __i_;
954
955    typedef  __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
956
957public:
958    typedef forward_iterator_tag                                 iterator_category;
959    typedef typename _NodeTypes::__map_value_type                value_type;
960    typedef typename _NodeTypes::difference_type                 difference_type;
961    typedef const value_type&                                    reference;
962    typedef typename _NodeTypes::__const_map_value_type_pointer  pointer;
963
964    _LIBCPP_INLINE_VISIBILITY
965    __hash_map_const_iterator() _NOEXCEPT {}
966
967    _LIBCPP_INLINE_VISIBILITY
968    __hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
969    _LIBCPP_INLINE_VISIBILITY
970    __hash_map_const_iterator(
971            __hash_map_iterator<typename _HashIterator::__non_const_iterator> __i)
972                 _NOEXCEPT
973                : __i_(__i.__i_) {}
974
975    _LIBCPP_INLINE_VISIBILITY
976    reference operator*() const {return __i_->__get_value();}
977    _LIBCPP_INLINE_VISIBILITY
978    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
979
980    _LIBCPP_INLINE_VISIBILITY
981    __hash_map_const_iterator& operator++() {++__i_; return *this;}
982    _LIBCPP_INLINE_VISIBILITY
983    __hash_map_const_iterator operator++(int)
984    {
985        __hash_map_const_iterator __t(*this);
986        ++(*this);
987        return __t;
988    }
989
990    friend _LIBCPP_INLINE_VISIBILITY
991        bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
992        {return __x.__i_ == __y.__i_;}
993    friend _LIBCPP_INLINE_VISIBILITY
994        bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
995        {return __x.__i_ != __y.__i_;}
996
997    template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
998    template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
999    template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
1000    template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
1001};
1002
1003template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1004class unordered_multimap;
1005
1006template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1007          class _Alloc = allocator<pair<const _Key, _Tp> > >
1008class _LIBCPP_TEMPLATE_VIS unordered_map
1009{
1010public:
1011    // types
1012    typedef _Key                                           key_type;
1013    typedef _Tp                                            mapped_type;
1014    typedef __identity_t<_Hash>                            hasher;
1015    typedef __identity_t<_Pred>                            key_equal;
1016    typedef __identity_t<_Alloc>                           allocator_type;
1017    typedef pair<const key_type, mapped_type>              value_type;
1018    typedef value_type&                                    reference;
1019    typedef const value_type&                              const_reference;
1020    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1021                  "Invalid allocator::value_type");
1022
1023private:
1024    typedef __hash_value_type<key_type, mapped_type>                          __value_type;
1025    typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
1026    typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher>  __key_equal;
1027    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1028                                                 __value_type>::type          __allocator_type;
1029
1030    typedef __hash_table<__value_type, __hasher,
1031                         __key_equal,  __allocator_type>   __table;
1032
1033    __table __table_;
1034
1035    typedef typename __table::_NodeTypes                   _NodeTypes;
1036    typedef typename __table::__node_pointer               __node_pointer;
1037    typedef typename __table::__node_const_pointer         __node_const_pointer;
1038    typedef typename __table::__node_traits                __node_traits;
1039    typedef typename __table::__node_allocator             __node_allocator;
1040    typedef typename __table::__node                       __node;
1041    typedef __hash_map_node_destructor<__node_allocator>   _Dp;
1042    typedef unique_ptr<__node, _Dp>                         __node_holder;
1043    typedef allocator_traits<allocator_type>               __alloc_traits;
1044
1045    static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
1046    static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
1047public:
1048    typedef typename __alloc_traits::pointer         pointer;
1049    typedef typename __alloc_traits::const_pointer   const_pointer;
1050    typedef typename __table::size_type              size_type;
1051    typedef typename __table::difference_type        difference_type;
1052
1053    typedef __hash_map_iterator<typename __table::iterator>       iterator;
1054    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1055    typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1056    typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1057
1058#if _LIBCPP_STD_VER > 14
1059    typedef __map_node_handle<__node, allocator_type> node_type;
1060    typedef __insert_return_type<iterator, node_type> insert_return_type;
1061#endif
1062
1063    template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1064        friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1065    template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1066        friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1067
1068    _LIBCPP_INLINE_VISIBILITY
1069    unordered_map()
1070        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1071    {
1072        _VSTD::__debug_db_insert_c(this);
1073    }
1074    explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
1075                           const key_equal& __eql = key_equal());
1076    unordered_map(size_type __n, const hasher& __hf,
1077                  const key_equal& __eql,
1078                  const allocator_type& __a);
1079    template <class _InputIterator>
1080        unordered_map(_InputIterator __first, _InputIterator __last);
1081    template <class _InputIterator>
1082        unordered_map(_InputIterator __first, _InputIterator __last,
1083                      size_type __n, const hasher& __hf = hasher(),
1084                      const key_equal& __eql = key_equal());
1085    template <class _InputIterator>
1086        unordered_map(_InputIterator __first, _InputIterator __last,
1087                      size_type __n, const hasher& __hf,
1088                      const key_equal& __eql,
1089                      const allocator_type& __a);
1090    _LIBCPP_INLINE_VISIBILITY
1091    explicit unordered_map(const allocator_type& __a);
1092    unordered_map(const unordered_map& __u);
1093    unordered_map(const unordered_map& __u, const allocator_type& __a);
1094#ifndef _LIBCPP_CXX03_LANG
1095    _LIBCPP_INLINE_VISIBILITY
1096    unordered_map(unordered_map&& __u)
1097        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
1098    unordered_map(unordered_map&& __u, const allocator_type& __a);
1099    unordered_map(initializer_list<value_type> __il);
1100    unordered_map(initializer_list<value_type> __il, size_type __n,
1101                  const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
1102    unordered_map(initializer_list<value_type> __il, size_type __n,
1103                  const hasher& __hf, const key_equal& __eql,
1104                  const allocator_type& __a);
1105#endif // _LIBCPP_CXX03_LANG
1106#if _LIBCPP_STD_VER > 11
1107    _LIBCPP_INLINE_VISIBILITY
1108    unordered_map(size_type __n, const allocator_type& __a)
1109      : unordered_map(__n, hasher(), key_equal(), __a) {}
1110    _LIBCPP_INLINE_VISIBILITY
1111    unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
1112      : unordered_map(__n, __hf, key_equal(), __a) {}
1113    template <class _InputIterator>
1114    _LIBCPP_INLINE_VISIBILITY
1115      unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
1116      : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
1117    template <class _InputIterator>
1118    _LIBCPP_INLINE_VISIBILITY
1119      unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
1120        const allocator_type& __a)
1121      : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
1122    _LIBCPP_INLINE_VISIBILITY
1123    unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
1124      : unordered_map(__il, __n, hasher(), key_equal(), __a) {}
1125    _LIBCPP_INLINE_VISIBILITY
1126    unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1127      const allocator_type& __a)
1128      : unordered_map(__il, __n, __hf, key_equal(), __a) {}
1129#endif
1130    _LIBCPP_INLINE_VISIBILITY
1131    ~unordered_map() {
1132        static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
1133    }
1134
1135    _LIBCPP_INLINE_VISIBILITY
1136    unordered_map& operator=(const unordered_map& __u)
1137    {
1138#ifndef _LIBCPP_CXX03_LANG
1139        __table_ = __u.__table_;
1140#else
1141        if (this != _VSTD::addressof(__u)) {
1142            __table_.clear();
1143            __table_.hash_function() = __u.__table_.hash_function();
1144            __table_.key_eq() = __u.__table_.key_eq();
1145            __table_.max_load_factor() = __u.__table_.max_load_factor();
1146            __table_.__copy_assign_alloc(__u.__table_);
1147            insert(__u.begin(), __u.end());
1148        }
1149#endif
1150        return *this;
1151    }
1152#ifndef _LIBCPP_CXX03_LANG
1153    _LIBCPP_INLINE_VISIBILITY
1154    unordered_map& operator=(unordered_map&& __u)
1155        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
1156    _LIBCPP_INLINE_VISIBILITY
1157    unordered_map& operator=(initializer_list<value_type> __il);
1158#endif // _LIBCPP_CXX03_LANG
1159
1160    _LIBCPP_INLINE_VISIBILITY
1161    allocator_type get_allocator() const _NOEXCEPT
1162        {return allocator_type(__table_.__node_alloc());}
1163
1164    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1165    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
1166    _LIBCPP_INLINE_VISIBILITY
1167    size_type size() const _NOEXCEPT  {return __table_.size();}
1168    _LIBCPP_INLINE_VISIBILITY
1169    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
1170
1171    _LIBCPP_INLINE_VISIBILITY
1172    iterator       begin() _NOEXCEPT        {return __table_.begin();}
1173    _LIBCPP_INLINE_VISIBILITY
1174    iterator       end() _NOEXCEPT          {return __table_.end();}
1175    _LIBCPP_INLINE_VISIBILITY
1176    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
1177    _LIBCPP_INLINE_VISIBILITY
1178    const_iterator end()    const _NOEXCEPT {return __table_.end();}
1179    _LIBCPP_INLINE_VISIBILITY
1180    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
1181    _LIBCPP_INLINE_VISIBILITY
1182    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
1183
1184    _LIBCPP_INLINE_VISIBILITY
1185    pair<iterator, bool> insert(const value_type& __x)
1186        {return __table_.__insert_unique(__x);}
1187
1188    iterator insert(const_iterator __p, const value_type& __x) {
1189#if _LIBCPP_DEBUG_LEVEL == 2
1190        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1191            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1192            " referring to this unordered_map");
1193#else
1194        ((void)__p);
1195#endif
1196        return insert(__x).first;
1197    }
1198
1199    template <class _InputIterator>
1200        _LIBCPP_INLINE_VISIBILITY
1201        void insert(_InputIterator __first, _InputIterator __last);
1202
1203#ifndef _LIBCPP_CXX03_LANG
1204    _LIBCPP_INLINE_VISIBILITY
1205    void insert(initializer_list<value_type> __il)
1206        {insert(__il.begin(), __il.end());}
1207
1208    _LIBCPP_INLINE_VISIBILITY
1209    pair<iterator, bool> insert(value_type&& __x)
1210        {return __table_.__insert_unique(_VSTD::move(__x));}
1211
1212    iterator insert(const_iterator __p, value_type&& __x) {
1213#if _LIBCPP_DEBUG_LEVEL == 2
1214        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1215            "unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
1216            " referring to this unordered_map");
1217#else
1218        ((void)__p);
1219#endif
1220        return __table_.__insert_unique(_VSTD::move(__x)).first;
1221    }
1222
1223    template <class _Pp,
1224              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1225        _LIBCPP_INLINE_VISIBILITY
1226        pair<iterator, bool> insert(_Pp&& __x)
1227            {return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
1228
1229    template <class _Pp,
1230              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
1231        _LIBCPP_INLINE_VISIBILITY
1232        iterator insert(const_iterator __p, _Pp&& __x)
1233        {
1234#if _LIBCPP_DEBUG_LEVEL == 2
1235            _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1236                "unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
1237                " referring to this unordered_map");
1238#else
1239          ((void)__p);
1240#endif
1241            return insert(_VSTD::forward<_Pp>(__x)).first;
1242        }
1243
1244    template <class... _Args>
1245    _LIBCPP_INLINE_VISIBILITY
1246    pair<iterator, bool> emplace(_Args&&... __args) {
1247        return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
1248    }
1249
1250    template <class... _Args>
1251    _LIBCPP_INLINE_VISIBILITY
1252    iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1253#if _LIBCPP_DEBUG_LEVEL == 2
1254        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1255            "unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
1256            " referring to this unordered_map");
1257#else
1258          ((void)__p);
1259#endif
1260        return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
1261    }
1262
1263#endif // _LIBCPP_CXX03_LANG
1264
1265#if _LIBCPP_STD_VER > 14
1266    template <class... _Args>
1267        _LIBCPP_INLINE_VISIBILITY
1268        pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
1269    {
1270        return __table_.__emplace_unique_key_args(__k, piecewise_construct,
1271            _VSTD::forward_as_tuple(__k),
1272            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1273    }
1274
1275    template <class... _Args>
1276        _LIBCPP_INLINE_VISIBILITY
1277        pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
1278    {
1279        return __table_.__emplace_unique_key_args(__k, piecewise_construct,
1280            _VSTD::forward_as_tuple(_VSTD::move(__k)),
1281            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
1282    }
1283
1284    template <class... _Args>
1285        _LIBCPP_INLINE_VISIBILITY
1286        iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
1287    {
1288#if _LIBCPP_DEBUG_LEVEL == 2
1289        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1290            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1291            " referring to this unordered_map");
1292#else
1293        ((void)__h);
1294#endif
1295        return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
1296    }
1297
1298    template <class... _Args>
1299        _LIBCPP_INLINE_VISIBILITY
1300        iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
1301    {
1302#if _LIBCPP_DEBUG_LEVEL == 2
1303        _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
1304            "unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
1305            " referring to this unordered_map");
1306#else
1307        ((void)__h);
1308#endif
1309        return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
1310    }
1311
1312    template <class _Vp>
1313        _LIBCPP_INLINE_VISIBILITY
1314        pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
1315    {
1316        pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1317            __k, _VSTD::forward<_Vp>(__v));
1318        if (!__res.second) {
1319            __res.first->second = _VSTD::forward<_Vp>(__v);
1320        }
1321        return __res;
1322    }
1323
1324    template <class _Vp>
1325        _LIBCPP_INLINE_VISIBILITY
1326        pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
1327    {
1328        pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
1329            _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1330        if (!__res.second) {
1331            __res.first->second = _VSTD::forward<_Vp>(__v);
1332        }
1333        return __res;
1334    }
1335
1336    template <class _Vp>
1337        _LIBCPP_INLINE_VISIBILITY
1338        iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
1339     {
1340          // FIXME: Add debug mode checking for the iterator input
1341          return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
1342     }
1343
1344    template <class _Vp>
1345        _LIBCPP_INLINE_VISIBILITY
1346        iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
1347     {
1348        // FIXME: Add debug mode checking for the iterator input
1349        return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
1350     }
1351#endif // _LIBCPP_STD_VER > 14
1352
1353    _LIBCPP_INLINE_VISIBILITY
1354    iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
1355    _LIBCPP_INLINE_VISIBILITY
1356    iterator erase(iterator __p)       {return __table_.erase(__p.__i_);}
1357    _LIBCPP_INLINE_VISIBILITY
1358    size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
1359    _LIBCPP_INLINE_VISIBILITY
1360    iterator erase(const_iterator __first, const_iterator __last)
1361        {return __table_.erase(__first.__i_, __last.__i_);}
1362    _LIBCPP_INLINE_VISIBILITY
1363        void clear() _NOEXCEPT {__table_.clear();}
1364
1365#if _LIBCPP_STD_VER > 14
1366    _LIBCPP_INLINE_VISIBILITY
1367    insert_return_type insert(node_type&& __nh)
1368    {
1369        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1370            "node_type with incompatible allocator passed to unordered_map::insert()");
1371        return __table_.template __node_handle_insert_unique<
1372            node_type, insert_return_type>(_VSTD::move(__nh));
1373    }
1374    _LIBCPP_INLINE_VISIBILITY
1375    iterator insert(const_iterator __hint, node_type&& __nh)
1376    {
1377        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1378            "node_type with incompatible allocator passed to unordered_map::insert()");
1379        return __table_.template __node_handle_insert_unique<node_type>(
1380            __hint.__i_, _VSTD::move(__nh));
1381    }
1382    _LIBCPP_INLINE_VISIBILITY
1383    node_type extract(key_type const& __key)
1384    {
1385        return __table_.template __node_handle_extract<node_type>(__key);
1386    }
1387    _LIBCPP_INLINE_VISIBILITY
1388    node_type extract(const_iterator __it)
1389    {
1390        return __table_.template __node_handle_extract<node_type>(
1391            __it.__i_);
1392    }
1393
1394    template <class _H2, class _P2>
1395    _LIBCPP_INLINE_VISIBILITY
1396    void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
1397    {
1398        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1399                       "merging container with incompatible allocator");
1400        return __table_.__node_handle_merge_unique(__source.__table_);
1401    }
1402    template <class _H2, class _P2>
1403    _LIBCPP_INLINE_VISIBILITY
1404    void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
1405    {
1406        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1407                       "merging container with incompatible allocator");
1408        return __table_.__node_handle_merge_unique(__source.__table_);
1409    }
1410    template <class _H2, class _P2>
1411    _LIBCPP_INLINE_VISIBILITY
1412    void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
1413    {
1414        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1415                       "merging container with incompatible allocator");
1416        return __table_.__node_handle_merge_unique(__source.__table_);
1417    }
1418    template <class _H2, class _P2>
1419    _LIBCPP_INLINE_VISIBILITY
1420    void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
1421    {
1422        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1423                       "merging container with incompatible allocator");
1424        return __table_.__node_handle_merge_unique(__source.__table_);
1425    }
1426#endif
1427
1428    _LIBCPP_INLINE_VISIBILITY
1429    void swap(unordered_map& __u)
1430        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
1431        { __table_.swap(__u.__table_);}
1432
1433    _LIBCPP_INLINE_VISIBILITY
1434    hasher hash_function() const
1435        {return __table_.hash_function().hash_function();}
1436    _LIBCPP_INLINE_VISIBILITY
1437    key_equal key_eq() const
1438        {return __table_.key_eq().key_eq();}
1439
1440    _LIBCPP_INLINE_VISIBILITY
1441    iterator       find(const key_type& __k)       {return __table_.find(__k);}
1442    _LIBCPP_INLINE_VISIBILITY
1443    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
1444#if _LIBCPP_STD_VER > 17
1445    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1446    _LIBCPP_INLINE_VISIBILITY
1447    iterator       find(const _K2& __k)            {return __table_.find(__k);}
1448    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1449    _LIBCPP_INLINE_VISIBILITY
1450    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
1451#endif // _LIBCPP_STD_VER > 17
1452
1453    _LIBCPP_INLINE_VISIBILITY
1454    size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
1455#if _LIBCPP_STD_VER > 17
1456    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1457    _LIBCPP_INLINE_VISIBILITY
1458    size_type count(const _K2& __k) const      {return __table_.__count_unique(__k);}
1459#endif // _LIBCPP_STD_VER > 17
1460
1461#if _LIBCPP_STD_VER > 17
1462    _LIBCPP_INLINE_VISIBILITY
1463    bool contains(const key_type& __k) const {return find(__k) != end();}
1464
1465    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1466    _LIBCPP_INLINE_VISIBILITY
1467    bool contains(const _K2& __k) const      {return find(__k) != end();}
1468#endif // _LIBCPP_STD_VER > 17
1469
1470    _LIBCPP_INLINE_VISIBILITY
1471    pair<iterator, iterator>             equal_range(const key_type& __k)
1472        {return __table_.__equal_range_unique(__k);}
1473    _LIBCPP_INLINE_VISIBILITY
1474    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
1475        {return __table_.__equal_range_unique(__k);}
1476#if _LIBCPP_STD_VER > 17
1477    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1478    _LIBCPP_INLINE_VISIBILITY
1479    pair<iterator, iterator>             equal_range(const _K2& __k)
1480        {return __table_.__equal_range_unique(__k);}
1481    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
1482    _LIBCPP_INLINE_VISIBILITY
1483    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
1484        {return __table_.__equal_range_unique(__k);}
1485#endif // _LIBCPP_STD_VER > 17
1486
1487    mapped_type& operator[](const key_type& __k);
1488#ifndef _LIBCPP_CXX03_LANG
1489    mapped_type& operator[](key_type&& __k);
1490#endif
1491
1492    mapped_type&       at(const key_type& __k);
1493    const mapped_type& at(const key_type& __k) const;
1494
1495    _LIBCPP_INLINE_VISIBILITY
1496    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
1497    _LIBCPP_INLINE_VISIBILITY
1498    size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
1499
1500    _LIBCPP_INLINE_VISIBILITY
1501    size_type bucket_size(size_type __n) const
1502        {return __table_.bucket_size(__n);}
1503    _LIBCPP_INLINE_VISIBILITY
1504    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
1505
1506    _LIBCPP_INLINE_VISIBILITY
1507    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
1508    _LIBCPP_INLINE_VISIBILITY
1509    local_iterator       end(size_type __n)          {return __table_.end(__n);}
1510    _LIBCPP_INLINE_VISIBILITY
1511    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
1512    _LIBCPP_INLINE_VISIBILITY
1513    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
1514    _LIBCPP_INLINE_VISIBILITY
1515    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
1516    _LIBCPP_INLINE_VISIBILITY
1517    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
1518
1519    _LIBCPP_INLINE_VISIBILITY
1520    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
1521    _LIBCPP_INLINE_VISIBILITY
1522    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
1523    _LIBCPP_INLINE_VISIBILITY
1524    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
1525    _LIBCPP_INLINE_VISIBILITY
1526    void rehash(size_type __n) {__table_.rehash(__n);}
1527    _LIBCPP_INLINE_VISIBILITY
1528    void reserve(size_type __n) {__table_.reserve(__n);}
1529
1530#if _LIBCPP_DEBUG_LEVEL == 2
1531
1532    bool __dereferenceable(const const_iterator* __i) const
1533        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
1534    bool __decrementable(const const_iterator* __i) const
1535        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
1536    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
1537        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
1538    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1539        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
1540
1541#endif // _LIBCPP_DEBUG_LEVEL == 2
1542
1543private:
1544
1545#ifdef _LIBCPP_CXX03_LANG
1546    __node_holder __construct_node_with_key(const key_type& __k);
1547#endif
1548};
1549
1550#if _LIBCPP_STD_VER >= 17
1551template<class _InputIterator,
1552         class _Hash = hash<__iter_key_type<_InputIterator>>,
1553         class _Pred = equal_to<__iter_key_type<_InputIterator>>,
1554         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1555         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1556         class = enable_if_t<!__is_allocator<_Hash>::value>,
1557         class = enable_if_t<!is_integral<_Hash>::value>,
1558         class = enable_if_t<!__is_allocator<_Pred>::value>,
1559         class = enable_if_t<__is_allocator<_Allocator>::value>>
1560unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
1561              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1562  -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
1563
1564template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
1565         class _Pred = equal_to<remove_const_t<_Key>>,
1566         class _Allocator = allocator<pair<const _Key, _Tp>>,
1567         class = enable_if_t<!__is_allocator<_Hash>::value>,
1568         class = enable_if_t<!is_integral<_Hash>::value>,
1569         class = enable_if_t<!__is_allocator<_Pred>::value>,
1570         class = enable_if_t<__is_allocator<_Allocator>::value>>
1571unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
1572              _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
1573  -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
1574
1575template<class _InputIterator, class _Allocator,
1576         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1577         class = enable_if_t<__is_allocator<_Allocator>::value>>
1578unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
1579  -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1580                   hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1581
1582template<class _InputIterator, class _Allocator,
1583         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1584         class = enable_if_t<__is_allocator<_Allocator>::value>>
1585unordered_map(_InputIterator, _InputIterator, _Allocator)
1586  -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1587                   hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1588
1589template<class _InputIterator, class _Hash, class _Allocator,
1590         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1591         class = enable_if_t<!__is_allocator<_Hash>::value>,
1592         class = enable_if_t<!is_integral<_Hash>::value>,
1593         class = enable_if_t<__is_allocator<_Allocator>::value>>
1594unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1595  -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
1596                   _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
1597
1598template<class _Key, class _Tp, class _Allocator,
1599         class = enable_if_t<__is_allocator<_Allocator>::value>>
1600unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
1601  -> unordered_map<remove_const_t<_Key>, _Tp,
1602                   hash<remove_const_t<_Key>>,
1603                   equal_to<remove_const_t<_Key>>, _Allocator>;
1604
1605template<class _Key, class _Tp, class _Allocator,
1606         class = enable_if_t<__is_allocator<_Allocator>::value>>
1607unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1608  -> unordered_map<remove_const_t<_Key>, _Tp,
1609                   hash<remove_const_t<_Key>>,
1610                   equal_to<remove_const_t<_Key>>, _Allocator>;
1611
1612template<class _Key, class _Tp, class _Hash, class _Allocator,
1613         class = enable_if_t<!__is_allocator<_Hash>::value>,
1614         class = enable_if_t<!is_integral<_Hash>::value>,
1615         class = enable_if_t<__is_allocator<_Allocator>::value>>
1616unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
1617  -> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
1618                   equal_to<remove_const_t<_Key>>, _Allocator>;
1619#endif
1620
1621template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1622unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1623        size_type __n, const hasher& __hf, const key_equal& __eql)
1624    : __table_(__hf, __eql)
1625{
1626    _VSTD::__debug_db_insert_c(this);
1627    __table_.rehash(__n);
1628}
1629
1630template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1631unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1632        size_type __n, const hasher& __hf, const key_equal& __eql,
1633        const allocator_type& __a)
1634    : __table_(__hf, __eql, typename __table::allocator_type(__a))
1635{
1636    _VSTD::__debug_db_insert_c(this);
1637    __table_.rehash(__n);
1638}
1639
1640template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1641inline
1642unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1643        const allocator_type& __a)
1644    : __table_(typename __table::allocator_type(__a))
1645{
1646    _VSTD::__debug_db_insert_c(this);
1647}
1648
1649template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1650template <class _InputIterator>
1651unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1652        _InputIterator __first, _InputIterator __last)
1653{
1654    _VSTD::__debug_db_insert_c(this);
1655    insert(__first, __last);
1656}
1657
1658template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1659template <class _InputIterator>
1660unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1661        _InputIterator __first, _InputIterator __last, size_type __n,
1662        const hasher& __hf, const key_equal& __eql)
1663    : __table_(__hf, __eql)
1664{
1665    _VSTD::__debug_db_insert_c(this);
1666    __table_.rehash(__n);
1667    insert(__first, __last);
1668}
1669
1670template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1671template <class _InputIterator>
1672unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1673        _InputIterator __first, _InputIterator __last, size_type __n,
1674        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
1675    : __table_(__hf, __eql, typename __table::allocator_type(__a))
1676{
1677    _VSTD::__debug_db_insert_c(this);
1678    __table_.rehash(__n);
1679    insert(__first, __last);
1680}
1681
1682template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1683unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1684        const unordered_map& __u)
1685    : __table_(__u.__table_)
1686{
1687    _VSTD::__debug_db_insert_c(this);
1688    __table_.rehash(__u.bucket_count());
1689    insert(__u.begin(), __u.end());
1690}
1691
1692template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1693unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1694        const unordered_map& __u, const allocator_type& __a)
1695    : __table_(__u.__table_, typename __table::allocator_type(__a))
1696{
1697    _VSTD::__debug_db_insert_c(this);
1698    __table_.rehash(__u.bucket_count());
1699    insert(__u.begin(), __u.end());
1700}
1701
1702#ifndef _LIBCPP_CXX03_LANG
1703
1704template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1705inline
1706unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1707        unordered_map&& __u)
1708    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
1709    : __table_(_VSTD::move(__u.__table_))
1710{
1711    _VSTD::__debug_db_insert_c(this);
1712#if _LIBCPP_DEBUG_LEVEL == 2
1713    __get_db()->swap(this, &__u);
1714#endif
1715}
1716
1717template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1718unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1719        unordered_map&& __u, const allocator_type& __a)
1720    : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
1721{
1722    _VSTD::__debug_db_insert_c(this);
1723    if (__a != __u.get_allocator())
1724    {
1725        iterator __i = __u.begin();
1726        while (__u.size() != 0) {
1727            __table_.__emplace_unique(
1728                __u.__table_.remove((__i++).__i_)->__value_.__move());
1729        }
1730    }
1731#if _LIBCPP_DEBUG_LEVEL == 2
1732    else
1733        __get_db()->swap(this, &__u);
1734#endif
1735}
1736
1737template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1738unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1739        initializer_list<value_type> __il)
1740{
1741    _VSTD::__debug_db_insert_c(this);
1742    insert(__il.begin(), __il.end());
1743}
1744
1745template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1746unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1747        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1748        const key_equal& __eql)
1749    : __table_(__hf, __eql)
1750{
1751    _VSTD::__debug_db_insert_c(this);
1752    __table_.rehash(__n);
1753    insert(__il.begin(), __il.end());
1754}
1755
1756template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1757unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
1758        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
1759        const key_equal& __eql, const allocator_type& __a)
1760    : __table_(__hf, __eql, typename __table::allocator_type(__a))
1761{
1762    _VSTD::__debug_db_insert_c(this);
1763    __table_.rehash(__n);
1764    insert(__il.begin(), __il.end());
1765}
1766
1767template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1768inline
1769unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1770unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
1771    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
1772{
1773    __table_ = _VSTD::move(__u.__table_);
1774    return *this;
1775}
1776
1777template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1778inline
1779unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
1780unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
1781        initializer_list<value_type> __il)
1782{
1783    __table_.__assign_unique(__il.begin(), __il.end());
1784    return *this;
1785}
1786
1787#endif // _LIBCPP_CXX03_LANG
1788
1789template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1790template <class _InputIterator>
1791inline
1792void
1793unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
1794                                                       _InputIterator __last)
1795{
1796    for (; __first != __last; ++__first)
1797        __table_.__insert_unique(*__first);
1798}
1799
1800#ifndef _LIBCPP_CXX03_LANG
1801
1802template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1803_Tp&
1804unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1805{
1806    return __table_.__emplace_unique_key_args(__k,
1807        piecewise_construct, _VSTD::forward_as_tuple(__k),
1808                             _VSTD::forward_as_tuple()).first->__get_value().second;
1809}
1810
1811template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1812_Tp&
1813unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
1814{
1815    return __table_.__emplace_unique_key_args(__k,
1816        piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)),
1817                             _VSTD::forward_as_tuple()).first->__get_value().second;
1818}
1819#else // _LIBCPP_CXX03_LANG
1820
1821template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1822typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
1823unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
1824{
1825    __node_allocator& __na = __table_.__node_alloc();
1826    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1827    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
1828    __h.get_deleter().__first_constructed = true;
1829    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
1830    __h.get_deleter().__second_constructed = true;
1831    return __h;
1832}
1833
1834template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1835_Tp&
1836unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
1837{
1838    iterator __i = find(__k);
1839    if (__i != end())
1840        return __i->second;
1841    __node_holder __h = __construct_node_with_key(__k);
1842    pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
1843    __h.release();
1844    return __r.first->second;
1845}
1846
1847#endif // _LIBCPP_CXX03_LANG
1848
1849template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1850_Tp&
1851unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
1852{
1853    iterator __i = find(__k);
1854    if (__i == end())
1855        __throw_out_of_range("unordered_map::at: key not found");
1856    return __i->second;
1857}
1858
1859template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1860const _Tp&
1861unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
1862{
1863    const_iterator __i = find(__k);
1864    if (__i == end())
1865        __throw_out_of_range("unordered_map::at: key not found");
1866    return __i->second;
1867}
1868
1869template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1870inline _LIBCPP_INLINE_VISIBILITY
1871void
1872swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1873     unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1874    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1875{
1876    __x.swap(__y);
1877}
1878
1879#if _LIBCPP_STD_VER > 17
1880template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
1881          class _Predicate>
1882inline _LIBCPP_INLINE_VISIBILITY
1883    typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
1884    erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
1885             _Predicate __pred) {
1886  return _VSTD::__libcpp_erase_if_container(__c, __pred);
1887}
1888#endif
1889
1890template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1891bool
1892operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1893           const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1894{
1895    if (__x.size() != __y.size())
1896        return false;
1897    typedef typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
1898                                                                 const_iterator;
1899    for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
1900            __i != __ex; ++__i)
1901    {
1902        const_iterator __j = __y.find(__i->first);
1903        if (__j == __ey || !(*__i == *__j))
1904            return false;
1905    }
1906    return true;
1907}
1908
1909template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
1910inline _LIBCPP_INLINE_VISIBILITY
1911bool
1912operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
1913           const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
1914{
1915    return !(__x == __y);
1916}
1917
1918template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
1919          class _Alloc = allocator<pair<const _Key, _Tp> > >
1920class _LIBCPP_TEMPLATE_VIS unordered_multimap
1921{
1922public:
1923    // types
1924    typedef _Key                                           key_type;
1925    typedef _Tp                                            mapped_type;
1926    typedef __identity_t<_Hash>                            hasher;
1927    typedef __identity_t<_Pred>                            key_equal;
1928    typedef __identity_t<_Alloc>                           allocator_type;
1929    typedef pair<const key_type, mapped_type>              value_type;
1930    typedef value_type&                                    reference;
1931    typedef const value_type&                              const_reference;
1932    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
1933                  "Invalid allocator::value_type");
1934
1935private:
1936    typedef __hash_value_type<key_type, mapped_type>                          __value_type;
1937    typedef __unordered_map_hasher<key_type, __value_type, hasher, key_equal> __hasher;
1938    typedef __unordered_map_equal<key_type, __value_type, key_equal, hasher>  __key_equal;
1939    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
1940                                                 __value_type>::type          __allocator_type;
1941
1942    typedef __hash_table<__value_type, __hasher,
1943                         __key_equal,  __allocator_type>   __table;
1944
1945    __table __table_;
1946
1947    typedef typename __table::_NodeTypes                   _NodeTypes;
1948    typedef typename __table::__node_traits                __node_traits;
1949    typedef typename __table::__node_allocator             __node_allocator;
1950    typedef typename __table::__node                       __node;
1951    typedef __hash_map_node_destructor<__node_allocator>   _Dp;
1952    typedef unique_ptr<__node, _Dp>                         __node_holder;
1953    typedef allocator_traits<allocator_type>               __alloc_traits;
1954    static_assert((is_same<typename __node_traits::size_type,
1955                          typename __alloc_traits::size_type>::value),
1956                 "Allocator uses different size_type for different types");
1957public:
1958    typedef typename __alloc_traits::pointer         pointer;
1959    typedef typename __alloc_traits::const_pointer   const_pointer;
1960    typedef typename __table::size_type              size_type;
1961    typedef typename __table::difference_type        difference_type;
1962
1963    typedef __hash_map_iterator<typename __table::iterator>       iterator;
1964    typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
1965    typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
1966    typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
1967
1968#if _LIBCPP_STD_VER > 14
1969    typedef __map_node_handle<__node, allocator_type> node_type;
1970#endif
1971
1972    template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1973        friend class _LIBCPP_TEMPLATE_VIS unordered_map;
1974    template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
1975        friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
1976
1977    _LIBCPP_INLINE_VISIBILITY
1978    unordered_multimap()
1979        _NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
1980    {
1981        _VSTD::__debug_db_insert_c(this);
1982    }
1983    explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
1984                                const key_equal& __eql = key_equal());
1985    unordered_multimap(size_type __n, const hasher& __hf,
1986                                const key_equal& __eql,
1987                                const allocator_type& __a);
1988    template <class _InputIterator>
1989        unordered_multimap(_InputIterator __first, _InputIterator __last);
1990    template <class _InputIterator>
1991        unordered_multimap(_InputIterator __first, _InputIterator __last,
1992                      size_type __n, const hasher& __hf = hasher(),
1993                      const key_equal& __eql = key_equal());
1994    template <class _InputIterator>
1995        unordered_multimap(_InputIterator __first, _InputIterator __last,
1996                      size_type __n, const hasher& __hf,
1997                      const key_equal& __eql,
1998                      const allocator_type& __a);
1999    _LIBCPP_INLINE_VISIBILITY
2000    explicit unordered_multimap(const allocator_type& __a);
2001    unordered_multimap(const unordered_multimap& __u);
2002    unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
2003#ifndef _LIBCPP_CXX03_LANG
2004    _LIBCPP_INLINE_VISIBILITY
2005    unordered_multimap(unordered_multimap&& __u)
2006        _NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
2007    unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
2008    unordered_multimap(initializer_list<value_type> __il);
2009    unordered_multimap(initializer_list<value_type> __il, size_type __n,
2010                       const hasher& __hf = hasher(),
2011                       const key_equal& __eql = key_equal());
2012    unordered_multimap(initializer_list<value_type> __il, size_type __n,
2013                       const hasher& __hf, const key_equal& __eql,
2014                       const allocator_type& __a);
2015#endif // _LIBCPP_CXX03_LANG
2016#if _LIBCPP_STD_VER > 11
2017    _LIBCPP_INLINE_VISIBILITY
2018    unordered_multimap(size_type __n, const allocator_type& __a)
2019      : unordered_multimap(__n, hasher(), key_equal(), __a) {}
2020    _LIBCPP_INLINE_VISIBILITY
2021    unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
2022      : unordered_multimap(__n, __hf, key_equal(), __a) {}
2023    template <class _InputIterator>
2024    _LIBCPP_INLINE_VISIBILITY
2025      unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
2026      : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
2027    template <class _InputIterator>
2028    _LIBCPP_INLINE_VISIBILITY
2029      unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
2030        const allocator_type& __a)
2031      : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
2032    _LIBCPP_INLINE_VISIBILITY
2033    unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
2034      : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
2035    _LIBCPP_INLINE_VISIBILITY
2036    unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2037      const allocator_type& __a)
2038      : unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
2039#endif
2040    _LIBCPP_INLINE_VISIBILITY
2041    ~unordered_multimap() {
2042        static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
2043    }
2044
2045    _LIBCPP_INLINE_VISIBILITY
2046    unordered_multimap& operator=(const unordered_multimap& __u)
2047    {
2048#ifndef _LIBCPP_CXX03_LANG
2049        __table_ = __u.__table_;
2050#else
2051        if (this != _VSTD::addressof(__u)) {
2052            __table_.clear();
2053            __table_.hash_function() = __u.__table_.hash_function();
2054            __table_.key_eq() = __u.__table_.key_eq();
2055            __table_.max_load_factor() = __u.__table_.max_load_factor();
2056            __table_.__copy_assign_alloc(__u.__table_);
2057            insert(__u.begin(), __u.end());
2058        }
2059#endif
2060        return *this;
2061    }
2062#ifndef _LIBCPP_CXX03_LANG
2063    _LIBCPP_INLINE_VISIBILITY
2064    unordered_multimap& operator=(unordered_multimap&& __u)
2065        _NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
2066    _LIBCPP_INLINE_VISIBILITY
2067    unordered_multimap& operator=(initializer_list<value_type> __il);
2068#endif // _LIBCPP_CXX03_LANG
2069
2070    _LIBCPP_INLINE_VISIBILITY
2071    allocator_type get_allocator() const _NOEXCEPT
2072        {return allocator_type(__table_.__node_alloc());}
2073
2074    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2075    bool      empty() const _NOEXCEPT {return __table_.size() == 0;}
2076    _LIBCPP_INLINE_VISIBILITY
2077    size_type size() const _NOEXCEPT  {return __table_.size();}
2078    _LIBCPP_INLINE_VISIBILITY
2079    size_type max_size() const _NOEXCEPT {return __table_.max_size();}
2080
2081    _LIBCPP_INLINE_VISIBILITY
2082    iterator       begin() _NOEXCEPT        {return __table_.begin();}
2083    _LIBCPP_INLINE_VISIBILITY
2084    iterator       end() _NOEXCEPT          {return __table_.end();}
2085    _LIBCPP_INLINE_VISIBILITY
2086    const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
2087    _LIBCPP_INLINE_VISIBILITY
2088    const_iterator end()    const _NOEXCEPT {return __table_.end();}
2089    _LIBCPP_INLINE_VISIBILITY
2090    const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
2091    _LIBCPP_INLINE_VISIBILITY
2092    const_iterator cend()   const _NOEXCEPT {return __table_.end();}
2093
2094    _LIBCPP_INLINE_VISIBILITY
2095    iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
2096
2097    _LIBCPP_INLINE_VISIBILITY
2098    iterator insert(const_iterator __p, const value_type& __x)
2099        {return __table_.__insert_multi(__p.__i_, __x);}
2100
2101    template <class _InputIterator>
2102    _LIBCPP_INLINE_VISIBILITY
2103    void insert(_InputIterator __first, _InputIterator __last);
2104
2105#ifndef _LIBCPP_CXX03_LANG
2106    _LIBCPP_INLINE_VISIBILITY
2107    void insert(initializer_list<value_type> __il)
2108        {insert(__il.begin(), __il.end());}
2109    _LIBCPP_INLINE_VISIBILITY
2110    iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
2111
2112    _LIBCPP_INLINE_VISIBILITY
2113    iterator insert(const_iterator __p, value_type&& __x)
2114        {return __table_.__insert_multi(__p.__i_, _VSTD::move(__x));}
2115
2116    template <class _Pp,
2117              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2118    _LIBCPP_INLINE_VISIBILITY
2119    iterator insert(_Pp&& __x)
2120        {return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
2121
2122    template <class _Pp,
2123              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
2124    _LIBCPP_INLINE_VISIBILITY
2125    iterator insert(const_iterator __p, _Pp&& __x)
2126        {return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
2127
2128    template <class... _Args>
2129    iterator emplace(_Args&&... __args) {
2130        return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
2131    }
2132
2133    template <class... _Args>
2134    iterator emplace_hint(const_iterator __p, _Args&&... __args) {
2135        return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
2136    }
2137#endif // _LIBCPP_CXX03_LANG
2138
2139
2140    _LIBCPP_INLINE_VISIBILITY
2141    iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
2142    _LIBCPP_INLINE_VISIBILITY
2143    iterator erase(iterator __p)       {return __table_.erase(__p.__i_);}
2144    _LIBCPP_INLINE_VISIBILITY
2145    size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
2146    _LIBCPP_INLINE_VISIBILITY
2147    iterator erase(const_iterator __first, const_iterator __last)
2148        {return __table_.erase(__first.__i_, __last.__i_);}
2149    _LIBCPP_INLINE_VISIBILITY
2150    void clear() _NOEXCEPT {__table_.clear();}
2151
2152#if _LIBCPP_STD_VER > 14
2153    _LIBCPP_INLINE_VISIBILITY
2154    iterator insert(node_type&& __nh)
2155    {
2156        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
2157            "node_type with incompatible allocator passed to unordered_multimap::insert()");
2158        return __table_.template __node_handle_insert_multi<node_type>(
2159            _VSTD::move(__nh));
2160    }
2161    _LIBCPP_INLINE_VISIBILITY
2162    iterator insert(const_iterator __hint, node_type&& __nh)
2163    {
2164        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
2165            "node_type with incompatible allocator passed to unordered_multimap::insert()");
2166        return __table_.template __node_handle_insert_multi<node_type>(
2167            __hint.__i_, _VSTD::move(__nh));
2168    }
2169    _LIBCPP_INLINE_VISIBILITY
2170    node_type extract(key_type const& __key)
2171    {
2172        return __table_.template __node_handle_extract<node_type>(__key);
2173    }
2174    _LIBCPP_INLINE_VISIBILITY
2175    node_type extract(const_iterator __it)
2176    {
2177        return __table_.template __node_handle_extract<node_type>(
2178            __it.__i_);
2179    }
2180
2181    template <class _H2, class _P2>
2182    _LIBCPP_INLINE_VISIBILITY
2183    void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
2184    {
2185        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2186                       "merging container with incompatible allocator");
2187        return __table_.__node_handle_merge_multi(__source.__table_);
2188    }
2189    template <class _H2, class _P2>
2190    _LIBCPP_INLINE_VISIBILITY
2191    void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
2192    {
2193        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2194                       "merging container with incompatible allocator");
2195        return __table_.__node_handle_merge_multi(__source.__table_);
2196    }
2197    template <class _H2, class _P2>
2198    _LIBCPP_INLINE_VISIBILITY
2199    void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
2200    {
2201        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2202                       "merging container with incompatible allocator");
2203        return __table_.__node_handle_merge_multi(__source.__table_);
2204    }
2205    template <class _H2, class _P2>
2206    _LIBCPP_INLINE_VISIBILITY
2207    void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
2208    {
2209        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
2210                       "merging container with incompatible allocator");
2211        return __table_.__node_handle_merge_multi(__source.__table_);
2212    }
2213#endif
2214
2215    _LIBCPP_INLINE_VISIBILITY
2216    void swap(unordered_multimap& __u)
2217        _NOEXCEPT_(__is_nothrow_swappable<__table>::value)
2218        {__table_.swap(__u.__table_);}
2219
2220    _LIBCPP_INLINE_VISIBILITY
2221    hasher hash_function() const
2222        {return __table_.hash_function().hash_function();}
2223    _LIBCPP_INLINE_VISIBILITY
2224    key_equal key_eq() const
2225        {return __table_.key_eq().key_eq();}
2226
2227    _LIBCPP_INLINE_VISIBILITY
2228    iterator       find(const key_type& __k)       {return __table_.find(__k);}
2229    _LIBCPP_INLINE_VISIBILITY
2230    const_iterator find(const key_type& __k) const {return __table_.find(__k);}
2231#if _LIBCPP_STD_VER > 17
2232    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2233    _LIBCPP_INLINE_VISIBILITY
2234    iterator       find(const _K2& __k)            {return __table_.find(__k);}
2235    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2236    _LIBCPP_INLINE_VISIBILITY
2237    const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
2238#endif // _LIBCPP_STD_VER > 17
2239
2240    _LIBCPP_INLINE_VISIBILITY
2241    size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
2242#if _LIBCPP_STD_VER > 17
2243    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2244    _LIBCPP_INLINE_VISIBILITY
2245    size_type count(const _K2& __k) const      {return __table_.__count_multi(__k);}
2246#endif // _LIBCPP_STD_VER > 17
2247
2248#if _LIBCPP_STD_VER > 17
2249    _LIBCPP_INLINE_VISIBILITY
2250    bool contains(const key_type& __k) const {return find(__k) != end();}
2251
2252    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2253    _LIBCPP_INLINE_VISIBILITY
2254    bool contains(const _K2& __k) const      {return find(__k) != end();}
2255#endif // _LIBCPP_STD_VER > 17
2256
2257    _LIBCPP_INLINE_VISIBILITY
2258    pair<iterator, iterator>             equal_range(const key_type& __k)
2259        {return __table_.__equal_range_multi(__k);}
2260    _LIBCPP_INLINE_VISIBILITY
2261    pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
2262        {return __table_.__equal_range_multi(__k);}
2263#if _LIBCPP_STD_VER > 17
2264    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2265    _LIBCPP_INLINE_VISIBILITY
2266    pair<iterator, iterator>             equal_range(const _K2& __k)
2267        {return __table_.__equal_range_multi(__k);}
2268    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
2269    _LIBCPP_INLINE_VISIBILITY
2270    pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
2271        {return __table_.__equal_range_multi(__k);}
2272#endif // _LIBCPP_STD_VER > 17
2273
2274    _LIBCPP_INLINE_VISIBILITY
2275    size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
2276    _LIBCPP_INLINE_VISIBILITY
2277    size_type max_bucket_count() const _NOEXCEPT
2278        {return __table_.max_bucket_count();}
2279
2280    _LIBCPP_INLINE_VISIBILITY
2281    size_type bucket_size(size_type __n) const
2282        {return __table_.bucket_size(__n);}
2283    _LIBCPP_INLINE_VISIBILITY
2284    size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
2285
2286    _LIBCPP_INLINE_VISIBILITY
2287    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
2288    _LIBCPP_INLINE_VISIBILITY
2289    local_iterator       end(size_type __n)          {return __table_.end(__n);}
2290    _LIBCPP_INLINE_VISIBILITY
2291    const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
2292    _LIBCPP_INLINE_VISIBILITY
2293    const_local_iterator end(size_type __n) const    {return __table_.cend(__n);}
2294    _LIBCPP_INLINE_VISIBILITY
2295    const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
2296    _LIBCPP_INLINE_VISIBILITY
2297    const_local_iterator cend(size_type __n) const   {return __table_.cend(__n);}
2298
2299    _LIBCPP_INLINE_VISIBILITY
2300    float load_factor() const _NOEXCEPT {return __table_.load_factor();}
2301    _LIBCPP_INLINE_VISIBILITY
2302    float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
2303    _LIBCPP_INLINE_VISIBILITY
2304    void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
2305    _LIBCPP_INLINE_VISIBILITY
2306    void rehash(size_type __n) {__table_.rehash(__n);}
2307    _LIBCPP_INLINE_VISIBILITY
2308    void reserve(size_type __n) {__table_.reserve(__n);}
2309
2310#if _LIBCPP_DEBUG_LEVEL == 2
2311
2312    bool __dereferenceable(const const_iterator* __i) const
2313        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
2314    bool __decrementable(const const_iterator* __i) const
2315        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
2316    bool __addable(const const_iterator* __i, ptrdiff_t __n) const
2317        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
2318    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2319        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
2320
2321#endif // _LIBCPP_DEBUG_LEVEL == 2
2322
2323
2324};
2325
2326#if _LIBCPP_STD_VER >= 17
2327template<class _InputIterator,
2328         class _Hash = hash<__iter_key_type<_InputIterator>>,
2329         class _Pred = equal_to<__iter_key_type<_InputIterator>>,
2330         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2331         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2332         class = enable_if_t<!__is_allocator<_Hash>::value>,
2333         class = enable_if_t<!is_integral<_Hash>::value>,
2334         class = enable_if_t<!__is_allocator<_Pred>::value>,
2335         class = enable_if_t<__is_allocator<_Allocator>::value>>
2336unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
2337                   _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
2338  -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
2339
2340template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
2341         class _Pred = equal_to<remove_const_t<_Key>>,
2342         class _Allocator = allocator<pair<const _Key, _Tp>>,
2343         class = enable_if_t<!__is_allocator<_Hash>::value>,
2344         class = enable_if_t<!is_integral<_Hash>::value>,
2345         class = enable_if_t<!__is_allocator<_Pred>::value>,
2346         class = enable_if_t<__is_allocator<_Allocator>::value>>
2347unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
2348                   _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
2349  -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
2350
2351template<class _InputIterator, class _Allocator,
2352         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2353         class = enable_if_t<__is_allocator<_Allocator>::value>>
2354unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
2355  -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2356                        hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2357
2358template<class _InputIterator, class _Allocator,
2359         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2360         class = enable_if_t<__is_allocator<_Allocator>::value>>
2361unordered_multimap(_InputIterator, _InputIterator, _Allocator)
2362  -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2363                        hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2364
2365template<class _InputIterator, class _Hash, class _Allocator,
2366         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
2367         class = enable_if_t<!__is_allocator<_Hash>::value>,
2368         class = enable_if_t<!is_integral<_Hash>::value>,
2369         class = enable_if_t<__is_allocator<_Allocator>::value>>
2370unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
2371  -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
2372                        _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
2373
2374template<class _Key, class _Tp, class _Allocator,
2375         class = enable_if_t<__is_allocator<_Allocator>::value>>
2376unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
2377  -> unordered_multimap<remove_const_t<_Key>, _Tp,
2378                        hash<remove_const_t<_Key>>,
2379                        equal_to<remove_const_t<_Key>>, _Allocator>;
2380
2381template<class _Key, class _Tp, class _Allocator,
2382         class = enable_if_t<__is_allocator<_Allocator>::value>>
2383unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2384  -> unordered_multimap<remove_const_t<_Key>, _Tp,
2385                        hash<remove_const_t<_Key>>,
2386                        equal_to<remove_const_t<_Key>>, _Allocator>;
2387
2388template<class _Key, class _Tp, class _Hash, class _Allocator,
2389         class = enable_if_t<!__is_allocator<_Hash>::value>,
2390         class = enable_if_t<!is_integral<_Hash>::value>,
2391         class = enable_if_t<__is_allocator<_Allocator>::value>>
2392unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
2393  -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
2394                        equal_to<remove_const_t<_Key>>, _Allocator>;
2395#endif
2396
2397template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2398unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2399        size_type __n, const hasher& __hf, const key_equal& __eql)
2400    : __table_(__hf, __eql)
2401{
2402    _VSTD::__debug_db_insert_c(this);
2403    __table_.rehash(__n);
2404}
2405
2406template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2407unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2408        size_type __n, const hasher& __hf, const key_equal& __eql,
2409        const allocator_type& __a)
2410    : __table_(__hf, __eql, typename __table::allocator_type(__a))
2411{
2412    _VSTD::__debug_db_insert_c(this);
2413    __table_.rehash(__n);
2414}
2415
2416template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2417template <class _InputIterator>
2418unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2419        _InputIterator __first, _InputIterator __last)
2420{
2421    _VSTD::__debug_db_insert_c(this);
2422    insert(__first, __last);
2423}
2424
2425template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2426template <class _InputIterator>
2427unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2428        _InputIterator __first, _InputIterator __last, size_type __n,
2429        const hasher& __hf, const key_equal& __eql)
2430    : __table_(__hf, __eql)
2431{
2432    _VSTD::__debug_db_insert_c(this);
2433    __table_.rehash(__n);
2434    insert(__first, __last);
2435}
2436
2437template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2438template <class _InputIterator>
2439unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2440        _InputIterator __first, _InputIterator __last, size_type __n,
2441        const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
2442    : __table_(__hf, __eql, typename __table::allocator_type(__a))
2443{
2444    _VSTD::__debug_db_insert_c(this);
2445    __table_.rehash(__n);
2446    insert(__first, __last);
2447}
2448
2449template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2450inline
2451unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2452        const allocator_type& __a)
2453    : __table_(typename __table::allocator_type(__a))
2454{
2455    _VSTD::__debug_db_insert_c(this);
2456}
2457
2458template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2459unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2460        const unordered_multimap& __u)
2461    : __table_(__u.__table_)
2462{
2463    _VSTD::__debug_db_insert_c(this);
2464    __table_.rehash(__u.bucket_count());
2465    insert(__u.begin(), __u.end());
2466}
2467
2468template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2469unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2470        const unordered_multimap& __u, const allocator_type& __a)
2471    : __table_(__u.__table_, typename __table::allocator_type(__a))
2472{
2473    _VSTD::__debug_db_insert_c(this);
2474    __table_.rehash(__u.bucket_count());
2475    insert(__u.begin(), __u.end());
2476}
2477
2478#ifndef _LIBCPP_CXX03_LANG
2479
2480template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2481inline
2482unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2483        unordered_multimap&& __u)
2484    _NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
2485    : __table_(_VSTD::move(__u.__table_))
2486{
2487    _VSTD::__debug_db_insert_c(this);
2488#if _LIBCPP_DEBUG_LEVEL == 2
2489    __get_db()->swap(this, &__u);
2490#endif
2491}
2492
2493template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2494unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2495        unordered_multimap&& __u, const allocator_type& __a)
2496    : __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__a))
2497{
2498    _VSTD::__debug_db_insert_c(this);
2499    if (__a != __u.get_allocator())
2500    {
2501        iterator __i = __u.begin();
2502        while (__u.size() != 0)
2503        {
2504            __table_.__insert_multi(
2505                __u.__table_.remove((__i++).__i_)->__value_.__move());
2506        }
2507    }
2508#if _LIBCPP_DEBUG_LEVEL == 2
2509    else
2510        __get_db()->swap(this, &__u);
2511#endif
2512}
2513
2514template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2515unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2516        initializer_list<value_type> __il)
2517{
2518    _VSTD::__debug_db_insert_c(this);
2519    insert(__il.begin(), __il.end());
2520}
2521
2522template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2523unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2524        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2525        const key_equal& __eql)
2526    : __table_(__hf, __eql)
2527{
2528    _VSTD::__debug_db_insert_c(this);
2529    __table_.rehash(__n);
2530    insert(__il.begin(), __il.end());
2531}
2532
2533template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2534unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
2535        initializer_list<value_type> __il, size_type __n, const hasher& __hf,
2536        const key_equal& __eql, const allocator_type& __a)
2537    : __table_(__hf, __eql, typename __table::allocator_type(__a))
2538{
2539    _VSTD::__debug_db_insert_c(this);
2540    __table_.rehash(__n);
2541    insert(__il.begin(), __il.end());
2542}
2543
2544template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2545inline
2546unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2547unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
2548    _NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
2549{
2550    __table_ = _VSTD::move(__u.__table_);
2551    return *this;
2552}
2553
2554template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2555inline
2556unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
2557unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
2558        initializer_list<value_type> __il)
2559{
2560    __table_.__assign_multi(__il.begin(), __il.end());
2561    return *this;
2562}
2563
2564#endif // _LIBCPP_CXX03_LANG
2565
2566
2567
2568template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2569template <class _InputIterator>
2570inline
2571void
2572unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
2573                                                            _InputIterator __last)
2574{
2575    for (; __first != __last; ++__first)
2576        __table_.__insert_multi(*__first);
2577}
2578
2579template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2580inline _LIBCPP_INLINE_VISIBILITY
2581void
2582swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2583     unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2584    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2585{
2586    __x.swap(__y);
2587}
2588
2589#if _LIBCPP_STD_VER > 17
2590template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc,
2591          class _Predicate>
2592inline _LIBCPP_INLINE_VISIBILITY
2593    typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type
2594    erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c,
2595             _Predicate __pred) {
2596  return _VSTD::__libcpp_erase_if_container(__c, __pred);
2597}
2598#endif
2599
2600template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2601bool
2602operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2603           const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2604{
2605    if (__x.size() != __y.size())
2606        return false;
2607    typedef typename unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator
2608                                                                 const_iterator;
2609    typedef pair<const_iterator, const_iterator> _EqRng;
2610    for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
2611    {
2612        _EqRng __xeq = __x.equal_range(__i->first);
2613        _EqRng __yeq = __y.equal_range(__i->first);
2614        if (_VSTD::distance(__xeq.first, __xeq.second) !=
2615            _VSTD::distance(__yeq.first, __yeq.second) ||
2616                  !_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
2617            return false;
2618        __i = __xeq.second;
2619    }
2620    return true;
2621}
2622
2623template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
2624inline _LIBCPP_INLINE_VISIBILITY
2625bool
2626operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
2627           const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
2628{
2629    return !(__x == __y);
2630}
2631
2632_LIBCPP_END_NAMESPACE_STD
2633
2634#endif // _LIBCPP_UNORDERED_MAP
2635