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