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