10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_MAP
110b57cec5SDimitry Andric#define _LIBCPP_MAP
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric    map synopsis
160b57cec5SDimitry Andric
170b57cec5SDimitry Andricnamespace std
180b57cec5SDimitry Andric{
190b57cec5SDimitry Andric
200b57cec5SDimitry Andrictemplate <class Key, class T, class Compare = less<Key>,
210b57cec5SDimitry Andric          class Allocator = allocator<pair<const Key, T>>>
220b57cec5SDimitry Andricclass map
230b57cec5SDimitry Andric{
240b57cec5SDimitry Andricpublic:
250b57cec5SDimitry Andric    // types:
260b57cec5SDimitry Andric    typedef Key                                      key_type;
270b57cec5SDimitry Andric    typedef T                                        mapped_type;
280b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
290b57cec5SDimitry Andric    typedef Compare                                  key_compare;
300b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
310b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
320b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
330b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
340b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
350b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
360b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
390b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
400b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
410b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
420b57cec5SDimitry Andric    typedef unspecified                              node_type;              // C++17
430b57cec5SDimitry Andric    typedef INSERT_RETURN_TYPE<iterator, node_type>  insert_return_type;     // C++17
440b57cec5SDimitry Andric
450b57cec5SDimitry Andric    class value_compare
460b57cec5SDimitry Andric    {
470b57cec5SDimitry Andric        friend class map;
480b57cec5SDimitry Andric    protected:
490b57cec5SDimitry Andric        key_compare comp;
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric        value_compare(key_compare c);
520b57cec5SDimitry Andric    public:
53fe6060f1SDimitry Andric        typedef bool result_type;  // deprecated in C++17, removed in C++20
54fe6060f1SDimitry Andric        typedef value_type first_argument_type;  // deprecated in C++17, removed in C++20
55fe6060f1SDimitry Andric        typedef value_type second_argument_type;  // deprecated in C++17, removed in C++20
560b57cec5SDimitry Andric        bool operator()(const value_type& x, const value_type& y) const;
570b57cec5SDimitry Andric    };
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    // construct/copy/destroy:
600b57cec5SDimitry Andric    map()
610b57cec5SDimitry Andric        noexcept(
620b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
630b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
640b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value);
650b57cec5SDimitry Andric    explicit map(const key_compare& comp);
660b57cec5SDimitry Andric    map(const key_compare& comp, const allocator_type& a);
670b57cec5SDimitry Andric    template <class InputIterator>
680b57cec5SDimitry Andric        map(InputIterator first, InputIterator last,
690b57cec5SDimitry Andric            const key_compare& comp = key_compare());
700b57cec5SDimitry Andric    template <class InputIterator>
710b57cec5SDimitry Andric        map(InputIterator first, InputIterator last,
720b57cec5SDimitry Andric            const key_compare& comp, const allocator_type& a);
73fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
74fe013be4SDimitry Andric      map(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
750b57cec5SDimitry Andric    map(const map& m);
760b57cec5SDimitry Andric    map(map&& m)
770b57cec5SDimitry Andric        noexcept(
780b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
790b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
800b57cec5SDimitry Andric    explicit map(const allocator_type& a);
810b57cec5SDimitry Andric    map(const map& m, const allocator_type& a);
820b57cec5SDimitry Andric    map(map&& m, const allocator_type& a);
830b57cec5SDimitry Andric    map(initializer_list<value_type> il, const key_compare& comp = key_compare());
840b57cec5SDimitry Andric    map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
850b57cec5SDimitry Andric    template <class InputIterator>
860b57cec5SDimitry Andric        map(InputIterator first, InputIterator last, const allocator_type& a)
870b57cec5SDimitry Andric            : map(first, last, Compare(), a) {}  // C++14
88fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
89fe013be4SDimitry Andric      map(from_range_t, R&& rg, const Allocator& a))
90fe013be4SDimitry Andric        : map(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
910b57cec5SDimitry Andric    map(initializer_list<value_type> il, const allocator_type& a)
920b57cec5SDimitry Andric        : map(il, Compare(), a) {}  // C++14
930b57cec5SDimitry Andric   ~map();
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric    map& operator=(const map& m);
960b57cec5SDimitry Andric    map& operator=(map&& m)
970b57cec5SDimitry Andric        noexcept(
980b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
990b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
1000b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
1010b57cec5SDimitry Andric    map& operator=(initializer_list<value_type> il);
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric    // iterators:
1040b57cec5SDimitry Andric          iterator begin() noexcept;
1050b57cec5SDimitry Andric    const_iterator begin() const noexcept;
1060b57cec5SDimitry Andric          iterator end() noexcept;
1070b57cec5SDimitry Andric    const_iterator end()   const noexcept;
1080b57cec5SDimitry Andric
1090b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
1100b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
1110b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
1120b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
1150b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
1160b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
1170b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andric    // capacity:
1200b57cec5SDimitry Andric    bool      empty()    const noexcept;
1210b57cec5SDimitry Andric    size_type size()     const noexcept;
1220b57cec5SDimitry Andric    size_type max_size() const noexcept;
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric    // element access:
1250b57cec5SDimitry Andric    mapped_type& operator[](const key_type& k);
1260b57cec5SDimitry Andric    mapped_type& operator[](key_type&& k);
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andric          mapped_type& at(const key_type& k);
1290b57cec5SDimitry Andric    const mapped_type& at(const key_type& k) const;
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric    // modifiers:
1320b57cec5SDimitry Andric    template <class... Args>
1330b57cec5SDimitry Andric        pair<iterator, bool> emplace(Args&&... args);
1340b57cec5SDimitry Andric    template <class... Args>
1350b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
1360b57cec5SDimitry Andric    pair<iterator, bool> insert(const value_type& v);
1370b57cec5SDimitry Andric    pair<iterator, bool> insert(      value_type&& v);                                // C++17
1380b57cec5SDimitry Andric    template <class P>
1390b57cec5SDimitry Andric        pair<iterator, bool> insert(P&& p);
1400b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
1410b57cec5SDimitry Andric    iterator insert(const_iterator position,       value_type&& v);                   // C++17
1420b57cec5SDimitry Andric    template <class P>
1430b57cec5SDimitry Andric        iterator insert(const_iterator position, P&& p);
1440b57cec5SDimitry Andric    template <class InputIterator>
1450b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
146fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
147fe013be4SDimitry Andric      void insert_range(R&& rg);                                                      // C++23
1480b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
1490b57cec5SDimitry Andric
1500b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
1510b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
1520b57cec5SDimitry Andric    insert_return_type insert(node_type&& nh);                                        // C++17
1530b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
1540b57cec5SDimitry Andric
1550b57cec5SDimitry Andric    template <class... Args>
1560b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);          // C++17
1570b57cec5SDimitry Andric    template <class... Args>
1580b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);               // C++17
1590b57cec5SDimitry Andric    template <class... Args>
1600b57cec5SDimitry Andric        iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
1610b57cec5SDimitry Andric    template <class... Args>
1620b57cec5SDimitry Andric        iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);      // C++17
1630b57cec5SDimitry Andric    template <class M>
1640b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);            // C++17
1650b57cec5SDimitry Andric    template <class M>
1660b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);                 // C++17
1670b57cec5SDimitry Andric    template <class M>
1680b57cec5SDimitry Andric        iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);   // C++17
1690b57cec5SDimitry Andric    template <class M>
1700b57cec5SDimitry Andric        iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);        // C++17
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andric    iterator  erase(const_iterator position);
1730b57cec5SDimitry Andric    iterator  erase(iterator position); // C++14
1740b57cec5SDimitry Andric    size_type erase(const key_type& k);
1750b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
1760b57cec5SDimitry Andric    void clear() noexcept;
1770b57cec5SDimitry Andric
1780b57cec5SDimitry Andric    template<class C2>
1790b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>& source);         // C++17
1800b57cec5SDimitry Andric    template<class C2>
1810b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>&& source);        // C++17
1820b57cec5SDimitry Andric    template<class C2>
1830b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>& source);    // C++17
1840b57cec5SDimitry Andric    template<class C2>
1850b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>&& source);   // C++17
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric    void swap(map& m)
1880b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
1890b57cec5SDimitry Andric            is_nothrow_swappable<key_compare>::value); // C++17
1900b57cec5SDimitry Andric
1910b57cec5SDimitry Andric    // observers:
1920b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
1930b57cec5SDimitry Andric    key_compare    key_comp()      const;
1940b57cec5SDimitry Andric    value_compare  value_comp()    const;
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric    // map operations:
1970b57cec5SDimitry Andric          iterator find(const key_type& k);
1980b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
1990b57cec5SDimitry Andric    template<typename K>
2000b57cec5SDimitry Andric        iterator find(const K& x);              // C++14
2010b57cec5SDimitry Andric    template<typename K>
2020b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
203fe6060f1SDimitry Andric
2040b57cec5SDimitry Andric    template<typename K>
2050b57cec5SDimitry Andric      size_type count(const K& x) const;        // C++14
2060b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
207fe6060f1SDimitry Andric
2080b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
209fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
210fe6060f1SDimitry Andric
2110b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
2120b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
2130b57cec5SDimitry Andric    template<typename K>
2140b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
2150b57cec5SDimitry Andric    template<typename K>
2160b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
2190b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
2200b57cec5SDimitry Andric    template<typename K>
2210b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
2220b57cec5SDimitry Andric    template<typename K>
2230b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
2260b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
2270b57cec5SDimitry Andric    template<typename K>
2280b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
2290b57cec5SDimitry Andric    template<typename K>
2300b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
2310b57cec5SDimitry Andric};
2320b57cec5SDimitry Andric
233349cc55cSDimitry Andrictemplate <class InputIterator,
234349cc55cSDimitry Andric      class Compare = less<iter_key_t<InputIterator>>,
235349cc55cSDimitry Andric      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
236349cc55cSDimitry Andricmap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
237349cc55cSDimitry Andric  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
238349cc55cSDimitry Andric
239fe013be4SDimitry Andrictemplate<ranges::input_range R, class Compare = less<range-key-type<R>,
240fe013be4SDimitry Andric         class Allocator = allocator<range-to-alloc-type<R>>>
241fe013be4SDimitry Andric  map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
242fe013be4SDimitry Andric    -> map<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23
243fe013be4SDimitry Andric
244349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>,
245349cc55cSDimitry Andric    class Allocator = allocator<pair<const Key, T>>>
246349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
247349cc55cSDimitry Andric  -> map<Key, T, Compare, Allocator>; // C++17
248349cc55cSDimitry Andric
249349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator>
250349cc55cSDimitry Andricmap(InputIterator, InputIterator, Allocator)
251349cc55cSDimitry Andric  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>,
252349cc55cSDimitry Andric    Allocator>; // C++17
253349cc55cSDimitry Andric
254fe013be4SDimitry Andrictemplate<ranges::input_range R, class Allocator>
255fe013be4SDimitry Andric  map(from_range_t, R&&, Allocator)
256fe013be4SDimitry Andric    -> map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23
257fe013be4SDimitry Andric
258349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator>
259349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17
260349cc55cSDimitry Andric
2610b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2620b57cec5SDimitry Andricbool
2630b57cec5SDimitry Andricoperator==(const map<Key, T, Compare, Allocator>& x,
2640b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2650b57cec5SDimitry Andric
2660b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2670b57cec5SDimitry Andricbool
2680b57cec5SDimitry Andricoperator< (const map<Key, T, Compare, Allocator>& x,
269fe013be4SDimitry Andric           const map<Key, T, Compare, Allocator>& y);      // removed in C++20
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2720b57cec5SDimitry Andricbool
2730b57cec5SDimitry Andricoperator!=(const map<Key, T, Compare, Allocator>& x,
274fe013be4SDimitry Andric           const map<Key, T, Compare, Allocator>& y);      // removed in C++20
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2770b57cec5SDimitry Andricbool
2780b57cec5SDimitry Andricoperator> (const map<Key, T, Compare, Allocator>& x,
279fe013be4SDimitry Andric           const map<Key, T, Compare, Allocator>& y);      // removed in C++20
2800b57cec5SDimitry Andric
2810b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2820b57cec5SDimitry Andricbool
2830b57cec5SDimitry Andricoperator>=(const map<Key, T, Compare, Allocator>& x,
284fe013be4SDimitry Andric           const map<Key, T, Compare, Allocator>& y);      // removed in C++20
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2870b57cec5SDimitry Andricbool
2880b57cec5SDimitry Andricoperator<=(const map<Key, T, Compare, Allocator>& x,
289fe013be4SDimitry Andric           const map<Key, T, Compare, Allocator>& y);      // removed in C++20
290fe013be4SDimitry Andric
291fe013be4SDimitry Andrictemplate<class Key, class T, class Compare, class Allocator>
292fe013be4SDimitry Andric  synth-three-way-result<pair<const Key, T>>
293fe013be4SDimitry Andric    operator<=>(const map<Key, T, Compare, Allocator>& x,
294fe013be4SDimitry Andric                const map<Key, T, Compare, Allocator>& y); // since C++20
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andric// specialized algorithms:
2970b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2980b57cec5SDimitry Andricvoid
2990b57cec5SDimitry Andricswap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
3000b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
3010b57cec5SDimitry Andric
3020b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate>
3035ffd83dbSDimitry Andrictypename map<Key, T, Compare, Allocator>::size_type
3045ffd83dbSDimitry Andricerase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andrictemplate <class Key, class T, class Compare = less<Key>,
3080b57cec5SDimitry Andric          class Allocator = allocator<pair<const Key, T>>>
3090b57cec5SDimitry Andricclass multimap
3100b57cec5SDimitry Andric{
3110b57cec5SDimitry Andricpublic:
3120b57cec5SDimitry Andric    // types:
3130b57cec5SDimitry Andric    typedef Key                                      key_type;
3140b57cec5SDimitry Andric    typedef T                                        mapped_type;
3150b57cec5SDimitry Andric    typedef pair<const key_type,mapped_type>         value_type;
3160b57cec5SDimitry Andric    typedef Compare                                  key_compare;
3170b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
3180b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
3190b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
3200b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
3210b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
3220b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
3230b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
3240b57cec5SDimitry Andric
3250b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
3260b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
3270b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
3280b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
3290b57cec5SDimitry Andric    typedef unspecified                              node_type;              // C++17
3300b57cec5SDimitry Andric
3310b57cec5SDimitry Andric    class value_compare
3320b57cec5SDimitry Andric    {
3330b57cec5SDimitry Andric        friend class multimap;
3340b57cec5SDimitry Andric    protected:
3350b57cec5SDimitry Andric        key_compare comp;
3360b57cec5SDimitry Andric        value_compare(key_compare c);
3370b57cec5SDimitry Andric    public:
338fe6060f1SDimitry Andric        typedef bool result_type;  // deprecated in C++17, removed in C++20
339fe6060f1SDimitry Andric        typedef value_type first_argument_type;  // deprecated in C++17, removed in C++20
340fe6060f1SDimitry Andric        typedef value_type second_argument_type;  // deprecated in C++17, removed in C++20
3410b57cec5SDimitry Andric        bool operator()(const value_type& x, const value_type& y) const;
3420b57cec5SDimitry Andric    };
3430b57cec5SDimitry Andric
3440b57cec5SDimitry Andric    // construct/copy/destroy:
3450b57cec5SDimitry Andric    multimap()
3460b57cec5SDimitry Andric        noexcept(
3470b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
3480b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
3490b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value);
3500b57cec5SDimitry Andric    explicit multimap(const key_compare& comp);
3510b57cec5SDimitry Andric    multimap(const key_compare& comp, const allocator_type& a);
3520b57cec5SDimitry Andric    template <class InputIterator>
3530b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const key_compare& comp);
3540b57cec5SDimitry Andric    template <class InputIterator>
3550b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const key_compare& comp,
3560b57cec5SDimitry Andric                 const allocator_type& a);
357fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
358fe013be4SDimitry Andric      multimap(from_range_t, R&& rg,
359fe013be4SDimitry Andric               const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
3600b57cec5SDimitry Andric    multimap(const multimap& m);
3610b57cec5SDimitry Andric    multimap(multimap&& m)
3620b57cec5SDimitry Andric        noexcept(
3630b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
3640b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
3650b57cec5SDimitry Andric    explicit multimap(const allocator_type& a);
3660b57cec5SDimitry Andric    multimap(const multimap& m, const allocator_type& a);
3670b57cec5SDimitry Andric    multimap(multimap&& m, const allocator_type& a);
3680b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
3690b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const key_compare& comp,
3700b57cec5SDimitry Andric             const allocator_type& a);
3710b57cec5SDimitry Andric    template <class InputIterator>
3720b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const allocator_type& a)
3730b57cec5SDimitry Andric            : multimap(first, last, Compare(), a) {} // C++14
374fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
375fe013be4SDimitry Andric      multimap(from_range_t, R&& rg, const Allocator& a))
376fe013be4SDimitry Andric        : multimap(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
3770b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const allocator_type& a)
3780b57cec5SDimitry Andric        : multimap(il, Compare(), a) {} // C++14
3790b57cec5SDimitry Andric    ~multimap();
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andric    multimap& operator=(const multimap& m);
3820b57cec5SDimitry Andric    multimap& operator=(multimap&& m)
3830b57cec5SDimitry Andric        noexcept(
3840b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
3850b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
3860b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
3870b57cec5SDimitry Andric    multimap& operator=(initializer_list<value_type> il);
3880b57cec5SDimitry Andric
3890b57cec5SDimitry Andric    // iterators:
3900b57cec5SDimitry Andric          iterator begin() noexcept;
3910b57cec5SDimitry Andric    const_iterator begin() const noexcept;
3920b57cec5SDimitry Andric          iterator end() noexcept;
3930b57cec5SDimitry Andric    const_iterator end()   const noexcept;
3940b57cec5SDimitry Andric
3950b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
3960b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
3970b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
3980b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
3990b57cec5SDimitry Andric
4000b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
4010b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
4020b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
4030b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric    // capacity:
4060b57cec5SDimitry Andric    bool      empty()    const noexcept;
4070b57cec5SDimitry Andric    size_type size()     const noexcept;
4080b57cec5SDimitry Andric    size_type max_size() const noexcept;
4090b57cec5SDimitry Andric
4100b57cec5SDimitry Andric    // modifiers:
4110b57cec5SDimitry Andric    template <class... Args>
4120b57cec5SDimitry Andric        iterator emplace(Args&&... args);
4130b57cec5SDimitry Andric    template <class... Args>
4140b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
4150b57cec5SDimitry Andric    iterator insert(const value_type& v);
4160b57cec5SDimitry Andric    iterator insert(      value_type&& v);                                            // C++17
4170b57cec5SDimitry Andric    template <class P>
4180b57cec5SDimitry Andric        iterator insert(P&& p);
4190b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
4200b57cec5SDimitry Andric    iterator insert(const_iterator position,       value_type&& v);                   // C++17
4210b57cec5SDimitry Andric    template <class P>
4220b57cec5SDimitry Andric        iterator insert(const_iterator position, P&& p);
4230b57cec5SDimitry Andric    template <class InputIterator>
4240b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
425fe013be4SDimitry Andric    template<container-compatible-range<value_type> R>
426fe013be4SDimitry Andric      void insert_range(R&& rg);                                                      // C++23
4270b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
4300b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
4310b57cec5SDimitry Andric    iterator insert(node_type&& nh);                                                  // C++17
4320b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
4330b57cec5SDimitry Andric
4340b57cec5SDimitry Andric    iterator  erase(const_iterator position);
4350b57cec5SDimitry Andric    iterator  erase(iterator position); // C++14
4360b57cec5SDimitry Andric    size_type erase(const key_type& k);
4370b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
4380b57cec5SDimitry Andric    void clear() noexcept;
4390b57cec5SDimitry Andric
4400b57cec5SDimitry Andric    template<class C2>
4410b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>& source);    // C++17
4420b57cec5SDimitry Andric    template<class C2>
4430b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>&& source);   // C++17
4440b57cec5SDimitry Andric    template<class C2>
4450b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>& source);         // C++17
4460b57cec5SDimitry Andric    template<class C2>
4470b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>&& source);        // C++17
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andric    void swap(multimap& m)
4500b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
4510b57cec5SDimitry Andric            is_nothrow_swappable<key_compare>::value); // C++17
4520b57cec5SDimitry Andric
4530b57cec5SDimitry Andric    // observers:
4540b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
4550b57cec5SDimitry Andric    key_compare    key_comp()      const;
4560b57cec5SDimitry Andric    value_compare  value_comp()    const;
4570b57cec5SDimitry Andric
4580b57cec5SDimitry Andric    // map operations:
4590b57cec5SDimitry Andric          iterator find(const key_type& k);
4600b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
4610b57cec5SDimitry Andric    template<typename K>
4620b57cec5SDimitry Andric        iterator find(const K& x);              // C++14
4630b57cec5SDimitry Andric    template<typename K>
4640b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
465fe6060f1SDimitry Andric
4660b57cec5SDimitry Andric    template<typename K>
4670b57cec5SDimitry Andric      size_type count(const K& x) const;        // C++14
4680b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
469fe6060f1SDimitry Andric
4700b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
471fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
472fe6060f1SDimitry Andric
4730b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
4740b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
4750b57cec5SDimitry Andric    template<typename K>
4760b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
4770b57cec5SDimitry Andric    template<typename K>
4780b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
4810b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
4820b57cec5SDimitry Andric    template<typename K>
4830b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
4840b57cec5SDimitry Andric    template<typename K>
4850b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
4860b57cec5SDimitry Andric
4870b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
4880b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
4890b57cec5SDimitry Andric    template<typename K>
4900b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
4910b57cec5SDimitry Andric    template<typename K>
4920b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
4930b57cec5SDimitry Andric};
4940b57cec5SDimitry Andric
495349cc55cSDimitry Andrictemplate <class InputIterator,
496349cc55cSDimitry Andric      class Compare = less<iter_key_t<InputIterator>>,
497349cc55cSDimitry Andric      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
498349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
499349cc55cSDimitry Andric  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
500349cc55cSDimitry Andric
501fe013be4SDimitry Andrictemplate<ranges::input_range R, class Compare = less<range-key-type<R>>,
502fe013be4SDimitry Andric          class Allocator = allocator<range-to-alloc-type<R>>>
503fe013be4SDimitry Andric  multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
504fe013be4SDimitry Andric    -> multimap<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23
505fe013be4SDimitry Andric
506349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>,
507349cc55cSDimitry Andric    class Allocator = allocator<pair<const Key, T>>>
508349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
509349cc55cSDimitry Andric  -> multimap<Key, T, Compare, Allocator>; // C++17
510349cc55cSDimitry Andric
511349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator>
512349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Allocator)
513349cc55cSDimitry Andric  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
514349cc55cSDimitry Andric    less<iter_key_t<InputIterator>>, Allocator>; // C++17
515349cc55cSDimitry Andric
516fe013be4SDimitry Andrictemplate<ranges::input_range R, class Allocator>
517fe013be4SDimitry Andric  multimap(from_range_t, R&&, Allocator)
518fe013be4SDimitry Andric    -> multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23
519fe013be4SDimitry Andric
520349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator>
521349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Allocator)
522349cc55cSDimitry Andric  -> multimap<Key, T, less<Key>, Allocator>; // C++17
523349cc55cSDimitry Andric
5240b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5250b57cec5SDimitry Andricbool
5260b57cec5SDimitry Andricoperator==(const multimap<Key, T, Compare, Allocator>& x,
5270b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5300b57cec5SDimitry Andricbool
5310b57cec5SDimitry Andricoperator< (const multimap<Key, T, Compare, Allocator>& x,
532fe013be4SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);      // removed in C++20
5330b57cec5SDimitry Andric
5340b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5350b57cec5SDimitry Andricbool
5360b57cec5SDimitry Andricoperator!=(const multimap<Key, T, Compare, Allocator>& x,
537fe013be4SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);      // removed in C++20
5380b57cec5SDimitry Andric
5390b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5400b57cec5SDimitry Andricbool
5410b57cec5SDimitry Andricoperator> (const multimap<Key, T, Compare, Allocator>& x,
542fe013be4SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);      // removed in C++20
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5450b57cec5SDimitry Andricbool
5460b57cec5SDimitry Andricoperator>=(const multimap<Key, T, Compare, Allocator>& x,
547fe013be4SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);      // removed in C++20
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5500b57cec5SDimitry Andricbool
5510b57cec5SDimitry Andricoperator<=(const multimap<Key, T, Compare, Allocator>& x,
552fe013be4SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);      // removed in C++20
553fe013be4SDimitry Andric
554fe013be4SDimitry Andrictemplate<class Key, class T, class Compare, class Allocator>
555fe013be4SDimitry Andric  synth-three-way-result<pair<const Key, T>>
556fe013be4SDimitry Andric    operator<=>(const multimap<Key, T, Compare, Allocator>& x,
557fe013be4SDimitry Andric                const multimap<Key, T, Compare, Allocator>& y); // since c++20
5580b57cec5SDimitry Andric
5590b57cec5SDimitry Andric// specialized algorithms:
5600b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5610b57cec5SDimitry Andricvoid
5620b57cec5SDimitry Andricswap(multimap<Key, T, Compare, Allocator>& x,
5630b57cec5SDimitry Andric     multimap<Key, T, Compare, Allocator>& y)
5640b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate>
5675ffd83dbSDimitry Andrictypename multimap<Key, T, Compare, Allocator>::size_type
5685ffd83dbSDimitry Andricerase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
5690b57cec5SDimitry Andric
5700b57cec5SDimitry Andric}  // std
5710b57cec5SDimitry Andric
5720b57cec5SDimitry Andric*/
5730b57cec5SDimitry Andric
57481ad6265SDimitry Andric#include <__algorithm/equal.h>
57581ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
576fe013be4SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h>
57781ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
578fe013be4SDimitry Andric#include <__availability>
5790b57cec5SDimitry Andric#include <__config>
58081ad6265SDimitry Andric#include <__functional/binary_function.h>
581fe6060f1SDimitry Andric#include <__functional/is_transparent.h>
58281ad6265SDimitry Andric#include <__functional/operations.h>
58381ad6265SDimitry Andric#include <__iterator/erase_if_container.h>
584349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
585fe013be4SDimitry Andric#include <__iterator/ranges_iterator_traits.h>
58681ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
587fe013be4SDimitry Andric#include <__memory/addressof.h>
588bdd1243dSDimitry Andric#include <__memory/allocator.h>
589bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h>
5900b57cec5SDimitry Andric#include <__node_handle>
591fe013be4SDimitry Andric#include <__ranges/concepts.h>
592fe013be4SDimitry Andric#include <__ranges/container_compatible_range.h>
593fe013be4SDimitry Andric#include <__ranges/from_range.h>
594fe6060f1SDimitry Andric#include <__tree>
595bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h>
596fe6060f1SDimitry Andric#include <__utility/forward.h>
597bdd1243dSDimitry Andric#include <__utility/piecewise_construct.h>
59881ad6265SDimitry Andric#include <__utility/swap.h>
599c9157d92SDimitry Andric#include <stdexcept>
600bdd1243dSDimitry Andric#include <tuple>
6010b57cec5SDimitry Andric#include <version>
6020b57cec5SDimitry Andric
60381ad6265SDimitry Andric// standard-mandated includes
60481ad6265SDimitry Andric
60581ad6265SDimitry Andric// [iterator.range]
60681ad6265SDimitry Andric#include <__iterator/access.h>
60781ad6265SDimitry Andric#include <__iterator/data.h>
60881ad6265SDimitry Andric#include <__iterator/empty.h>
60981ad6265SDimitry Andric#include <__iterator/reverse_access.h>
61081ad6265SDimitry Andric#include <__iterator/size.h>
61181ad6265SDimitry Andric
61281ad6265SDimitry Andric// [associative.map.syn]
61381ad6265SDimitry Andric#include <compare>
61481ad6265SDimitry Andric#include <initializer_list>
61581ad6265SDimitry Andric
6160b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6170b57cec5SDimitry Andric#  pragma GCC system_header
6180b57cec5SDimitry Andric#endif
6190b57cec5SDimitry Andric
620*b9d9368bSDimitry Andric_LIBCPP_PUSH_MACROS
621*b9d9368bSDimitry Andric#include <__undef_macros>
622*b9d9368bSDimitry Andric
6230b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
6240b57cec5SDimitry Andric
625e710425bSDimitry Andrictemplate <class _Key,
626e710425bSDimitry Andric          class _CP,
627e710425bSDimitry Andric          class _Compare,
6280b57cec5SDimitry Andric          bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
629e710425bSDimitry Andricclass __map_value_compare : private _Compare {
6300b57cec5SDimitry Andricpublic:
631e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
6320b57cec5SDimitry Andric      : _Compare() {}
633e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
634753f127fSDimitry Andric      : _Compare(__c) {}
635e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return *this; }
636e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
637e710425bSDimitry Andric    return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);
638e710425bSDimitry Andric  }
639e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
640e710425bSDimitry Andric    return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
641e710425bSDimitry Andric  }
642e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
643e710425bSDimitry Andric    return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
644e710425bSDimitry Andric  }
645e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) {
646c9157d92SDimitry Andric    using std::swap;
6470b57cec5SDimitry Andric    swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
6480b57cec5SDimitry Andric  }
6490b57cec5SDimitry Andric
650fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
6510b57cec5SDimitry Andric  template <typename _K2>
652e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
653e710425bSDimitry Andric    return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);
654e710425bSDimitry Andric  }
6550b57cec5SDimitry Andric
6560b57cec5SDimitry Andric  template <typename _K2>
657e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
658e710425bSDimitry Andric    return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);
659e710425bSDimitry Andric  }
6600b57cec5SDimitry Andric#endif
6610b57cec5SDimitry Andric};
6620b57cec5SDimitry Andric
6630b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare>
664e710425bSDimitry Andricclass __map_value_compare<_Key, _CP, _Compare, false> {
665bdd1243dSDimitry Andric  _Compare __comp_;
6660b57cec5SDimitry Andric
6670b57cec5SDimitry Andricpublic:
668e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_value_compare() _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
669bdd1243dSDimitry Andric      : __comp_() {}
670e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_value_compare(_Compare __c) _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
671bdd1243dSDimitry Andric      : __comp_(__c) {}
672e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const _Compare& key_comp() const _NOEXCEPT { return __comp_; }
6730b57cec5SDimitry Andric
674e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _CP& __y) const {
675e710425bSDimitry Andric    return __comp_(__x.__get_value().first, __y.__get_value().first);
676e710425bSDimitry Andric  }
677e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _Key& __y) const {
678e710425bSDimitry Andric    return __comp_(__x.__get_value().first, __y);
679e710425bSDimitry Andric  }
680e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _Key& __x, const _CP& __y) const {
681e710425bSDimitry Andric    return __comp_(__x, __y.__get_value().first);
682e710425bSDimitry Andric  }
683e710425bSDimitry Andric  void swap(__map_value_compare& __y) _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) {
684c9157d92SDimitry Andric    using std::swap;
685bdd1243dSDimitry Andric    swap(__comp_, __y.__comp_);
6860b57cec5SDimitry Andric  }
6870b57cec5SDimitry Andric
688fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
6890b57cec5SDimitry Andric  template <typename _K2>
690e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _K2& __x, const _CP& __y) const {
691e710425bSDimitry Andric    return __comp_(__x, __y.__get_value().first);
692e710425bSDimitry Andric  }
6930b57cec5SDimitry Andric
6940b57cec5SDimitry Andric  template <typename _K2>
695e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator()(const _CP& __x, const _K2& __y) const {
696e710425bSDimitry Andric    return __comp_(__x.__get_value().first, __y);
697e710425bSDimitry Andric  }
6980b57cec5SDimitry Andric#endif
6990b57cec5SDimitry Andric};
7000b57cec5SDimitry Andric
7010b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare, bool __b>
702e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
703e710425bSDimitry Andricswap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, __map_value_compare<_Key, _CP, _Compare, __b>& __y)
704e710425bSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
7050b57cec5SDimitry Andric  __x.swap(__y);
7060b57cec5SDimitry Andric}
7070b57cec5SDimitry Andric
7080b57cec5SDimitry Andrictemplate <class _Allocator>
709e710425bSDimitry Andricclass __map_node_destructor {
7100b57cec5SDimitry Andric  typedef _Allocator allocator_type;
7110b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
7120b57cec5SDimitry Andric
7130b57cec5SDimitry Andricpublic:
7140b57cec5SDimitry Andric  typedef typename __alloc_traits::pointer pointer;
7150b57cec5SDimitry Andric
7160b57cec5SDimitry Andricprivate:
7170b57cec5SDimitry Andric  allocator_type& __na_;
7180b57cec5SDimitry Andric
7190b57cec5SDimitry Andric  __map_node_destructor& operator=(const __map_node_destructor&);
7200b57cec5SDimitry Andric
7210b57cec5SDimitry Andricpublic:
7220b57cec5SDimitry Andric  bool __first_constructed;
7230b57cec5SDimitry Andric  bool __second_constructed;
7240b57cec5SDimitry Andric
725e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
7260b57cec5SDimitry Andric      : __na_(__na),
7270b57cec5SDimitry Andric        __first_constructed(false),
728e710425bSDimitry Andric        __second_constructed(false) {}
7290b57cec5SDimitry Andric
7300b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
731e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
7320b57cec5SDimitry Andric      : __na_(__x.__na_),
7330b57cec5SDimitry Andric        __first_constructed(__x.__value_constructed),
734e710425bSDimitry Andric        __second_constructed(__x.__value_constructed) {
7350b57cec5SDimitry Andric    __x.__value_constructed = false;
7360b57cec5SDimitry Andric  }
7370b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7380b57cec5SDimitry Andric
739e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT {
7400b57cec5SDimitry Andric    if (__second_constructed)
741c9157d92SDimitry Andric      __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().second));
7420b57cec5SDimitry Andric    if (__first_constructed)
743c9157d92SDimitry Andric      __alloc_traits::destroy(__na_, std::addressof(__p->__value_.__get_value().first));
7440b57cec5SDimitry Andric    if (__p)
7450b57cec5SDimitry Andric      __alloc_traits::deallocate(__na_, __p, 1);
7460b57cec5SDimitry Andric  }
7470b57cec5SDimitry Andric};
7480b57cec5SDimitry Andric
7490b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
7500b57cec5SDimitry Andricclass map;
7510b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
7520b57cec5SDimitry Andricclass multimap;
753e710425bSDimitry Andrictemplate <class _TreeIterator>
754e710425bSDimitry Andricclass __map_const_iterator;
7550b57cec5SDimitry Andric
7560b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7570b57cec5SDimitry Andric
7580b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
759e710425bSDimitry Andricstruct _LIBCPP_STANDALONE_DEBUG __value_type {
7600b57cec5SDimitry Andric  typedef _Key key_type;
7610b57cec5SDimitry Andric  typedef _Tp mapped_type;
7620b57cec5SDimitry Andric  typedef pair<const key_type, mapped_type> value_type;
7630b57cec5SDimitry Andric  typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
7640b57cec5SDimitry Andric  typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
7650b57cec5SDimitry Andric
7660b57cec5SDimitry Andricprivate:
767bdd1243dSDimitry Andric  value_type __cc_;
7680b57cec5SDimitry Andric
7690b57cec5SDimitry Andricpublic:
770e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_type& __get_value() {
771fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 17
772c9157d92SDimitry Andric    return *std::launder(std::addressof(__cc_));
7730b57cec5SDimitry Andric#  else
774bdd1243dSDimitry Andric    return __cc_;
7750b57cec5SDimitry Andric#  endif
7760b57cec5SDimitry Andric  }
7770b57cec5SDimitry Andric
778e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const {
779fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 17
780c9157d92SDimitry Andric    return *std::launder(std::addressof(__cc_));
7810b57cec5SDimitry Andric#  else
782bdd1243dSDimitry Andric    return __cc_;
7830b57cec5SDimitry Andric#  endif
7840b57cec5SDimitry Andric  }
7850b57cec5SDimitry Andric
786e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __nc_ref_pair_type __ref() {
7870b57cec5SDimitry Andric    value_type& __v = __get_value();
7880b57cec5SDimitry Andric    return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
7890b57cec5SDimitry Andric  }
7900b57cec5SDimitry Andric
791e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __nc_rref_pair_type __move() {
7920b57cec5SDimitry Andric    value_type& __v = __get_value();
793e710425bSDimitry Andric    return __nc_rref_pair_type(std::move(const_cast<key_type&>(__v.first)), std::move(__v.second));
7940b57cec5SDimitry Andric  }
7950b57cec5SDimitry Andric
796e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __value_type& operator=(const __value_type& __v) {
7970b57cec5SDimitry Andric    __ref() = __v.__get_value();
7980b57cec5SDimitry Andric    return *this;
7990b57cec5SDimitry Andric  }
8000b57cec5SDimitry Andric
801e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __value_type& operator=(__value_type&& __v) {
8020b57cec5SDimitry Andric    __ref() = __v.__move();
8030b57cec5SDimitry Andric    return *this;
8040b57cec5SDimitry Andric  }
8050b57cec5SDimitry Andric
806e710425bSDimitry Andric  template <class _ValueTp, class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value> >
807e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __value_type& operator=(_ValueTp&& __v) {
808c9157d92SDimitry Andric    __ref() = std::forward<_ValueTp>(__v);
8090b57cec5SDimitry Andric    return *this;
8100b57cec5SDimitry Andric  }
8110b57cec5SDimitry Andric
8120b57cec5SDimitry Andricprivate:
813349cc55cSDimitry Andric  __value_type()                    = delete;
814349cc55cSDimitry Andric  ~__value_type()                   = delete;
815349cc55cSDimitry Andric  __value_type(const __value_type&) = delete;
816349cc55cSDimitry Andric  __value_type(__value_type&&)      = delete;
8170b57cec5SDimitry Andric};
8180b57cec5SDimitry Andric
8190b57cec5SDimitry Andric#else
8200b57cec5SDimitry Andric
8210b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
822e710425bSDimitry Andricstruct __value_type {
8230b57cec5SDimitry Andric  typedef _Key key_type;
8240b57cec5SDimitry Andric  typedef _Tp mapped_type;
8250b57cec5SDimitry Andric  typedef pair<const key_type, mapped_type> value_type;
8260b57cec5SDimitry Andric
8270b57cec5SDimitry Andricprivate:
828bdd1243dSDimitry Andric  value_type __cc_;
8290b57cec5SDimitry Andric
8300b57cec5SDimitry Andricpublic:
831e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_type& __get_value() { return __cc_; }
832e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const value_type& __get_value() const { return __cc_; }
8330b57cec5SDimitry Andric
8340b57cec5SDimitry Andricprivate:
8350b57cec5SDimitry Andric  __value_type();
8360b57cec5SDimitry Andric  __value_type(__value_type const&);
8370b57cec5SDimitry Andric  __value_type& operator=(__value_type const&);
8380b57cec5SDimitry Andric  ~__value_type();
8390b57cec5SDimitry Andric};
8400b57cec5SDimitry Andric
8410b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8420b57cec5SDimitry Andric
8430b57cec5SDimitry Andrictemplate <class _Tp>
8440b57cec5SDimitry Andricstruct __extract_key_value_types;
8450b57cec5SDimitry Andric
8460b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
847e710425bSDimitry Andricstruct __extract_key_value_types<__value_type<_Key, _Tp> > {
8480b57cec5SDimitry Andric  typedef _Key const __key_type;
8490b57cec5SDimitry Andric  typedef _Tp __mapped_type;
8500b57cec5SDimitry Andric};
8510b57cec5SDimitry Andric
8520b57cec5SDimitry Andrictemplate <class _TreeIterator>
853e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_iterator {
8540b57cec5SDimitry Andric  typedef typename _TreeIterator::_NodeTypes _NodeTypes;
8550b57cec5SDimitry Andric  typedef typename _TreeIterator::__pointer_traits __pointer_traits;
8560b57cec5SDimitry Andric
8570b57cec5SDimitry Andric  _TreeIterator __i_;
8580b57cec5SDimitry Andric
8590b57cec5SDimitry Andricpublic:
8600b57cec5SDimitry Andric  typedef bidirectional_iterator_tag iterator_category;
8610b57cec5SDimitry Andric  typedef typename _NodeTypes::__map_value_type value_type;
8620b57cec5SDimitry Andric  typedef typename _TreeIterator::difference_type difference_type;
8630b57cec5SDimitry Andric  typedef value_type& reference;
8640b57cec5SDimitry Andric  typedef typename _NodeTypes::__map_value_type_pointer pointer;
8650b57cec5SDimitry Andric
866e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator() _NOEXCEPT {}
8670b57cec5SDimitry Andric
868e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
8690b57cec5SDimitry Andric
870e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
871e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
8720b57cec5SDimitry Andric
873e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator& operator++() {
874e710425bSDimitry Andric    ++__i_;
875e710425bSDimitry Andric    return *this;
876e710425bSDimitry Andric  }
877e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator operator++(int) {
8780b57cec5SDimitry Andric    __map_iterator __t(*this);
8790b57cec5SDimitry Andric    ++(*this);
8800b57cec5SDimitry Andric    return __t;
8810b57cec5SDimitry Andric  }
8820b57cec5SDimitry Andric
883e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator& operator--() {
884e710425bSDimitry Andric    --__i_;
885e710425bSDimitry Andric    return *this;
886e710425bSDimitry Andric  }
887e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_iterator operator--(int) {
8880b57cec5SDimitry Andric    __map_iterator __t(*this);
8890b57cec5SDimitry Andric    --(*this);
8900b57cec5SDimitry Andric    return __t;
8910b57cec5SDimitry Andric  }
8920b57cec5SDimitry Andric
893e710425bSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_iterator& __x, const __map_iterator& __y) {
894e710425bSDimitry Andric    return __x.__i_ == __y.__i_;
895e710425bSDimitry Andric  }
896e710425bSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_iterator& __x, const __map_iterator& __y) {
897e710425bSDimitry Andric    return __x.__i_ != __y.__i_;
898e710425bSDimitry Andric  }
8990b57cec5SDimitry Andric
900e710425bSDimitry Andric  template <class, class, class, class>
901e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS map;
902e710425bSDimitry Andric  template <class, class, class, class>
903e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multimap;
904e710425bSDimitry Andric  template <class>
905e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
9060b57cec5SDimitry Andric};
9070b57cec5SDimitry Andric
9080b57cec5SDimitry Andrictemplate <class _TreeIterator>
909e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_const_iterator {
9100b57cec5SDimitry Andric  typedef typename _TreeIterator::_NodeTypes _NodeTypes;
9110b57cec5SDimitry Andric  typedef typename _TreeIterator::__pointer_traits __pointer_traits;
9120b57cec5SDimitry Andric
9130b57cec5SDimitry Andric  _TreeIterator __i_;
9140b57cec5SDimitry Andric
9150b57cec5SDimitry Andricpublic:
9160b57cec5SDimitry Andric  typedef bidirectional_iterator_tag iterator_category;
9170b57cec5SDimitry Andric  typedef typename _NodeTypes::__map_value_type value_type;
9180b57cec5SDimitry Andric  typedef typename _TreeIterator::difference_type difference_type;
9190b57cec5SDimitry Andric  typedef const value_type& reference;
9200b57cec5SDimitry Andric  typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
9210b57cec5SDimitry Andric
922e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator() _NOEXCEPT {}
9230b57cec5SDimitry Andric
924e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
925c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
926e710425bSDimitry Andric  __map_const_iterator(__map_iterator< typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT : __i_(__i.__i_) {}
9270b57cec5SDimitry Andric
928e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __i_->__get_value(); }
929e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return pointer_traits<pointer>::pointer_to(__i_->__get_value()); }
9300b57cec5SDimitry Andric
931e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator++() {
932e710425bSDimitry Andric    ++__i_;
933e710425bSDimitry Andric    return *this;
934e710425bSDimitry Andric  }
935e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator++(int) {
9360b57cec5SDimitry Andric    __map_const_iterator __t(*this);
9370b57cec5SDimitry Andric    ++(*this);
9380b57cec5SDimitry Andric    return __t;
9390b57cec5SDimitry Andric  }
9400b57cec5SDimitry Andric
941e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator& operator--() {
942e710425bSDimitry Andric    --__i_;
943e710425bSDimitry Andric    return *this;
944e710425bSDimitry Andric  }
945e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __map_const_iterator operator--(int) {
9460b57cec5SDimitry Andric    __map_const_iterator __t(*this);
9470b57cec5SDimitry Andric    --(*this);
9480b57cec5SDimitry Andric    return __t;
9490b57cec5SDimitry Andric  }
9500b57cec5SDimitry Andric
951e710425bSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y) {
952e710425bSDimitry Andric    return __x.__i_ == __y.__i_;
953e710425bSDimitry Andric  }
954e710425bSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y) {
955e710425bSDimitry Andric    return __x.__i_ != __y.__i_;
956e710425bSDimitry Andric  }
9570b57cec5SDimitry Andric
958e710425bSDimitry Andric  template <class, class, class, class>
959e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS map;
960e710425bSDimitry Andric  template <class, class, class, class>
961e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multimap;
962e710425bSDimitry Andric  template <class, class, class>
963e710425bSDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
9640b57cec5SDimitry Andric};
9650b57cec5SDimitry Andric
966e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
967e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS map {
9680b57cec5SDimitry Andricpublic:
9690b57cec5SDimitry Andric  // types:
9700b57cec5SDimitry Andric  typedef _Key key_type;
9710b57cec5SDimitry Andric  typedef _Tp mapped_type;
9720b57cec5SDimitry Andric  typedef pair<const key_type, mapped_type> value_type;
97381ad6265SDimitry Andric  typedef __type_identity_t<_Compare> key_compare;
97481ad6265SDimitry Andric  typedef __type_identity_t<_Allocator> allocator_type;
9750b57cec5SDimitry Andric  typedef value_type& reference;
9760b57cec5SDimitry Andric  typedef const value_type& const_reference;
9770b57cec5SDimitry Andric
9780b57cec5SDimitry Andric  static_assert((is_same<typename allocator_type::value_type, value_type>::value),
9790b57cec5SDimitry Andric                "Allocator::value_type must be same type as value_type");
9800b57cec5SDimitry Andric
981e710425bSDimitry Andric  class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
9820b57cec5SDimitry Andric    friend class map;
983e710425bSDimitry Andric
9840b57cec5SDimitry Andric  protected:
9850b57cec5SDimitry Andric    key_compare comp;
9860b57cec5SDimitry Andric
987c9157d92SDimitry Andric    _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : comp(__c) {}
988e710425bSDimitry Andric
9890b57cec5SDimitry Andric  public:
990e710425bSDimitry Andric    _LIBCPP_HIDE_FROM_ABI bool operator()(const value_type& __x, const value_type& __y) const {
991e710425bSDimitry Andric      return comp(__x.first, __y.first);
992e710425bSDimitry Andric    }
9930b57cec5SDimitry Andric  };
9940b57cec5SDimitry Andric
9950b57cec5SDimitry Andricprivate:
996c9157d92SDimitry Andric  typedef std::__value_type<key_type, mapped_type> __value_type;
9970b57cec5SDimitry Andric  typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
998bdd1243dSDimitry Andric  typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
9990b57cec5SDimitry Andric  typedef __tree<__value_type, __vc, __allocator_type> __base;
10000b57cec5SDimitry Andric  typedef typename __base::__node_traits __node_traits;
10010b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
10020b57cec5SDimitry Andric
1003bdd1243dSDimitry Andric  static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
1004bdd1243dSDimitry Andric                "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
1005bdd1243dSDimitry Andric                "original allocator");
1006bdd1243dSDimitry Andric
10070b57cec5SDimitry Andric  __base __tree_;
10080b57cec5SDimitry Andric
10090b57cec5SDimitry Andricpublic:
10100b57cec5SDimitry Andric  typedef typename __alloc_traits::pointer pointer;
10110b57cec5SDimitry Andric  typedef typename __alloc_traits::const_pointer const_pointer;
10120b57cec5SDimitry Andric  typedef typename __alloc_traits::size_type size_type;
10130b57cec5SDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
10140b57cec5SDimitry Andric  typedef __map_iterator<typename __base::iterator> iterator;
10150b57cec5SDimitry Andric  typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1016c9157d92SDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
1017c9157d92SDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
10180b57cec5SDimitry Andric
1019fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
10200b57cec5SDimitry Andric  typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
10210b57cec5SDimitry Andric  typedef __insert_return_type<iterator, node_type> insert_return_type;
10220b57cec5SDimitry Andric#endif
10230b57cec5SDimitry Andric
10240b57cec5SDimitry Andric  template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10250b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS map;
10260b57cec5SDimitry Andric  template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10270b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multimap;
10280b57cec5SDimitry Andric
1029e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map() _NOEXCEPT_(
1030e710425bSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
10310b57cec5SDimitry Andric          is_nothrow_copy_constructible<key_compare>::value)
10320b57cec5SDimitry Andric      : __tree_(__vc(key_compare())) {}
10330b57cec5SDimitry Andric
1034e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp) _NOEXCEPT_(
1035e710425bSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
10360b57cec5SDimitry Andric      : __tree_(__vc(__comp)) {}
10370b57cec5SDimitry Andric
1038e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit map(const key_compare& __comp, const allocator_type& __a)
10390b57cec5SDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
10400b57cec5SDimitry Andric
10410b57cec5SDimitry Andric  template <class _InputIterator>
1042e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
1043e710425bSDimitry Andric      : __tree_(__vc(__comp)) {
10440b57cec5SDimitry Andric    insert(__f, __l);
10450b57cec5SDimitry Andric  }
10460b57cec5SDimitry Andric
10470b57cec5SDimitry Andric  template <class _InputIterator>
1048c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1049e710425bSDimitry Andric  map(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a)
1050e710425bSDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
10510b57cec5SDimitry Andric    insert(__f, __l);
10520b57cec5SDimitry Andric  }
10530b57cec5SDimitry Andric
1054fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1055fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1056fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1057e710425bSDimitry Andric  map(from_range_t,
1058e710425bSDimitry Andric      _Range&& __range,
1059e710425bSDimitry Andric      const key_compare& __comp = key_compare(),
1060fe013be4SDimitry Andric      const allocator_type& __a = allocator_type())
1061fe013be4SDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1062fe013be4SDimitry Andric    insert_range(std::forward<_Range>(__range));
1063fe013be4SDimitry Andric  }
1064fe013be4SDimitry Andric#endif
1065fe013be4SDimitry Andric
1066fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
10670b57cec5SDimitry Andric  template <class _InputIterator>
1068e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10690b57cec5SDimitry Andric      : map(__f, __l, key_compare(), __a) {}
10700b57cec5SDimitry Andric#endif
10710b57cec5SDimitry Andric
1072fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1073fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1074e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(from_range_t, _Range&& __range, const allocator_type& __a)
1075fe013be4SDimitry Andric      : map(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1076fe013be4SDimitry Andric#endif
1077fe013be4SDimitry Andric
1078e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
10790b57cec5SDimitry Andric
1080e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
10810b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10820b57cec5SDimitry Andric    __tree_ = __m.__tree_;
10830b57cec5SDimitry Andric#else
1084c9157d92SDimitry Andric    if (this != std::addressof(__m)) {
10850b57cec5SDimitry Andric      __tree_.clear();
10860b57cec5SDimitry Andric      __tree_.value_comp() = __m.__tree_.value_comp();
10870b57cec5SDimitry Andric      __tree_.__copy_assign_alloc(__m.__tree_);
10880b57cec5SDimitry Andric      insert(__m.begin(), __m.end());
10890b57cec5SDimitry Andric    }
10900b57cec5SDimitry Andric#endif
10910b57cec5SDimitry Andric    return *this;
10920b57cec5SDimitry Andric  }
10930b57cec5SDimitry Andric
10940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10950b57cec5SDimitry Andric
1096e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(map&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1097e710425bSDimitry Andric      : __tree_(std::move(__m.__tree_)) {}
10980b57cec5SDimitry Andric
1099fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
11000b57cec5SDimitry Andric
1101e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
1102c9157d92SDimitry Andric    __tree_ = std::move(__m.__tree_);
11030b57cec5SDimitry Andric    return *this;
11040b57cec5SDimitry Andric  }
11050b57cec5SDimitry Andric
1106e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1107e710425bSDimitry Andric      : __tree_(__vc(__comp)) {
11080b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
11090b57cec5SDimitry Andric  }
11100b57cec5SDimitry Andric
1111e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1112e710425bSDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
11130b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
11140b57cec5SDimitry Andric  }
11150b57cec5SDimitry Andric
1116fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 14
1117e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const allocator_type& __a)
11180b57cec5SDimitry Andric      : map(__il, key_compare(), __a) {}
11190b57cec5SDimitry Andric#  endif
11200b57cec5SDimitry Andric
1121e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map& operator=(initializer_list<value_type> __il) {
11220b57cec5SDimitry Andric    __tree_.__assign_unique(__il.begin(), __il.end());
11230b57cec5SDimitry Andric    return *this;
11240b57cec5SDimitry Andric  }
11250b57cec5SDimitry Andric
11260b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11270b57cec5SDimitry Andric
1128e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit map(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
11290b57cec5SDimitry Andric
1130e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI map(const map& __m, const allocator_type& __a)
1131e710425bSDimitry Andric      : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) {
11320b57cec5SDimitry Andric    insert(__m.begin(), __m.end());
11330b57cec5SDimitry Andric  }
11340b57cec5SDimitry Andric
1135e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~map() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
11360b57cec5SDimitry Andric
1137e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
1138e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
1139e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
1140e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
11410b57cec5SDimitry Andric
1142e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1143e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1144e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1145e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
11460b57cec5SDimitry Andric
1147e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
1148e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
1149e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1150e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
11510b57cec5SDimitry Andric
1152e710425bSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1153e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
1154e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
11550b57cec5SDimitry Andric
1156fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __k);
11570b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1158fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __k);
11590b57cec5SDimitry Andric#endif
11600b57cec5SDimitry Andric
1161fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __k);
1162fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __k) const;
11630b57cec5SDimitry Andric
1164e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(__tree_.__alloc()); }
1165e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
1166e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
11670b57cec5SDimitry Andric
11680b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11690b57cec5SDimitry Andric  template <class... _Args>
1170e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
1171c9157d92SDimitry Andric    return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
11720b57cec5SDimitry Andric  }
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric  template <class... _Args>
1175e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1176c9157d92SDimitry Andric    return __tree_.__emplace_hint_unique(__p.__i_, std::forward<_Args>(__args)...);
11770b57cec5SDimitry Andric  }
11780b57cec5SDimitry Andric
1179e710425bSDimitry Andric  template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
1180e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __p) {
1181e710425bSDimitry Andric    return __tree_.__insert_unique(std::forward<_Pp>(__p));
1182e710425bSDimitry Andric  }
11830b57cec5SDimitry Andric
1184e710425bSDimitry Andric  template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
1185e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1186e710425bSDimitry Andric    return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
1187e710425bSDimitry Andric  }
11880b57cec5SDimitry Andric
11890b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11900b57cec5SDimitry Andric
1191e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
11920b57cec5SDimitry Andric
1193e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1194e710425bSDimitry Andric    return __tree_.__insert_unique(__p.__i_, __v);
1195e710425bSDimitry Andric  }
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1198e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
1199e710425bSDimitry Andric    return __tree_.__insert_unique(std::move(__v));
1200e710425bSDimitry Andric  }
12010b57cec5SDimitry Andric
1202e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1203e710425bSDimitry Andric    return __tree_.__insert_unique(__p.__i_, std::move(__v));
1204e710425bSDimitry Andric  }
12050b57cec5SDimitry Andric
1206e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
12070b57cec5SDimitry Andric#endif
12080b57cec5SDimitry Andric
12090b57cec5SDimitry Andric  template <class _InputIterator>
1210e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
12110b57cec5SDimitry Andric    for (const_iterator __e = cend(); __f != __l; ++__f)
12120b57cec5SDimitry Andric      insert(__e.__i_, *__f);
12130b57cec5SDimitry Andric  }
12140b57cec5SDimitry Andric
1215fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1216fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1217e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
1218fe013be4SDimitry Andric    const_iterator __end = cend();
1219fe013be4SDimitry Andric    for (auto&& __element : __range) {
1220fe013be4SDimitry Andric      insert(__end.__i_, std::forward<decltype(__element)>(__element));
1221fe013be4SDimitry Andric    }
1222fe013be4SDimitry Andric  }
1223fe013be4SDimitry Andric#endif
1224fe013be4SDimitry Andric
1225fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
12260b57cec5SDimitry Andric
12270b57cec5SDimitry Andric  template <class... _Args>
1228e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) {
1229e710425bSDimitry Andric    return __tree_.__emplace_unique_key_args(
1230e710425bSDimitry Andric        __k,
1231c9157d92SDimitry Andric        std::piecewise_construct,
1232c9157d92SDimitry Andric        std::forward_as_tuple(__k),
1233c9157d92SDimitry Andric        std::forward_as_tuple(std::forward<_Args>(__args)...));
12340b57cec5SDimitry Andric  }
12350b57cec5SDimitry Andric
12360b57cec5SDimitry Andric  template <class... _Args>
1237e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) {
1238e710425bSDimitry Andric    return __tree_.__emplace_unique_key_args(
1239e710425bSDimitry Andric        __k,
1240c9157d92SDimitry Andric        std::piecewise_construct,
1241c9157d92SDimitry Andric        std::forward_as_tuple(std::move(__k)),
1242c9157d92SDimitry Andric        std::forward_as_tuple(std::forward<_Args>(__args)...));
12430b57cec5SDimitry Andric  }
12440b57cec5SDimitry Andric
12450b57cec5SDimitry Andric  template <class... _Args>
1246e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) {
1247e710425bSDimitry Andric    return __tree_
1248e710425bSDimitry Andric        .__emplace_hint_unique_key_args(
1249e710425bSDimitry Andric            __h.__i_,
1250e710425bSDimitry Andric            __k,
1251c9157d92SDimitry Andric            std::piecewise_construct,
1252c9157d92SDimitry Andric            std::forward_as_tuple(__k),
1253e710425bSDimitry Andric            std::forward_as_tuple(std::forward<_Args>(__args)...))
1254e710425bSDimitry Andric        .first;
12550b57cec5SDimitry Andric  }
12560b57cec5SDimitry Andric
12570b57cec5SDimitry Andric  template <class... _Args>
1258e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) {
1259e710425bSDimitry Andric    return __tree_
1260e710425bSDimitry Andric        .__emplace_hint_unique_key_args(
1261e710425bSDimitry Andric            __h.__i_,
1262e710425bSDimitry Andric            __k,
1263c9157d92SDimitry Andric            std::piecewise_construct,
1264c9157d92SDimitry Andric            std::forward_as_tuple(std::move(__k)),
1265e710425bSDimitry Andric            std::forward_as_tuple(std::forward<_Args>(__args)...))
1266e710425bSDimitry Andric        .first;
12670b57cec5SDimitry Andric  }
12680b57cec5SDimitry Andric
12690b57cec5SDimitry Andric  template <class _Vp>
1270e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) {
12710b57cec5SDimitry Andric    iterator __p = lower_bound(__k);
1272e710425bSDimitry Andric    if (__p != end() && !key_comp()(__k, __p->first)) {
1273c9157d92SDimitry Andric      __p->second = std::forward<_Vp>(__v);
1274c9157d92SDimitry Andric      return std::make_pair(__p, false);
12750b57cec5SDimitry Andric    }
1276c9157d92SDimitry Andric    return std::make_pair(emplace_hint(__p, __k, std::forward<_Vp>(__v)), true);
12770b57cec5SDimitry Andric  }
12780b57cec5SDimitry Andric
12790b57cec5SDimitry Andric  template <class _Vp>
1280e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) {
12810b57cec5SDimitry Andric    iterator __p = lower_bound(__k);
1282e710425bSDimitry Andric    if (__p != end() && !key_comp()(__k, __p->first)) {
1283c9157d92SDimitry Andric      __p->second = std::forward<_Vp>(__v);
1284c9157d92SDimitry Andric      return std::make_pair(__p, false);
12850b57cec5SDimitry Andric    }
1286c9157d92SDimitry Andric    return std::make_pair(emplace_hint(__p, std::move(__k), std::forward<_Vp>(__v)), true);
12870b57cec5SDimitry Andric  }
12880b57cec5SDimitry Andric
12890b57cec5SDimitry Andric  template <class _Vp>
1290e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) {
1291e710425bSDimitry Andric    auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, __k, std::forward<_Vp>(__v));
1292e8d8bef9SDimitry Andric
1293e8d8bef9SDimitry Andric    if (!__inserted)
1294c9157d92SDimitry Andric      __r->__get_value().second = std::forward<_Vp>(__v);
1295e8d8bef9SDimitry Andric
1296e8d8bef9SDimitry Andric    return __r;
12970b57cec5SDimitry Andric  }
12980b57cec5SDimitry Andric
12990b57cec5SDimitry Andric  template <class _Vp>
1300e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) {
1301e710425bSDimitry Andric    auto [__r, __inserted] =
1302e710425bSDimitry Andric        __tree_.__emplace_hint_unique_key_args(__h.__i_, __k, std::move(__k), std::forward<_Vp>(__v));
1303e8d8bef9SDimitry Andric
1304e8d8bef9SDimitry Andric    if (!__inserted)
1305c9157d92SDimitry Andric      __r->__get_value().second = std::forward<_Vp>(__v);
1306e8d8bef9SDimitry Andric
1307e8d8bef9SDimitry Andric    return __r;
13080b57cec5SDimitry Andric  }
13090b57cec5SDimitry Andric
1310fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 17
13110b57cec5SDimitry Andric
1312e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
1313e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
1314e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
1315e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
1316e710425bSDimitry Andric    return __tree_.erase(__f.__i_, __l.__i_);
1317e710425bSDimitry Andric  }
1318e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
13190b57cec5SDimitry Andric
1320fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
1321e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
1322fe013be4SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
13230b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to map::insert()");
1324e710425bSDimitry Andric    return __tree_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
13250b57cec5SDimitry Andric  }
1326e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
1327fe013be4SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
13280b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to map::insert()");
1329e710425bSDimitry Andric    return __tree_.template __node_handle_insert_unique<node_type>(__hint.__i_, std::move(__nh));
13300b57cec5SDimitry Andric  }
1331e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
13320b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__key);
13330b57cec5SDimitry Andric  }
1334e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
13350b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__it.__i_);
13360b57cec5SDimitry Andric  }
13370b57cec5SDimitry Andric  template <class _Compare2>
1338e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1339e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1340e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13410b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
13420b57cec5SDimitry Andric  }
13430b57cec5SDimitry Andric  template <class _Compare2>
1344e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1345e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1346e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13470b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
13480b57cec5SDimitry Andric  }
13490b57cec5SDimitry Andric  template <class _Compare2>
1350e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1351e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1352e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13530b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
13540b57cec5SDimitry Andric  }
13550b57cec5SDimitry Andric  template <class _Compare2>
1356e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1357e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1358e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
13590b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
13600b57cec5SDimitry Andric  }
13610b57cec5SDimitry Andric#endif
13620b57cec5SDimitry Andric
1363e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(map& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
1364e710425bSDimitry Andric    __tree_.swap(__m.__tree_);
1365e710425bSDimitry Andric  }
13660b57cec5SDimitry Andric
1367e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
1368e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1369fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1370c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1371e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
1372e710425bSDimitry Andric    return __tree_.find(__k);
1373e710425bSDimitry Andric  }
1374c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1375e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
1376e710425bSDimitry Andric    return __tree_.find(__k);
1377e710425bSDimitry Andric  }
13780b57cec5SDimitry Andric#endif
13790b57cec5SDimitry Andric
1380e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
1381fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1382c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1383e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
1384e710425bSDimitry Andric    return __tree_.__count_multi(__k);
1385e710425bSDimitry Andric  }
13860b57cec5SDimitry Andric#endif
13870b57cec5SDimitry Andric
1388fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20
1389e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
1390c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1391e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
1392e710425bSDimitry Andric    return find(__k) != end();
1393e710425bSDimitry Andric  }
1394fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
13950b57cec5SDimitry Andric
1396e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
1397e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1398fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1399c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1400e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
1401e710425bSDimitry Andric    return __tree_.lower_bound(__k);
1402e710425bSDimitry Andric  }
14030b57cec5SDimitry Andric
1404c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1405e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
1406e710425bSDimitry Andric    return __tree_.lower_bound(__k);
1407e710425bSDimitry Andric  }
14080b57cec5SDimitry Andric#endif
14090b57cec5SDimitry Andric
1410e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
1411e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
1412fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1413c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1414e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
1415e710425bSDimitry Andric    return __tree_.upper_bound(__k);
1416e710425bSDimitry Andric  }
1417c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1418e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
1419e710425bSDimitry Andric    return __tree_.upper_bound(__k);
1420e710425bSDimitry Andric  }
14210b57cec5SDimitry Andric#endif
14220b57cec5SDimitry Andric
1423e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
1424e710425bSDimitry Andric    return __tree_.__equal_range_unique(__k);
1425e710425bSDimitry Andric  }
1426e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
1427e710425bSDimitry Andric    return __tree_.__equal_range_unique(__k);
1428e710425bSDimitry Andric  }
1429fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1430c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1431e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
1432e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
1433e710425bSDimitry Andric  }
1434c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1435e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
1436e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
1437e710425bSDimitry Andric  }
14380b57cec5SDimitry Andric#endif
14390b57cec5SDimitry Andric
14400b57cec5SDimitry Andricprivate:
14410b57cec5SDimitry Andric  typedef typename __base::__node __node;
14420b57cec5SDimitry Andric  typedef typename __base::__node_allocator __node_allocator;
14430b57cec5SDimitry Andric  typedef typename __base::__node_pointer __node_pointer;
14440b57cec5SDimitry Andric  typedef typename __base::__node_base_pointer __node_base_pointer;
14450b57cec5SDimitry Andric  typedef typename __base::__parent_pointer __parent_pointer;
14460b57cec5SDimitry Andric
14470b57cec5SDimitry Andric  typedef __map_node_destructor<__node_allocator> _Dp;
14480b57cec5SDimitry Andric  typedef unique_ptr<__node, _Dp> __node_holder;
14490b57cec5SDimitry Andric
14500b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
1451fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI __node_holder __construct_node_with_key(const key_type& __k);
14520b57cec5SDimitry Andric#endif
14530b57cec5SDimitry Andric};
14540b57cec5SDimitry Andric
1455349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
1456e710425bSDimitry Andrictemplate <class _InputIterator,
1457e710425bSDimitry Andric          class _Compare   = less<__iter_key_type<_InputIterator>>,
14580b57cec5SDimitry Andric          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1459fe013be4SDimitry Andric          class            = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1460349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
1461349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
14620b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
14630b57cec5SDimitry Andric    -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
14640b57cec5SDimitry Andric
1465fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 23
1466e710425bSDimitry Andrictemplate <ranges::input_range _Range,
1467e710425bSDimitry Andric          class _Compare   = less<__range_key_type<_Range>>,
1468fe013be4SDimitry Andric          class _Allocator = allocator<__range_to_alloc_type<_Range>>,
1469fe013be4SDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
1470fe013be4SDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
1471fe013be4SDimitry Andricmap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
1472fe013be4SDimitry Andric    -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
1473fe013be4SDimitry Andric#  endif
1474fe013be4SDimitry Andric
1475e710425bSDimitry Andrictemplate <class _Key,
1476e710425bSDimitry Andric          class _Tp,
1477e710425bSDimitry Andric          class _Compare   = less<remove_const_t<_Key>>,
14780b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp>>,
1479349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
1480349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
14810b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
14820b57cec5SDimitry Andric    -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
14830b57cec5SDimitry Andric
1484e710425bSDimitry Andrictemplate <class _InputIterator,
1485e710425bSDimitry Andric          class _Allocator,
1486fe013be4SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1487349cc55cSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value, void>>
14880b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Allocator)
1489e710425bSDimitry Andric    -> map<__iter_key_type<_InputIterator>,
1490e710425bSDimitry Andric           __iter_mapped_type<_InputIterator>,
1491e710425bSDimitry Andric           less<__iter_key_type<_InputIterator>>,
1492e710425bSDimitry Andric           _Allocator>;
14930b57cec5SDimitry Andric
1494fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 23
1495e710425bSDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1496fe013be4SDimitry Andricmap(from_range_t, _Range&&, _Allocator)
1497fe013be4SDimitry Andric    -> map<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
1498fe013be4SDimitry Andric#  endif
1499fe013be4SDimitry Andric
1500e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15010b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Allocator)
15020b57cec5SDimitry Andric    -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
15030b57cec5SDimitry Andric#endif
15040b57cec5SDimitry Andric
15050b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
15060b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15070b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
1508e710425bSDimitry Andric    : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
1509e710425bSDimitry Andric  if (__a != __m.get_allocator()) {
15100b57cec5SDimitry Andric    const_iterator __e = cend();
15110b57cec5SDimitry Andric    while (!__m.empty())
1512e710425bSDimitry Andric      __tree_.__insert_unique(__e.__i_, __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
15130b57cec5SDimitry Andric  }
15140b57cec5SDimitry Andric}
15150b57cec5SDimitry Andric
15160b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1517e710425bSDimitry Andric_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
1518e710425bSDimitry Andric  return __tree_
1519e710425bSDimitry Andric      .__emplace_unique_key_args(__k, std::piecewise_construct, std::forward_as_tuple(__k), std::forward_as_tuple())
1520e710425bSDimitry Andric      .first->__get_value()
1521e710425bSDimitry Andric      .second;
15220b57cec5SDimitry Andric}
15230b57cec5SDimitry Andric
15240b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1525e710425bSDimitry Andric_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) {
1526c9157d92SDimitry Andric  // TODO investigate this clang-tidy warning.
1527e710425bSDimitry Andric  // NOLINTBEGIN(bugprone-use-after-move)
1528e710425bSDimitry Andric  return __tree_
1529e710425bSDimitry Andric      .__emplace_unique_key_args(
1530e710425bSDimitry Andric          __k, std::piecewise_construct, std::forward_as_tuple(std::move(__k)), std::forward_as_tuple())
1531e710425bSDimitry Andric      .first->__get_value()
1532e710425bSDimitry Andric      .second;
1533e710425bSDimitry Andric  // NOLINTEND(bugprone-use-after-move)
15340b57cec5SDimitry Andric}
15350b57cec5SDimitry Andric
15360b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG
15370b57cec5SDimitry Andric
15380b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15390b57cec5SDimitry Andrictypename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
1540e710425bSDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k) {
15410b57cec5SDimitry Andric  __node_allocator& __na = __tree_.__node_alloc();
15420b57cec5SDimitry Andric  __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
1543c9157d92SDimitry Andric  __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().first), __k);
15440b57cec5SDimitry Andric  __h.get_deleter().__first_constructed = true;
1545c9157d92SDimitry Andric  __node_traits::construct(__na, std::addressof(__h->__value_.__get_value().second));
15460b57cec5SDimitry Andric  __h.get_deleter().__second_constructed = true;
1547e8d8bef9SDimitry Andric  return __h;
15480b57cec5SDimitry Andric}
15490b57cec5SDimitry Andric
15500b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1551e710425bSDimitry Andric_Tp& map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) {
15520b57cec5SDimitry Andric  __parent_pointer __parent;
15530b57cec5SDimitry Andric  __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
15540b57cec5SDimitry Andric  __node_pointer __r           = static_cast<__node_pointer>(__child);
1555e710425bSDimitry Andric  if (__child == nullptr) {
15560b57cec5SDimitry Andric    __node_holder __h = __construct_node_with_key(__k);
15570b57cec5SDimitry Andric    __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
15580b57cec5SDimitry Andric    __r = __h.release();
15590b57cec5SDimitry Andric  }
15600b57cec5SDimitry Andric  return __r->__value_.__get_value().second;
15610b57cec5SDimitry Andric}
15620b57cec5SDimitry Andric
15630b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
15640b57cec5SDimitry Andric
15650b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1566e710425bSDimitry Andric_Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) {
15670b57cec5SDimitry Andric  __parent_pointer __parent;
15680b57cec5SDimitry Andric  __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
15690b57cec5SDimitry Andric  if (__child == nullptr)
15700b57cec5SDimitry Andric    __throw_out_of_range("map::at:  key not found");
15710b57cec5SDimitry Andric  return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
15720b57cec5SDimitry Andric}
15730b57cec5SDimitry Andric
15740b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1575e710425bSDimitry Andricconst _Tp& map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const {
15760b57cec5SDimitry Andric  __parent_pointer __parent;
15770b57cec5SDimitry Andric  __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
15780b57cec5SDimitry Andric  if (__child == nullptr)
15790b57cec5SDimitry Andric    __throw_out_of_range("map::at:  key not found");
15800b57cec5SDimitry Andric  return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
15810b57cec5SDimitry Andric}
15820b57cec5SDimitry Andric
15830b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1584e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1585e710425bSDimitry Andricoperator==(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1586c9157d92SDimitry Andric  return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
15870b57cec5SDimitry Andric}
15880b57cec5SDimitry Andric
1589fe013be4SDimitry Andric#if _LIBCPP_STD_VER <= 17
1590fe013be4SDimitry Andric
15910b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1592e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1593e710425bSDimitry Andricoperator<(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1594c9157d92SDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
15950b57cec5SDimitry Andric}
15960b57cec5SDimitry Andric
15970b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1598e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1599e710425bSDimitry Andricoperator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
16000b57cec5SDimitry Andric  return !(__x == __y);
16010b57cec5SDimitry Andric}
16020b57cec5SDimitry Andric
16030b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1604e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1605e710425bSDimitry Andricoperator>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
16060b57cec5SDimitry Andric  return __y < __x;
16070b57cec5SDimitry Andric}
16080b57cec5SDimitry Andric
16090b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1610e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1611e710425bSDimitry Andricoperator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
16120b57cec5SDimitry Andric  return !(__x < __y);
16130b57cec5SDimitry Andric}
16140b57cec5SDimitry Andric
16150b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1616e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1617e710425bSDimitry Andricoperator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
16180b57cec5SDimitry Andric  return !(__y < __x);
16190b57cec5SDimitry Andric}
16200b57cec5SDimitry Andric
1621fe013be4SDimitry Andric#else // #if _LIBCPP_STD_VER <= 17
1622fe013be4SDimitry Andric
1623fe013be4SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1624fe013be4SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
1625fe013be4SDimitry Andricoperator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x, const map<_Key, _Tp, _Compare, _Allocator>& __y) {
1626fe013be4SDimitry Andric  return std::lexicographical_compare_three_way(
1627fe013be4SDimitry Andric      __x.begin(),
1628fe013be4SDimitry Andric      __x.end(),
1629fe013be4SDimitry Andric      __y.begin(),
1630fe013be4SDimitry Andric      __y.end(),
1631fe013be4SDimitry Andric      std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
1632fe013be4SDimitry Andric}
1633fe013be4SDimitry Andric
1634fe013be4SDimitry Andric#endif // #if _LIBCPP_STD_VER <= 17
1635fe013be4SDimitry Andric
16360b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
1637e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
1638e710425bSDimitry Andricswap(map<_Key, _Tp, _Compare, _Allocator>& __x, map<_Key, _Tp, _Compare, _Allocator>& __y)
1639e710425bSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
16400b57cec5SDimitry Andric  __x.swap(__y);
16410b57cec5SDimitry Andric}
16420b57cec5SDimitry Andric
1643fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20
1644e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
1645e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename map<_Key, _Tp, _Compare, _Allocator>::size_type
16465ffd83dbSDimitry Andricerase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1647c9157d92SDimitry Andric  return std::__libcpp_erase_if_container(__c, __pred);
16485ffd83dbSDimitry Andric}
16490b57cec5SDimitry Andric#endif
16500b57cec5SDimitry Andric
1651e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>, class _Allocator = allocator<pair<const _Key, _Tp> > >
1652e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS multimap {
16530b57cec5SDimitry Andricpublic:
16540b57cec5SDimitry Andric  // types:
16550b57cec5SDimitry Andric  typedef _Key key_type;
16560b57cec5SDimitry Andric  typedef _Tp mapped_type;
16570b57cec5SDimitry Andric  typedef pair<const key_type, mapped_type> value_type;
165881ad6265SDimitry Andric  typedef __type_identity_t<_Compare> key_compare;
165981ad6265SDimitry Andric  typedef __type_identity_t<_Allocator> allocator_type;
16600b57cec5SDimitry Andric  typedef value_type& reference;
16610b57cec5SDimitry Andric  typedef const value_type& const_reference;
16620b57cec5SDimitry Andric
16630b57cec5SDimitry Andric  static_assert((is_same<typename allocator_type::value_type, value_type>::value),
16640b57cec5SDimitry Andric                "Allocator::value_type must be same type as value_type");
16650b57cec5SDimitry Andric
1666e710425bSDimitry Andric  class _LIBCPP_TEMPLATE_VIS value_compare : public __binary_function<value_type, value_type, bool> {
16670b57cec5SDimitry Andric    friend class multimap;
1668e710425bSDimitry Andric
16690b57cec5SDimitry Andric  protected:
16700b57cec5SDimitry Andric    key_compare comp;
16710b57cec5SDimitry Andric
1672e710425bSDimitry Andric    _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : comp(__c) {}
1673e710425bSDimitry Andric
16740b57cec5SDimitry Andric  public:
1675e710425bSDimitry Andric    _LIBCPP_HIDE_FROM_ABI bool operator()(const value_type& __x, const value_type& __y) const {
1676e710425bSDimitry Andric      return comp(__x.first, __y.first);
1677e710425bSDimitry Andric    }
16780b57cec5SDimitry Andric  };
16790b57cec5SDimitry Andric
16800b57cec5SDimitry Andricprivate:
1681c9157d92SDimitry Andric  typedef std::__value_type<key_type, mapped_type> __value_type;
16820b57cec5SDimitry Andric  typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
1683bdd1243dSDimitry Andric  typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
16840b57cec5SDimitry Andric  typedef __tree<__value_type, __vc, __allocator_type> __base;
16850b57cec5SDimitry Andric  typedef typename __base::__node_traits __node_traits;
16860b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
16870b57cec5SDimitry Andric
1688bdd1243dSDimitry Andric  static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
1689bdd1243dSDimitry Andric                "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
1690bdd1243dSDimitry Andric                "original allocator");
1691bdd1243dSDimitry Andric
16920b57cec5SDimitry Andric  __base __tree_;
16930b57cec5SDimitry Andric
16940b57cec5SDimitry Andricpublic:
16950b57cec5SDimitry Andric  typedef typename __alloc_traits::pointer pointer;
16960b57cec5SDimitry Andric  typedef typename __alloc_traits::const_pointer const_pointer;
16970b57cec5SDimitry Andric  typedef typename __alloc_traits::size_type size_type;
16980b57cec5SDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
16990b57cec5SDimitry Andric  typedef __map_iterator<typename __base::iterator> iterator;
17000b57cec5SDimitry Andric  typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
1701c9157d92SDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
1702c9157d92SDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
17030b57cec5SDimitry Andric
1704fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
17050b57cec5SDimitry Andric  typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
17060b57cec5SDimitry Andric#endif
17070b57cec5SDimitry Andric
17080b57cec5SDimitry Andric  template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
17090b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS map;
17100b57cec5SDimitry Andric  template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
17110b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multimap;
17120b57cec5SDimitry Andric
1713e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap() _NOEXCEPT_(
1714e710425bSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
17150b57cec5SDimitry Andric          is_nothrow_copy_constructible<key_compare>::value)
17160b57cec5SDimitry Andric      : __tree_(__vc(key_compare())) {}
17170b57cec5SDimitry Andric
1718e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multimap(const key_compare& __comp) _NOEXCEPT_(
1719e710425bSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
17200b57cec5SDimitry Andric      : __tree_(__vc(__comp)) {}
17210b57cec5SDimitry Andric
1722e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multimap(const key_compare& __comp, const allocator_type& __a)
17230b57cec5SDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
17240b57cec5SDimitry Andric
17250b57cec5SDimitry Andric  template <class _InputIterator>
1726e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp = key_compare())
1727e710425bSDimitry Andric      : __tree_(__vc(__comp)) {
17280b57cec5SDimitry Andric    insert(__f, __l);
17290b57cec5SDimitry Andric  }
17300b57cec5SDimitry Andric
17310b57cec5SDimitry Andric  template <class _InputIterator>
1732c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1733e710425bSDimitry Andric  multimap(_InputIterator __f, _InputIterator __l, const key_compare& __comp, const allocator_type& __a)
1734e710425bSDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
17350b57cec5SDimitry Andric    insert(__f, __l);
17360b57cec5SDimitry Andric  }
17370b57cec5SDimitry Andric
1738fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1739fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1740fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1741e710425bSDimitry Andric  multimap(from_range_t,
1742e710425bSDimitry Andric           _Range&& __range,
1743e710425bSDimitry Andric           const key_compare& __comp = key_compare(),
1744fe013be4SDimitry Andric           const allocator_type& __a = allocator_type())
1745fe013be4SDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
1746fe013be4SDimitry Andric    insert_range(std::forward<_Range>(__range));
1747fe013be4SDimitry Andric  }
1748fe013be4SDimitry Andric#endif
1749fe013be4SDimitry Andric
1750fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
17510b57cec5SDimitry Andric  template <class _InputIterator>
1752e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
17530b57cec5SDimitry Andric      : multimap(__f, __l, key_compare(), __a) {}
17540b57cec5SDimitry Andric#endif
17550b57cec5SDimitry Andric
1756fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1757fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1758e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(from_range_t, _Range&& __range, const allocator_type& __a)
1759fe013be4SDimitry Andric      : multimap(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
1760fe013be4SDimitry Andric#endif
1761fe013be4SDimitry Andric
1762e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m)
17630b57cec5SDimitry Andric      : __tree_(__m.__tree_.value_comp(),
1764e710425bSDimitry Andric                __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc())) {
17650b57cec5SDimitry Andric    insert(__m.begin(), __m.end());
17660b57cec5SDimitry Andric  }
17670b57cec5SDimitry Andric
1768e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
17690b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
17700b57cec5SDimitry Andric    __tree_ = __m.__tree_;
17710b57cec5SDimitry Andric#else
1772c9157d92SDimitry Andric    if (this != std::addressof(__m)) {
17730b57cec5SDimitry Andric      __tree_.clear();
17740b57cec5SDimitry Andric      __tree_.value_comp() = __m.__tree_.value_comp();
17750b57cec5SDimitry Andric      __tree_.__copy_assign_alloc(__m.__tree_);
17760b57cec5SDimitry Andric      insert(__m.begin(), __m.end());
17770b57cec5SDimitry Andric    }
17780b57cec5SDimitry Andric#endif
17790b57cec5SDimitry Andric    return *this;
17800b57cec5SDimitry Andric  }
17810b57cec5SDimitry Andric
17820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
17830b57cec5SDimitry Andric
1784e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1785e710425bSDimitry Andric      : __tree_(std::move(__m.__tree_)) {}
17860b57cec5SDimitry Andric
1787fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a);
17880b57cec5SDimitry Andric
1789e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap& operator=(multimap&& __m) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
1790c9157d92SDimitry Andric    __tree_ = std::move(__m.__tree_);
17910b57cec5SDimitry Andric    return *this;
17920b57cec5SDimitry Andric  }
17930b57cec5SDimitry Andric
1794e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1795e710425bSDimitry Andric      : __tree_(__vc(__comp)) {
17960b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
17970b57cec5SDimitry Andric  }
17980b57cec5SDimitry Andric
1799c9157d92SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
18000b57cec5SDimitry Andric  multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
1801e710425bSDimitry Andric      : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {
18020b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
18030b57cec5SDimitry Andric  }
18040b57cec5SDimitry Andric
1805fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 14
1806e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const allocator_type& __a)
18070b57cec5SDimitry Andric      : multimap(__il, key_compare(), __a) {}
18080b57cec5SDimitry Andric#  endif
18090b57cec5SDimitry Andric
1810e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap& operator=(initializer_list<value_type> __il) {
18110b57cec5SDimitry Andric    __tree_.__assign_multi(__il.begin(), __il.end());
18120b57cec5SDimitry Andric    return *this;
18130b57cec5SDimitry Andric  }
18140b57cec5SDimitry Andric
18150b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
18160b57cec5SDimitry Andric
1817e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multimap(const allocator_type& __a) : __tree_(typename __base::allocator_type(__a)) {}
18180b57cec5SDimitry Andric
1819e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multimap(const multimap& __m, const allocator_type& __a)
1820e710425bSDimitry Andric      : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a)) {
18210b57cec5SDimitry Andric    insert(__m.begin(), __m.end());
18220b57cec5SDimitry Andric  }
18230b57cec5SDimitry Andric
1824e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~multimap() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
18250b57cec5SDimitry Andric
1826e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
1827e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
1828e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
1829e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
18300b57cec5SDimitry Andric
1831e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1832e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1833e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1834e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
18350b57cec5SDimitry Andric
1836e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
1837e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
1838e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1839e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
18400b57cec5SDimitry Andric
1841e710425bSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1842e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
1843e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
18440b57cec5SDimitry Andric
1845e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(__tree_.__alloc()); }
1846e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp().key_comp(); }
1847e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__tree_.value_comp().key_comp()); }
18480b57cec5SDimitry Andric
18490b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18500b57cec5SDimitry Andric
18510b57cec5SDimitry Andric  template <class... _Args>
1852e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
1853c9157d92SDimitry Andric    return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
18540b57cec5SDimitry Andric  }
18550b57cec5SDimitry Andric
18560b57cec5SDimitry Andric  template <class... _Args>
1857e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1858c9157d92SDimitry Andric    return __tree_.__emplace_hint_multi(__p.__i_, std::forward<_Args>(__args)...);
18590b57cec5SDimitry Andric  }
18600b57cec5SDimitry Andric
1861e710425bSDimitry Andric  template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
1862e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __p) {
1863e710425bSDimitry Andric    return __tree_.__insert_multi(std::forward<_Pp>(__p));
1864e710425bSDimitry Andric  }
18650b57cec5SDimitry Andric
1866e710425bSDimitry Andric  template <class _Pp, class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
1867e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1868e710425bSDimitry Andric    return __tree_.__insert_multi(__pos.__i_, std::forward<_Pp>(__p));
1869e710425bSDimitry Andric  }
18700b57cec5SDimitry Andric
1871e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
18720b57cec5SDimitry Andric
1873e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1874e710425bSDimitry Andric    return __tree_.__insert_multi(__p.__i_, std::move(__v));
1875e710425bSDimitry Andric  }
18760b57cec5SDimitry Andric
1877e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
18780b57cec5SDimitry Andric
18790b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
18800b57cec5SDimitry Andric
1881e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
18820b57cec5SDimitry Andric
1883e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1884e710425bSDimitry Andric    return __tree_.__insert_multi(__p.__i_, __v);
1885e710425bSDimitry Andric  }
18860b57cec5SDimitry Andric
18870b57cec5SDimitry Andric  template <class _InputIterator>
1888e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
18890b57cec5SDimitry Andric    for (const_iterator __e = cend(); __f != __l; ++__f)
18900b57cec5SDimitry Andric      __tree_.__insert_multi(__e.__i_, *__f);
18910b57cec5SDimitry Andric  }
18920b57cec5SDimitry Andric
1893fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23
1894fe013be4SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1895e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
1896fe013be4SDimitry Andric    const_iterator __end = cend();
1897fe013be4SDimitry Andric    for (auto&& __element : __range) {
1898fe013be4SDimitry Andric      __tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
1899fe013be4SDimitry Andric    }
1900fe013be4SDimitry Andric  }
1901fe013be4SDimitry Andric#endif
1902fe013be4SDimitry Andric
1903e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p.__i_); }
1904e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __p) { return __tree_.erase(__p.__i_); }
1905e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
1906e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) {
1907e710425bSDimitry Andric    return __tree_.erase(__f.__i_, __l.__i_);
1908e710425bSDimitry Andric  }
19090b57cec5SDimitry Andric
1910fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
1911e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
1912fe013be4SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
19130b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to multimap::insert()");
1914e710425bSDimitry Andric    return __tree_.template __node_handle_insert_multi<node_type>(std::move(__nh));
19150b57cec5SDimitry Andric  }
1916e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
1917fe013be4SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
19180b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to multimap::insert()");
1919e710425bSDimitry Andric    return __tree_.template __node_handle_insert_multi<node_type>(__hint.__i_, std::move(__nh));
19200b57cec5SDimitry Andric  }
1921e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
19220b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__key);
19230b57cec5SDimitry Andric  }
1924e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
1925e710425bSDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__it.__i_);
19260b57cec5SDimitry Andric  }
19270b57cec5SDimitry Andric  template <class _Compare2>
1928e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1929e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1930e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
19310b57cec5SDimitry Andric    return __tree_.__node_handle_merge_multi(__source.__tree_);
19320b57cec5SDimitry Andric  }
19330b57cec5SDimitry Andric  template <class _Compare2>
1934e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1935e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1936e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
19370b57cec5SDimitry Andric    return __tree_.__node_handle_merge_multi(__source.__tree_);
19380b57cec5SDimitry Andric  }
19390b57cec5SDimitry Andric  template <class _Compare2>
1940e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source) {
1941e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1942e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
19430b57cec5SDimitry Andric    return __tree_.__node_handle_merge_multi(__source.__tree_);
19440b57cec5SDimitry Andric  }
19450b57cec5SDimitry Andric  template <class _Compare2>
1946e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source) {
1947e710425bSDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1948e710425bSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
19490b57cec5SDimitry Andric    return __tree_.__node_handle_merge_multi(__source.__tree_);
19500b57cec5SDimitry Andric  }
19510b57cec5SDimitry Andric#endif
19520b57cec5SDimitry Andric
1953e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
19540b57cec5SDimitry Andric
1955e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(multimap& __m) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
1956e710425bSDimitry Andric    __tree_.swap(__m.__tree_);
1957e710425bSDimitry Andric  }
19580b57cec5SDimitry Andric
1959e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
1960e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
1961fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1962c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1963e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
1964e710425bSDimitry Andric    return __tree_.find(__k);
1965e710425bSDimitry Andric  }
1966c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1967e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
1968e710425bSDimitry Andric    return __tree_.find(__k);
1969e710425bSDimitry Andric  }
19700b57cec5SDimitry Andric#endif
19710b57cec5SDimitry Andric
1972e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
1973fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1974c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1975e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
1976e710425bSDimitry Andric    return __tree_.__count_multi(__k);
1977e710425bSDimitry Andric  }
19780b57cec5SDimitry Andric#endif
19790b57cec5SDimitry Andric
1980fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20
1981e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
1982c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1983e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
1984e710425bSDimitry Andric    return find(__k) != end();
1985e710425bSDimitry Andric  }
1986fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
19870b57cec5SDimitry Andric
1988e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
1989e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
1990fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
1991c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1992e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
1993e710425bSDimitry Andric    return __tree_.lower_bound(__k);
1994e710425bSDimitry Andric  }
19950b57cec5SDimitry Andric
1996c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1997e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
1998e710425bSDimitry Andric    return __tree_.lower_bound(__k);
1999e710425bSDimitry Andric  }
20000b57cec5SDimitry Andric#endif
20010b57cec5SDimitry Andric
2002e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
2003e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
2004fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
2005c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2006e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
2007e710425bSDimitry Andric    return __tree_.upper_bound(__k);
2008e710425bSDimitry Andric  }
2009c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2010e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
2011e710425bSDimitry Andric    return __tree_.upper_bound(__k);
2012e710425bSDimitry Andric  }
20130b57cec5SDimitry Andric#endif
20140b57cec5SDimitry Andric
2015e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
2016e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
2017e710425bSDimitry Andric  }
2018e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
2019e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
2020e710425bSDimitry Andric  }
2021fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14
2022c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2023e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
2024e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
2025e710425bSDimitry Andric  }
2026c9157d92SDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
2027e710425bSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
2028e710425bSDimitry Andric    return __tree_.__equal_range_multi(__k);
2029e710425bSDimitry Andric  }
20300b57cec5SDimitry Andric#endif
20310b57cec5SDimitry Andric
20320b57cec5SDimitry Andricprivate:
20330b57cec5SDimitry Andric  typedef typename __base::__node __node;
20340b57cec5SDimitry Andric  typedef typename __base::__node_allocator __node_allocator;
20350b57cec5SDimitry Andric  typedef typename __base::__node_pointer __node_pointer;
20360b57cec5SDimitry Andric
20370b57cec5SDimitry Andric  typedef __map_node_destructor<__node_allocator> _Dp;
20380b57cec5SDimitry Andric  typedef unique_ptr<__node, _Dp> __node_holder;
20390b57cec5SDimitry Andric};
20400b57cec5SDimitry Andric
2041349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
2042e710425bSDimitry Andrictemplate <class _InputIterator,
2043e710425bSDimitry Andric          class _Compare   = less<__iter_key_type<_InputIterator>>,
20440b57cec5SDimitry Andric          class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2045fe013be4SDimitry Andric          class            = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
2046349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
2047349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
20480b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
20490b57cec5SDimitry Andric    -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
20500b57cec5SDimitry Andric
2051fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 23
2052e710425bSDimitry Andrictemplate <ranges::input_range _Range,
2053e710425bSDimitry Andric          class _Compare   = less<__range_key_type<_Range>>,
2054fe013be4SDimitry Andric          class _Allocator = allocator<__range_to_alloc_type<_Range>>,
2055fe013be4SDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
2056fe013be4SDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
2057fe013be4SDimitry Andricmultimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
2058fe013be4SDimitry Andric    -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, _Compare, _Allocator>;
2059fe013be4SDimitry Andric#  endif
2060fe013be4SDimitry Andric
2061e710425bSDimitry Andrictemplate <class _Key,
2062e710425bSDimitry Andric          class _Tp,
2063e710425bSDimitry Andric          class _Compare   = less<remove_const_t<_Key>>,
20640b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp>>,
2065349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
2066349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
20670b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
20680b57cec5SDimitry Andric    -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
20690b57cec5SDimitry Andric
2070e710425bSDimitry Andrictemplate <class _InputIterator,
2071e710425bSDimitry Andric          class _Allocator,
2072fe013be4SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
2073349cc55cSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value, void>>
20740b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Allocator)
2075e710425bSDimitry Andric    -> multimap<__iter_key_type<_InputIterator>,
2076e710425bSDimitry Andric                __iter_mapped_type<_InputIterator>,
2077e710425bSDimitry Andric                less<__iter_key_type<_InputIterator>>,
2078e710425bSDimitry Andric                _Allocator>;
20790b57cec5SDimitry Andric
2080fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 23
2081e710425bSDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
2082fe013be4SDimitry Andricmultimap(from_range_t, _Range&&, _Allocator)
2083fe013be4SDimitry Andric    -> multimap<__range_key_type<_Range>, __range_mapped_type<_Range>, less<__range_key_type<_Range>>, _Allocator>;
2084fe013be4SDimitry Andric#  endif
2085fe013be4SDimitry Andric
2086e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
20870b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
20880b57cec5SDimitry Andric    -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
20890b57cec5SDimitry Andric#endif
20900b57cec5SDimitry Andric
20910b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
20920b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
20930b57cec5SDimitry Andricmultimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
2094e710425bSDimitry Andric    : __tree_(std::move(__m.__tree_), typename __base::allocator_type(__a)) {
2095e710425bSDimitry Andric  if (__a != __m.get_allocator()) {
20960b57cec5SDimitry Andric    const_iterator __e = cend();
20970b57cec5SDimitry Andric    while (!__m.empty())
2098e710425bSDimitry Andric      __tree_.__insert_multi(__e.__i_, std::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
20990b57cec5SDimitry Andric  }
21000b57cec5SDimitry Andric}
21010b57cec5SDimitry Andric#endif
21020b57cec5SDimitry Andric
21030b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2104e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2105e710425bSDimitry Andricoperator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2106c9157d92SDimitry Andric  return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
21070b57cec5SDimitry Andric}
21080b57cec5SDimitry Andric
2109fe013be4SDimitry Andric#if _LIBCPP_STD_VER <= 17
2110fe013be4SDimitry Andric
21110b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2112e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2113e710425bSDimitry Andricoperator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2114c9157d92SDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
21150b57cec5SDimitry Andric}
21160b57cec5SDimitry Andric
21170b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2118e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2119e710425bSDimitry Andricoperator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
21200b57cec5SDimitry Andric  return !(__x == __y);
21210b57cec5SDimitry Andric}
21220b57cec5SDimitry Andric
21230b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2124e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2125e710425bSDimitry Andricoperator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
21260b57cec5SDimitry Andric  return __y < __x;
21270b57cec5SDimitry Andric}
21280b57cec5SDimitry Andric
21290b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2130e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2131e710425bSDimitry Andricoperator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
21320b57cec5SDimitry Andric  return !(__x < __y);
21330b57cec5SDimitry Andric}
21340b57cec5SDimitry Andric
21350b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2136e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
2137e710425bSDimitry Andricoperator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
21380b57cec5SDimitry Andric  return !(__y < __x);
21390b57cec5SDimitry Andric}
21400b57cec5SDimitry Andric
2141fe013be4SDimitry Andric#else // #if _LIBCPP_STD_VER <= 17
2142fe013be4SDimitry Andric
2143fe013be4SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2144fe013be4SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<pair<const _Key, _Tp>>
2145fe013be4SDimitry Andricoperator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
2146fe013be4SDimitry Andric            const multimap<_Key, _Tp, _Compare, _Allocator>& __y) {
2147fe013be4SDimitry Andric  return std::lexicographical_compare_three_way(
2148fe013be4SDimitry Andric      __x.begin(),
2149fe013be4SDimitry Andric      __x.end(),
2150fe013be4SDimitry Andric      __y.begin(),
2151fe013be4SDimitry Andric      __y.end(),
2152fe013be4SDimitry Andric      std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
2153fe013be4SDimitry Andric}
2154fe013be4SDimitry Andric
2155fe013be4SDimitry Andric#endif // #if _LIBCPP_STD_VER <= 17
2156fe013be4SDimitry Andric
21570b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
2158e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
2159e710425bSDimitry Andricswap(multimap<_Key, _Tp, _Compare, _Allocator>& __x, multimap<_Key, _Tp, _Compare, _Allocator>& __y)
2160e710425bSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
21610b57cec5SDimitry Andric  __x.swap(__y);
21620b57cec5SDimitry Andric}
21630b57cec5SDimitry Andric
2164fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20
2165e710425bSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
2166e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
2167e710425bSDimitry Andricerase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
2168c9157d92SDimitry Andric  return std::__libcpp_erase_if_container(__c, __pred);
21695ffd83dbSDimitry Andric}
21700b57cec5SDimitry Andric#endif
21710b57cec5SDimitry Andric
21720b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
21730b57cec5SDimitry Andric
2174fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17
2175bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2176bdd1243dSDimitry Andricnamespace pmr {
2177bdd1243dSDimitry Andrictemplate <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>>
2178e710425bSDimitry Andricusing map _LIBCPP_AVAILABILITY_PMR =
2179e710425bSDimitry Andric    std::map<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
2180bdd1243dSDimitry Andric
2181bdd1243dSDimitry Andrictemplate <class _KeyT, class _ValueT, class _CompareT = std::less<_KeyT>>
2182e710425bSDimitry Andricusing multimap _LIBCPP_AVAILABILITY_PMR =
2183e710425bSDimitry Andric    std::multimap<_KeyT, _ValueT, _CompareT, polymorphic_allocator<std::pair<const _KeyT, _ValueT>>>;
2184bdd1243dSDimitry Andric} // namespace pmr
2185bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
2186bdd1243dSDimitry Andric#endif
2187bdd1243dSDimitry Andric
2188*b9d9368bSDimitry Andric_LIBCPP_POP_MACROS
2189*b9d9368bSDimitry Andric
2190bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2191bdd1243dSDimitry Andric#  include <concepts>
2192fe013be4SDimitry Andric#  include <cstdlib>
2193bdd1243dSDimitry Andric#  include <functional>
2194bdd1243dSDimitry Andric#  include <iterator>
2195fe013be4SDimitry Andric#  include <type_traits>
2196bdd1243dSDimitry Andric#  include <utility>
2197bdd1243dSDimitry Andric#endif
2198bdd1243dSDimitry Andric
21990b57cec5SDimitry Andric#endif // _LIBCPP_MAP
2200