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