2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
20 template <class Key, class T, class Compare = less<Key>,
21 class Allocator = allocator<pair<const Key, T>>>
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;
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
51 value_compare(key_compare c);
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;
59 // construct/copy/destroy:
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 explicit map(const key_compare& comp);
66 map(const key_compare& comp, const allocator_type& a);
67 template <class InputIterator>
68 map(InputIterator first, InputIterator last,
69 const key_compare& comp = key_compare());
70 template <class InputIterator>
71 map(InputIterator first, InputIterator last,
72 const key_compare& comp, const allocator_type& a);
73 template<container-compatible-range<value_type> R>
74 map(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
78 is_nothrow_move_constructible<allocator_type>::value &&
79 is_nothrow_move_constructible<key_compare>::value);
80 explicit map(const allocator_type& a);
81 map(const map& m, const allocator_type& a);
82 map(map&& m, const allocator_type& a);
83 map(initializer_list<value_type> il, const key_compare& comp = key_compare());
84 map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
85 template <class InputIterator>
86 map(InputIterator first, InputIterator last, const allocator_type& a)
87 : map(first, last, Compare(), a) {} // C++14
88 template<container-compatible-range<value_type> R>
89 map(from_range_t, R&& rg, const Allocator& a))
90 : map(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
91 map(initializer_list<value_type> il, const allocator_type& a)
92 : map(il, Compare(), a) {} // C++14
95 map& operator=(const map& m);
96 map& operator=(map&& m)
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 map& operator=(initializer_list<value_type> il);
104 iterator begin() noexcept;
105 const_iterator begin() const noexcept;
106 iterator end() noexcept;
107 const_iterator end() const noexcept;
109 reverse_iterator rbegin() noexcept;
110 const_reverse_iterator rbegin() const noexcept;
111 reverse_iterator rend() noexcept;
112 const_reverse_iterator rend() const noexcept;
114 const_iterator cbegin() const noexcept;
115 const_iterator cend() const noexcept;
116 const_reverse_iterator crbegin() const noexcept;
117 const_reverse_iterator crend() const noexcept;
120 bool empty() const noexcept;
121 size_type size() const noexcept;
122 size_type max_size() const noexcept;
125 mapped_type& operator[](const key_type& k);
126 mapped_type& operator[](key_type&& k);
128 mapped_type& at(const key_type& k);
129 const mapped_type& at(const key_type& k) const;
132 template <class... Args>
133 pair<iterator, bool> emplace(Args&&... args);
134 template <class... Args>
135 iterator emplace_hint(const_iterator position, Args&&... args);
136 pair<iterator, bool> insert(const value_type& v);
137 pair<iterator, bool> insert( value_type&& v); // C++17
139 pair<iterator, bool> insert(P&& p);
140 iterator insert(const_iterator position, const value_type& v);
141 iterator insert(const_iterator position, value_type&& v); // C++17
143 iterator insert(const_iterator position, P&& p);
144 template <class InputIterator>
145 void insert(InputIterator first, InputIterator last);
146 template<container-compatible-range<value_type> R>
147 void insert_range(R&& rg); // C++23
148 void insert(initializer_list<value_type> il);
150 node_type extract(const_iterator position); // C++17
151 node_type extract(const key_type& x); // C++17
152 insert_return_type insert(node_type&& nh); // C++17
153 iterator insert(const_iterator hint, node_type&& nh); // C++17
155 template <class... Args>
156 pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
157 template <class... Args>
158 pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
159 template <class... Args>
160 iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
161 template <class... Args>
162 iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
164 pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
166 pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
168 iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
170 iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
172 iterator erase(const_iterator position);
173 iterator erase(iterator position); // C++14
174 size_type erase(const key_type& k);
175 iterator erase(const_iterator first, const_iterator last);
176 void clear() noexcept;
179 void merge(map<Key, T, C2, Allocator>& source); // C++17
181 void merge(map<Key, T, C2, Allocator>&& source); // C++17
183 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
185 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
188 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
189 is_nothrow_swappable<key_compare>::value); // C++17
192 allocator_type get_allocator() const noexcept;
193 key_compare key_comp() const;
194 value_compare value_comp() const;
197 iterator find(const key_type& k);
198 const_iterator find(const key_type& k) const;
200 iterator find(const K& x); // C++14
202 const_iterator find(const K& x) const; // C++14
205 size_type count(const K& x) const; // C++14
206 size_type count(const key_type& k) const;
208 bool contains(const key_type& x) const; // C++20
209 template<class K> bool contains(const K& x) const; // C++20
211 iterator lower_bound(const key_type& k);
212 const_iterator lower_bound(const key_type& k) const;
214 iterator lower_bound(const K& x); // C++14
216 const_iterator lower_bound(const K& x) const; // C++14
218 iterator upper_bound(const key_type& k);
219 const_iterator upper_bound(const key_type& k) const;
221 iterator upper_bound(const K& x); // C++14
223 const_iterator upper_bound(const K& x) const; // C++14
225 pair<iterator,iterator> equal_range(const key_type& k);
226 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
228 pair<iterator,iterator> equal_range(const K& x); // C++14
230 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
233 template <class InputIterator,
234 class Compare = less<iter_key_t<InputIterator>>,
235 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
236 map(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
237 -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
239 template<ranges::input_range R, class Compare = less<range-key-type<R>,
240 class Allocator = allocator<range-to-alloc-type<R>>>
241 map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
242 -> map<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23
244 template<class Key, class T, class Compare = less<Key>,
245 class Allocator = allocator<pair<const Key, T>>>
246 map(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
247 -> map<Key, T, Compare, Allocator>; // C++17
249 template <class InputIterator, class Allocator>
250 map(InputIterator, InputIterator, Allocator)
251 -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>,
254 template<ranges::input_range R, class Allocator>
255 map(from_range_t, R&&, Allocator)
256 -> map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23
258 template<class Key, class T, class Allocator>
259 map(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17
261 template <class Key, class T, class Compare, class Allocator>
263 operator==(const map<Key, T, Compare, Allocator>& x,
264 const map<Key, T, Compare, Allocator>& y);
266 template <class Key, class T, class Compare, class Allocator>
268 operator< (const map<Key, T, Compare, Allocator>& x,
269 const map<Key, T, Compare, Allocator>& y); // removed in C++20
271 template <class Key, class T, class Compare, class Allocator>
273 operator!=(const map<Key, T, Compare, Allocator>& x,
274 const map<Key, T, Compare, Allocator>& y); // removed in C++20
276 template <class Key, class T, class Compare, class Allocator>
278 operator> (const map<Key, T, Compare, Allocator>& x,
279 const map<Key, T, Compare, Allocator>& y); // removed in C++20
281 template <class Key, class T, class Compare, class Allocator>
283 operator>=(const map<Key, T, Compare, Allocator>& x,
284 const map<Key, T, Compare, Allocator>& y); // removed in C++20
286 template <class Key, class T, class Compare, class Allocator>
288 operator<=(const map<Key, T, Compare, Allocator>& x,
289 const map<Key, T, Compare, Allocator>& y); // removed in C++20
291 template<class Key, class T, class Compare, class Allocator>
292 synth-three-way-result<pair<const Key, T>>
293 operator<=>(const map<Key, T, Compare, Allocator>& x,
294 const map<Key, T, Compare, Allocator>& y); // since C++20
296 // specialized algorithms:
297 template <class Key, class T, class Compare, class Allocator>
299 swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
300 noexcept(noexcept(x.swap(y)));
302 template <class Key, class T, class Compare, class Allocator, class Predicate>
303 typename map<Key, T, Compare, Allocator>::size_type
304 erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
307 template <class Key, class T, class Compare = less<Key>,
308 class Allocator = allocator<pair<const Key, T>>>
313 typedef Key key_type;
314 typedef T mapped_type;
315 typedef pair<const key_type,mapped_type> value_type;
316 typedef Compare key_compare;
317 typedef Allocator allocator_type;
318 typedef typename allocator_type::reference reference;
319 typedef typename allocator_type::const_reference const_reference;
320 typedef typename allocator_type::size_type size_type;
321 typedef typename allocator_type::difference_type difference_type;
322 typedef typename allocator_type::pointer pointer;
323 typedef typename allocator_type::const_pointer const_pointer;
325 typedef implementation-defined iterator;
326 typedef implementation-defined const_iterator;
327 typedef std::reverse_iterator<iterator> reverse_iterator;
328 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
329 typedef unspecified node_type; // C++17
333 friend class multimap;
336 value_compare(key_compare c);
338 typedef bool result_type; // deprecated in C++17, removed in C++20
339 typedef value_type first_argument_type; // deprecated in C++17, removed in C++20
340 typedef value_type second_argument_type; // deprecated in C++17, removed in C++20
341 bool operator()(const value_type& x, const value_type& y) const;
344 // construct/copy/destroy:
347 is_nothrow_default_constructible<allocator_type>::value &&
348 is_nothrow_default_constructible<key_compare>::value &&
349 is_nothrow_copy_constructible<key_compare>::value);
350 explicit multimap(const key_compare& comp);
351 multimap(const key_compare& comp, const allocator_type& a);
352 template <class InputIterator>
353 multimap(InputIterator first, InputIterator last, const key_compare& comp);
354 template <class InputIterator>
355 multimap(InputIterator first, InputIterator last, const key_compare& comp,
356 const allocator_type& a);
357 template<container-compatible-range<value_type> R>
358 multimap(from_range_t, R&& rg,
359 const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
360 multimap(const multimap& m);
361 multimap(multimap&& m)
363 is_nothrow_move_constructible<allocator_type>::value &&
364 is_nothrow_move_constructible<key_compare>::value);
365 explicit multimap(const allocator_type& a);
366 multimap(const multimap& m, const allocator_type& a);
367 multimap(multimap&& m, const allocator_type& a);
368 multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
369 multimap(initializer_list<value_type> il, const key_compare& comp,
370 const allocator_type& a);
371 template <class InputIterator>
372 multimap(InputIterator first, InputIterator last, const allocator_type& a)
373 : multimap(first, last, Compare(), a) {} // C++14
374 template<container-compatible-range<value_type> R>
375 multimap(from_range_t, R&& rg, const Allocator& a))
376 : multimap(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
377 multimap(initializer_list<value_type> il, const allocator_type& a)
378 : multimap(il, Compare(), a) {} // C++14
381 multimap& operator=(const multimap& m);
382 multimap& operator=(multimap&& m)
384 allocator_type::propagate_on_container_move_assignment::value &&
385 is_nothrow_move_assignable<allocator_type>::value &&
386 is_nothrow_move_assignable<key_compare>::value);
387 multimap& operator=(initializer_list<value_type> il);
390 iterator begin() noexcept;
391 const_iterator begin() const noexcept;
392 iterator end() noexcept;
393 const_iterator end() const noexcept;
395 reverse_iterator rbegin() noexcept;
396 const_reverse_iterator rbegin() const noexcept;
397 reverse_iterator rend() noexcept;
398 const_reverse_iterator rend() const noexcept;
400 const_iterator cbegin() const noexcept;
401 const_iterator cend() const noexcept;
402 const_reverse_iterator crbegin() const noexcept;
403 const_reverse_iterator crend() const noexcept;
406 bool empty() const noexcept;
407 size_type size() const noexcept;
408 size_type max_size() const noexcept;
411 template <class... Args>
412 iterator emplace(Args&&... args);
413 template <class... Args>
414 iterator emplace_hint(const_iterator position, Args&&... args);
415 iterator insert(const value_type& v);
416 iterator insert( value_type&& v); // C++17
418 iterator insert(P&& p);
419 iterator insert(const_iterator position, const value_type& v);
420 iterator insert(const_iterator position, value_type&& v); // C++17
422 iterator insert(const_iterator position, P&& p);
423 template <class InputIterator>
424 void insert(InputIterator first, InputIterator last);
425 template<container-compatible-range<value_type> R>
426 void insert_range(R&& rg); // C++23
427 void insert(initializer_list<value_type> il);
429 node_type extract(const_iterator position); // C++17
430 node_type extract(const key_type& x); // C++17
431 iterator insert(node_type&& nh); // C++17
432 iterator insert(const_iterator hint, node_type&& nh); // C++17
434 iterator erase(const_iterator position);
435 iterator erase(iterator position); // C++14
436 size_type erase(const key_type& k);
437 iterator erase(const_iterator first, const_iterator last);
438 void clear() noexcept;
441 void merge(multimap<Key, T, C2, Allocator>& source); // C++17
443 void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
445 void merge(map<Key, T, C2, Allocator>& source); // C++17
447 void merge(map<Key, T, C2, Allocator>&& source); // C++17
449 void swap(multimap& m)
450 noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
451 is_nothrow_swappable<key_compare>::value); // C++17
454 allocator_type get_allocator() const noexcept;
455 key_compare key_comp() const;
456 value_compare value_comp() const;
459 iterator find(const key_type& k);
460 const_iterator find(const key_type& k) const;
462 iterator find(const K& x); // C++14
464 const_iterator find(const K& x) const; // C++14
467 size_type count(const K& x) const; // C++14
468 size_type count(const key_type& k) const;
470 bool contains(const key_type& x) const; // C++20
471 template<class K> bool contains(const K& x) const; // C++20
473 iterator lower_bound(const key_type& k);
474 const_iterator lower_bound(const key_type& k) const;
476 iterator lower_bound(const K& x); // C++14
478 const_iterator lower_bound(const K& x) const; // C++14
480 iterator upper_bound(const key_type& k);
481 const_iterator upper_bound(const key_type& k) const;
483 iterator upper_bound(const K& x); // C++14
485 const_iterator upper_bound(const K& x) const; // C++14
487 pair<iterator,iterator> equal_range(const key_type& k);
488 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
490 pair<iterator,iterator> equal_range(const K& x); // C++14
492 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
495 template <class InputIterator,
496 class Compare = less<iter_key_t<InputIterator>>,
497 class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
498 multimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
499 -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
501 template<ranges::input_range R, class Compare = less<range-key-type<R>>,
502 class Allocator = allocator<range-to-alloc-type<R>>>
503 multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
504 -> multimap<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23
506 template<class Key, class T, class Compare = less<Key>,
507 class Allocator = allocator<pair<const Key, T>>>
508 multimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
509 -> multimap<Key, T, Compare, Allocator>; // C++17
511 template <class InputIterator, class Allocator>
512 multimap(InputIterator, InputIterator, Allocator)
513 -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
514 less<iter_key_t<InputIterator>>, Allocator>; // C++17
516 template<ranges::input_range R, class Allocator>
517 multimap(from_range_t, R&&, Allocator)
518 -> multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23
520 template<class Key, class T, class Allocator>
521 multimap(initializer_list<pair<const Key, T>>, Allocator)
522 -> multimap<Key, T, less<Key>, Allocator>; // C++17
524 template <class Key, class T, class Compare, class Allocator>
526 operator==(const multimap<Key, T, Compare, Allocator>& x,
527 const multimap<Key, T, Compare, Allocator>& y);
529 template <class Key, class T, class Compare, class Allocator>
531 operator< (const multimap<Key, T, Compare, Allocator>& x,
532 const multimap<Key, T, Compare, Allocator>& y); // removed in C++20
534 template <class Key, class T, class Compare, class Allocator>
536 operator!=(const multimap<Key, T, Compare, Allocator>& x,
537 const multimap<Key, T, Compare, Allocator>& y); // removed in C++20
539 template <class Key, class T, class Compare, class Allocator>
541 operator> (const multimap<Key, T, Compare, Allocator>& x,
542 const multimap<Key, T, Compare, Allocator>& y); // removed in C++20
544 template <class Key, class T, class Compare, class Allocator>
546 operator>=(const multimap<Key, T, Compare, Allocator>& x,
547 const multimap<Key, T, Compare, Allocator>& y); // removed in C++20
549 template <class Key, class T, class Compare, class Allocator>
551 operator<=(const multimap<Key, T, Compare, Allocator>& x,
552 const multimap<Key, T, Compare, Allocator>& y); // removed in C++20
554 template<class Key, class T, class Compare, class Allocator>
555 synth-three-way-result<pair<const Key, T>>
556 operator<=>(const multimap<Key, T, Compare, Allocator>& x,
557 const multimap<Key, T, Compare, Allocator>& y); // since c++20
559 // specialized algorithms:
560 template <class Key, class T, class Compare, class Allocator>
562 swap(multimap<Key, T, Compare, Allocator>& x,
563 multimap<Key, T, Compare, Allocator>& y)
564 noexcept(noexcept(x.swap(y)));
566 template <class Key, class T, class Compare, class Allocator, class Predicate>
567 typename multimap<Key, T, Compare, Allocator>::size_type
568 erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
574 #include <__algorithm/equal.h>
575 #include <__algorithm/lexicographical_compare.h>
576 #include <__algorithm/lexicographical_compare_three_way.h>
577 #include <__assert> // all public C++ headers provide the assertion handler
578 #include <__availability>
580 #include <__functional/binary_function.h>
581 #include <__functional/is_transparent.h>
582 #include <__functional/operations.h>
583 #include <__iterator/erase_if_container.h>
584 #include <__iterator/iterator_traits.h>
585 #include <__iterator/ranges_iterator_traits.h>
586 #include <__iterator/reverse_iterator.h>
587 #include <__memory/addressof.h>
588 #include <__memory/allocator.h>
589 #include <__memory_resource/polymorphic_allocator.h>
590 #include <__node_handle>
591 #include <__ranges/concepts.h>
592 #include <__ranges/container_compatible_range.h>
593 #include <__ranges/from_range.h>
595 #include <__type_traits/is_allocator.h>
596 #include <__utility/forward.h>
597 #include <__utility/piecewise_construct.h>
598 #include <__utility/swap.h>
603 // standard-mandated includes
606 #include <__iterator/access.h>
607 #include <__iterator/data.h>
608 #include <__iterator/empty.h>
609 #include <__iterator/reverse_access.h>
610 #include <__iterator/size.h>
612 // [associative.map.syn]
614 #include <initializer_list>
616 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
617 # pragma GCC system_header
621 #include <__undef_macros>
623 _LIBCPP_BEGIN_NAMESPACE_STD
625 template <class _Key,
628 bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
629 class __map_value_compare : private _Compare {
631 _LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
633 _LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
635 _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return *this; }
636 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
637 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);
639 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
640 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
642 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
643 return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
645 _LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) {
647 swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
650 #if _LIBCPP_STD_VER >= 14
651 template <typename _K2>
652 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
653 return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
656 template <typename _K2>
657 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
658 return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
663 template <class _Key, class _CP, class _Compare>
664 class __map_value_compare<_Key, _CP, _Compare, false> {
668 _LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
670 _LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
672 _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return __comp_; }
674 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
675 return __comp_(__x.__get_value().first, __y.__get_value().first);
677 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
678 return __comp_(__x.__get_value().first, __y);
680 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
681 return __comp_(__x, __y.__get_value().first);
683 void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) {
685 swap(__comp_, __y.__comp_);
688 #if _LIBCPP_STD_VER >= 14
689 template <typename _K2>
690 _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
691 return __comp_(__x, __y.__get_value().first);
694 template <typename _K2>
695 _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
696 return __comp_(__x.__get_value().first, __y);
701 template <class _Key, class _CP, class _Compare, bool __b>
702 inline _LIBCPP_HIDE_FROM_ABI void
703 swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, __map_value_compare<_Key, _CP, _Compare, __b>& __y)
704 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
708 template <class _Allocator>
709 class __map_node_destructor {
710 typedef _Allocator allocator_type;
711 typedef allocator_traits<allocator_type> __alloc_traits;
714 typedef typename __alloc_traits::pointer pointer;
717 allocator_type& __na_;
719 __map_node_destructor& operator=(const __map_node_destructor&);
722 bool __first_constructed;
723 bool __second_constructed;
725 _LIBCPP_HIDE_FROM_ABI explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
727 __first_constructed(false),
728 __second_constructed(false) {}
730 #ifndef _LIBCPP_CXX03_LANG
731 _LIBCPP_HIDE_FROM_ABI __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
733 __first_constructed(__x.__value_constructed),
734 __second_constructed(__x.__value_constructed) {
735 __x.__value_constructed = false;
737 #endif // _LIBCPP_CXX03_LANG
739 _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
740 if (__second_constructed)
741 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().second));
742 if (__first_constructed)
743 __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().first));
745 __alloc_traits::deallocate(__na_, __p, 1);
749 template <class _Key, class _Tp, class _Compare, class _Allocator>
751 template <class _Key, class _Tp, class _Compare, class _Allocator>
753 template <class _TreeIterator>
754 class __map_const_iterator;
756 #ifndef _LIBCPP_CXX03_LANG
758 template <class _Key, class _Tp>
759 struct _LIBCPP_STANDALONE_DEBUG __value_type {
760 typedef _Key key_type;
761 typedef _Tp mapped_type;
762 typedef pair<const key_type, mapped_type> value_type;
763 typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
764 typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
770 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
771 # if _LIBCPP_STD_VER >= 17
772 return *std::launder(std::addressof(__cc_));
778 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
779 # if _LIBCPP_STD_VER >= 17
780 return *std::launder(std::addressof(__cc_));
786 _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
787 value_type& __v = __get_value();
788 return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
791 _LIBCPP_HIDE_FROM_ABI __nc_rref_pair_type __move() {
792 value_type& __v = __get_value();
793 return __nc_rref_pair_type(std::move(const_cast<key_type&>(__v.first)), std::move(__v.second));
796 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(const __value_type& __v) {
797 __ref() = __v.__get_value();
801 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(__value_type&& __v) {
802 __ref() = __v.__move();
806 template <class _ValueTp, class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value> >
807 _LIBCPP_HIDE_FROM_ABI __value_type& operator=(_ValueTp&& __v) {
808 __ref() = std::forward<_ValueTp>(__v);
813 __value_type() = delete;
814 ~__value_type() = delete;
815 __value_type(const __value_type&) = delete;
816 __value_type(__value_type&&) = delete;
821 template <class _Key, class _Tp>
822 struct __value_type {
823 typedef _Key key_type;
824 typedef _Tp mapped_type;
825 typedef pair<const key_type, mapped_type> value_type;
831 _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
832 _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
836 __value_type(__value_type const&);
837 __value_type& operator=(__value_type const&);
841 #endif // _LIBCPP_CXX03_LANG
844 struct __extract_key_value_types;
846 template <class _Key, class _Tp>
847 struct __extract_key_value_types<__value_type<_Key, _Tp> > {
848 typedef _Key const __key_type;
849 typedef _Tp __mapped_type;
852 template <class _TreeIterator>
853 class _LIBCPP_TEMPLATE_VIS __map_iterator {
854 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
855 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
860 typedef bidirectional_iterator_tag iterator_category;
861 typedef typename _NodeTypes::__map_value_type value_type;
862 typedef typename _TreeIterator::difference_type difference_type;
863 typedef value_type& reference;
864 typedef typename _NodeTypes::__map_value_type_pointer pointer;
866 _LIBCPP_HIDE_FROM_ABI __map_iterator() _NOEXCEPT {}
868 _LIBCPP_HIDE_FROM_ABI __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
870 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
871 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
873 _LIBCPP_HIDE_FROM_ABI __map_iterator& operator++() {
877 _LIBCPP_HIDE_FROM_ABI __map_iterator operator++(int) {
878 __map_iterator __t(*this);
883 _LIBCPP_HIDE_FROM_ABI __map_iterator& operator--() {
887 _LIBCPP_HIDE_FROM_ABI __map_iterator operator--(int) {
888 __map_iterator __t(*this);
893 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
894 return __x.__i_ == __y.__i_;
896 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
897 return __x.__i_ != __y.__i_;
900 template <class, class, class, class>
901 friend class _LIBCPP_TEMPLATE_VIS map;
902 template <class, class, class, class>
903 friend class _LIBCPP_TEMPLATE_VIS multimap;
905 friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
908 template <class _TreeIterator>
909 class _LIBCPP_TEMPLATE_VIS __map_const_iterator {
910 typedef typename _TreeIterator::_NodeTypes _NodeTypes;
911 typedef typename _TreeIterator::__pointer_traits __pointer_traits;
916 typedef bidirectional_iterator_tag iterator_category;
917 typedef typename _NodeTypes::__map_value_type value_type;
918 typedef typename _TreeIterator::difference_type difference_type;
919 typedef const value_type& reference;
920 typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
922 _LIBCPP_HIDE_FROM_ABI __map_const_iterator() _NOEXCEPT {}
924 _LIBCPP_HIDE_FROM_ABI __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
925 _LIBCPP_HIDE_FROM_ABI
926 __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
928 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
929 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
931 _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator++() {
935 _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator++(int) {
936 __map_const_iterator __t(*this);
941 _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator--() {
945 _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator--(int) {
946 __map_const_iterator __t(*this);
951 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
952 return __x.__i_ == __y.__i_;
954 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
955 return __x.__i_ != __y.__i_;
958 template <class, class, class, class>
959 friend class _LIBCPP_TEMPLATE_VIS map;
960 template <class, class, class, class>
961 friend class _LIBCPP_TEMPLATE_VIS multimap;
962 template <class, class, class>
963 friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
966 template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
967 class _LIBCPP_TEMPLATE_VIS map {
970 typedef _Key key_type;
971 typedef _Tp mapped_type;
972 typedef pair<const key_type, mapped_type> value_type;
973 typedef __type_identity_t<_Compare> key_compare;
974 typedef __type_identity_t<_Allocator> allocator_type;
975 typedef value_type& reference;
976 typedef const value_type& const_reference;
978 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
979 "Allocator::value_type must be same type as value_type");
981 class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
987 _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : comp(__c) {}
990 _LIBCPP_HIDE_FROM_ABI bool operator()(const value_type& __x, const value_type& __y) const {
991 return comp(__x.first, __y.first);
996 typedef std::__value_type<key_type, mapped_type> __value_type;
997 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
998 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
999 typedef __tree<__value_type, __vc, __allocator_type> __base;
1000 typedef typename __base::__node_traits __node_traits;
1001 typedef allocator_traits<allocator_type> __alloc_traits;
1003 static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
1004 "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
1005 "original allocator");
1010 typedef typename __alloc_traits::pointer pointer;
1011 typedef typename __alloc_traits::const_pointer const_pointer;
1012 typedef typename __alloc_traits::size_type size_type;
1013 typedef typename __alloc_traits::difference_type difference_type;
1014 typedef __map_iterator<typename __base::iterator> iterator;
1015 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1016 typedef std::reverse_iterator<iterator> reverse_iterator;
1017 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1019 #if _LIBCPP_STD_VER >= 17
1020 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1021 typedef __insert_return_type<iterator, node_type> insert_return_type;
1024 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1025 friend class _LIBCPP_TEMPLATE_VIS map;
1026 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1027 friend class _LIBCPP_TEMPLATE_VIS multimap;
1029 _LIBCPP_HIDE_FROM_ABI map() _NOEXCEPT_(
1030 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
1031 is_nothrow_copy_constructible<key_compare>::value)
1032 : __tree_(__vc(key_compare())) {}
1034 _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp) _NOEXCEPT_(
1035 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
1036 : __tree_(__vc(__comp)) {}
1038 _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp, const allocator_type& __a)
1039 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
1041 template <class _InputIterator>
1042 _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
1043 : __tree_(__vc(__comp)) {
1047 template <class _InputIterator>
1048 _LIBCPP_HIDE_FROM_ABI
1049 map(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a)
1050 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1054 #if _LIBCPP_STD_VER >= 23
1055 template <_ContainerCompatibleRange<value_type> _Range>
1056 _LIBCPP_HIDE_FROM_ABI
1059 const key_compare& __comp = key_compare(),
1060 const allocator_type& __a = allocator_type())
1061 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1062 insert_range(std::forward<_Range>(__range));
1066 #if _LIBCPP_STD_VER >= 14
1067 template <class _InputIterator>
1068 _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1069 : map(__f, __l, key_compare(), __a) {}
1072 #if _LIBCPP_STD_VER >= 23
1073 template <_ContainerCompatibleRange<value_type> _Range>
1074 _LIBCPP_HIDE_FROM_ABI map(from_range_t, _Range&& __range, const allocator_type& __a)
1075 : map(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1078 _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
1080 _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
1081 #ifndef _LIBCPP_CXX03_LANG
1082 __tree_ = __m.__tree_;
1084 if (this != std::addressof(__m)) {
1086 __tree_.value_comp() = __m.__tree_.value_comp();
1087 __tree_.__copy_assign_alloc(__m.__tree_);
1088 insert(__m.begin(), __m.end());
1094 #ifndef _LIBCPP_CXX03_LANG
1096 _LIBCPP_HIDE_FROM_ABI map(map&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1097 : __tree_(std::move(__m.__tree_)) {}
1099 _LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
1101 _LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
1102 __tree_ = std::move(__m.__tree_);
1106 _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1107 : __tree_(__vc(__comp)) {
1108 insert(__il.begin(), __il.end());
1111 _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1112 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1113 insert(__il.begin(), __il.end());
1116 # if _LIBCPP_STD_VER >= 14
1117 _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const allocator_type& __a)
1118 : map(__il, key_compare(), __a) {}
1121 _LIBCPP_HIDE_FROM_ABI map& operator=(initializer_list<value_type> __il) {
1122 __tree_.__assign_unique(__il.begin(), __il.end());
1126 #endif // _LIBCPP_CXX03_LANG
1128 _LIBCPP_HIDE_FROM_ABI explicit map(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
1130 _LIBCPP_HIDE_FROM_ABI map(const map& __m, const allocator_type& __a)
1131 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) {
1132 insert(__m.begin(), __m.end());
1135 _LIBCPP_HIDE_FROM_ABI ~map() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
1137 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
1138 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
1139 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
1140 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
1142 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1143 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1144 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1145 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
1147 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
1148 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
1149 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1150 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
1152 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1153 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
1154 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
1156 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
1157 #ifndef _LIBCPP_CXX03_LANG
1158 _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
1161 _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
1162 _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
1164 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(__tree_.__alloc()); }
1165 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
1166 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
1168 #ifndef _LIBCPP_CXX03_LANG
1169 template <class... _Args>
1170 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
1171 return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
1174 template <class... _Args>
1175 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1176 return __tree_.__emplace_hint_unique(__p.__i_, std::forward<_Args>(__args)...);
1179 template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
1180 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __p) {
1181 return __tree_.__insert_unique(std::forward<_Pp>(__p));
1184 template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
1185 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1186 return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
1189 #endif // _LIBCPP_CXX03_LANG
1191 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
1193 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1194 return __tree_.__insert_unique(__p.__i_, __v);
1197 #ifndef _LIBCPP_CXX03_LANG
1198 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
1199 return __tree_.__insert_unique(std::move(__v));
1202 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1203 return __tree_.__insert_unique(__p.__i_, std::move(__v));
1206 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
1209 template <class _InputIterator>
1210 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
1211 for (const_iterator __e = cend(); __f != __l; ++__f)
1212 insert(__e.__i_, *__f);
1215 #if _LIBCPP_STD_VER >= 23
1216 template <_ContainerCompatibleRange<value_type> _Range>
1217 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
1218 const_iterator __end = cend();
1219 for (auto&& __element : __range) {
1220 insert(__end.__i_, std::forward<decltype(__element)>(__element));
1225 #if _LIBCPP_STD_VER >= 17
1227 template <class... _Args>
1228 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
1229 return __tree_.__emplace_unique_key_args(
1231 std::piecewise_construct,
1232 std::forward_as_tuple(__k),
1233 std::forward_as_tuple(std::forward<_Args>(__args)...));
1236 template <class... _Args>
1237 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) {
1238 return __tree_.__emplace_unique_key_args(
1240 std::piecewise_construct,
1241 std::forward_as_tuple(std::move(__k)),
1242 std::forward_as_tuple(std::forward<_Args>(__args)...));
1245 template <class... _Args>
1246 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) {
1248 .__emplace_hint_unique_key_args(
1251 std::piecewise_construct,
1252 std::forward_as_tuple(__k),
1253 std::forward_as_tuple(std::forward<_Args>(__args)...))
1257 template <class... _Args>
1258 _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) {
1260 .__emplace_hint_unique_key_args(
1263 std::piecewise_construct,
1264 std::forward_as_tuple(std::move(__k)),
1265 std::forward_as_tuple(std::forward<_Args>(__args)...))
1269 template <class _Vp>
1270 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) {
1271 iterator __p = lower_bound(__k);
1272 if (__p != end() && !key_comp()(__k, __p->first)) {
1273 __p->second = std::forward<_Vp>(__v);
1274 return std::make_pair(__p, false);
1276 return std::make_pair(emplace_hint(__p, __k, std::forward<_Vp>(__v)), true);
1279 template <class _Vp>
1280 _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) {
1281 iterator __p = lower_bound(__k);
1282 if (__p != end() && !key_comp()(__k, __p->first)) {
1283 __p->second = std::forward<_Vp>(__v);
1284 return std::make_pair(__p, false);
1286 return std::make_pair(emplace_hint(__p, std::move(__k), std::forward<_Vp>(__v)), true);
1289 template <class _Vp>
1290 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) {
1291 auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, __k, std::forward<_Vp>(__v));
1294 __r->__get_value().second = std::forward<_Vp>(__v);
1299 template <class _Vp>
1300 _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) {
1301 auto [__r, __inserted] =
1302 __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, std::move(__k), std::forward<_Vp>(__v));
1305 __r->__get_value().second = std::forward<_Vp>(__v);
1310 #endif // _LIBCPP_STD_VER >= 17
1312 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
1313 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
1314 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
1315 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
1316 return __tree_.erase(__f.__i_, __l.__i_);
1318 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
1320 #if _LIBCPP_STD_VER >= 17
1321 _LIBCPP_HIDE_FROM_ABI insert_return_type insert(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()");
1324 return __tree_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
1326 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
1327 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
1328 "node_type with incompatible allocator passed to map::insert()");
1329 return __tree_.template __node_handle_insert_unique<node_type>(__hint.__i_, std::move(__nh));
1331 _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
1332 return __tree_.template __node_handle_extract<node_type>(__key);
1334 _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
1335 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1337 template <class _Compare2>
1338 _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1339 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1340 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1341 __tree_.__node_handle_merge_unique(__source.__tree_);
1343 template <class _Compare2>
1344 _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1345 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1346 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1347 __tree_.__node_handle_merge_unique(__source.__tree_);
1349 template <class _Compare2>
1350 _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1351 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1352 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1353 __tree_.__node_handle_merge_unique(__source.__tree_);
1355 template <class _Compare2>
1356 _LIBCPP_HIDE_FROM_ABI void merge(multimap<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_);
1363 _LIBCPP_HIDE_FROM_ABI void swap(map& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
1364 __tree_.swap(__m.__tree_);
1367 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
1368 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1369 #if _LIBCPP_STD_VER >= 14
1370 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1371 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
1372 return __tree_.find(__k);
1374 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1375 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
1376 return __tree_.find(__k);
1380 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
1381 #if _LIBCPP_STD_VER >= 14
1382 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1383 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
1384 return __tree_.__count_multi(__k);
1388 #if _LIBCPP_STD_VER >= 20
1389 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
1390 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1391 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
1392 return find(__k) != end();
1394 #endif // _LIBCPP_STD_VER >= 20
1396 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
1397 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1398 #if _LIBCPP_STD_VER >= 14
1399 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1400 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
1401 return __tree_.lower_bound(__k);
1404 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1405 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
1406 return __tree_.lower_bound(__k);
1410 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
1411 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
1412 #if _LIBCPP_STD_VER >= 14
1413 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1414 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
1415 return __tree_.upper_bound(__k);
1417 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1418 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
1419 return __tree_.upper_bound(__k);
1423 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
1424 return __tree_.__equal_range_unique(__k);
1426 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
1427 return __tree_.__equal_range_unique(__k);
1429 #if _LIBCPP_STD_VER >= 14
1430 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1431 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
1432 return __tree_.__equal_range_multi(__k);
1434 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1435 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
1436 return __tree_.__equal_range_multi(__k);
1441 typedef typename __base::__node __node;
1442 typedef typename __base::__node_allocator __node_allocator;
1443 typedef typename __base::__node_pointer __node_pointer;
1444 typedef typename __base::__node_base_pointer __node_base_pointer;
1445 typedef typename __base::__parent_pointer __parent_pointer;
1447 typedef __map_node_destructor<__node_allocator> _Dp;
1448 typedef unique_ptr<__node, _Dp> __node_holder;
1450 #ifdef _LIBCPP_CXX03_LANG
1451 _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
1455 #if _LIBCPP_STD_VER >= 17
1456 template <class _InputIterator,
1457 class _Compare = less<__iter_key_type<_InputIterator>>,
1458 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1459 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1460 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1461 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1462 map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1463 -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
1465 # if _LIBCPP_STD_VER >= 23
1466 template <ranges::input_range _Range,
1467 class _Compare = less<__range_key_type<_Range>>,
1468 class _Allocator = allocator<__range_to_alloc_type<_Range>>,
1469 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1470 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1471 map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
1472 -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
1475 template <class _Key,
1477 class _Compare = less<remove_const_t<_Key>>,
1478 class _Allocator = allocator<pair<const _Key, _Tp>>,
1479 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1480 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1481 map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
1482 -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
1484 template <class _InputIterator,
1486 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1487 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1488 map(_InputIterator, _InputIterator, _Allocator)
1489 -> map<__iter_key_type<_InputIterator>,
1490 __iter_mapped_type<_InputIterator>,
1491 less<__iter_key_type<_InputIterator>>,
1494 # if _LIBCPP_STD_VER >= 23
1495 template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1496 map(from_range_t, _Range&&, _Allocator)
1497 -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
1500 template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1501 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1502 -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
1505 #ifndef _LIBCPP_CXX03_LANG
1506 template <class _Key, class _Tp, class _Compare, class _Allocator>
1507 map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
1508 : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
1509 if (__a != __m.get_allocator()) {
1510 const_iterator __e = cend();
1511 while (!__m.empty())
1512 __tree_.__insert_unique(__e.__i_, __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
1516 template <class _Key, class _Tp, class _Compare, class _Allocator>
1517 _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
1519 .__emplace_unique_key_args(__k, std::piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
1520 .first->__get_value()
1524 template <class _Key, class _Tp, class _Compare, class _Allocator>
1525 _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
1526 // TODO investigate this clang-tidy warning.
1527 // NOLINTBEGIN(bugprone-use-after-move)
1529 .__emplace_unique_key_args(
1530 __k, std::piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple())
1531 .first->__get_value()
1533 // NOLINTEND(bugprone-use-after-move)
1536 #else // _LIBCPP_CXX03_LANG
1538 template <class _Key, class _Tp, class _Compare, class _Allocator>
1539 typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1540 map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) {
1541 __node_allocator& __na = __tree_.__node_alloc();
1542 __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1543 __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().first), __k);
1544 __h.get_deleter().__first_constructed = true;
1545 __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().second));
1546 __h.get_deleter().__second_constructed = true;
1550 template <class _Key, class _Tp, class _Compare, class _Allocator>
1551 _Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
1552 __parent_pointer __parent;
1553 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
1554 __node_pointer __r = static_cast<__node_pointer>(__child);
1555 if (__child == nullptr) {
1556 __node_holder __h = __construct_node_with_key(__k);
1557 __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
1558 __r = __h.release();
1560 return __r->__value_.__get_value().second;
1563 #endif // _LIBCPP_CXX03_LANG
1565 template <class _Key, class _Tp, class _Compare, class _Allocator>
1566 _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
1567 __parent_pointer __parent;
1568 __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
1569 if (__child == nullptr)
1570 __throw_out_of_range("map::at: key not found");
1571 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1574 template <class _Key, class _Tp, class _Compare, class _Allocator>
1575 const _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {
1576 __parent_pointer __parent;
1577 __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
1578 if (__child == nullptr)
1579 __throw_out_of_range("map::at: key not found");
1580 return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
1583 template <class _Key, class _Tp, class _Compare, class _Allocator>
1584 inline _LIBCPP_HIDE_FROM_ABI bool
1585 operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1586 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
1589 #if _LIBCPP_STD_VER <= 17
1591 template <class _Key, class _Tp, class _Compare, class _Allocator>
1592 inline _LIBCPP_HIDE_FROM_ABI bool
1593 operator<(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1594 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1597 template <class _Key, class _Tp, class _Compare, class _Allocator>
1598 inline _LIBCPP_HIDE_FROM_ABI bool
1599 operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1600 return !(__x == __y);
1603 template <class _Key, class _Tp, class _Compare, class _Allocator>
1604 inline _LIBCPP_HIDE_FROM_ABI bool
1605 operator>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1609 template <class _Key, class _Tp, class _Compare, class _Allocator>
1610 inline _LIBCPP_HIDE_FROM_ABI bool
1611 operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1612 return !(__x < __y);
1615 template <class _Key, class _Tp, class _Compare, class _Allocator>
1616 inline _LIBCPP_HIDE_FROM_ABI bool
1617 operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1618 return !(__y < __x);
1621 #else // #if _LIBCPP_STD_VER <= 17
1623 template <class _Key, class _Tp, class _Compare, class _Allocator>
1624 _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
1625 operator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1626 return std::lexicographical_compare_three_way(
1631 std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
1634 #endif // #if _LIBCPP_STD_VER <= 17
1636 template <class _Key, class _Tp, class _Compare, class _Allocator>
1637 inline _LIBCPP_HIDE_FROM_ABI void
1638 swap(map<_Key, _Tp, _Compare, _Allocator>& __x, map<_Key, _Tp, _Compare, _Allocator>& __y)
1639 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
1643 #if _LIBCPP_STD_VER >= 20
1644 template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1645 inline _LIBCPP_HIDE_FROM_ABI typename map<_Key, _Tp, _Compare, _Allocator>::size_type
1646 erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1647 return std::__libcpp_erase_if_container(__c, __pred);
1651 template <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
1652 class _LIBCPP_TEMPLATE_VIS multimap {
1655 typedef _Key key_type;
1656 typedef _Tp mapped_type;
1657 typedef pair<const key_type, mapped_type> value_type;
1658 typedef __type_identity_t<_Compare> key_compare;
1659 typedef __type_identity_t<_Allocator> allocator_type;
1660 typedef value_type& reference;
1661 typedef const value_type& const_reference;
1663 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1664 "Allocator::value_type must be same type as value_type");
1666 class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
1667 friend class multimap;
1672 _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : comp(__c) {}
1675 _LIBCPP_HIDE_FROM_ABI bool operator()(const value_type& __x, const value_type& __y) const {
1676 return comp(__x.first, __y.first);
1681 typedef std::__value_type<key_type, mapped_type> __value_type;
1682 typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1683 typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
1684 typedef __tree<__value_type, __vc, __allocator_type> __base;
1685 typedef typename __base::__node_traits __node_traits;
1686 typedef allocator_traits<allocator_type> __alloc_traits;
1688 static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
1689 "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
1690 "original allocator");
1695 typedef typename __alloc_traits::pointer pointer;
1696 typedef typename __alloc_traits::const_pointer const_pointer;
1697 typedef typename __alloc_traits::size_type size_type;
1698 typedef typename __alloc_traits::difference_type difference_type;
1699 typedef __map_iterator<typename __base::iterator> iterator;
1700 typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1701 typedef std::reverse_iterator<iterator> reverse_iterator;
1702 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1704 #if _LIBCPP_STD_VER >= 17
1705 typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
1708 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1709 friend class _LIBCPP_TEMPLATE_VIS map;
1710 template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
1711 friend class _LIBCPP_TEMPLATE_VIS multimap;
1713 _LIBCPP_HIDE_FROM_ABI multimap() _NOEXCEPT_(
1714 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
1715 is_nothrow_copy_constructible<key_compare>::value)
1716 : __tree_(__vc(key_compare())) {}
1718 _LIBCPP_HIDE_FROM_ABI explicit multimap(const key_compare& __comp) _NOEXCEPT_(
1719 is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
1720 : __tree_(__vc(__comp)) {}
1722 _LIBCPP_HIDE_FROM_ABI explicit multimap(const key_compare& __comp, const allocator_type& __a)
1723 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
1725 template <class _InputIterator>
1726 _LIBCPP_HIDE_FROM_ABI multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
1727 : __tree_(__vc(__comp)) {
1731 template <class _InputIterator>
1732 _LIBCPP_HIDE_FROM_ABI
1733 multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a)
1734 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1738 #if _LIBCPP_STD_VER >= 23
1739 template <_ContainerCompatibleRange<value_type> _Range>
1740 _LIBCPP_HIDE_FROM_ABI
1741 multimap(from_range_t,
1743 const key_compare& __comp = key_compare(),
1744 const allocator_type& __a = allocator_type())
1745 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1746 insert_range(std::forward<_Range>(__range));
1750 #if _LIBCPP_STD_VER >= 14
1751 template <class _InputIterator>
1752 _LIBCPP_HIDE_FROM_ABI multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1753 : multimap(__f, __l, key_compare(), __a) {}
1756 #if _LIBCPP_STD_VER >= 23
1757 template <_ContainerCompatibleRange<value_type> _Range>
1758 _LIBCPP_HIDE_FROM_ABI multimap(from_range_t, _Range&& __range, const allocator_type& __a)
1759 : multimap(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1762 _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m)
1763 : __tree_(__m.__tree_.value_comp(),
1764 __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) {
1765 insert(__m.begin(), __m.end());
1768 _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
1769 #ifndef _LIBCPP_CXX03_LANG
1770 __tree_ = __m.__tree_;
1772 if (this != std::addressof(__m)) {
1774 __tree_.value_comp() = __m.__tree_.value_comp();
1775 __tree_.__copy_assign_alloc(__m.__tree_);
1776 insert(__m.begin(), __m.end());
1782 #ifndef _LIBCPP_CXX03_LANG
1784 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1785 : __tree_(std::move(__m.__tree_)) {}
1787 _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a);
1789 _LIBCPP_HIDE_FROM_ABI multimap& operator=(multimap&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
1790 __tree_ = std::move(__m.__tree_);
1794 _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1795 : __tree_(__vc(__comp)) {
1796 insert(__il.begin(), __il.end());
1799 _LIBCPP_HIDE_FROM_ABI
1800 multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1801 : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1802 insert(__il.begin(), __il.end());
1805 # if _LIBCPP_STD_VER >= 14
1806 _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const allocator_type& __a)
1807 : multimap(__il, key_compare(), __a) {}
1810 _LIBCPP_HIDE_FROM_ABI multimap& operator=(initializer_list<value_type> __il) {
1811 __tree_.__assign_multi(__il.begin(), __il.end());
1815 #endif // _LIBCPP_CXX03_LANG
1817 _LIBCPP_HIDE_FROM_ABI explicit multimap(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
1819 _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m, const allocator_type& __a)
1820 : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) {
1821 insert(__m.begin(), __m.end());
1824 _LIBCPP_HIDE_FROM_ABI ~multimap() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
1826 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
1827 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
1828 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
1829 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
1831 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1832 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1833 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1834 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
1836 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
1837 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
1838 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1839 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
1841 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1842 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
1843 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
1845 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(__tree_.__alloc()); }
1846 _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
1847 _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
1849 #ifndef _LIBCPP_CXX03_LANG
1851 template <class... _Args>
1852 _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
1853 return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
1856 template <class... _Args>
1857 _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1858 return __tree_.__emplace_hint_multi(__p.__i_, std::forward<_Args>(__args)...);
1861 template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
1862 _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __p) {
1863 return __tree_.__insert_multi(std::forward<_Pp>(__p));
1866 template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
1867 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1868 return __tree_.__insert_multi(__pos.__i_, std::forward<_Pp>(__p));
1871 _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
1873 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1874 return __tree_.__insert_multi(__p.__i_, std::move(__v));
1877 _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
1879 #endif // _LIBCPP_CXX03_LANG
1881 _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1883 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1884 return __tree_.__insert_multi(__p.__i_, __v);
1887 template <class _InputIterator>
1888 _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
1889 for (const_iterator __e = cend(); __f != __l; ++__f)
1890 __tree_.__insert_multi(__e.__i_, *__f);
1893 #if _LIBCPP_STD_VER >= 23
1894 template <_ContainerCompatibleRange<value_type> _Range>
1895 _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
1896 const_iterator __end = cend();
1897 for (auto&& __element : __range) {
1898 __tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
1903 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
1904 _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
1905 _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
1906 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
1907 return __tree_.erase(__f.__i_, __l.__i_);
1910 #if _LIBCPP_STD_VER >= 17
1911 _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
1912 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
1913 "node_type with incompatible allocator passed to multimap::insert()");
1914 return __tree_.template __node_handle_insert_multi<node_type>(std::move(__nh));
1916 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
1917 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
1918 "node_type with incompatible allocator passed to multimap::insert()");
1919 return __tree_.template __node_handle_insert_multi<node_type>(__hint.__i_, std::move(__nh));
1921 _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
1922 return __tree_.template __node_handle_extract<node_type>(__key);
1924 _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
1925 return __tree_.template __node_handle_extract<node_type>(__it.__i_);
1927 template <class _Compare2>
1928 _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1929 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1930 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1931 return __tree_.__node_handle_merge_multi(__source.__tree_);
1933 template <class _Compare2>
1934 _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1935 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1936 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1937 return __tree_.__node_handle_merge_multi(__source.__tree_);
1939 template <class _Compare2>
1940 _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1941 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1942 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1943 return __tree_.__node_handle_merge_multi(__source.__tree_);
1945 template <class _Compare2>
1946 _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1947 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1948 __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
1949 return __tree_.__node_handle_merge_multi(__source.__tree_);
1953 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
1955 _LIBCPP_HIDE_FROM_ABI void swap(multimap& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
1956 __tree_.swap(__m.__tree_);
1959 _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
1960 _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1961 #if _LIBCPP_STD_VER >= 14
1962 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1963 _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
1964 return __tree_.find(__k);
1966 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1967 _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
1968 return __tree_.find(__k);
1972 _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
1973 #if _LIBCPP_STD_VER >= 14
1974 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1975 _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
1976 return __tree_.__count_multi(__k);
1980 #if _LIBCPP_STD_VER >= 20
1981 _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
1982 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1983 _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
1984 return find(__k) != end();
1986 #endif // _LIBCPP_STD_VER >= 20
1988 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
1989 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1990 #if _LIBCPP_STD_VER >= 14
1991 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1992 _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
1993 return __tree_.lower_bound(__k);
1996 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1997 _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
1998 return __tree_.lower_bound(__k);
2002 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
2003 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
2004 #if _LIBCPP_STD_VER >= 14
2005 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2006 _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
2007 return __tree_.upper_bound(__k);
2009 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2010 _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
2011 return __tree_.upper_bound(__k);
2015 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
2016 return __tree_.__equal_range_multi(__k);
2018 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
2019 return __tree_.__equal_range_multi(__k);
2021 #if _LIBCPP_STD_VER >= 14
2022 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2023 _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
2024 return __tree_.__equal_range_multi(__k);
2026 template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2027 _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
2028 return __tree_.__equal_range_multi(__k);
2033 typedef typename __base::__node __node;
2034 typedef typename __base::__node_allocator __node_allocator;
2035 typedef typename __base::__node_pointer __node_pointer;
2037 typedef __map_node_destructor<__node_allocator> _Dp;
2038 typedef unique_ptr<__node, _Dp> __node_holder;
2041 #if _LIBCPP_STD_VER >= 17
2042 template <class _InputIterator,
2043 class _Compare = less<__iter_key_type<_InputIterator>>,
2044 class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2045 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
2046 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2047 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2048 multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
2049 -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
2051 # if _LIBCPP_STD_VER >= 23
2052 template <ranges::input_range _Range,
2053 class _Compare = less<__range_key_type<_Range>>,
2054 class _Allocator = allocator<__range_to_alloc_type<_Range>>,
2055 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2056 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2057 multimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
2058 -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
2061 template <class _Key,
2063 class _Compare = less<remove_const_t<_Key>>,
2064 class _Allocator = allocator<pair<const _Key, _Tp>>,
2065 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2066 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2067 multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
2068 -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
2070 template <class _InputIterator,
2072 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
2073 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2074 multimap(_InputIterator, _InputIterator, _Allocator)
2075 -> multimap<__iter_key_type<_InputIterator>,
2076 __iter_mapped_type<_InputIterator>,
2077 less<__iter_key_type<_InputIterator>>,
2080 # if _LIBCPP_STD_VER >= 23
2081 template <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2082 multimap(from_range_t, _Range&&, _Allocator)
2083 -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
2086 template <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2087 multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
2088 -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
2091 #ifndef _LIBCPP_CXX03_LANG
2092 template <class _Key, class _Tp, class _Compare, class _Allocator>
2093 multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
2094 : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
2095 if (__a != __m.get_allocator()) {
2096 const_iterator __e = cend();
2097 while (!__m.empty())
2098 __tree_.__insert_multi(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
2103 template <class _Key, class _Tp, class _Compare, class _Allocator>
2104 inline _LIBCPP_HIDE_FROM_ABI bool
2105 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2106 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
2109 #if _LIBCPP_STD_VER <= 17
2111 template <class _Key, class _Tp, class _Compare, class _Allocator>
2112 inline _LIBCPP_HIDE_FROM_ABI bool
2113 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2114 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2117 template <class _Key, class _Tp, class _Compare, class _Allocator>
2118 inline _LIBCPP_HIDE_FROM_ABI bool
2119 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2120 return !(__x == __y);
2123 template <class _Key, class _Tp, class _Compare, class _Allocator>
2124 inline _LIBCPP_HIDE_FROM_ABI bool
2125 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2129 template <class _Key, class _Tp, class _Compare, class _Allocator>
2130 inline _LIBCPP_HIDE_FROM_ABI bool
2131 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2132 return !(__x < __y);
2135 template <class _Key, class _Tp, class _Compare, class _Allocator>
2136 inline _LIBCPP_HIDE_FROM_ABI bool
2137 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2138 return !(__y < __x);
2141 #else // #if _LIBCPP_STD_VER <= 17
2143 template <class _Key, class _Tp, class _Compare, class _Allocator>
2144 _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
2145 operator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2146 const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2147 return std::lexicographical_compare_three_way(
2152 std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
2155 #endif // #if _LIBCPP_STD_VER <= 17
2157 template <class _Key, class _Tp, class _Compare, class _Allocator>
2158 inline _LIBCPP_HIDE_FROM_ABI void
2159 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2160 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
2164 #if _LIBCPP_STD_VER >= 20
2165 template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2166 inline _LIBCPP_HIDE_FROM_ABI typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2167 erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
2168 return std::__libcpp_erase_if_container(__c, __pred);
2172 _LIBCPP_END_NAMESPACE_STD
2174 #if _LIBCPP_STD_VER >= 17
2175 _LIBCPP_BEGIN_NAMESPACE_STD
2177 template <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>>
2178 using map _LIBCPP_AVAILABILITY_PMR =
2179 std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
2181 template <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>>
2182 using multimap _LIBCPP_AVAILABILITY_PMR =
2183 std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
2185 _LIBCPP_END_NAMESPACE_STD
2190 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2191 # include <concepts>
2193 # include <functional>
2194 # include <iterator>
2195 # include <type_traits>
2199 #endif // _LIBCPP_MAP