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