xref: /freebsd/contrib/llvm-project/libcxx/include/map (revision 753f127f3ace09432b2baeffd71a308760641a62)
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);
730b57cec5SDimitry Andric    map(const map& m);
740b57cec5SDimitry Andric    map(map&& m)
750b57cec5SDimitry Andric        noexcept(
760b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
770b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
780b57cec5SDimitry Andric    explicit map(const allocator_type& a);
790b57cec5SDimitry Andric    map(const map& m, const allocator_type& a);
800b57cec5SDimitry Andric    map(map&& m, const allocator_type& a);
810b57cec5SDimitry Andric    map(initializer_list<value_type> il, const key_compare& comp = key_compare());
820b57cec5SDimitry Andric    map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
830b57cec5SDimitry Andric    template <class InputIterator>
840b57cec5SDimitry Andric        map(InputIterator first, InputIterator last, const allocator_type& a)
850b57cec5SDimitry Andric            : map(first, last, Compare(), a) {}  // C++14
860b57cec5SDimitry Andric    map(initializer_list<value_type> il, const allocator_type& a)
870b57cec5SDimitry Andric        : map(il, Compare(), a) {}  // C++14
880b57cec5SDimitry Andric   ~map();
890b57cec5SDimitry Andric
900b57cec5SDimitry Andric    map& operator=(const map& m);
910b57cec5SDimitry Andric    map& operator=(map&& m)
920b57cec5SDimitry Andric        noexcept(
930b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
940b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
950b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
960b57cec5SDimitry Andric    map& operator=(initializer_list<value_type> il);
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric    // iterators:
990b57cec5SDimitry Andric          iterator begin() noexcept;
1000b57cec5SDimitry Andric    const_iterator begin() const noexcept;
1010b57cec5SDimitry Andric          iterator end() noexcept;
1020b57cec5SDimitry Andric    const_iterator end()   const noexcept;
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
1050b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
1060b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
1070b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
1080b57cec5SDimitry Andric
1090b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
1100b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
1110b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
1120b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andric    // capacity:
1150b57cec5SDimitry Andric    bool      empty()    const noexcept;
1160b57cec5SDimitry Andric    size_type size()     const noexcept;
1170b57cec5SDimitry Andric    size_type max_size() const noexcept;
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andric    // element access:
1200b57cec5SDimitry Andric    mapped_type& operator[](const key_type& k);
1210b57cec5SDimitry Andric    mapped_type& operator[](key_type&& k);
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric          mapped_type& at(const key_type& k);
1240b57cec5SDimitry Andric    const mapped_type& at(const key_type& k) const;
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andric    // modifiers:
1270b57cec5SDimitry Andric    template <class... Args>
1280b57cec5SDimitry Andric        pair<iterator, bool> emplace(Args&&... args);
1290b57cec5SDimitry Andric    template <class... Args>
1300b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
1310b57cec5SDimitry Andric    pair<iterator, bool> insert(const value_type& v);
1320b57cec5SDimitry Andric    pair<iterator, bool> insert(      value_type&& v);                                // C++17
1330b57cec5SDimitry Andric    template <class P>
1340b57cec5SDimitry Andric        pair<iterator, bool> insert(P&& p);
1350b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
1360b57cec5SDimitry Andric    iterator insert(const_iterator position,       value_type&& v);                   // C++17
1370b57cec5SDimitry Andric    template <class P>
1380b57cec5SDimitry Andric        iterator insert(const_iterator position, P&& p);
1390b57cec5SDimitry Andric    template <class InputIterator>
1400b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
1410b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
1440b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
1450b57cec5SDimitry Andric    insert_return_type insert(node_type&& nh);                                        // C++17
1460b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric    template <class... Args>
1490b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);          // C++17
1500b57cec5SDimitry Andric    template <class... Args>
1510b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);               // C++17
1520b57cec5SDimitry Andric    template <class... Args>
1530b57cec5SDimitry Andric        iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
1540b57cec5SDimitry Andric    template <class... Args>
1550b57cec5SDimitry Andric        iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);      // C++17
1560b57cec5SDimitry Andric    template <class M>
1570b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);            // C++17
1580b57cec5SDimitry Andric    template <class M>
1590b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);                 // C++17
1600b57cec5SDimitry Andric    template <class M>
1610b57cec5SDimitry Andric        iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);   // C++17
1620b57cec5SDimitry Andric    template <class M>
1630b57cec5SDimitry Andric        iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);        // C++17
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric    iterator  erase(const_iterator position);
1660b57cec5SDimitry Andric    iterator  erase(iterator position); // C++14
1670b57cec5SDimitry Andric    size_type erase(const key_type& k);
1680b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
1690b57cec5SDimitry Andric    void clear() noexcept;
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric    template<class C2>
1720b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>& source);         // C++17
1730b57cec5SDimitry Andric    template<class C2>
1740b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>&& source);        // C++17
1750b57cec5SDimitry Andric    template<class C2>
1760b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>& source);    // C++17
1770b57cec5SDimitry Andric    template<class C2>
1780b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>&& source);   // C++17
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric    void swap(map& m)
1810b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
1820b57cec5SDimitry Andric            is_nothrow_swappable<key_compare>::value); // C++17
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric    // observers:
1850b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
1860b57cec5SDimitry Andric    key_compare    key_comp()      const;
1870b57cec5SDimitry Andric    value_compare  value_comp()    const;
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andric    // map operations:
1900b57cec5SDimitry Andric          iterator find(const key_type& k);
1910b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
1920b57cec5SDimitry Andric    template<typename K>
1930b57cec5SDimitry Andric        iterator find(const K& x);              // C++14
1940b57cec5SDimitry Andric    template<typename K>
1950b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
196fe6060f1SDimitry Andric
1970b57cec5SDimitry Andric    template<typename K>
1980b57cec5SDimitry Andric      size_type count(const K& x) const;        // C++14
1990b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
200fe6060f1SDimitry Andric
2010b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
202fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
203fe6060f1SDimitry Andric
2040b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
2050b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
2060b57cec5SDimitry Andric    template<typename K>
2070b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
2080b57cec5SDimitry Andric    template<typename K>
2090b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
2100b57cec5SDimitry Andric
2110b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
2120b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
2130b57cec5SDimitry Andric    template<typename K>
2140b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
2150b57cec5SDimitry Andric    template<typename K>
2160b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
2190b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
2200b57cec5SDimitry Andric    template<typename K>
2210b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
2220b57cec5SDimitry Andric    template<typename K>
2230b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
2240b57cec5SDimitry Andric};
2250b57cec5SDimitry Andric
226349cc55cSDimitry Andrictemplate <class InputIterator,
227349cc55cSDimitry Andric      class Compare = less<iter_key_t<InputIterator>>,
228349cc55cSDimitry Andric      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
229349cc55cSDimitry Andricmap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
230349cc55cSDimitry Andric  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
231349cc55cSDimitry Andric
232349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>,
233349cc55cSDimitry Andric    class Allocator = allocator<pair<const Key, T>>>
234349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
235349cc55cSDimitry Andric  -> map<Key, T, Compare, Allocator>; // C++17
236349cc55cSDimitry Andric
237349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator>
238349cc55cSDimitry Andricmap(InputIterator, InputIterator, Allocator)
239349cc55cSDimitry Andric  -> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, less<iter_key_t<InputIterator>>,
240349cc55cSDimitry Andric    Allocator>; // C++17
241349cc55cSDimitry Andric
242349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator>
243349cc55cSDimitry Andricmap(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>; // C++17
244349cc55cSDimitry Andric
2450b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2460b57cec5SDimitry Andricbool
2470b57cec5SDimitry Andricoperator==(const map<Key, T, Compare, Allocator>& x,
2480b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2510b57cec5SDimitry Andricbool
2520b57cec5SDimitry Andricoperator< (const map<Key, T, Compare, Allocator>& x,
2530b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2560b57cec5SDimitry Andricbool
2570b57cec5SDimitry Andricoperator!=(const map<Key, T, Compare, Allocator>& x,
2580b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2590b57cec5SDimitry Andric
2600b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2610b57cec5SDimitry Andricbool
2620b57cec5SDimitry Andricoperator> (const map<Key, T, Compare, Allocator>& x,
2630b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2640b57cec5SDimitry Andric
2650b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2660b57cec5SDimitry Andricbool
2670b57cec5SDimitry Andricoperator>=(const map<Key, T, Compare, Allocator>& x,
2680b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2710b57cec5SDimitry Andricbool
2720b57cec5SDimitry Andricoperator<=(const map<Key, T, Compare, Allocator>& x,
2730b57cec5SDimitry Andric           const map<Key, T, Compare, Allocator>& y);
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric// specialized algorithms:
2760b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
2770b57cec5SDimitry Andricvoid
2780b57cec5SDimitry Andricswap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
2790b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
2800b57cec5SDimitry Andric
2810b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate>
2825ffd83dbSDimitry Andrictypename map<Key, T, Compare, Allocator>::size_type
2835ffd83dbSDimitry Andricerase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
2840b57cec5SDimitry Andric
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andrictemplate <class Key, class T, class Compare = less<Key>,
2870b57cec5SDimitry Andric          class Allocator = allocator<pair<const Key, T>>>
2880b57cec5SDimitry Andricclass multimap
2890b57cec5SDimitry Andric{
2900b57cec5SDimitry Andricpublic:
2910b57cec5SDimitry Andric    // types:
2920b57cec5SDimitry Andric    typedef Key                                      key_type;
2930b57cec5SDimitry Andric    typedef T                                        mapped_type;
2940b57cec5SDimitry Andric    typedef pair<const key_type,mapped_type>         value_type;
2950b57cec5SDimitry Andric    typedef Compare                                  key_compare;
2960b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
2970b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
2980b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
2990b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
3000b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
3010b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
3020b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
3050b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
3060b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
3070b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
3080b57cec5SDimitry Andric    typedef unspecified                              node_type;              // C++17
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric    class value_compare
3110b57cec5SDimitry Andric    {
3120b57cec5SDimitry Andric        friend class multimap;
3130b57cec5SDimitry Andric    protected:
3140b57cec5SDimitry Andric        key_compare comp;
3150b57cec5SDimitry Andric        value_compare(key_compare c);
3160b57cec5SDimitry Andric    public:
317fe6060f1SDimitry Andric        typedef bool result_type;  // deprecated in C++17, removed in C++20
318fe6060f1SDimitry Andric        typedef value_type first_argument_type;  // deprecated in C++17, removed in C++20
319fe6060f1SDimitry Andric        typedef value_type second_argument_type;  // deprecated in C++17, removed in C++20
3200b57cec5SDimitry Andric        bool operator()(const value_type& x, const value_type& y) const;
3210b57cec5SDimitry Andric    };
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andric    // construct/copy/destroy:
3240b57cec5SDimitry Andric    multimap()
3250b57cec5SDimitry Andric        noexcept(
3260b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
3270b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
3280b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value);
3290b57cec5SDimitry Andric    explicit multimap(const key_compare& comp);
3300b57cec5SDimitry Andric    multimap(const key_compare& comp, const allocator_type& a);
3310b57cec5SDimitry Andric    template <class InputIterator>
3320b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const key_compare& comp);
3330b57cec5SDimitry Andric    template <class InputIterator>
3340b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const key_compare& comp,
3350b57cec5SDimitry Andric                 const allocator_type& a);
3360b57cec5SDimitry Andric    multimap(const multimap& m);
3370b57cec5SDimitry Andric    multimap(multimap&& m)
3380b57cec5SDimitry Andric        noexcept(
3390b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
3400b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
3410b57cec5SDimitry Andric    explicit multimap(const allocator_type& a);
3420b57cec5SDimitry Andric    multimap(const multimap& m, const allocator_type& a);
3430b57cec5SDimitry Andric    multimap(multimap&& m, const allocator_type& a);
3440b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
3450b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const key_compare& comp,
3460b57cec5SDimitry Andric             const allocator_type& a);
3470b57cec5SDimitry Andric    template <class InputIterator>
3480b57cec5SDimitry Andric        multimap(InputIterator first, InputIterator last, const allocator_type& a)
3490b57cec5SDimitry Andric            : multimap(first, last, Compare(), a) {} // C++14
3500b57cec5SDimitry Andric    multimap(initializer_list<value_type> il, const allocator_type& a)
3510b57cec5SDimitry Andric        : multimap(il, Compare(), a) {} // C++14
3520b57cec5SDimitry Andric    ~multimap();
3530b57cec5SDimitry Andric
3540b57cec5SDimitry Andric    multimap& operator=(const multimap& m);
3550b57cec5SDimitry Andric    multimap& operator=(multimap&& m)
3560b57cec5SDimitry Andric        noexcept(
3570b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
3580b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
3590b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
3600b57cec5SDimitry Andric    multimap& operator=(initializer_list<value_type> il);
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andric    // iterators:
3630b57cec5SDimitry Andric          iterator begin() noexcept;
3640b57cec5SDimitry Andric    const_iterator begin() const noexcept;
3650b57cec5SDimitry Andric          iterator end() noexcept;
3660b57cec5SDimitry Andric    const_iterator end()   const noexcept;
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
3690b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
3700b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
3710b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
3720b57cec5SDimitry Andric
3730b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
3740b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
3750b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
3760b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
3770b57cec5SDimitry Andric
3780b57cec5SDimitry Andric    // capacity:
3790b57cec5SDimitry Andric    bool      empty()    const noexcept;
3800b57cec5SDimitry Andric    size_type size()     const noexcept;
3810b57cec5SDimitry Andric    size_type max_size() const noexcept;
3820b57cec5SDimitry Andric
3830b57cec5SDimitry Andric    // modifiers:
3840b57cec5SDimitry Andric    template <class... Args>
3850b57cec5SDimitry Andric        iterator emplace(Args&&... args);
3860b57cec5SDimitry Andric    template <class... Args>
3870b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
3880b57cec5SDimitry Andric    iterator insert(const value_type& v);
3890b57cec5SDimitry Andric    iterator insert(      value_type&& v);                                            // C++17
3900b57cec5SDimitry Andric    template <class P>
3910b57cec5SDimitry Andric        iterator insert(P&& p);
3920b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
3930b57cec5SDimitry Andric    iterator insert(const_iterator position,       value_type&& v);                   // C++17
3940b57cec5SDimitry Andric    template <class P>
3950b57cec5SDimitry Andric        iterator insert(const_iterator position, P&& p);
3960b57cec5SDimitry Andric    template <class InputIterator>
3970b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
3980b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
3990b57cec5SDimitry Andric
4000b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
4010b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
4020b57cec5SDimitry Andric    iterator insert(node_type&& nh);                                                  // C++17
4030b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric    iterator  erase(const_iterator position);
4060b57cec5SDimitry Andric    iterator  erase(iterator position); // C++14
4070b57cec5SDimitry Andric    size_type erase(const key_type& k);
4080b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
4090b57cec5SDimitry Andric    void clear() noexcept;
4100b57cec5SDimitry Andric
4110b57cec5SDimitry Andric    template<class C2>
4120b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>& source);    // C++17
4130b57cec5SDimitry Andric    template<class C2>
4140b57cec5SDimitry Andric      void merge(multimap<Key, T, C2, Allocator>&& source);   // C++17
4150b57cec5SDimitry Andric    template<class C2>
4160b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>& source);         // C++17
4170b57cec5SDimitry Andric    template<class C2>
4180b57cec5SDimitry Andric      void merge(map<Key, T, C2, Allocator>&& source);        // C++17
4190b57cec5SDimitry Andric
4200b57cec5SDimitry Andric    void swap(multimap& m)
4210b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
4220b57cec5SDimitry Andric            is_nothrow_swappable<key_compare>::value); // C++17
4230b57cec5SDimitry Andric
4240b57cec5SDimitry Andric    // observers:
4250b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
4260b57cec5SDimitry Andric    key_compare    key_comp()      const;
4270b57cec5SDimitry Andric    value_compare  value_comp()    const;
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric    // map operations:
4300b57cec5SDimitry Andric          iterator find(const key_type& k);
4310b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
4320b57cec5SDimitry Andric    template<typename K>
4330b57cec5SDimitry Andric        iterator find(const K& x);              // C++14
4340b57cec5SDimitry Andric    template<typename K>
4350b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
436fe6060f1SDimitry Andric
4370b57cec5SDimitry Andric    template<typename K>
4380b57cec5SDimitry Andric      size_type count(const K& x) const;        // C++14
4390b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
440fe6060f1SDimitry Andric
4410b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
442fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
443fe6060f1SDimitry Andric
4440b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
4450b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
4460b57cec5SDimitry Andric    template<typename K>
4470b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
4480b57cec5SDimitry Andric    template<typename K>
4490b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
4500b57cec5SDimitry Andric
4510b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
4520b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
4530b57cec5SDimitry Andric    template<typename K>
4540b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
4550b57cec5SDimitry Andric    template<typename K>
4560b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
4570b57cec5SDimitry Andric
4580b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
4590b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
4600b57cec5SDimitry Andric    template<typename K>
4610b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
4620b57cec5SDimitry Andric    template<typename K>
4630b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
4640b57cec5SDimitry Andric};
4650b57cec5SDimitry Andric
466349cc55cSDimitry Andrictemplate <class InputIterator,
467349cc55cSDimitry Andric      class Compare = less<iter_key_t<InputIterator>>,
468349cc55cSDimitry Andric      class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
469349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
470349cc55cSDimitry Andric  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>; // C++17
471349cc55cSDimitry Andric
472349cc55cSDimitry Andrictemplate<class Key, class T, class Compare = less<Key>,
473349cc55cSDimitry Andric    class Allocator = allocator<pair<const Key, T>>>
474349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
475349cc55cSDimitry Andric  -> multimap<Key, T, Compare, Allocator>; // C++17
476349cc55cSDimitry Andric
477349cc55cSDimitry Andrictemplate <class InputIterator, class Allocator>
478349cc55cSDimitry Andricmultimap(InputIterator, InputIterator, Allocator)
479349cc55cSDimitry Andric  -> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
480349cc55cSDimitry Andric    less<iter_key_t<InputIterator>>, Allocator>; // C++17
481349cc55cSDimitry Andric
482349cc55cSDimitry Andrictemplate<class Key, class T, class Allocator>
483349cc55cSDimitry Andricmultimap(initializer_list<pair<const Key, T>>, Allocator)
484349cc55cSDimitry Andric  -> multimap<Key, T, less<Key>, Allocator>; // C++17
485349cc55cSDimitry Andric
4860b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
4870b57cec5SDimitry Andricbool
4880b57cec5SDimitry Andricoperator==(const multimap<Key, T, Compare, Allocator>& x,
4890b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
4900b57cec5SDimitry Andric
4910b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
4920b57cec5SDimitry Andricbool
4930b57cec5SDimitry Andricoperator< (const multimap<Key, T, Compare, Allocator>& x,
4940b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
4950b57cec5SDimitry Andric
4960b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
4970b57cec5SDimitry Andricbool
4980b57cec5SDimitry Andricoperator!=(const multimap<Key, T, Compare, Allocator>& x,
4990b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5020b57cec5SDimitry Andricbool
5030b57cec5SDimitry Andricoperator> (const multimap<Key, T, Compare, Allocator>& x,
5040b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5070b57cec5SDimitry Andricbool
5080b57cec5SDimitry Andricoperator>=(const multimap<Key, T, Compare, Allocator>& x,
5090b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
5100b57cec5SDimitry Andric
5110b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5120b57cec5SDimitry Andricbool
5130b57cec5SDimitry Andricoperator<=(const multimap<Key, T, Compare, Allocator>& x,
5140b57cec5SDimitry Andric           const multimap<Key, T, Compare, Allocator>& y);
5150b57cec5SDimitry Andric
5160b57cec5SDimitry Andric// specialized algorithms:
5170b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator>
5180b57cec5SDimitry Andricvoid
5190b57cec5SDimitry Andricswap(multimap<Key, T, Compare, Allocator>& x,
5200b57cec5SDimitry Andric     multimap<Key, T, Compare, Allocator>& y)
5210b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
5220b57cec5SDimitry Andric
5230b57cec5SDimitry Andrictemplate <class Key, class T, class Compare, class Allocator, class Predicate>
5245ffd83dbSDimitry Andrictypename multimap<Key, T, Compare, Allocator>::size_type
5255ffd83dbSDimitry Andricerase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);  // C++20
5260b57cec5SDimitry Andric
5270b57cec5SDimitry Andric}  // std
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andric*/
5300b57cec5SDimitry Andric
53181ad6265SDimitry Andric#include <__algorithm/equal.h>
53281ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
53381ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
5340b57cec5SDimitry Andric#include <__config>
53581ad6265SDimitry Andric#include <__functional/binary_function.h>
536fe6060f1SDimitry Andric#include <__functional/is_transparent.h>
53781ad6265SDimitry Andric#include <__functional/operations.h>
53881ad6265SDimitry Andric#include <__iterator/erase_if_container.h>
539349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
54081ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
5410b57cec5SDimitry Andric#include <__node_handle>
542fe6060f1SDimitry Andric#include <__tree>
543fe6060f1SDimitry Andric#include <__utility/forward.h>
54481ad6265SDimitry Andric#include <__utility/swap.h>
545fe6060f1SDimitry Andric#include <memory>
5460b57cec5SDimitry Andric#include <type_traits>
5470b57cec5SDimitry Andric#include <version>
5480b57cec5SDimitry Andric
54981ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
55081ad6265SDimitry Andric#  include <functional>
55181ad6265SDimitry Andric#  include <iterator>
55281ad6265SDimitry Andric#  include <utility>
55381ad6265SDimitry Andric#endif
55481ad6265SDimitry Andric
55581ad6265SDimitry Andric// standard-mandated includes
55681ad6265SDimitry Andric
55781ad6265SDimitry Andric// [iterator.range]
55881ad6265SDimitry Andric#include <__iterator/access.h>
55981ad6265SDimitry Andric#include <__iterator/data.h>
56081ad6265SDimitry Andric#include <__iterator/empty.h>
56181ad6265SDimitry Andric#include <__iterator/reverse_access.h>
56281ad6265SDimitry Andric#include <__iterator/size.h>
56381ad6265SDimitry Andric
56481ad6265SDimitry Andric// [associative.map.syn]
56581ad6265SDimitry Andric#include <compare>
56681ad6265SDimitry Andric#include <initializer_list>
56781ad6265SDimitry Andric
5680b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5690b57cec5SDimitry Andric#  pragma GCC system_header
5700b57cec5SDimitry Andric#endif
5710b57cec5SDimitry Andric
5720b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
5730b57cec5SDimitry Andric
5740b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare,
5750b57cec5SDimitry Andric          bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
5760b57cec5SDimitry Andricclass __map_value_compare
5770b57cec5SDimitry Andric    : private _Compare
5780b57cec5SDimitry Andric{
5790b57cec5SDimitry Andricpublic:
5800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5810b57cec5SDimitry Andric    __map_value_compare()
5820b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
5830b57cec5SDimitry Andric        : _Compare() {}
5840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
585*753f127fSDimitry Andric    __map_value_compare(_Compare __c)
5860b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
587*753f127fSDimitry Andric        : _Compare(__c) {}
5880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5890b57cec5SDimitry Andric    const _Compare& key_comp() const _NOEXCEPT {return *this;}
5900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5910b57cec5SDimitry Andric    bool operator()(const _CP& __x, const _CP& __y) const
5920b57cec5SDimitry Andric        {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
5930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5940b57cec5SDimitry Andric    bool operator()(const _CP& __x, const _Key& __y) const
5950b57cec5SDimitry Andric        {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
5960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5970b57cec5SDimitry Andric    bool operator()(const _Key& __x, const _CP& __y) const
5980b57cec5SDimitry Andric        {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
5990b57cec5SDimitry Andric    void swap(__map_value_compare& __y)
6000b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
6010b57cec5SDimitry Andric    {
6020b57cec5SDimitry Andric      using _VSTD::swap;
6030b57cec5SDimitry Andric      swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
6040b57cec5SDimitry Andric    }
6050b57cec5SDimitry Andric
6060b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
6070b57cec5SDimitry Andric    template <typename _K2>
6080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
609349cc55cSDimitry Andric    bool operator()(const _K2& __x, const _CP& __y) const
6100b57cec5SDimitry Andric        {return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
6110b57cec5SDimitry Andric
6120b57cec5SDimitry Andric    template <typename _K2>
6130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
614349cc55cSDimitry Andric    bool operator()(const _CP& __x, const _K2& __y) const
6150b57cec5SDimitry Andric        {return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
6160b57cec5SDimitry Andric#endif
6170b57cec5SDimitry Andric};
6180b57cec5SDimitry Andric
6190b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare>
6200b57cec5SDimitry Andricclass __map_value_compare<_Key, _CP, _Compare, false>
6210b57cec5SDimitry Andric{
6220b57cec5SDimitry Andric    _Compare comp;
6230b57cec5SDimitry Andric
6240b57cec5SDimitry Andricpublic:
6250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6260b57cec5SDimitry Andric    __map_value_compare()
6270b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
6280b57cec5SDimitry Andric        : comp() {}
6290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
630*753f127fSDimitry Andric    __map_value_compare(_Compare __c)
6310b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
632*753f127fSDimitry Andric        : comp(__c) {}
6330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6340b57cec5SDimitry Andric    const _Compare& key_comp() const _NOEXCEPT {return comp;}
6350b57cec5SDimitry Andric
6360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6370b57cec5SDimitry Andric    bool operator()(const _CP& __x, const _CP& __y) const
6380b57cec5SDimitry Andric        {return comp(__x.__get_value().first, __y.__get_value().first);}
6390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6400b57cec5SDimitry Andric    bool operator()(const _CP& __x, const _Key& __y) const
6410b57cec5SDimitry Andric        {return comp(__x.__get_value().first, __y);}
6420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6430b57cec5SDimitry Andric    bool operator()(const _Key& __x, const _CP& __y) const
6440b57cec5SDimitry Andric        {return comp(__x, __y.__get_value().first);}
6450b57cec5SDimitry Andric    void swap(__map_value_compare& __y)
6460b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
6470b57cec5SDimitry Andric    {
6480b57cec5SDimitry Andric        using _VSTD::swap;
6490b57cec5SDimitry Andric        swap(comp, __y.comp);
6500b57cec5SDimitry Andric    }
6510b57cec5SDimitry Andric
6520b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
6530b57cec5SDimitry Andric    template <typename _K2>
6540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
655349cc55cSDimitry Andric    bool operator()(const _K2& __x, const _CP& __y) const
6560b57cec5SDimitry Andric        {return comp(__x, __y.__get_value().first);}
6570b57cec5SDimitry Andric
6580b57cec5SDimitry Andric    template <typename _K2>
6590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
660349cc55cSDimitry Andric    bool operator()(const _CP& __x, const _K2& __y) const
6610b57cec5SDimitry Andric        {return comp(__x.__get_value().first, __y);}
6620b57cec5SDimitry Andric#endif
6630b57cec5SDimitry Andric};
6640b57cec5SDimitry Andric
6650b57cec5SDimitry Andrictemplate <class _Key, class _CP, class _Compare, bool __b>
6660b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
6670b57cec5SDimitry Andricvoid
6680b57cec5SDimitry Andricswap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
6690b57cec5SDimitry Andric     __map_value_compare<_Key, _CP, _Compare, __b>& __y)
6700b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
6710b57cec5SDimitry Andric{
6720b57cec5SDimitry Andric    __x.swap(__y);
6730b57cec5SDimitry Andric}
6740b57cec5SDimitry Andric
6750b57cec5SDimitry Andrictemplate <class _Allocator>
6760b57cec5SDimitry Andricclass __map_node_destructor
6770b57cec5SDimitry Andric{
6780b57cec5SDimitry Andric    typedef _Allocator                          allocator_type;
6790b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>    __alloc_traits;
6800b57cec5SDimitry Andric
6810b57cec5SDimitry Andricpublic:
6820b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer    pointer;
6830b57cec5SDimitry Andric
6840b57cec5SDimitry Andricprivate:
6850b57cec5SDimitry Andric    allocator_type& __na_;
6860b57cec5SDimitry Andric
6870b57cec5SDimitry Andric    __map_node_destructor& operator=(const __map_node_destructor&);
6880b57cec5SDimitry Andric
6890b57cec5SDimitry Andricpublic:
6900b57cec5SDimitry Andric    bool __first_constructed;
6910b57cec5SDimitry Andric    bool __second_constructed;
6920b57cec5SDimitry Andric
6930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6940b57cec5SDimitry Andric    explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
6950b57cec5SDimitry Andric        : __na_(__na),
6960b57cec5SDimitry Andric          __first_constructed(false),
6970b57cec5SDimitry Andric          __second_constructed(false)
6980b57cec5SDimitry Andric        {}
6990b57cec5SDimitry Andric
7000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7020b57cec5SDimitry Andric    __map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
7030b57cec5SDimitry Andric        : __na_(__x.__na_),
7040b57cec5SDimitry Andric          __first_constructed(__x.__value_constructed),
7050b57cec5SDimitry Andric          __second_constructed(__x.__value_constructed)
7060b57cec5SDimitry Andric        {
7070b57cec5SDimitry Andric            __x.__value_constructed = false;
7080b57cec5SDimitry Andric        }
7090b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7100b57cec5SDimitry Andric
7110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7120b57cec5SDimitry Andric    void operator()(pointer __p) _NOEXCEPT
7130b57cec5SDimitry Andric    {
7140b57cec5SDimitry Andric        if (__second_constructed)
7150b57cec5SDimitry Andric            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
7160b57cec5SDimitry Andric        if (__first_constructed)
7170b57cec5SDimitry Andric            __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
7180b57cec5SDimitry Andric        if (__p)
7190b57cec5SDimitry Andric            __alloc_traits::deallocate(__na_, __p, 1);
7200b57cec5SDimitry Andric    }
7210b57cec5SDimitry Andric};
7220b57cec5SDimitry Andric
7230b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
7240b57cec5SDimitry Andric    class map;
7250b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
7260b57cec5SDimitry Andric    class multimap;
7270b57cec5SDimitry Andrictemplate <class _TreeIterator> class __map_const_iterator;
7280b57cec5SDimitry Andric
7290b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7300b57cec5SDimitry Andric
7310b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
732fe6060f1SDimitry Andricstruct _LIBCPP_STANDALONE_DEBUG __value_type
7330b57cec5SDimitry Andric{
7340b57cec5SDimitry Andric    typedef _Key                                     key_type;
7350b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
7360b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
7370b57cec5SDimitry Andric    typedef pair<key_type&, mapped_type&>            __nc_ref_pair_type;
7380b57cec5SDimitry Andric    typedef pair<key_type&&, mapped_type&&>          __nc_rref_pair_type;
7390b57cec5SDimitry Andric
7400b57cec5SDimitry Andricprivate:
7410b57cec5SDimitry Andric    value_type __cc;
7420b57cec5SDimitry Andric
7430b57cec5SDimitry Andricpublic:
7440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7450b57cec5SDimitry Andric    value_type& __get_value()
7460b57cec5SDimitry Andric    {
7470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
7480b57cec5SDimitry Andric        return *_VSTD::launder(_VSTD::addressof(__cc));
7490b57cec5SDimitry Andric#else
7500b57cec5SDimitry Andric        return __cc;
7510b57cec5SDimitry Andric#endif
7520b57cec5SDimitry Andric    }
7530b57cec5SDimitry Andric
7540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7550b57cec5SDimitry Andric    const value_type& __get_value() const
7560b57cec5SDimitry Andric    {
7570b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
7580b57cec5SDimitry Andric        return *_VSTD::launder(_VSTD::addressof(__cc));
7590b57cec5SDimitry Andric#else
7600b57cec5SDimitry Andric        return __cc;
7610b57cec5SDimitry Andric#endif
7620b57cec5SDimitry Andric    }
7630b57cec5SDimitry Andric
7640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7650b57cec5SDimitry Andric    __nc_ref_pair_type __ref()
7660b57cec5SDimitry Andric    {
7670b57cec5SDimitry Andric        value_type& __v = __get_value();
7680b57cec5SDimitry Andric        return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
7690b57cec5SDimitry Andric    }
7700b57cec5SDimitry Andric
7710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7720b57cec5SDimitry Andric    __nc_rref_pair_type __move()
7730b57cec5SDimitry Andric    {
7740b57cec5SDimitry Andric        value_type& __v = __get_value();
7750b57cec5SDimitry Andric        return __nc_rref_pair_type(
7760b57cec5SDimitry Andric            _VSTD::move(const_cast<key_type&>(__v.first)),
7770b57cec5SDimitry Andric            _VSTD::move(__v.second));
7780b57cec5SDimitry Andric    }
7790b57cec5SDimitry Andric
7800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7810b57cec5SDimitry Andric    __value_type& operator=(const __value_type& __v)
7820b57cec5SDimitry Andric    {
7830b57cec5SDimitry Andric        __ref() = __v.__get_value();
7840b57cec5SDimitry Andric        return *this;
7850b57cec5SDimitry Andric    }
7860b57cec5SDimitry Andric
7870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7880b57cec5SDimitry Andric    __value_type& operator=(__value_type&& __v)
7890b57cec5SDimitry Andric    {
7900b57cec5SDimitry Andric        __ref() = __v.__move();
7910b57cec5SDimitry Andric        return *this;
7920b57cec5SDimitry Andric    }
7930b57cec5SDimitry Andric
7940b57cec5SDimitry Andric    template <class _ValueTp,
795*753f127fSDimitry Andric              class = __enable_if_t<__is_same_uncvref<_ValueTp, value_type>::value>
7960b57cec5SDimitry Andric             >
7970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7980b57cec5SDimitry Andric    __value_type& operator=(_ValueTp&& __v)
7990b57cec5SDimitry Andric    {
8000b57cec5SDimitry Andric        __ref() = _VSTD::forward<_ValueTp>(__v);
8010b57cec5SDimitry Andric        return *this;
8020b57cec5SDimitry Andric    }
8030b57cec5SDimitry Andric
8040b57cec5SDimitry Andricprivate:
805349cc55cSDimitry Andric    __value_type() = delete;
806349cc55cSDimitry Andric    ~__value_type() = delete;
807349cc55cSDimitry Andric    __value_type(const __value_type&) = delete;
808349cc55cSDimitry Andric    __value_type(__value_type&&) = delete;
8090b57cec5SDimitry Andric};
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andric#else
8120b57cec5SDimitry Andric
8130b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
8140b57cec5SDimitry Andricstruct __value_type
8150b57cec5SDimitry Andric{
8160b57cec5SDimitry Andric    typedef _Key                                     key_type;
8170b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
8180b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andricprivate:
8210b57cec5SDimitry Andric    value_type __cc;
8220b57cec5SDimitry Andric
8230b57cec5SDimitry Andricpublic:
8240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8250b57cec5SDimitry Andric    value_type& __get_value() { return __cc; }
8260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8270b57cec5SDimitry Andric    const value_type& __get_value() const { return __cc; }
8280b57cec5SDimitry Andric
8290b57cec5SDimitry Andricprivate:
8300b57cec5SDimitry Andric   __value_type();
8310b57cec5SDimitry Andric   __value_type(__value_type const&);
8320b57cec5SDimitry Andric   __value_type& operator=(__value_type const&);
8330b57cec5SDimitry Andric   ~__value_type();
8340b57cec5SDimitry Andric};
8350b57cec5SDimitry Andric
8360b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8370b57cec5SDimitry Andric
8380b57cec5SDimitry Andrictemplate <class _Tp>
8390b57cec5SDimitry Andricstruct __extract_key_value_types;
8400b57cec5SDimitry Andric
8410b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
8420b57cec5SDimitry Andricstruct __extract_key_value_types<__value_type<_Key, _Tp> >
8430b57cec5SDimitry Andric{
8440b57cec5SDimitry Andric  typedef _Key const __key_type;
8450b57cec5SDimitry Andric  typedef _Tp        __mapped_type;
8460b57cec5SDimitry Andric};
8470b57cec5SDimitry Andric
8480b57cec5SDimitry Andrictemplate <class _TreeIterator>
8490b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_iterator
8500b57cec5SDimitry Andric{
8510b57cec5SDimitry Andric    typedef typename _TreeIterator::_NodeTypes                   _NodeTypes;
8520b57cec5SDimitry Andric    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
8530b57cec5SDimitry Andric
8540b57cec5SDimitry Andric    _TreeIterator __i_;
8550b57cec5SDimitry Andric
8560b57cec5SDimitry Andricpublic:
8570b57cec5SDimitry Andric    typedef bidirectional_iterator_tag                           iterator_category;
8580b57cec5SDimitry Andric    typedef typename _NodeTypes::__map_value_type                value_type;
8590b57cec5SDimitry Andric    typedef typename _TreeIterator::difference_type              difference_type;
8600b57cec5SDimitry Andric    typedef value_type&                                          reference;
8610b57cec5SDimitry Andric    typedef typename _NodeTypes::__map_value_type_pointer        pointer;
8620b57cec5SDimitry Andric
8630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8640b57cec5SDimitry Andric    __map_iterator() _NOEXCEPT {}
8650b57cec5SDimitry Andric
8660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8670b57cec5SDimitry Andric    __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
8680b57cec5SDimitry Andric
8690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8700b57cec5SDimitry Andric    reference operator*() const {return __i_->__get_value();}
8710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8720b57cec5SDimitry Andric    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
8730b57cec5SDimitry Andric
8740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8750b57cec5SDimitry Andric    __map_iterator& operator++() {++__i_; return *this;}
8760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8770b57cec5SDimitry Andric    __map_iterator operator++(int)
8780b57cec5SDimitry Andric    {
8790b57cec5SDimitry Andric        __map_iterator __t(*this);
8800b57cec5SDimitry Andric        ++(*this);
8810b57cec5SDimitry Andric        return __t;
8820b57cec5SDimitry Andric    }
8830b57cec5SDimitry Andric
8840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8850b57cec5SDimitry Andric    __map_iterator& operator--() {--__i_; return *this;}
8860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8870b57cec5SDimitry Andric    __map_iterator operator--(int)
8880b57cec5SDimitry Andric    {
8890b57cec5SDimitry Andric        __map_iterator __t(*this);
8900b57cec5SDimitry Andric        --(*this);
8910b57cec5SDimitry Andric        return __t;
8920b57cec5SDimitry Andric    }
8930b57cec5SDimitry Andric
8940b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
8950b57cec5SDimitry Andric    bool operator==(const __map_iterator& __x, const __map_iterator& __y)
8960b57cec5SDimitry Andric        {return __x.__i_ == __y.__i_;}
8970b57cec5SDimitry Andric    friend
8980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8990b57cec5SDimitry Andric    bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
9000b57cec5SDimitry Andric        {return __x.__i_ != __y.__i_;}
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
9030b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
9040b57cec5SDimitry Andric    template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
9050b57cec5SDimitry Andric};
9060b57cec5SDimitry Andric
9070b57cec5SDimitry Andrictemplate <class _TreeIterator>
9080b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_const_iterator
9090b57cec5SDimitry Andric{
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
9220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9230b57cec5SDimitry Andric    __map_const_iterator() _NOEXCEPT {}
9240b57cec5SDimitry Andric
9250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9260b57cec5SDimitry Andric    __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
9270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9280b57cec5SDimitry Andric    __map_const_iterator(__map_iterator<
9290b57cec5SDimitry Andric        typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
9300b57cec5SDimitry Andric        : __i_(__i.__i_) {}
9310b57cec5SDimitry Andric
9320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9330b57cec5SDimitry Andric    reference operator*() const {return __i_->__get_value();}
9340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9350b57cec5SDimitry Andric    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
9360b57cec5SDimitry Andric
9370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9380b57cec5SDimitry Andric    __map_const_iterator& operator++() {++__i_; return *this;}
9390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9400b57cec5SDimitry Andric    __map_const_iterator operator++(int)
9410b57cec5SDimitry Andric    {
9420b57cec5SDimitry Andric        __map_const_iterator __t(*this);
9430b57cec5SDimitry Andric        ++(*this);
9440b57cec5SDimitry Andric        return __t;
9450b57cec5SDimitry Andric    }
9460b57cec5SDimitry Andric
9470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9480b57cec5SDimitry Andric    __map_const_iterator& operator--() {--__i_; return *this;}
9490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9500b57cec5SDimitry Andric    __map_const_iterator operator--(int)
9510b57cec5SDimitry Andric    {
9520b57cec5SDimitry Andric        __map_const_iterator __t(*this);
9530b57cec5SDimitry Andric        --(*this);
9540b57cec5SDimitry Andric        return __t;
9550b57cec5SDimitry Andric    }
9560b57cec5SDimitry Andric
9570b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
9580b57cec5SDimitry Andric    bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
9590b57cec5SDimitry Andric        {return __x.__i_ == __y.__i_;}
9600b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
9610b57cec5SDimitry Andric    bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
9620b57cec5SDimitry Andric        {return __x.__i_ != __y.__i_;}
9630b57cec5SDimitry Andric
9640b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
9650b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
9660b57cec5SDimitry Andric    template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
9670b57cec5SDimitry Andric};
9680b57cec5SDimitry Andric
9690b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>,
9700b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp> > >
9710b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS map
9720b57cec5SDimitry Andric{
9730b57cec5SDimitry Andricpublic:
9740b57cec5SDimitry Andric    // types:
9750b57cec5SDimitry Andric    typedef _Key                                     key_type;
9760b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
9770b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
97881ad6265SDimitry Andric    typedef __type_identity_t<_Compare>              key_compare;
97981ad6265SDimitry Andric    typedef __type_identity_t<_Allocator>            allocator_type;
9800b57cec5SDimitry Andric    typedef value_type&                              reference;
9810b57cec5SDimitry Andric    typedef const value_type&                        const_reference;
9820b57cec5SDimitry Andric
9830b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
9840b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
9850b57cec5SDimitry Andric
9860b57cec5SDimitry Andric    class _LIBCPP_TEMPLATE_VIS value_compare
98781ad6265SDimitry Andric        : public __binary_function<value_type, value_type, bool>
9880b57cec5SDimitry Andric    {
9890b57cec5SDimitry Andric        friend class map;
9900b57cec5SDimitry Andric    protected:
9910b57cec5SDimitry Andric        key_compare comp;
9920b57cec5SDimitry Andric
993*753f127fSDimitry Andric        _LIBCPP_INLINE_VISIBILITY value_compare(key_compare __c) : comp(__c) {}
9940b57cec5SDimitry Andric    public:
9950b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
9960b57cec5SDimitry Andric        bool operator()(const value_type& __x, const value_type& __y) const
9970b57cec5SDimitry Andric            {return comp(__x.first, __y.first);}
9980b57cec5SDimitry Andric    };
9990b57cec5SDimitry Andric
10000b57cec5SDimitry Andricprivate:
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andric    typedef _VSTD::__value_type<key_type, mapped_type>             __value_type;
10030b57cec5SDimitry Andric    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
10040b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
10050b57cec5SDimitry Andric                                                 __value_type>::type __allocator_type;
10060b57cec5SDimitry Andric    typedef __tree<__value_type, __vc, __allocator_type>   __base;
10070b57cec5SDimitry Andric    typedef typename __base::__node_traits                 __node_traits;
10080b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>               __alloc_traits;
10090b57cec5SDimitry Andric
10100b57cec5SDimitry Andric    __base __tree_;
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andricpublic:
10130b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer               pointer;
10140b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer         const_pointer;
10150b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type             size_type;
10160b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type       difference_type;
10170b57cec5SDimitry Andric    typedef __map_iterator<typename __base::iterator>             iterator;
10180b57cec5SDimitry Andric    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
10190b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
10200b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
10210b57cec5SDimitry Andric
10220b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
10230b57cec5SDimitry Andric    typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
10240b57cec5SDimitry Andric    typedef __insert_return_type<iterator, node_type> insert_return_type;
10250b57cec5SDimitry Andric#endif
10260b57cec5SDimitry Andric
10270b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10280b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS map;
10290b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10300b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS multimap;
10310b57cec5SDimitry Andric
10320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10330b57cec5SDimitry Andric    map()
10340b57cec5SDimitry Andric        _NOEXCEPT_(
10350b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
10360b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
10370b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
10380b57cec5SDimitry Andric        : __tree_(__vc(key_compare())) {}
10390b57cec5SDimitry Andric
10400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10410b57cec5SDimitry Andric    explicit map(const key_compare& __comp)
10420b57cec5SDimitry Andric        _NOEXCEPT_(
10430b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
10440b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
10450b57cec5SDimitry Andric        : __tree_(__vc(__comp)) {}
10460b57cec5SDimitry Andric
10470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10480b57cec5SDimitry Andric    explicit map(const key_compare& __comp, const allocator_type& __a)
10490b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
10500b57cec5SDimitry Andric
10510b57cec5SDimitry Andric    template <class _InputIterator>
10520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10530b57cec5SDimitry Andric        map(_InputIterator __f, _InputIterator __l,
10540b57cec5SDimitry Andric            const key_compare& __comp = key_compare())
10550b57cec5SDimitry Andric        : __tree_(__vc(__comp))
10560b57cec5SDimitry Andric        {
10570b57cec5SDimitry Andric            insert(__f, __l);
10580b57cec5SDimitry Andric        }
10590b57cec5SDimitry Andric
10600b57cec5SDimitry Andric    template <class _InputIterator>
10610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10620b57cec5SDimitry Andric        map(_InputIterator __f, _InputIterator __l,
10630b57cec5SDimitry Andric            const key_compare& __comp, const allocator_type& __a)
10640b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
10650b57cec5SDimitry Andric        {
10660b57cec5SDimitry Andric            insert(__f, __l);
10670b57cec5SDimitry Andric        }
10680b57cec5SDimitry Andric
10690b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
10700b57cec5SDimitry Andric    template <class _InputIterator>
10710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10720b57cec5SDimitry Andric    map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10730b57cec5SDimitry Andric        : map(__f, __l, key_compare(), __a) {}
10740b57cec5SDimitry Andric#endif
10750b57cec5SDimitry Andric
10760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10770b57cec5SDimitry Andric    map(const map& __m)
10780b57cec5SDimitry Andric        : __tree_(__m.__tree_)
10790b57cec5SDimitry Andric        {
10800b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
10810b57cec5SDimitry Andric        }
10820b57cec5SDimitry Andric
10830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10840b57cec5SDimitry Andric    map& operator=(const map& __m)
10850b57cec5SDimitry Andric        {
10860b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10870b57cec5SDimitry Andric            __tree_ = __m.__tree_;
10880b57cec5SDimitry Andric#else
1089349cc55cSDimitry Andric            if (this != _VSTD::addressof(__m)) {
10900b57cec5SDimitry Andric                __tree_.clear();
10910b57cec5SDimitry Andric                __tree_.value_comp() = __m.__tree_.value_comp();
10920b57cec5SDimitry Andric                __tree_.__copy_assign_alloc(__m.__tree_);
10930b57cec5SDimitry Andric                insert(__m.begin(), __m.end());
10940b57cec5SDimitry Andric            }
10950b57cec5SDimitry Andric#endif
10960b57cec5SDimitry Andric            return *this;
10970b57cec5SDimitry Andric        }
10980b57cec5SDimitry Andric
10990b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11000b57cec5SDimitry Andric
11010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11020b57cec5SDimitry Andric    map(map&& __m)
11030b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
11040b57cec5SDimitry Andric        : __tree_(_VSTD::move(__m.__tree_))
11050b57cec5SDimitry Andric        {
11060b57cec5SDimitry Andric        }
11070b57cec5SDimitry Andric
11080b57cec5SDimitry Andric    map(map&& __m, const allocator_type& __a);
11090b57cec5SDimitry Andric
11100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11110b57cec5SDimitry Andric    map& operator=(map&& __m)
11120b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
11130b57cec5SDimitry Andric        {
11140b57cec5SDimitry Andric            __tree_ = _VSTD::move(__m.__tree_);
11150b57cec5SDimitry Andric            return *this;
11160b57cec5SDimitry Andric        }
11170b57cec5SDimitry Andric
11180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11190b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
11200b57cec5SDimitry Andric        : __tree_(__vc(__comp))
11210b57cec5SDimitry Andric        {
11220b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
11230b57cec5SDimitry Andric        }
11240b57cec5SDimitry Andric
11250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11260b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
11270b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
11280b57cec5SDimitry Andric        {
11290b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
11300b57cec5SDimitry Andric        }
11310b57cec5SDimitry Andric
11320b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
11330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11340b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const allocator_type& __a)
11350b57cec5SDimitry Andric        : map(__il, key_compare(), __a) {}
11360b57cec5SDimitry Andric#endif
11370b57cec5SDimitry Andric
11380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11390b57cec5SDimitry Andric    map& operator=(initializer_list<value_type> __il)
11400b57cec5SDimitry Andric        {
11410b57cec5SDimitry Andric            __tree_.__assign_unique(__il.begin(), __il.end());
11420b57cec5SDimitry Andric            return *this;
11430b57cec5SDimitry Andric        }
11440b57cec5SDimitry Andric
11450b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11460b57cec5SDimitry Andric
11470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11480b57cec5SDimitry Andric    explicit map(const allocator_type& __a)
11490b57cec5SDimitry Andric        : __tree_(typename __base::allocator_type(__a))
11500b57cec5SDimitry Andric        {
11510b57cec5SDimitry Andric        }
11520b57cec5SDimitry Andric
11530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11540b57cec5SDimitry Andric    map(const map& __m, const allocator_type& __a)
11550b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
11560b57cec5SDimitry Andric        {
11570b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
11580b57cec5SDimitry Andric        }
11590b57cec5SDimitry Andric
11600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11610b57cec5SDimitry Andric    ~map() {
11620b57cec5SDimitry Andric        static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
11630b57cec5SDimitry Andric    }
11640b57cec5SDimitry Andric
11650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11660b57cec5SDimitry Andric          iterator begin() _NOEXCEPT {return __tree_.begin();}
11670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11680b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
11690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11700b57cec5SDimitry Andric          iterator end() _NOEXCEPT {return __tree_.end();}
11710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11720b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return __tree_.end();}
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11750b57cec5SDimitry Andric          reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
11760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11770b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
11780b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
11790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11800b57cec5SDimitry Andric          reverse_iterator rend() _NOEXCEPT
11810b57cec5SDimitry Andric            {return       reverse_iterator(begin());}
11820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11830b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
11840b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
11850b57cec5SDimitry Andric
11860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11870b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
11880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11890b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
11900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11910b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
11920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11930b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
11940b57cec5SDimitry Andric
11950b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
11960b57cec5SDimitry Andric    bool      empty() const _NOEXCEPT {return __tree_.size() == 0;}
11970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11980b57cec5SDimitry Andric    size_type size() const _NOEXCEPT {return __tree_.size();}
11990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12000b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
12010b57cec5SDimitry Andric
12020b57cec5SDimitry Andric    mapped_type& operator[](const key_type& __k);
12030b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12040b57cec5SDimitry Andric    mapped_type& operator[](key_type&& __k);
12050b57cec5SDimitry Andric#endif
12060b57cec5SDimitry Andric
12070b57cec5SDimitry Andric          mapped_type& at(const key_type& __k);
12080b57cec5SDimitry Andric    const mapped_type& at(const key_type& __k) const;
12090b57cec5SDimitry Andric
12100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12110b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
12120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12130b57cec5SDimitry Andric    key_compare    key_comp()      const {return __tree_.value_comp().key_comp();}
12140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12150b57cec5SDimitry Andric    value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12180b57cec5SDimitry Andric    template <class ..._Args>
12190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12200b57cec5SDimitry Andric    pair<iterator, bool> emplace(_Args&& ...__args) {
12210b57cec5SDimitry Andric        return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
12220b57cec5SDimitry Andric    }
12230b57cec5SDimitry Andric
12240b57cec5SDimitry Andric    template <class ..._Args>
12250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12260b57cec5SDimitry Andric    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
12270b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
12280b57cec5SDimitry Andric    }
12290b57cec5SDimitry Andric
12300b57cec5SDimitry Andric    template <class _Pp,
1231*753f127fSDimitry Andric              class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12320b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12330b57cec5SDimitry Andric        pair<iterator, bool> insert(_Pp&& __p)
12340b57cec5SDimitry Andric            {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
12350b57cec5SDimitry Andric
12360b57cec5SDimitry Andric    template <class _Pp,
1237*753f127fSDimitry Andric              class = __enable_if_t<is_constructible<value_type, _Pp>::value> >
12380b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12390b57cec5SDimitry Andric        iterator insert(const_iterator __pos, _Pp&& __p)
12400b57cec5SDimitry Andric            {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
12410b57cec5SDimitry Andric
12420b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
12430b57cec5SDimitry Andric
12440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12450b57cec5SDimitry Andric    pair<iterator, bool>
12460b57cec5SDimitry Andric        insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
12470b57cec5SDimitry Andric
12480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12490b57cec5SDimitry Andric    iterator
12500b57cec5SDimitry Andric        insert(const_iterator __p, const value_type& __v)
12510b57cec5SDimitry Andric            {return __tree_.__insert_unique(__p.__i_, __v);}
12520b57cec5SDimitry Andric
12530b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12550b57cec5SDimitry Andric    pair<iterator, bool>
12560b57cec5SDimitry Andric    insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
12570b57cec5SDimitry Andric
12580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12590b57cec5SDimitry Andric    iterator insert(const_iterator __p,  value_type&& __v)
12600b57cec5SDimitry Andric    {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
12610b57cec5SDimitry Andric
12620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12630b57cec5SDimitry Andric    void insert(initializer_list<value_type> __il)
12640b57cec5SDimitry Andric        {insert(__il.begin(), __il.end());}
12650b57cec5SDimitry Andric#endif
12660b57cec5SDimitry Andric
12670b57cec5SDimitry Andric    template <class _InputIterator>
12680b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12690b57cec5SDimitry Andric        void insert(_InputIterator __f, _InputIterator __l)
12700b57cec5SDimitry Andric        {
12710b57cec5SDimitry Andric            for (const_iterator __e = cend(); __f != __l; ++__f)
12720b57cec5SDimitry Andric                insert(__e.__i_, *__f);
12730b57cec5SDimitry Andric        }
12740b57cec5SDimitry Andric
12750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
12760b57cec5SDimitry Andric
12770b57cec5SDimitry Andric    template <class... _Args>
12780b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12790b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
12800b57cec5SDimitry Andric    {
12810b57cec5SDimitry Andric        return __tree_.__emplace_unique_key_args(__k,
12820b57cec5SDimitry Andric            _VSTD::piecewise_construct,
12830b57cec5SDimitry Andric            _VSTD::forward_as_tuple(__k),
12840b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
12850b57cec5SDimitry Andric    }
12860b57cec5SDimitry Andric
12870b57cec5SDimitry Andric    template <class... _Args>
12880b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12890b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
12900b57cec5SDimitry Andric    {
12910b57cec5SDimitry Andric        return __tree_.__emplace_unique_key_args(__k,
12920b57cec5SDimitry Andric            _VSTD::piecewise_construct,
12930b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::move(__k)),
12940b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
12950b57cec5SDimitry Andric    }
12960b57cec5SDimitry Andric
12970b57cec5SDimitry Andric    template <class... _Args>
12980b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12990b57cec5SDimitry Andric        iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
13000b57cec5SDimitry Andric    {
13010b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
13020b57cec5SDimitry Andric            _VSTD::piecewise_construct,
13030b57cec5SDimitry Andric            _VSTD::forward_as_tuple(__k),
1304e8d8bef9SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
13050b57cec5SDimitry Andric    }
13060b57cec5SDimitry Andric
13070b57cec5SDimitry Andric    template <class... _Args>
13080b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13090b57cec5SDimitry Andric        iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
13100b57cec5SDimitry Andric    {
13110b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
13120b57cec5SDimitry Andric            _VSTD::piecewise_construct,
13130b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::move(__k)),
1314e8d8bef9SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
13150b57cec5SDimitry Andric    }
13160b57cec5SDimitry Andric
13170b57cec5SDimitry Andric    template <class _Vp>
13180b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13190b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
13200b57cec5SDimitry Andric    {
13210b57cec5SDimitry Andric        iterator __p = lower_bound(__k);
13220b57cec5SDimitry Andric        if ( __p != end() && !key_comp()(__k, __p->first))
13230b57cec5SDimitry Andric        {
13240b57cec5SDimitry Andric            __p->second = _VSTD::forward<_Vp>(__v);
13250b57cec5SDimitry Andric            return _VSTD::make_pair(__p, false);
13260b57cec5SDimitry Andric        }
13270b57cec5SDimitry Andric        return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
13280b57cec5SDimitry Andric    }
13290b57cec5SDimitry Andric
13300b57cec5SDimitry Andric    template <class _Vp>
13310b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13320b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
13330b57cec5SDimitry Andric    {
13340b57cec5SDimitry Andric        iterator __p = lower_bound(__k);
13350b57cec5SDimitry Andric        if ( __p != end() && !key_comp()(__k, __p->first))
13360b57cec5SDimitry Andric        {
13370b57cec5SDimitry Andric            __p->second = _VSTD::forward<_Vp>(__v);
13380b57cec5SDimitry Andric            return _VSTD::make_pair(__p, false);
13390b57cec5SDimitry Andric        }
13400b57cec5SDimitry Andric        return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
13410b57cec5SDimitry Andric    }
13420b57cec5SDimitry Andric
13430b57cec5SDimitry Andric    template <class _Vp>
1344e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1345e8d8bef9SDimitry Andric                                                        const key_type& __k,
1346e8d8bef9SDimitry Andric                                                        _Vp&& __v) {
1347e8d8bef9SDimitry Andric      auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1348e8d8bef9SDimitry Andric          __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v));
1349e8d8bef9SDimitry Andric
1350e8d8bef9SDimitry Andric      if (!__inserted)
1351e8d8bef9SDimitry Andric        __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1352e8d8bef9SDimitry Andric
1353e8d8bef9SDimitry Andric      return __r;
13540b57cec5SDimitry Andric    }
13550b57cec5SDimitry Andric
13560b57cec5SDimitry Andric    template <class _Vp>
1357e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1358e8d8bef9SDimitry Andric                                                        key_type&& __k,
1359e8d8bef9SDimitry Andric                                                        _Vp&& __v) {
1360e8d8bef9SDimitry Andric      auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1361e8d8bef9SDimitry Andric          __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1362e8d8bef9SDimitry Andric
1363e8d8bef9SDimitry Andric      if (!__inserted)
1364e8d8bef9SDimitry Andric        __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1365e8d8bef9SDimitry Andric
1366e8d8bef9SDimitry Andric      return __r;
13670b57cec5SDimitry Andric    }
13680b57cec5SDimitry Andric
13690b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 14
13700b57cec5SDimitry Andric
13710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13720b57cec5SDimitry Andric    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
13730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13740b57cec5SDimitry Andric    iterator erase(iterator __p)       {return __tree_.erase(__p.__i_);}
13750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13760b57cec5SDimitry Andric    size_type erase(const key_type& __k)
13770b57cec5SDimitry Andric        {return __tree_.__erase_unique(__k);}
13780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13790b57cec5SDimitry Andric    iterator  erase(const_iterator __f, const_iterator __l)
13800b57cec5SDimitry Andric        {return __tree_.erase(__f.__i_, __l.__i_);}
13810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13820b57cec5SDimitry Andric    void clear() _NOEXCEPT {__tree_.clear();}
13830b57cec5SDimitry Andric
13840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
13850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13860b57cec5SDimitry Andric    insert_return_type insert(node_type&& __nh)
13870b57cec5SDimitry Andric    {
13880b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
13890b57cec5SDimitry Andric            "node_type with incompatible allocator passed to map::insert()");
13900b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_unique<
13910b57cec5SDimitry Andric            node_type, insert_return_type>(_VSTD::move(__nh));
13920b57cec5SDimitry Andric    }
13930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13940b57cec5SDimitry Andric    iterator insert(const_iterator __hint, node_type&& __nh)
13950b57cec5SDimitry Andric    {
13960b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
13970b57cec5SDimitry Andric            "node_type with incompatible allocator passed to map::insert()");
13980b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_unique<node_type>(
13990b57cec5SDimitry Andric            __hint.__i_, _VSTD::move(__nh));
14000b57cec5SDimitry Andric    }
14010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14020b57cec5SDimitry Andric    node_type extract(key_type const& __key)
14030b57cec5SDimitry Andric    {
14040b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__key);
14050b57cec5SDimitry Andric    }
14060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14070b57cec5SDimitry Andric    node_type extract(const_iterator __it)
14080b57cec5SDimitry Andric    {
14090b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__it.__i_);
14100b57cec5SDimitry Andric    }
14110b57cec5SDimitry Andric    template <class _Compare2>
14120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14130b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
14140b57cec5SDimitry Andric    {
14150b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14160b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14170b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14180b57cec5SDimitry Andric    }
14190b57cec5SDimitry Andric    template <class _Compare2>
14200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14210b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
14220b57cec5SDimitry Andric    {
14230b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14240b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14250b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14260b57cec5SDimitry Andric    }
14270b57cec5SDimitry Andric    template <class _Compare2>
14280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14290b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
14300b57cec5SDimitry Andric    {
14310b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14320b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14330b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14340b57cec5SDimitry Andric    }
14350b57cec5SDimitry Andric    template <class _Compare2>
14360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14370b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
14380b57cec5SDimitry Andric    {
14390b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14400b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14410b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14420b57cec5SDimitry Andric    }
14430b57cec5SDimitry Andric#endif
14440b57cec5SDimitry Andric
14450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14460b57cec5SDimitry Andric    void swap(map& __m)
14470b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
14480b57cec5SDimitry Andric        {__tree_.swap(__m.__tree_);}
14490b57cec5SDimitry Andric
14500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14510b57cec5SDimitry Andric    iterator find(const key_type& __k)             {return __tree_.find(__k);}
14520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14530b57cec5SDimitry Andric    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
14540b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14550b57cec5SDimitry Andric    template <typename _K2>
14560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1457*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
14580b57cec5SDimitry Andric    find(const _K2& __k)                           {return __tree_.find(__k);}
14590b57cec5SDimitry Andric    template <typename _K2>
14600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1461*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
14620b57cec5SDimitry Andric    find(const _K2& __k) const                     {return __tree_.find(__k);}
14630b57cec5SDimitry Andric#endif
14640b57cec5SDimitry Andric
14650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14660b57cec5SDimitry Andric    size_type      count(const key_type& __k) const
14670b57cec5SDimitry Andric        {return __tree_.__count_unique(__k);}
14680b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14690b57cec5SDimitry Andric    template <typename _K2>
14700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1471*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type>
14720b57cec5SDimitry Andric    count(const _K2& __k) const {return __tree_.__count_multi(__k);}
14730b57cec5SDimitry Andric#endif
14740b57cec5SDimitry Andric
14750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
14760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14770b57cec5SDimitry Andric    bool contains(const key_type& __k) const {return find(__k) != end();}
1478fe6060f1SDimitry Andric    template <typename _K2>
1479fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1480*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, bool>
1481fe6060f1SDimitry Andric    contains(const _K2& __k) const { return find(__k) != end(); }
14820b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
14830b57cec5SDimitry Andric
14840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14850b57cec5SDimitry Andric    iterator lower_bound(const key_type& __k)
14860b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
14870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14880b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& __k) const
14890b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
14900b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14910b57cec5SDimitry Andric    template <typename _K2>
14920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1493*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
14940b57cec5SDimitry Andric    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
14950b57cec5SDimitry Andric
14960b57cec5SDimitry Andric    template <typename _K2>
14970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1498*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
14990b57cec5SDimitry Andric    lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
15000b57cec5SDimitry Andric#endif
15010b57cec5SDimitry Andric
15020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15030b57cec5SDimitry Andric    iterator upper_bound(const key_type& __k)
15040b57cec5SDimitry Andric        {return __tree_.upper_bound(__k);}
15050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15060b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& __k) const
15070b57cec5SDimitry Andric        {return __tree_.upper_bound(__k);}
15080b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
15090b57cec5SDimitry Andric    template <typename _K2>
15100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1511*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
15120b57cec5SDimitry Andric    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
15130b57cec5SDimitry Andric    template <typename _K2>
15140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1515*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
15160b57cec5SDimitry Andric    upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
15170b57cec5SDimitry Andric#endif
15180b57cec5SDimitry Andric
15190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15200b57cec5SDimitry Andric    pair<iterator,iterator> equal_range(const key_type& __k)
15210b57cec5SDimitry Andric        {return __tree_.__equal_range_unique(__k);}
15220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15230b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
15240b57cec5SDimitry Andric        {return __tree_.__equal_range_unique(__k);}
15250b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
15260b57cec5SDimitry Andric    template <typename _K2>
15270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1528*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>>
15290b57cec5SDimitry Andric    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
15300b57cec5SDimitry Andric    template <typename _K2>
15310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1532*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>>
15330b57cec5SDimitry Andric    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
15340b57cec5SDimitry Andric#endif
15350b57cec5SDimitry Andric
15360b57cec5SDimitry Andricprivate:
15370b57cec5SDimitry Andric    typedef typename __base::__node                    __node;
15380b57cec5SDimitry Andric    typedef typename __base::__node_allocator          __node_allocator;
15390b57cec5SDimitry Andric    typedef typename __base::__node_pointer            __node_pointer;
15400b57cec5SDimitry Andric    typedef typename __base::__node_base_pointer       __node_base_pointer;
15410b57cec5SDimitry Andric    typedef typename __base::__parent_pointer          __parent_pointer;
15420b57cec5SDimitry Andric
15430b57cec5SDimitry Andric    typedef __map_node_destructor<__node_allocator> _Dp;
15440b57cec5SDimitry Andric    typedef unique_ptr<__node, _Dp> __node_holder;
15450b57cec5SDimitry Andric
15460b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
15470b57cec5SDimitry Andric    __node_holder __construct_node_with_key(const key_type& __k);
15480b57cec5SDimitry Andric#endif
15490b57cec5SDimitry Andric};
15500b57cec5SDimitry Andric
1551349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
15520b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
15530b57cec5SDimitry Andric         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1554349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1555349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1556349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15570b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
15580b57cec5SDimitry Andric  -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
15590b57cec5SDimitry Andric
15600b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
15610b57cec5SDimitry Andric         class _Allocator = allocator<pair<const _Key, _Tp>>,
1562349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1563349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15640b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
15650b57cec5SDimitry Andric  -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
15660b57cec5SDimitry Andric
15670b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator,
1568349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1569349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15700b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Allocator)
15710b57cec5SDimitry Andric  -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
15720b57cec5SDimitry Andric         less<__iter_key_type<_InputIterator>>, _Allocator>;
15730b57cec5SDimitry Andric
15740b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator,
1575349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15760b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Allocator)
15770b57cec5SDimitry Andric  -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
15780b57cec5SDimitry Andric#endif
15790b57cec5SDimitry Andric
15800b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
15810b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15820b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
15830b57cec5SDimitry Andric    : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
15840b57cec5SDimitry Andric{
15850b57cec5SDimitry Andric    if (__a != __m.get_allocator())
15860b57cec5SDimitry Andric    {
15870b57cec5SDimitry Andric        const_iterator __e = cend();
15880b57cec5SDimitry Andric        while (!__m.empty())
15890b57cec5SDimitry Andric            __tree_.__insert_unique(__e.__i_,
15900b57cec5SDimitry Andric                    __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
15910b57cec5SDimitry Andric    }
15920b57cec5SDimitry Andric}
15930b57cec5SDimitry Andric
15940b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15950b57cec5SDimitry Andric_Tp&
15960b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
15970b57cec5SDimitry Andric{
15980b57cec5SDimitry Andric    return __tree_.__emplace_unique_key_args(__k,
15990b57cec5SDimitry Andric        _VSTD::piecewise_construct,
16000b57cec5SDimitry Andric        _VSTD::forward_as_tuple(__k),
16010b57cec5SDimitry Andric        _VSTD::forward_as_tuple()).first->__get_value().second;
16020b57cec5SDimitry Andric}
16030b57cec5SDimitry Andric
16040b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16050b57cec5SDimitry Andric_Tp&
16060b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
16070b57cec5SDimitry Andric{
16080b57cec5SDimitry Andric    return __tree_.__emplace_unique_key_args(__k,
16090b57cec5SDimitry Andric        _VSTD::piecewise_construct,
16100b57cec5SDimitry Andric        _VSTD::forward_as_tuple(_VSTD::move(__k)),
16110b57cec5SDimitry Andric        _VSTD::forward_as_tuple()).first->__get_value().second;
16120b57cec5SDimitry Andric}
16130b57cec5SDimitry Andric
16140b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG
16150b57cec5SDimitry Andric
16160b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16170b57cec5SDimitry Andrictypename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
16180b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
16190b57cec5SDimitry Andric{
16200b57cec5SDimitry Andric    __node_allocator& __na = __tree_.__node_alloc();
16210b57cec5SDimitry Andric    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
16220b57cec5SDimitry Andric    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
16230b57cec5SDimitry Andric    __h.get_deleter().__first_constructed = true;
16240b57cec5SDimitry Andric    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
16250b57cec5SDimitry Andric    __h.get_deleter().__second_constructed = true;
1626e8d8bef9SDimitry Andric    return __h;
16270b57cec5SDimitry Andric}
16280b57cec5SDimitry Andric
16290b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16300b57cec5SDimitry Andric_Tp&
16310b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
16320b57cec5SDimitry Andric{
16330b57cec5SDimitry Andric    __parent_pointer __parent;
16340b57cec5SDimitry Andric    __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
16350b57cec5SDimitry Andric    __node_pointer __r = static_cast<__node_pointer>(__child);
16360b57cec5SDimitry Andric    if (__child == nullptr)
16370b57cec5SDimitry Andric    {
16380b57cec5SDimitry Andric        __node_holder __h = __construct_node_with_key(__k);
16390b57cec5SDimitry Andric        __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
16400b57cec5SDimitry Andric        __r = __h.release();
16410b57cec5SDimitry Andric    }
16420b57cec5SDimitry Andric    return __r->__value_.__get_value().second;
16430b57cec5SDimitry Andric}
16440b57cec5SDimitry Andric
16450b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
16460b57cec5SDimitry Andric
16470b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16480b57cec5SDimitry Andric_Tp&
16490b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
16500b57cec5SDimitry Andric{
16510b57cec5SDimitry Andric    __parent_pointer __parent;
16520b57cec5SDimitry Andric    __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
16530b57cec5SDimitry Andric    if (__child == nullptr)
16540b57cec5SDimitry Andric        __throw_out_of_range("map::at:  key not found");
16550b57cec5SDimitry Andric    return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
16560b57cec5SDimitry Andric}
16570b57cec5SDimitry Andric
16580b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16590b57cec5SDimitry Andricconst _Tp&
16600b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
16610b57cec5SDimitry Andric{
16620b57cec5SDimitry Andric    __parent_pointer __parent;
16630b57cec5SDimitry Andric    __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
16640b57cec5SDimitry Andric    if (__child == nullptr)
16650b57cec5SDimitry Andric        __throw_out_of_range("map::at:  key not found");
16660b57cec5SDimitry Andric    return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
16670b57cec5SDimitry Andric}
16680b57cec5SDimitry Andric
16690b57cec5SDimitry Andric
16700b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16720b57cec5SDimitry Andricbool
16730b57cec5SDimitry Andricoperator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
16740b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16750b57cec5SDimitry Andric{
16760b57cec5SDimitry Andric    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
16770b57cec5SDimitry Andric}
16780b57cec5SDimitry Andric
16790b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16810b57cec5SDimitry Andricbool
16820b57cec5SDimitry Andricoperator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
16830b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16840b57cec5SDimitry Andric{
16850b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
16860b57cec5SDimitry Andric}
16870b57cec5SDimitry Andric
16880b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16900b57cec5SDimitry Andricbool
16910b57cec5SDimitry Andricoperator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
16920b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16930b57cec5SDimitry Andric{
16940b57cec5SDimitry Andric    return !(__x == __y);
16950b57cec5SDimitry Andric}
16960b57cec5SDimitry Andric
16970b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16990b57cec5SDimitry Andricbool
17000b57cec5SDimitry Andricoperator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
17010b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17020b57cec5SDimitry Andric{
17030b57cec5SDimitry Andric    return __y < __x;
17040b57cec5SDimitry Andric}
17050b57cec5SDimitry Andric
17060b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17080b57cec5SDimitry Andricbool
17090b57cec5SDimitry Andricoperator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
17100b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17110b57cec5SDimitry Andric{
17120b57cec5SDimitry Andric    return !(__x < __y);
17130b57cec5SDimitry Andric}
17140b57cec5SDimitry Andric
17150b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17170b57cec5SDimitry Andricbool
17180b57cec5SDimitry Andricoperator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
17190b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17200b57cec5SDimitry Andric{
17210b57cec5SDimitry Andric    return !(__y < __x);
17220b57cec5SDimitry Andric}
17230b57cec5SDimitry Andric
17240b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17260b57cec5SDimitry Andricvoid
17270b57cec5SDimitry Andricswap(map<_Key, _Tp, _Compare, _Allocator>& __x,
17280b57cec5SDimitry Andric     map<_Key, _Tp, _Compare, _Allocator>& __y)
17290b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
17300b57cec5SDimitry Andric{
17310b57cec5SDimitry Andric    __x.swap(__y);
17320b57cec5SDimitry Andric}
17330b57cec5SDimitry Andric
17340b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
17355ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator,
17365ffd83dbSDimitry Andric          class _Predicate>
17370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17385ffd83dbSDimitry Andric    typename map<_Key, _Tp, _Compare, _Allocator>::size_type
17395ffd83dbSDimitry Andric    erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1740fe6060f1SDimitry Andric  return _VSTD::__libcpp_erase_if_container(__c, __pred);
17415ffd83dbSDimitry Andric}
17420b57cec5SDimitry Andric#endif
17430b57cec5SDimitry Andric
17440b57cec5SDimitry Andric
17450b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>,
17460b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp> > >
17470b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS multimap
17480b57cec5SDimitry Andric{
17490b57cec5SDimitry Andricpublic:
17500b57cec5SDimitry Andric    // types:
17510b57cec5SDimitry Andric    typedef _Key                                     key_type;
17520b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
17530b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
175481ad6265SDimitry Andric    typedef __type_identity_t<_Compare>              key_compare;
175581ad6265SDimitry Andric    typedef __type_identity_t<_Allocator>            allocator_type;
17560b57cec5SDimitry Andric    typedef value_type&                              reference;
17570b57cec5SDimitry Andric    typedef const value_type&                        const_reference;
17580b57cec5SDimitry Andric
17590b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
17600b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
17610b57cec5SDimitry Andric
17620b57cec5SDimitry Andric    class _LIBCPP_TEMPLATE_VIS value_compare
176381ad6265SDimitry Andric        : public __binary_function<value_type, value_type, bool>
17640b57cec5SDimitry Andric    {
17650b57cec5SDimitry Andric        friend class multimap;
17660b57cec5SDimitry Andric    protected:
17670b57cec5SDimitry Andric        key_compare comp;
17680b57cec5SDimitry Andric
17690b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
1770*753f127fSDimitry Andric        value_compare(key_compare __c) : comp(__c) {}
17710b57cec5SDimitry Andric    public:
17720b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
17730b57cec5SDimitry Andric        bool operator()(const value_type& __x, const value_type& __y) const
17740b57cec5SDimitry Andric            {return comp(__x.first, __y.first);}
17750b57cec5SDimitry Andric    };
17760b57cec5SDimitry Andric
17770b57cec5SDimitry Andricprivate:
17780b57cec5SDimitry Andric
17790b57cec5SDimitry Andric    typedef _VSTD::__value_type<key_type, mapped_type>             __value_type;
17800b57cec5SDimitry Andric    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
17810b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
17820b57cec5SDimitry Andric                                                 __value_type>::type __allocator_type;
17830b57cec5SDimitry Andric    typedef __tree<__value_type, __vc, __allocator_type>            __base;
17840b57cec5SDimitry Andric    typedef typename __base::__node_traits                          __node_traits;
17850b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>                        __alloc_traits;
17860b57cec5SDimitry Andric
17870b57cec5SDimitry Andric    __base __tree_;
17880b57cec5SDimitry Andric
17890b57cec5SDimitry Andricpublic:
17900b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer               pointer;
17910b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer         const_pointer;
17920b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type             size_type;
17930b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type       difference_type;
17940b57cec5SDimitry Andric    typedef __map_iterator<typename __base::iterator>      iterator;
17950b57cec5SDimitry Andric    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
17960b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
17970b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
17980b57cec5SDimitry Andric
17990b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
18000b57cec5SDimitry Andric    typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
18010b57cec5SDimitry Andric#endif
18020b57cec5SDimitry Andric
18030b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
18040b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS map;
18050b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
18060b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS multimap;
18070b57cec5SDimitry Andric
18080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18090b57cec5SDimitry Andric    multimap()
18100b57cec5SDimitry Andric        _NOEXCEPT_(
18110b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
18120b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
18130b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
18140b57cec5SDimitry Andric        : __tree_(__vc(key_compare())) {}
18150b57cec5SDimitry Andric
18160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18170b57cec5SDimitry Andric    explicit multimap(const key_compare& __comp)
18180b57cec5SDimitry Andric        _NOEXCEPT_(
18190b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
18200b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
18210b57cec5SDimitry Andric        : __tree_(__vc(__comp)) {}
18220b57cec5SDimitry Andric
18230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18240b57cec5SDimitry Andric    explicit multimap(const key_compare& __comp, const allocator_type& __a)
18250b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
18260b57cec5SDimitry Andric
18270b57cec5SDimitry Andric    template <class _InputIterator>
18280b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
18290b57cec5SDimitry Andric        multimap(_InputIterator __f, _InputIterator __l,
18300b57cec5SDimitry Andric            const key_compare& __comp = key_compare())
18310b57cec5SDimitry Andric        : __tree_(__vc(__comp))
18320b57cec5SDimitry Andric        {
18330b57cec5SDimitry Andric            insert(__f, __l);
18340b57cec5SDimitry Andric        }
18350b57cec5SDimitry Andric
18360b57cec5SDimitry Andric    template <class _InputIterator>
18370b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
18380b57cec5SDimitry Andric        multimap(_InputIterator __f, _InputIterator __l,
18390b57cec5SDimitry Andric            const key_compare& __comp, const allocator_type& __a)
18400b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
18410b57cec5SDimitry Andric        {
18420b57cec5SDimitry Andric            insert(__f, __l);
18430b57cec5SDimitry Andric        }
18440b57cec5SDimitry Andric
18450b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
18460b57cec5SDimitry Andric    template <class _InputIterator>
18470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18480b57cec5SDimitry Andric    multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
18490b57cec5SDimitry Andric        : multimap(__f, __l, key_compare(), __a) {}
18500b57cec5SDimitry Andric#endif
18510b57cec5SDimitry Andric
18520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18530b57cec5SDimitry Andric    multimap(const multimap& __m)
18540b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(),
18550b57cec5SDimitry Andric          __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
18560b57cec5SDimitry Andric        {
18570b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
18580b57cec5SDimitry Andric        }
18590b57cec5SDimitry Andric
18600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18610b57cec5SDimitry Andric    multimap& operator=(const multimap& __m)
18620b57cec5SDimitry Andric        {
18630b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18640b57cec5SDimitry Andric            __tree_ = __m.__tree_;
18650b57cec5SDimitry Andric#else
1866349cc55cSDimitry Andric            if (this != _VSTD::addressof(__m)) {
18670b57cec5SDimitry Andric                __tree_.clear();
18680b57cec5SDimitry Andric                __tree_.value_comp() = __m.__tree_.value_comp();
18690b57cec5SDimitry Andric                __tree_.__copy_assign_alloc(__m.__tree_);
18700b57cec5SDimitry Andric                insert(__m.begin(), __m.end());
18710b57cec5SDimitry Andric            }
18720b57cec5SDimitry Andric#endif
18730b57cec5SDimitry Andric            return *this;
18740b57cec5SDimitry Andric        }
18750b57cec5SDimitry Andric
18760b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18770b57cec5SDimitry Andric
18780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18790b57cec5SDimitry Andric    multimap(multimap&& __m)
18800b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
18810b57cec5SDimitry Andric        : __tree_(_VSTD::move(__m.__tree_))
18820b57cec5SDimitry Andric        {
18830b57cec5SDimitry Andric        }
18840b57cec5SDimitry Andric
18850b57cec5SDimitry Andric    multimap(multimap&& __m, const allocator_type& __a);
18860b57cec5SDimitry Andric
18870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18880b57cec5SDimitry Andric    multimap& operator=(multimap&& __m)
18890b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
18900b57cec5SDimitry Andric        {
18910b57cec5SDimitry Andric            __tree_ = _VSTD::move(__m.__tree_);
18920b57cec5SDimitry Andric            return *this;
18930b57cec5SDimitry Andric        }
18940b57cec5SDimitry Andric
18950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18960b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
18970b57cec5SDimitry Andric        : __tree_(__vc(__comp))
18980b57cec5SDimitry Andric        {
18990b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
19000b57cec5SDimitry Andric        }
19010b57cec5SDimitry Andric
19020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19030b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
19040b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
19050b57cec5SDimitry Andric        {
19060b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
19070b57cec5SDimitry Andric        }
19080b57cec5SDimitry Andric
19090b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
19100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19110b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const allocator_type& __a)
19120b57cec5SDimitry Andric        : multimap(__il, key_compare(), __a) {}
19130b57cec5SDimitry Andric#endif
19140b57cec5SDimitry Andric
19150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19160b57cec5SDimitry Andric    multimap& operator=(initializer_list<value_type> __il)
19170b57cec5SDimitry Andric        {
19180b57cec5SDimitry Andric            __tree_.__assign_multi(__il.begin(), __il.end());
19190b57cec5SDimitry Andric            return *this;
19200b57cec5SDimitry Andric        }
19210b57cec5SDimitry Andric
19220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
19230b57cec5SDimitry Andric
19240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19250b57cec5SDimitry Andric    explicit multimap(const allocator_type& __a)
19260b57cec5SDimitry Andric        : __tree_(typename __base::allocator_type(__a))
19270b57cec5SDimitry Andric        {
19280b57cec5SDimitry Andric        }
19290b57cec5SDimitry Andric
19300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19310b57cec5SDimitry Andric    multimap(const multimap& __m, const allocator_type& __a)
19320b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
19330b57cec5SDimitry Andric        {
19340b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
19350b57cec5SDimitry Andric        }
19360b57cec5SDimitry Andric
19370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19380b57cec5SDimitry Andric    ~multimap() {
19390b57cec5SDimitry Andric        static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
19400b57cec5SDimitry Andric    }
19410b57cec5SDimitry Andric
19420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19430b57cec5SDimitry Andric          iterator begin() _NOEXCEPT {return __tree_.begin();}
19440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19450b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
19460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19470b57cec5SDimitry Andric          iterator end() _NOEXCEPT {return __tree_.end();}
19480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19490b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return __tree_.end();}
19500b57cec5SDimitry Andric
19510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19520b57cec5SDimitry Andric          reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
19530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19540b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
19550b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
19560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19570b57cec5SDimitry Andric          reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
19580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19590b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
19600b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
19610b57cec5SDimitry Andric
19620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19630b57cec5SDimitry Andric    const_iterator cbegin()  const _NOEXCEPT {return begin();}
19640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19650b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
19660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19670b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
19680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19690b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
19700b57cec5SDimitry Andric
19710b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
19720b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
19730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19740b57cec5SDimitry Andric    size_type size() const _NOEXCEPT {return __tree_.size();}
19750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19760b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
19770b57cec5SDimitry Andric
19780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19790b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
19800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19810b57cec5SDimitry Andric    key_compare    key_comp() const {return __tree_.value_comp().key_comp();}
19820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19830b57cec5SDimitry Andric    value_compare  value_comp() const
19840b57cec5SDimitry Andric        {return value_compare(__tree_.value_comp().key_comp());}
19850b57cec5SDimitry Andric
19860b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
19870b57cec5SDimitry Andric
19880b57cec5SDimitry Andric    template <class ..._Args>
19890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19900b57cec5SDimitry Andric    iterator emplace(_Args&& ...__args) {
19910b57cec5SDimitry Andric        return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
19920b57cec5SDimitry Andric    }
19930b57cec5SDimitry Andric
19940b57cec5SDimitry Andric    template <class ..._Args>
19950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19960b57cec5SDimitry Andric    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
19970b57cec5SDimitry Andric        return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
19980b57cec5SDimitry Andric    }
19990b57cec5SDimitry Andric
20000b57cec5SDimitry Andric    template <class _Pp,
2001*753f127fSDimitry Andric              class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
20020b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20030b57cec5SDimitry Andric        iterator insert(_Pp&& __p)
20040b57cec5SDimitry Andric            {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
20050b57cec5SDimitry Andric
20060b57cec5SDimitry Andric    template <class _Pp,
2007*753f127fSDimitry Andric              class = __enable_if_t<is_constructible<value_type, _Pp>::value>>
20080b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20090b57cec5SDimitry Andric        iterator insert(const_iterator __pos, _Pp&& __p)
20100b57cec5SDimitry Andric            {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
20110b57cec5SDimitry Andric
20120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20130b57cec5SDimitry Andric    iterator insert(value_type&& __v)
20140b57cec5SDimitry Andric        {return __tree_.__insert_multi(_VSTD::move(__v));}
20150b57cec5SDimitry Andric
20160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20170b57cec5SDimitry Andric    iterator insert(const_iterator __p, value_type&& __v)
20180b57cec5SDimitry Andric        {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
20190b57cec5SDimitry Andric
20200b57cec5SDimitry Andric
20210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20220b57cec5SDimitry Andric    void insert(initializer_list<value_type> __il)
20230b57cec5SDimitry Andric        {insert(__il.begin(), __il.end());}
20240b57cec5SDimitry Andric
20250b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
20260b57cec5SDimitry Andric
20270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20280b57cec5SDimitry Andric    iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
20290b57cec5SDimitry Andric
20300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20310b57cec5SDimitry Andric    iterator insert(const_iterator __p, const value_type& __v)
20320b57cec5SDimitry Andric            {return __tree_.__insert_multi(__p.__i_, __v);}
20330b57cec5SDimitry Andric
20340b57cec5SDimitry Andric    template <class _InputIterator>
20350b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20360b57cec5SDimitry Andric        void insert(_InputIterator __f, _InputIterator __l)
20370b57cec5SDimitry Andric        {
20380b57cec5SDimitry Andric            for (const_iterator __e = cend(); __f != __l; ++__f)
20390b57cec5SDimitry Andric                __tree_.__insert_multi(__e.__i_, *__f);
20400b57cec5SDimitry Andric        }
20410b57cec5SDimitry Andric
20420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20430b57cec5SDimitry Andric    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
20440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20450b57cec5SDimitry Andric    iterator erase(iterator __p)       {return __tree_.erase(__p.__i_);}
20460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20470b57cec5SDimitry Andric    size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
20480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20490b57cec5SDimitry Andric    iterator  erase(const_iterator __f, const_iterator __l)
20500b57cec5SDimitry Andric        {return __tree_.erase(__f.__i_, __l.__i_);}
20510b57cec5SDimitry Andric
20520b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
20530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20540b57cec5SDimitry Andric    iterator insert(node_type&& __nh)
20550b57cec5SDimitry Andric    {
20560b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
20570b57cec5SDimitry Andric            "node_type with incompatible allocator passed to multimap::insert()");
20580b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_multi<node_type>(
20590b57cec5SDimitry Andric            _VSTD::move(__nh));
20600b57cec5SDimitry Andric    }
20610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20620b57cec5SDimitry Andric    iterator insert(const_iterator __hint, node_type&& __nh)
20630b57cec5SDimitry Andric    {
20640b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
20650b57cec5SDimitry Andric            "node_type with incompatible allocator passed to multimap::insert()");
20660b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_multi<node_type>(
20670b57cec5SDimitry Andric            __hint.__i_, _VSTD::move(__nh));
20680b57cec5SDimitry Andric    }
20690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20700b57cec5SDimitry Andric    node_type extract(key_type const& __key)
20710b57cec5SDimitry Andric    {
20720b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__key);
20730b57cec5SDimitry Andric    }
20740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20750b57cec5SDimitry Andric    node_type extract(const_iterator __it)
20760b57cec5SDimitry Andric    {
20770b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(
20780b57cec5SDimitry Andric            __it.__i_);
20790b57cec5SDimitry Andric    }
20800b57cec5SDimitry Andric    template <class _Compare2>
20810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20820b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
20830b57cec5SDimitry Andric    {
20840b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
20850b57cec5SDimitry Andric                       "merging container with incompatible allocator");
20860b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
20870b57cec5SDimitry Andric    }
20880b57cec5SDimitry Andric    template <class _Compare2>
20890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20900b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
20910b57cec5SDimitry Andric    {
20920b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
20930b57cec5SDimitry Andric                       "merging container with incompatible allocator");
20940b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
20950b57cec5SDimitry Andric    }
20960b57cec5SDimitry Andric    template <class _Compare2>
20970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20980b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
20990b57cec5SDimitry Andric    {
21000b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
21010b57cec5SDimitry Andric                       "merging container with incompatible allocator");
21020b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
21030b57cec5SDimitry Andric    }
21040b57cec5SDimitry Andric    template <class _Compare2>
21050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21060b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
21070b57cec5SDimitry Andric    {
21080b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
21090b57cec5SDimitry Andric                       "merging container with incompatible allocator");
21100b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
21110b57cec5SDimitry Andric    }
21120b57cec5SDimitry Andric#endif
21130b57cec5SDimitry Andric
21140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21150b57cec5SDimitry Andric    void clear() _NOEXCEPT {__tree_.clear();}
21160b57cec5SDimitry Andric
21170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21180b57cec5SDimitry Andric    void swap(multimap& __m)
21190b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
21200b57cec5SDimitry Andric        {__tree_.swap(__m.__tree_);}
21210b57cec5SDimitry Andric
21220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21230b57cec5SDimitry Andric    iterator find(const key_type& __k)             {return __tree_.find(__k);}
21240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21250b57cec5SDimitry Andric    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
21260b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21270b57cec5SDimitry Andric    template <typename _K2>
21280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2129*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21300b57cec5SDimitry Andric    find(const _K2& __k)                           {return __tree_.find(__k);}
21310b57cec5SDimitry Andric    template <typename _K2>
21320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2133*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21340b57cec5SDimitry Andric    find(const _K2& __k) const                     {return __tree_.find(__k);}
21350b57cec5SDimitry Andric#endif
21360b57cec5SDimitry Andric
21370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21380b57cec5SDimitry Andric    size_type      count(const key_type& __k) const
21390b57cec5SDimitry Andric        {return __tree_.__count_multi(__k);}
21400b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21410b57cec5SDimitry Andric    template <typename _K2>
21420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2143*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, size_type>
21440b57cec5SDimitry Andric    count(const _K2& __k) const {return __tree_.__count_multi(__k);}
21450b57cec5SDimitry Andric#endif
21460b57cec5SDimitry Andric
21470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
21480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21490b57cec5SDimitry Andric    bool contains(const key_type& __k) const {return find(__k) != end();}
2150fe6060f1SDimitry Andric    template <typename _K2>
2151fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2152*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, bool>
2153fe6060f1SDimitry Andric    contains(const _K2& __k) const { return find(__k) != end(); }
21540b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
21550b57cec5SDimitry Andric
21560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21570b57cec5SDimitry Andric    iterator lower_bound(const key_type& __k)
21580b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
21590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21600b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& __k) const
21610b57cec5SDimitry Andric            {return __tree_.lower_bound(__k);}
21620b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21630b57cec5SDimitry Andric    template <typename _K2>
21640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2165*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21660b57cec5SDimitry Andric    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
21670b57cec5SDimitry Andric
21680b57cec5SDimitry Andric    template <typename _K2>
21690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2170*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21710b57cec5SDimitry Andric    lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
21720b57cec5SDimitry Andric#endif
21730b57cec5SDimitry Andric
21740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21750b57cec5SDimitry Andric    iterator upper_bound(const key_type& __k)
21760b57cec5SDimitry Andric            {return __tree_.upper_bound(__k);}
21770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21780b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& __k) const
21790b57cec5SDimitry Andric            {return __tree_.upper_bound(__k);}
21800b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21810b57cec5SDimitry Andric    template <typename _K2>
21820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2183*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, iterator>
21840b57cec5SDimitry Andric    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
21850b57cec5SDimitry Andric    template <typename _K2>
21860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2187*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, const_iterator>
21880b57cec5SDimitry Andric    upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
21890b57cec5SDimitry Andric#endif
21900b57cec5SDimitry Andric
21910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21920b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& __k)
21930b57cec5SDimitry Andric            {return __tree_.__equal_range_multi(__k);}
21940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21950b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
21960b57cec5SDimitry Andric            {return __tree_.__equal_range_multi(__k);}
21970b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21980b57cec5SDimitry Andric    template <typename _K2>
21990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2200*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<iterator,iterator>>
22010b57cec5SDimitry Andric    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
22020b57cec5SDimitry Andric    template <typename _K2>
22030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2204*753f127fSDimitry Andric    __enable_if_t<__is_transparent<_Compare, _K2>::value, pair<const_iterator,const_iterator>>
22050b57cec5SDimitry Andric    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
22060b57cec5SDimitry Andric#endif
22070b57cec5SDimitry Andric
22080b57cec5SDimitry Andricprivate:
22090b57cec5SDimitry Andric    typedef typename __base::__node                    __node;
22100b57cec5SDimitry Andric    typedef typename __base::__node_allocator          __node_allocator;
22110b57cec5SDimitry Andric    typedef typename __base::__node_pointer            __node_pointer;
22120b57cec5SDimitry Andric
22130b57cec5SDimitry Andric    typedef __map_node_destructor<__node_allocator> _Dp;
22140b57cec5SDimitry Andric    typedef unique_ptr<__node, _Dp> __node_holder;
22150b57cec5SDimitry Andric};
22160b57cec5SDimitry Andric
2217349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
22180b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
22190b57cec5SDimitry Andric         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2220349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2221349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2222349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22230b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
22240b57cec5SDimitry Andric  -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
22250b57cec5SDimitry Andric
22260b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
22270b57cec5SDimitry Andric         class _Allocator = allocator<pair<const _Key, _Tp>>,
2228349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2229349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22300b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
22310b57cec5SDimitry Andric  -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
22320b57cec5SDimitry Andric
22330b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator,
2234349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2235349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22360b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Allocator)
22370b57cec5SDimitry Andric  -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
22380b57cec5SDimitry Andric         less<__iter_key_type<_InputIterator>>, _Allocator>;
22390b57cec5SDimitry Andric
22400b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator,
2241349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22420b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
22430b57cec5SDimitry Andric  -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
22440b57cec5SDimitry Andric#endif
22450b57cec5SDimitry Andric
22460b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22470b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22480b57cec5SDimitry Andricmultimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
22490b57cec5SDimitry Andric    : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
22500b57cec5SDimitry Andric{
22510b57cec5SDimitry Andric    if (__a != __m.get_allocator())
22520b57cec5SDimitry Andric    {
22530b57cec5SDimitry Andric        const_iterator __e = cend();
22540b57cec5SDimitry Andric        while (!__m.empty())
22550b57cec5SDimitry Andric            __tree_.__insert_multi(__e.__i_,
22560b57cec5SDimitry Andric                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
22570b57cec5SDimitry Andric    }
22580b57cec5SDimitry Andric}
22590b57cec5SDimitry Andric#endif
22600b57cec5SDimitry Andric
22610b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22630b57cec5SDimitry Andricbool
22640b57cec5SDimitry Andricoperator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22650b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22660b57cec5SDimitry Andric{
22670b57cec5SDimitry Andric    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
22680b57cec5SDimitry Andric}
22690b57cec5SDimitry Andric
22700b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22720b57cec5SDimitry Andricbool
22730b57cec5SDimitry Andricoperator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22740b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22750b57cec5SDimitry Andric{
22760b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
22770b57cec5SDimitry Andric}
22780b57cec5SDimitry Andric
22790b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22810b57cec5SDimitry Andricbool
22820b57cec5SDimitry Andricoperator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22830b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22840b57cec5SDimitry Andric{
22850b57cec5SDimitry Andric    return !(__x == __y);
22860b57cec5SDimitry Andric}
22870b57cec5SDimitry Andric
22880b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22900b57cec5SDimitry Andricbool
22910b57cec5SDimitry Andricoperator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22920b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22930b57cec5SDimitry Andric{
22940b57cec5SDimitry Andric    return __y < __x;
22950b57cec5SDimitry Andric}
22960b57cec5SDimitry Andric
22970b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22990b57cec5SDimitry Andricbool
23000b57cec5SDimitry Andricoperator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23010b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23020b57cec5SDimitry Andric{
23030b57cec5SDimitry Andric    return !(__x < __y);
23040b57cec5SDimitry Andric}
23050b57cec5SDimitry Andric
23060b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
23070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23080b57cec5SDimitry Andricbool
23090b57cec5SDimitry Andricoperator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23100b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23110b57cec5SDimitry Andric{
23120b57cec5SDimitry Andric    return !(__y < __x);
23130b57cec5SDimitry Andric}
23140b57cec5SDimitry Andric
23150b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
23160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23170b57cec5SDimitry Andricvoid
23180b57cec5SDimitry Andricswap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23190b57cec5SDimitry Andric     multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23200b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
23210b57cec5SDimitry Andric{
23220b57cec5SDimitry Andric    __x.swap(__y);
23230b57cec5SDimitry Andric}
23240b57cec5SDimitry Andric
23250b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
23265ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator,
23275ffd83dbSDimitry Andric          class _Predicate>
23280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23295ffd83dbSDimitry Andric    typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
23305ffd83dbSDimitry Andric    erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
23315ffd83dbSDimitry Andric             _Predicate __pred) {
2332fe6060f1SDimitry Andric  return _VSTD::__libcpp_erase_if_container(__c, __pred);
23335ffd83dbSDimitry Andric}
23340b57cec5SDimitry Andric#endif
23350b57cec5SDimitry Andric
23360b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
23370b57cec5SDimitry Andric
23380b57cec5SDimitry Andric#endif // _LIBCPP_MAP
2339