xref: /freebsd/contrib/llvm-project/libcxx/include/map (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
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
531*81ad6265SDimitry Andric#include <__algorithm/equal.h>
532*81ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
533*81ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
5340b57cec5SDimitry Andric#include <__config>
535*81ad6265SDimitry Andric#include <__functional/binary_function.h>
536fe6060f1SDimitry Andric#include <__functional/is_transparent.h>
537*81ad6265SDimitry Andric#include <__functional/operations.h>
538*81ad6265SDimitry Andric#include <__iterator/erase_if_container.h>
539349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
540*81ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
5410b57cec5SDimitry Andric#include <__node_handle>
542fe6060f1SDimitry Andric#include <__tree>
543fe6060f1SDimitry Andric#include <__utility/forward.h>
544*81ad6265SDimitry Andric#include <__utility/swap.h>
545fe6060f1SDimitry Andric#include <memory>
5460b57cec5SDimitry Andric#include <type_traits>
5470b57cec5SDimitry Andric#include <version>
5480b57cec5SDimitry Andric
549*81ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
550*81ad6265SDimitry Andric#  include <functional>
551*81ad6265SDimitry Andric#  include <iterator>
552*81ad6265SDimitry Andric#  include <utility>
553*81ad6265SDimitry Andric#endif
554*81ad6265SDimitry Andric
555*81ad6265SDimitry Andric// standard-mandated includes
556*81ad6265SDimitry Andric
557*81ad6265SDimitry Andric// [iterator.range]
558*81ad6265SDimitry Andric#include <__iterator/access.h>
559*81ad6265SDimitry Andric#include <__iterator/data.h>
560*81ad6265SDimitry Andric#include <__iterator/empty.h>
561*81ad6265SDimitry Andric#include <__iterator/reverse_access.h>
562*81ad6265SDimitry Andric#include <__iterator/size.h>
563*81ad6265SDimitry Andric
564*81ad6265SDimitry Andric// [associative.map.syn]
565*81ad6265SDimitry Andric#include <compare>
566*81ad6265SDimitry Andric#include <initializer_list>
567*81ad6265SDimitry 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
5850b57cec5SDimitry Andric    __map_value_compare(_Compare c)
5860b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
5870b57cec5SDimitry 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
6300b57cec5SDimitry Andric    __map_value_compare(_Compare c)
6310b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
6320b57cec5SDimitry 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,
7950b57cec5SDimitry Andric              class = typename enable_if<
7960b57cec5SDimitry Andric                    __is_same_uncvref<_ValueTp, value_type>::value
7970b57cec5SDimitry Andric                 >::type
7980b57cec5SDimitry Andric             >
7990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8000b57cec5SDimitry Andric    __value_type& operator=(_ValueTp&& __v)
8010b57cec5SDimitry Andric    {
8020b57cec5SDimitry Andric        __ref() = _VSTD::forward<_ValueTp>(__v);
8030b57cec5SDimitry Andric        return *this;
8040b57cec5SDimitry Andric    }
8050b57cec5SDimitry Andric
8060b57cec5SDimitry Andricprivate:
807349cc55cSDimitry Andric    __value_type() = delete;
808349cc55cSDimitry Andric    ~__value_type() = delete;
809349cc55cSDimitry Andric    __value_type(const __value_type&) = delete;
810349cc55cSDimitry Andric    __value_type(__value_type&&) = delete;
8110b57cec5SDimitry Andric};
8120b57cec5SDimitry Andric
8130b57cec5SDimitry Andric#else
8140b57cec5SDimitry Andric
8150b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
8160b57cec5SDimitry Andricstruct __value_type
8170b57cec5SDimitry Andric{
8180b57cec5SDimitry Andric    typedef _Key                                     key_type;
8190b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
8200b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
8210b57cec5SDimitry Andric
8220b57cec5SDimitry Andricprivate:
8230b57cec5SDimitry Andric    value_type __cc;
8240b57cec5SDimitry Andric
8250b57cec5SDimitry Andricpublic:
8260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8270b57cec5SDimitry Andric    value_type& __get_value() { return __cc; }
8280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8290b57cec5SDimitry Andric    const value_type& __get_value() const { return __cc; }
8300b57cec5SDimitry Andric
8310b57cec5SDimitry Andricprivate:
8320b57cec5SDimitry Andric   __value_type();
8330b57cec5SDimitry Andric   __value_type(__value_type const&);
8340b57cec5SDimitry Andric   __value_type& operator=(__value_type const&);
8350b57cec5SDimitry Andric   ~__value_type();
8360b57cec5SDimitry Andric};
8370b57cec5SDimitry Andric
8380b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8390b57cec5SDimitry Andric
8400b57cec5SDimitry Andrictemplate <class _Tp>
8410b57cec5SDimitry Andricstruct __extract_key_value_types;
8420b57cec5SDimitry Andric
8430b57cec5SDimitry Andrictemplate <class _Key, class _Tp>
8440b57cec5SDimitry Andricstruct __extract_key_value_types<__value_type<_Key, _Tp> >
8450b57cec5SDimitry Andric{
8460b57cec5SDimitry Andric  typedef _Key const __key_type;
8470b57cec5SDimitry Andric  typedef _Tp        __mapped_type;
8480b57cec5SDimitry Andric};
8490b57cec5SDimitry Andric
8500b57cec5SDimitry Andrictemplate <class _TreeIterator>
8510b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_iterator
8520b57cec5SDimitry Andric{
8530b57cec5SDimitry Andric    typedef typename _TreeIterator::_NodeTypes                   _NodeTypes;
8540b57cec5SDimitry Andric    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
8550b57cec5SDimitry Andric
8560b57cec5SDimitry Andric    _TreeIterator __i_;
8570b57cec5SDimitry Andric
8580b57cec5SDimitry Andricpublic:
8590b57cec5SDimitry Andric    typedef bidirectional_iterator_tag                           iterator_category;
8600b57cec5SDimitry Andric    typedef typename _NodeTypes::__map_value_type                value_type;
8610b57cec5SDimitry Andric    typedef typename _TreeIterator::difference_type              difference_type;
8620b57cec5SDimitry Andric    typedef value_type&                                          reference;
8630b57cec5SDimitry Andric    typedef typename _NodeTypes::__map_value_type_pointer        pointer;
8640b57cec5SDimitry Andric
8650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8660b57cec5SDimitry Andric    __map_iterator() _NOEXCEPT {}
8670b57cec5SDimitry Andric
8680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8690b57cec5SDimitry Andric    __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
8700b57cec5SDimitry Andric
8710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8720b57cec5SDimitry Andric    reference operator*() const {return __i_->__get_value();}
8730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8740b57cec5SDimitry Andric    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
8750b57cec5SDimitry Andric
8760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8770b57cec5SDimitry Andric    __map_iterator& operator++() {++__i_; return *this;}
8780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8790b57cec5SDimitry Andric    __map_iterator operator++(int)
8800b57cec5SDimitry Andric    {
8810b57cec5SDimitry Andric        __map_iterator __t(*this);
8820b57cec5SDimitry Andric        ++(*this);
8830b57cec5SDimitry Andric        return __t;
8840b57cec5SDimitry Andric    }
8850b57cec5SDimitry Andric
8860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8870b57cec5SDimitry Andric    __map_iterator& operator--() {--__i_; return *this;}
8880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8890b57cec5SDimitry Andric    __map_iterator operator--(int)
8900b57cec5SDimitry Andric    {
8910b57cec5SDimitry Andric        __map_iterator __t(*this);
8920b57cec5SDimitry Andric        --(*this);
8930b57cec5SDimitry Andric        return __t;
8940b57cec5SDimitry Andric    }
8950b57cec5SDimitry Andric
8960b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
8970b57cec5SDimitry Andric    bool operator==(const __map_iterator& __x, const __map_iterator& __y)
8980b57cec5SDimitry Andric        {return __x.__i_ == __y.__i_;}
8990b57cec5SDimitry Andric    friend
9000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9010b57cec5SDimitry Andric    bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
9020b57cec5SDimitry Andric        {return __x.__i_ != __y.__i_;}
9030b57cec5SDimitry Andric
9040b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
9050b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
9060b57cec5SDimitry Andric    template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
9070b57cec5SDimitry Andric};
9080b57cec5SDimitry Andric
9090b57cec5SDimitry Andrictemplate <class _TreeIterator>
9100b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __map_const_iterator
9110b57cec5SDimitry Andric{
9120b57cec5SDimitry Andric    typedef typename _TreeIterator::_NodeTypes                   _NodeTypes;
9130b57cec5SDimitry Andric    typedef typename _TreeIterator::__pointer_traits             __pointer_traits;
9140b57cec5SDimitry Andric
9150b57cec5SDimitry Andric    _TreeIterator __i_;
9160b57cec5SDimitry Andric
9170b57cec5SDimitry Andricpublic:
9180b57cec5SDimitry Andric    typedef bidirectional_iterator_tag                           iterator_category;
9190b57cec5SDimitry Andric    typedef typename _NodeTypes::__map_value_type                value_type;
9200b57cec5SDimitry Andric    typedef typename _TreeIterator::difference_type              difference_type;
9210b57cec5SDimitry Andric    typedef const value_type&                                    reference;
9220b57cec5SDimitry Andric    typedef typename _NodeTypes::__const_map_value_type_pointer  pointer;
9230b57cec5SDimitry Andric
9240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9250b57cec5SDimitry Andric    __map_const_iterator() _NOEXCEPT {}
9260b57cec5SDimitry Andric
9270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9280b57cec5SDimitry Andric    __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
9290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9300b57cec5SDimitry Andric    __map_const_iterator(__map_iterator<
9310b57cec5SDimitry Andric        typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
9320b57cec5SDimitry Andric        : __i_(__i.__i_) {}
9330b57cec5SDimitry Andric
9340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9350b57cec5SDimitry Andric    reference operator*() const {return __i_->__get_value();}
9360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9370b57cec5SDimitry Andric    pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9400b57cec5SDimitry Andric    __map_const_iterator& operator++() {++__i_; return *this;}
9410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9420b57cec5SDimitry Andric    __map_const_iterator operator++(int)
9430b57cec5SDimitry Andric    {
9440b57cec5SDimitry Andric        __map_const_iterator __t(*this);
9450b57cec5SDimitry Andric        ++(*this);
9460b57cec5SDimitry Andric        return __t;
9470b57cec5SDimitry Andric    }
9480b57cec5SDimitry Andric
9490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9500b57cec5SDimitry Andric    __map_const_iterator& operator--() {--__i_; return *this;}
9510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9520b57cec5SDimitry Andric    __map_const_iterator operator--(int)
9530b57cec5SDimitry Andric    {
9540b57cec5SDimitry Andric        __map_const_iterator __t(*this);
9550b57cec5SDimitry Andric        --(*this);
9560b57cec5SDimitry Andric        return __t;
9570b57cec5SDimitry Andric    }
9580b57cec5SDimitry Andric
9590b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
9600b57cec5SDimitry Andric    bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
9610b57cec5SDimitry Andric        {return __x.__i_ == __y.__i_;}
9620b57cec5SDimitry Andric    friend _LIBCPP_INLINE_VISIBILITY
9630b57cec5SDimitry Andric    bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
9640b57cec5SDimitry Andric        {return __x.__i_ != __y.__i_;}
9650b57cec5SDimitry Andric
9660b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
9670b57cec5SDimitry Andric    template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
9680b57cec5SDimitry Andric    template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator;
9690b57cec5SDimitry Andric};
9700b57cec5SDimitry Andric
9710b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>,
9720b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp> > >
9730b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS map
9740b57cec5SDimitry Andric{
9750b57cec5SDimitry Andricpublic:
9760b57cec5SDimitry Andric    // types:
9770b57cec5SDimitry Andric    typedef _Key                                     key_type;
9780b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
9790b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
980*81ad6265SDimitry Andric    typedef __type_identity_t<_Compare>              key_compare;
981*81ad6265SDimitry Andric    typedef __type_identity_t<_Allocator>            allocator_type;
9820b57cec5SDimitry Andric    typedef value_type&                              reference;
9830b57cec5SDimitry Andric    typedef const value_type&                        const_reference;
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
9860b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
9870b57cec5SDimitry Andric
9880b57cec5SDimitry Andric    class _LIBCPP_TEMPLATE_VIS value_compare
989*81ad6265SDimitry Andric        : public __binary_function<value_type, value_type, bool>
9900b57cec5SDimitry Andric    {
9910b57cec5SDimitry Andric        friend class map;
9920b57cec5SDimitry Andric    protected:
9930b57cec5SDimitry Andric        key_compare comp;
9940b57cec5SDimitry Andric
9950b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
9960b57cec5SDimitry Andric    public:
9970b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
9980b57cec5SDimitry Andric        bool operator()(const value_type& __x, const value_type& __y) const
9990b57cec5SDimitry Andric            {return comp(__x.first, __y.first);}
10000b57cec5SDimitry Andric    };
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andricprivate:
10030b57cec5SDimitry Andric
10040b57cec5SDimitry Andric    typedef _VSTD::__value_type<key_type, mapped_type>             __value_type;
10050b57cec5SDimitry Andric    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
10060b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
10070b57cec5SDimitry Andric                                                 __value_type>::type __allocator_type;
10080b57cec5SDimitry Andric    typedef __tree<__value_type, __vc, __allocator_type>   __base;
10090b57cec5SDimitry Andric    typedef typename __base::__node_traits                 __node_traits;
10100b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>               __alloc_traits;
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andric    __base __tree_;
10130b57cec5SDimitry Andric
10140b57cec5SDimitry Andricpublic:
10150b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer               pointer;
10160b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer         const_pointer;
10170b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type             size_type;
10180b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type       difference_type;
10190b57cec5SDimitry Andric    typedef __map_iterator<typename __base::iterator>             iterator;
10200b57cec5SDimitry Andric    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
10210b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
10220b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
10230b57cec5SDimitry Andric
10240b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
10250b57cec5SDimitry Andric    typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
10260b57cec5SDimitry Andric    typedef __insert_return_type<iterator, node_type> insert_return_type;
10270b57cec5SDimitry Andric#endif
10280b57cec5SDimitry Andric
10290b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10300b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS map;
10310b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
10320b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS multimap;
10330b57cec5SDimitry Andric
10340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10350b57cec5SDimitry Andric    map()
10360b57cec5SDimitry Andric        _NOEXCEPT_(
10370b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
10380b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
10390b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
10400b57cec5SDimitry Andric        : __tree_(__vc(key_compare())) {}
10410b57cec5SDimitry Andric
10420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10430b57cec5SDimitry Andric    explicit map(const key_compare& __comp)
10440b57cec5SDimitry Andric        _NOEXCEPT_(
10450b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
10460b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
10470b57cec5SDimitry Andric        : __tree_(__vc(__comp)) {}
10480b57cec5SDimitry Andric
10490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10500b57cec5SDimitry Andric    explicit map(const key_compare& __comp, const allocator_type& __a)
10510b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
10520b57cec5SDimitry Andric
10530b57cec5SDimitry Andric    template <class _InputIterator>
10540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10550b57cec5SDimitry Andric        map(_InputIterator __f, _InputIterator __l,
10560b57cec5SDimitry Andric            const key_compare& __comp = key_compare())
10570b57cec5SDimitry Andric        : __tree_(__vc(__comp))
10580b57cec5SDimitry Andric        {
10590b57cec5SDimitry Andric            insert(__f, __l);
10600b57cec5SDimitry Andric        }
10610b57cec5SDimitry Andric
10620b57cec5SDimitry Andric    template <class _InputIterator>
10630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10640b57cec5SDimitry Andric        map(_InputIterator __f, _InputIterator __l,
10650b57cec5SDimitry Andric            const key_compare& __comp, const allocator_type& __a)
10660b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
10670b57cec5SDimitry Andric        {
10680b57cec5SDimitry Andric            insert(__f, __l);
10690b57cec5SDimitry Andric        }
10700b57cec5SDimitry Andric
10710b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
10720b57cec5SDimitry Andric    template <class _InputIterator>
10730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10740b57cec5SDimitry Andric    map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10750b57cec5SDimitry Andric        : map(__f, __l, key_compare(), __a) {}
10760b57cec5SDimitry Andric#endif
10770b57cec5SDimitry Andric
10780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10790b57cec5SDimitry Andric    map(const map& __m)
10800b57cec5SDimitry Andric        : __tree_(__m.__tree_)
10810b57cec5SDimitry Andric        {
10820b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
10830b57cec5SDimitry Andric        }
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10860b57cec5SDimitry Andric    map& operator=(const map& __m)
10870b57cec5SDimitry Andric        {
10880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10890b57cec5SDimitry Andric            __tree_ = __m.__tree_;
10900b57cec5SDimitry Andric#else
1091349cc55cSDimitry Andric            if (this != _VSTD::addressof(__m)) {
10920b57cec5SDimitry Andric                __tree_.clear();
10930b57cec5SDimitry Andric                __tree_.value_comp() = __m.__tree_.value_comp();
10940b57cec5SDimitry Andric                __tree_.__copy_assign_alloc(__m.__tree_);
10950b57cec5SDimitry Andric                insert(__m.begin(), __m.end());
10960b57cec5SDimitry Andric            }
10970b57cec5SDimitry Andric#endif
10980b57cec5SDimitry Andric            return *this;
10990b57cec5SDimitry Andric        }
11000b57cec5SDimitry Andric
11010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11020b57cec5SDimitry Andric
11030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11040b57cec5SDimitry Andric    map(map&& __m)
11050b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
11060b57cec5SDimitry Andric        : __tree_(_VSTD::move(__m.__tree_))
11070b57cec5SDimitry Andric        {
11080b57cec5SDimitry Andric        }
11090b57cec5SDimitry Andric
11100b57cec5SDimitry Andric    map(map&& __m, const allocator_type& __a);
11110b57cec5SDimitry Andric
11120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11130b57cec5SDimitry Andric    map& operator=(map&& __m)
11140b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
11150b57cec5SDimitry Andric        {
11160b57cec5SDimitry Andric            __tree_ = _VSTD::move(__m.__tree_);
11170b57cec5SDimitry Andric            return *this;
11180b57cec5SDimitry Andric        }
11190b57cec5SDimitry Andric
11200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11210b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
11220b57cec5SDimitry Andric        : __tree_(__vc(__comp))
11230b57cec5SDimitry Andric        {
11240b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
11250b57cec5SDimitry Andric        }
11260b57cec5SDimitry Andric
11270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11280b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
11290b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
11300b57cec5SDimitry Andric        {
11310b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
11320b57cec5SDimitry Andric        }
11330b57cec5SDimitry Andric
11340b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
11350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11360b57cec5SDimitry Andric    map(initializer_list<value_type> __il, const allocator_type& __a)
11370b57cec5SDimitry Andric        : map(__il, key_compare(), __a) {}
11380b57cec5SDimitry Andric#endif
11390b57cec5SDimitry Andric
11400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11410b57cec5SDimitry Andric    map& operator=(initializer_list<value_type> __il)
11420b57cec5SDimitry Andric        {
11430b57cec5SDimitry Andric            __tree_.__assign_unique(__il.begin(), __il.end());
11440b57cec5SDimitry Andric            return *this;
11450b57cec5SDimitry Andric        }
11460b57cec5SDimitry Andric
11470b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11480b57cec5SDimitry Andric
11490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11500b57cec5SDimitry Andric    explicit map(const allocator_type& __a)
11510b57cec5SDimitry Andric        : __tree_(typename __base::allocator_type(__a))
11520b57cec5SDimitry Andric        {
11530b57cec5SDimitry Andric        }
11540b57cec5SDimitry Andric
11550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11560b57cec5SDimitry Andric    map(const map& __m, const allocator_type& __a)
11570b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
11580b57cec5SDimitry Andric        {
11590b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
11600b57cec5SDimitry Andric        }
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11630b57cec5SDimitry Andric    ~map() {
11640b57cec5SDimitry Andric        static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
11650b57cec5SDimitry Andric    }
11660b57cec5SDimitry Andric
11670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11680b57cec5SDimitry Andric          iterator begin() _NOEXCEPT {return __tree_.begin();}
11690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11700b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
11710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11720b57cec5SDimitry Andric          iterator end() _NOEXCEPT {return __tree_.end();}
11730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11740b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return __tree_.end();}
11750b57cec5SDimitry Andric
11760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11770b57cec5SDimitry Andric          reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
11780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11790b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
11800b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
11810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11820b57cec5SDimitry Andric          reverse_iterator rend() _NOEXCEPT
11830b57cec5SDimitry Andric            {return       reverse_iterator(begin());}
11840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11850b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
11860b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
11870b57cec5SDimitry Andric
11880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11890b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return begin();}
11900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11910b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
11920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11930b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
11940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11950b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
11980b57cec5SDimitry Andric    bool      empty() const _NOEXCEPT {return __tree_.size() == 0;}
11990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12000b57cec5SDimitry Andric    size_type size() const _NOEXCEPT {return __tree_.size();}
12010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12020b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
12030b57cec5SDimitry Andric
12040b57cec5SDimitry Andric    mapped_type& operator[](const key_type& __k);
12050b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12060b57cec5SDimitry Andric    mapped_type& operator[](key_type&& __k);
12070b57cec5SDimitry Andric#endif
12080b57cec5SDimitry Andric
12090b57cec5SDimitry Andric          mapped_type& at(const key_type& __k);
12100b57cec5SDimitry Andric    const mapped_type& at(const key_type& __k) const;
12110b57cec5SDimitry Andric
12120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12130b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
12140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12150b57cec5SDimitry Andric    key_compare    key_comp()      const {return __tree_.value_comp().key_comp();}
12160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12170b57cec5SDimitry Andric    value_compare  value_comp()    const {return value_compare(__tree_.value_comp().key_comp());}
12180b57cec5SDimitry Andric
12190b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12200b57cec5SDimitry Andric    template <class ..._Args>
12210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12220b57cec5SDimitry Andric    pair<iterator, bool> emplace(_Args&& ...__args) {
12230b57cec5SDimitry Andric        return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
12240b57cec5SDimitry Andric    }
12250b57cec5SDimitry Andric
12260b57cec5SDimitry Andric    template <class ..._Args>
12270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12280b57cec5SDimitry Andric    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
12290b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
12300b57cec5SDimitry Andric    }
12310b57cec5SDimitry Andric
12320b57cec5SDimitry Andric    template <class _Pp,
12330b57cec5SDimitry Andric              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
12340b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12350b57cec5SDimitry Andric        pair<iterator, bool> insert(_Pp&& __p)
12360b57cec5SDimitry Andric            {return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
12370b57cec5SDimitry Andric
12380b57cec5SDimitry Andric    template <class _Pp,
12390b57cec5SDimitry Andric              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
12400b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12410b57cec5SDimitry Andric        iterator insert(const_iterator __pos, _Pp&& __p)
12420b57cec5SDimitry Andric            {return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
12430b57cec5SDimitry Andric
12440b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
12450b57cec5SDimitry Andric
12460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12470b57cec5SDimitry Andric    pair<iterator, bool>
12480b57cec5SDimitry Andric        insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
12490b57cec5SDimitry Andric
12500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12510b57cec5SDimitry Andric    iterator
12520b57cec5SDimitry Andric        insert(const_iterator __p, const value_type& __v)
12530b57cec5SDimitry Andric            {return __tree_.__insert_unique(__p.__i_, __v);}
12540b57cec5SDimitry Andric
12550b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12570b57cec5SDimitry Andric    pair<iterator, bool>
12580b57cec5SDimitry Andric    insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
12590b57cec5SDimitry Andric
12600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12610b57cec5SDimitry Andric    iterator insert(const_iterator __p,  value_type&& __v)
12620b57cec5SDimitry Andric    {return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
12630b57cec5SDimitry Andric
12640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12650b57cec5SDimitry Andric    void insert(initializer_list<value_type> __il)
12660b57cec5SDimitry Andric        {insert(__il.begin(), __il.end());}
12670b57cec5SDimitry Andric#endif
12680b57cec5SDimitry Andric
12690b57cec5SDimitry Andric    template <class _InputIterator>
12700b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12710b57cec5SDimitry Andric        void insert(_InputIterator __f, _InputIterator __l)
12720b57cec5SDimitry Andric        {
12730b57cec5SDimitry Andric            for (const_iterator __e = cend(); __f != __l; ++__f)
12740b57cec5SDimitry Andric                insert(__e.__i_, *__f);
12750b57cec5SDimitry Andric        }
12760b57cec5SDimitry Andric
12770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
12780b57cec5SDimitry Andric
12790b57cec5SDimitry Andric    template <class... _Args>
12800b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12810b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
12820b57cec5SDimitry Andric    {
12830b57cec5SDimitry Andric        return __tree_.__emplace_unique_key_args(__k,
12840b57cec5SDimitry Andric            _VSTD::piecewise_construct,
12850b57cec5SDimitry Andric            _VSTD::forward_as_tuple(__k),
12860b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
12870b57cec5SDimitry Andric    }
12880b57cec5SDimitry Andric
12890b57cec5SDimitry Andric    template <class... _Args>
12900b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
12910b57cec5SDimitry Andric        pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
12920b57cec5SDimitry Andric    {
12930b57cec5SDimitry Andric        return __tree_.__emplace_unique_key_args(__k,
12940b57cec5SDimitry Andric            _VSTD::piecewise_construct,
12950b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::move(__k)),
12960b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
12970b57cec5SDimitry Andric    }
12980b57cec5SDimitry Andric
12990b57cec5SDimitry Andric    template <class... _Args>
13000b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13010b57cec5SDimitry Andric        iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
13020b57cec5SDimitry Andric    {
13030b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
13040b57cec5SDimitry Andric            _VSTD::piecewise_construct,
13050b57cec5SDimitry Andric            _VSTD::forward_as_tuple(__k),
1306e8d8bef9SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
13070b57cec5SDimitry Andric    }
13080b57cec5SDimitry Andric
13090b57cec5SDimitry Andric    template <class... _Args>
13100b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13110b57cec5SDimitry Andric        iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
13120b57cec5SDimitry Andric    {
13130b57cec5SDimitry Andric        return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
13140b57cec5SDimitry Andric            _VSTD::piecewise_construct,
13150b57cec5SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::move(__k)),
1316e8d8bef9SDimitry Andric            _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)).first;
13170b57cec5SDimitry Andric    }
13180b57cec5SDimitry Andric
13190b57cec5SDimitry Andric    template <class _Vp>
13200b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13210b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
13220b57cec5SDimitry Andric    {
13230b57cec5SDimitry Andric        iterator __p = lower_bound(__k);
13240b57cec5SDimitry Andric        if ( __p != end() && !key_comp()(__k, __p->first))
13250b57cec5SDimitry Andric        {
13260b57cec5SDimitry Andric            __p->second = _VSTD::forward<_Vp>(__v);
13270b57cec5SDimitry Andric            return _VSTD::make_pair(__p, false);
13280b57cec5SDimitry Andric        }
13290b57cec5SDimitry Andric        return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
13300b57cec5SDimitry Andric    }
13310b57cec5SDimitry Andric
13320b57cec5SDimitry Andric    template <class _Vp>
13330b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
13340b57cec5SDimitry Andric        pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
13350b57cec5SDimitry Andric    {
13360b57cec5SDimitry Andric        iterator __p = lower_bound(__k);
13370b57cec5SDimitry Andric        if ( __p != end() && !key_comp()(__k, __p->first))
13380b57cec5SDimitry Andric        {
13390b57cec5SDimitry Andric            __p->second = _VSTD::forward<_Vp>(__v);
13400b57cec5SDimitry Andric            return _VSTD::make_pair(__p, false);
13410b57cec5SDimitry Andric        }
13420b57cec5SDimitry Andric        return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
13430b57cec5SDimitry Andric    }
13440b57cec5SDimitry Andric
13450b57cec5SDimitry Andric    template <class _Vp>
1346e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1347e8d8bef9SDimitry Andric                                                        const key_type& __k,
1348e8d8bef9SDimitry Andric                                                        _Vp&& __v) {
1349e8d8bef9SDimitry Andric      auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1350e8d8bef9SDimitry Andric          __h.__i_, __k, __k, _VSTD::forward<_Vp>(__v));
1351e8d8bef9SDimitry Andric
1352e8d8bef9SDimitry Andric      if (!__inserted)
1353e8d8bef9SDimitry Andric        __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1354e8d8bef9SDimitry Andric
1355e8d8bef9SDimitry Andric      return __r;
13560b57cec5SDimitry Andric    }
13570b57cec5SDimitry Andric
13580b57cec5SDimitry Andric    template <class _Vp>
1359e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator insert_or_assign(const_iterator __h,
1360e8d8bef9SDimitry Andric                                                        key_type&& __k,
1361e8d8bef9SDimitry Andric                                                        _Vp&& __v) {
1362e8d8bef9SDimitry Andric      auto [__r, __inserted] = __tree_.__emplace_hint_unique_key_args(
1363e8d8bef9SDimitry Andric          __h.__i_, __k, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
1364e8d8bef9SDimitry Andric
1365e8d8bef9SDimitry Andric      if (!__inserted)
1366e8d8bef9SDimitry Andric        __r->__get_value().second = _VSTD::forward<_Vp>(__v);
1367e8d8bef9SDimitry Andric
1368e8d8bef9SDimitry Andric      return __r;
13690b57cec5SDimitry Andric    }
13700b57cec5SDimitry Andric
13710b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 14
13720b57cec5SDimitry Andric
13730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13740b57cec5SDimitry Andric    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
13750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13760b57cec5SDimitry Andric    iterator erase(iterator __p)       {return __tree_.erase(__p.__i_);}
13770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13780b57cec5SDimitry Andric    size_type erase(const key_type& __k)
13790b57cec5SDimitry Andric        {return __tree_.__erase_unique(__k);}
13800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13810b57cec5SDimitry Andric    iterator  erase(const_iterator __f, const_iterator __l)
13820b57cec5SDimitry Andric        {return __tree_.erase(__f.__i_, __l.__i_);}
13830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13840b57cec5SDimitry Andric    void clear() _NOEXCEPT {__tree_.clear();}
13850b57cec5SDimitry Andric
13860b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
13870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13880b57cec5SDimitry Andric    insert_return_type insert(node_type&& __nh)
13890b57cec5SDimitry Andric    {
13900b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
13910b57cec5SDimitry Andric            "node_type with incompatible allocator passed to map::insert()");
13920b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_unique<
13930b57cec5SDimitry Andric            node_type, insert_return_type>(_VSTD::move(__nh));
13940b57cec5SDimitry Andric    }
13950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13960b57cec5SDimitry Andric    iterator insert(const_iterator __hint, node_type&& __nh)
13970b57cec5SDimitry Andric    {
13980b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
13990b57cec5SDimitry Andric            "node_type with incompatible allocator passed to map::insert()");
14000b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_unique<node_type>(
14010b57cec5SDimitry Andric            __hint.__i_, _VSTD::move(__nh));
14020b57cec5SDimitry Andric    }
14030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14040b57cec5SDimitry Andric    node_type extract(key_type const& __key)
14050b57cec5SDimitry Andric    {
14060b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__key);
14070b57cec5SDimitry Andric    }
14080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14090b57cec5SDimitry Andric    node_type extract(const_iterator __it)
14100b57cec5SDimitry Andric    {
14110b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__it.__i_);
14120b57cec5SDimitry Andric    }
14130b57cec5SDimitry Andric    template <class _Compare2>
14140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14150b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
14160b57cec5SDimitry Andric    {
14170b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14180b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14190b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14200b57cec5SDimitry Andric    }
14210b57cec5SDimitry Andric    template <class _Compare2>
14220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14230b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
14240b57cec5SDimitry Andric    {
14250b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14260b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14270b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14280b57cec5SDimitry Andric    }
14290b57cec5SDimitry Andric    template <class _Compare2>
14300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14310b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
14320b57cec5SDimitry Andric    {
14330b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14340b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14350b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14360b57cec5SDimitry Andric    }
14370b57cec5SDimitry Andric    template <class _Compare2>
14380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14390b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
14400b57cec5SDimitry Andric    {
14410b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
14420b57cec5SDimitry Andric                       "merging container with incompatible allocator");
14430b57cec5SDimitry Andric        __tree_.__node_handle_merge_unique(__source.__tree_);
14440b57cec5SDimitry Andric    }
14450b57cec5SDimitry Andric#endif
14460b57cec5SDimitry Andric
14470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14480b57cec5SDimitry Andric    void swap(map& __m)
14490b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
14500b57cec5SDimitry Andric        {__tree_.swap(__m.__tree_);}
14510b57cec5SDimitry Andric
14520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14530b57cec5SDimitry Andric    iterator find(const key_type& __k)             {return __tree_.find(__k);}
14540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14550b57cec5SDimitry Andric    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
14560b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14570b57cec5SDimitry Andric    template <typename _K2>
14580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14590b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
14600b57cec5SDimitry Andric    find(const _K2& __k)                           {return __tree_.find(__k);}
14610b57cec5SDimitry Andric    template <typename _K2>
14620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14630b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
14640b57cec5SDimitry Andric    find(const _K2& __k) const                     {return __tree_.find(__k);}
14650b57cec5SDimitry Andric#endif
14660b57cec5SDimitry Andric
14670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14680b57cec5SDimitry Andric    size_type      count(const key_type& __k) const
14690b57cec5SDimitry Andric        {return __tree_.__count_unique(__k);}
14700b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14710b57cec5SDimitry Andric    template <typename _K2>
14720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14730b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
14740b57cec5SDimitry Andric    count(const _K2& __k) const {return __tree_.__count_multi(__k);}
14750b57cec5SDimitry Andric#endif
14760b57cec5SDimitry Andric
14770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
14780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14790b57cec5SDimitry Andric    bool contains(const key_type& __k) const {return find(__k) != end();}
1480fe6060f1SDimitry Andric    template <typename _K2>
1481fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1482fe6060f1SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1483fe6060f1SDimitry Andric    contains(const _K2& __k) const { return find(__k) != end(); }
14840b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
14850b57cec5SDimitry Andric
14860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14870b57cec5SDimitry Andric    iterator lower_bound(const key_type& __k)
14880b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
14890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14900b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& __k) const
14910b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
14920b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
14930b57cec5SDimitry Andric    template <typename _K2>
14940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14950b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
14960b57cec5SDimitry Andric    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
14970b57cec5SDimitry Andric
14980b57cec5SDimitry Andric    template <typename _K2>
14990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15000b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
15010b57cec5SDimitry Andric    lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
15020b57cec5SDimitry Andric#endif
15030b57cec5SDimitry Andric
15040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15050b57cec5SDimitry Andric    iterator upper_bound(const key_type& __k)
15060b57cec5SDimitry Andric        {return __tree_.upper_bound(__k);}
15070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15080b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& __k) const
15090b57cec5SDimitry Andric        {return __tree_.upper_bound(__k);}
15100b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
15110b57cec5SDimitry Andric    template <typename _K2>
15120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15130b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
15140b57cec5SDimitry Andric    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
15150b57cec5SDimitry Andric    template <typename _K2>
15160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15170b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
15180b57cec5SDimitry Andric    upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
15190b57cec5SDimitry Andric#endif
15200b57cec5SDimitry Andric
15210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15220b57cec5SDimitry Andric    pair<iterator,iterator> equal_range(const key_type& __k)
15230b57cec5SDimitry Andric        {return __tree_.__equal_range_unique(__k);}
15240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15250b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
15260b57cec5SDimitry Andric        {return __tree_.__equal_range_unique(__k);}
15270b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
15280b57cec5SDimitry Andric    template <typename _K2>
15290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15300b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
15310b57cec5SDimitry Andric    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
15320b57cec5SDimitry Andric    template <typename _K2>
15330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15340b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
15350b57cec5SDimitry Andric    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
15360b57cec5SDimitry Andric#endif
15370b57cec5SDimitry Andric
15380b57cec5SDimitry Andricprivate:
15390b57cec5SDimitry Andric    typedef typename __base::__node                    __node;
15400b57cec5SDimitry Andric    typedef typename __base::__node_allocator          __node_allocator;
15410b57cec5SDimitry Andric    typedef typename __base::__node_pointer            __node_pointer;
15420b57cec5SDimitry Andric    typedef typename __base::__node_base_pointer       __node_base_pointer;
15430b57cec5SDimitry Andric    typedef typename __base::__parent_pointer          __parent_pointer;
15440b57cec5SDimitry Andric
15450b57cec5SDimitry Andric    typedef __map_node_destructor<__node_allocator> _Dp;
15460b57cec5SDimitry Andric    typedef unique_ptr<__node, _Dp> __node_holder;
15470b57cec5SDimitry Andric
15480b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
15490b57cec5SDimitry Andric    __node_holder __construct_node_with_key(const key_type& __k);
15500b57cec5SDimitry Andric#endif
15510b57cec5SDimitry Andric};
15520b57cec5SDimitry Andric
1553349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
15540b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
15550b57cec5SDimitry Andric         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
1556349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1557349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1558349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15590b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
15600b57cec5SDimitry Andric  -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
15610b57cec5SDimitry Andric
15620b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
15630b57cec5SDimitry Andric         class _Allocator = allocator<pair<const _Key, _Tp>>,
1564349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
1565349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15660b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
15670b57cec5SDimitry Andric  -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
15680b57cec5SDimitry Andric
15690b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator,
1570349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1571349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15720b57cec5SDimitry Andricmap(_InputIterator, _InputIterator, _Allocator)
15730b57cec5SDimitry Andric  -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
15740b57cec5SDimitry Andric         less<__iter_key_type<_InputIterator>>, _Allocator>;
15750b57cec5SDimitry Andric
15760b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator,
1577349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
15780b57cec5SDimitry Andricmap(initializer_list<pair<_Key, _Tp>>, _Allocator)
15790b57cec5SDimitry Andric  -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
15800b57cec5SDimitry Andric#endif
15810b57cec5SDimitry Andric
15820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
15830b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15840b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
15850b57cec5SDimitry Andric    : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
15860b57cec5SDimitry Andric{
15870b57cec5SDimitry Andric    if (__a != __m.get_allocator())
15880b57cec5SDimitry Andric    {
15890b57cec5SDimitry Andric        const_iterator __e = cend();
15900b57cec5SDimitry Andric        while (!__m.empty())
15910b57cec5SDimitry Andric            __tree_.__insert_unique(__e.__i_,
15920b57cec5SDimitry Andric                    __m.__tree_.remove(__m.begin().__i_)->__value_.__move());
15930b57cec5SDimitry Andric    }
15940b57cec5SDimitry Andric}
15950b57cec5SDimitry Andric
15960b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
15970b57cec5SDimitry Andric_Tp&
15980b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
15990b57cec5SDimitry Andric{
16000b57cec5SDimitry Andric    return __tree_.__emplace_unique_key_args(__k,
16010b57cec5SDimitry Andric        _VSTD::piecewise_construct,
16020b57cec5SDimitry Andric        _VSTD::forward_as_tuple(__k),
16030b57cec5SDimitry Andric        _VSTD::forward_as_tuple()).first->__get_value().second;
16040b57cec5SDimitry Andric}
16050b57cec5SDimitry Andric
16060b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16070b57cec5SDimitry Andric_Tp&
16080b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
16090b57cec5SDimitry Andric{
16100b57cec5SDimitry Andric    return __tree_.__emplace_unique_key_args(__k,
16110b57cec5SDimitry Andric        _VSTD::piecewise_construct,
16120b57cec5SDimitry Andric        _VSTD::forward_as_tuple(_VSTD::move(__k)),
16130b57cec5SDimitry Andric        _VSTD::forward_as_tuple()).first->__get_value().second;
16140b57cec5SDimitry Andric}
16150b57cec5SDimitry Andric
16160b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG
16170b57cec5SDimitry Andric
16180b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16190b57cec5SDimitry Andrictypename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
16200b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
16210b57cec5SDimitry Andric{
16220b57cec5SDimitry Andric    __node_allocator& __na = __tree_.__node_alloc();
16230b57cec5SDimitry Andric    __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
16240b57cec5SDimitry Andric    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
16250b57cec5SDimitry Andric    __h.get_deleter().__first_constructed = true;
16260b57cec5SDimitry Andric    __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
16270b57cec5SDimitry Andric    __h.get_deleter().__second_constructed = true;
1628e8d8bef9SDimitry Andric    return __h;
16290b57cec5SDimitry Andric}
16300b57cec5SDimitry Andric
16310b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16320b57cec5SDimitry Andric_Tp&
16330b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
16340b57cec5SDimitry Andric{
16350b57cec5SDimitry Andric    __parent_pointer __parent;
16360b57cec5SDimitry Andric    __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
16370b57cec5SDimitry Andric    __node_pointer __r = static_cast<__node_pointer>(__child);
16380b57cec5SDimitry Andric    if (__child == nullptr)
16390b57cec5SDimitry Andric    {
16400b57cec5SDimitry Andric        __node_holder __h = __construct_node_with_key(__k);
16410b57cec5SDimitry Andric        __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
16420b57cec5SDimitry Andric        __r = __h.release();
16430b57cec5SDimitry Andric    }
16440b57cec5SDimitry Andric    return __r->__value_.__get_value().second;
16450b57cec5SDimitry Andric}
16460b57cec5SDimitry Andric
16470b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
16480b57cec5SDimitry Andric
16490b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16500b57cec5SDimitry Andric_Tp&
16510b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
16520b57cec5SDimitry Andric{
16530b57cec5SDimitry Andric    __parent_pointer __parent;
16540b57cec5SDimitry Andric    __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
16550b57cec5SDimitry Andric    if (__child == nullptr)
16560b57cec5SDimitry Andric        __throw_out_of_range("map::at:  key not found");
16570b57cec5SDimitry Andric    return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
16580b57cec5SDimitry Andric}
16590b57cec5SDimitry Andric
16600b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16610b57cec5SDimitry Andricconst _Tp&
16620b57cec5SDimitry Andricmap<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
16630b57cec5SDimitry Andric{
16640b57cec5SDimitry Andric    __parent_pointer __parent;
16650b57cec5SDimitry Andric    __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
16660b57cec5SDimitry Andric    if (__child == nullptr)
16670b57cec5SDimitry Andric        __throw_out_of_range("map::at:  key not found");
16680b57cec5SDimitry Andric    return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
16690b57cec5SDimitry Andric}
16700b57cec5SDimitry Andric
16710b57cec5SDimitry Andric
16720b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16740b57cec5SDimitry Andricbool
16750b57cec5SDimitry Andricoperator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
16760b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16770b57cec5SDimitry Andric{
16780b57cec5SDimitry Andric    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
16790b57cec5SDimitry Andric}
16800b57cec5SDimitry Andric
16810b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16820b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16830b57cec5SDimitry Andricbool
16840b57cec5SDimitry Andricoperator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
16850b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16860b57cec5SDimitry Andric{
16870b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
16880b57cec5SDimitry Andric}
16890b57cec5SDimitry Andric
16900b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
16910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16920b57cec5SDimitry Andricbool
16930b57cec5SDimitry Andricoperator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
16940b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
16950b57cec5SDimitry Andric{
16960b57cec5SDimitry Andric    return !(__x == __y);
16970b57cec5SDimitry Andric}
16980b57cec5SDimitry Andric
16990b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17000b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17010b57cec5SDimitry Andricbool
17020b57cec5SDimitry Andricoperator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
17030b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17040b57cec5SDimitry Andric{
17050b57cec5SDimitry Andric    return __y < __x;
17060b57cec5SDimitry Andric}
17070b57cec5SDimitry Andric
17080b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17090b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17100b57cec5SDimitry Andricbool
17110b57cec5SDimitry Andricoperator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
17120b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17130b57cec5SDimitry Andric{
17140b57cec5SDimitry Andric    return !(__x < __y);
17150b57cec5SDimitry Andric}
17160b57cec5SDimitry Andric
17170b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17190b57cec5SDimitry Andricbool
17200b57cec5SDimitry Andricoperator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
17210b57cec5SDimitry Andric           const map<_Key, _Tp, _Compare, _Allocator>& __y)
17220b57cec5SDimitry Andric{
17230b57cec5SDimitry Andric    return !(__y < __x);
17240b57cec5SDimitry Andric}
17250b57cec5SDimitry Andric
17260b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
17270b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17280b57cec5SDimitry Andricvoid
17290b57cec5SDimitry Andricswap(map<_Key, _Tp, _Compare, _Allocator>& __x,
17300b57cec5SDimitry Andric     map<_Key, _Tp, _Compare, _Allocator>& __y)
17310b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
17320b57cec5SDimitry Andric{
17330b57cec5SDimitry Andric    __x.swap(__y);
17340b57cec5SDimitry Andric}
17350b57cec5SDimitry Andric
17360b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
17375ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator,
17385ffd83dbSDimitry Andric          class _Predicate>
17390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17405ffd83dbSDimitry Andric    typename map<_Key, _Tp, _Compare, _Allocator>::size_type
17415ffd83dbSDimitry Andric    erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred) {
1742fe6060f1SDimitry Andric  return _VSTD::__libcpp_erase_if_container(__c, __pred);
17435ffd83dbSDimitry Andric}
17440b57cec5SDimitry Andric#endif
17450b57cec5SDimitry Andric
17460b57cec5SDimitry Andric
17470b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare = less<_Key>,
17480b57cec5SDimitry Andric          class _Allocator = allocator<pair<const _Key, _Tp> > >
17490b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS multimap
17500b57cec5SDimitry Andric{
17510b57cec5SDimitry Andricpublic:
17520b57cec5SDimitry Andric    // types:
17530b57cec5SDimitry Andric    typedef _Key                                     key_type;
17540b57cec5SDimitry Andric    typedef _Tp                                      mapped_type;
17550b57cec5SDimitry Andric    typedef pair<const key_type, mapped_type>        value_type;
1756*81ad6265SDimitry Andric    typedef __type_identity_t<_Compare>              key_compare;
1757*81ad6265SDimitry Andric    typedef __type_identity_t<_Allocator>            allocator_type;
17580b57cec5SDimitry Andric    typedef value_type&                              reference;
17590b57cec5SDimitry Andric    typedef const value_type&                        const_reference;
17600b57cec5SDimitry Andric
17610b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
17620b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
17630b57cec5SDimitry Andric
17640b57cec5SDimitry Andric    class _LIBCPP_TEMPLATE_VIS value_compare
1765*81ad6265SDimitry Andric        : public __binary_function<value_type, value_type, bool>
17660b57cec5SDimitry Andric    {
17670b57cec5SDimitry Andric        friend class multimap;
17680b57cec5SDimitry Andric    protected:
17690b57cec5SDimitry Andric        key_compare comp;
17700b57cec5SDimitry Andric
17710b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
17720b57cec5SDimitry Andric        value_compare(key_compare c) : comp(c) {}
17730b57cec5SDimitry Andric    public:
17740b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
17750b57cec5SDimitry Andric        bool operator()(const value_type& __x, const value_type& __y) const
17760b57cec5SDimitry Andric            {return comp(__x.first, __y.first);}
17770b57cec5SDimitry Andric    };
17780b57cec5SDimitry Andric
17790b57cec5SDimitry Andricprivate:
17800b57cec5SDimitry Andric
17810b57cec5SDimitry Andric    typedef _VSTD::__value_type<key_type, mapped_type>             __value_type;
17820b57cec5SDimitry Andric    typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
17830b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
17840b57cec5SDimitry Andric                                                 __value_type>::type __allocator_type;
17850b57cec5SDimitry Andric    typedef __tree<__value_type, __vc, __allocator_type>            __base;
17860b57cec5SDimitry Andric    typedef typename __base::__node_traits                          __node_traits;
17870b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>                        __alloc_traits;
17880b57cec5SDimitry Andric
17890b57cec5SDimitry Andric    __base __tree_;
17900b57cec5SDimitry Andric
17910b57cec5SDimitry Andricpublic:
17920b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer               pointer;
17930b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer         const_pointer;
17940b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type             size_type;
17950b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type       difference_type;
17960b57cec5SDimitry Andric    typedef __map_iterator<typename __base::iterator>      iterator;
17970b57cec5SDimitry Andric    typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
17980b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
17990b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
18000b57cec5SDimitry Andric
18010b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
18020b57cec5SDimitry Andric    typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
18030b57cec5SDimitry Andric#endif
18040b57cec5SDimitry Andric
18050b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
18060b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS map;
18070b57cec5SDimitry Andric    template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
18080b57cec5SDimitry Andric        friend class _LIBCPP_TEMPLATE_VIS multimap;
18090b57cec5SDimitry Andric
18100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18110b57cec5SDimitry Andric    multimap()
18120b57cec5SDimitry Andric        _NOEXCEPT_(
18130b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
18140b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
18150b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
18160b57cec5SDimitry Andric        : __tree_(__vc(key_compare())) {}
18170b57cec5SDimitry Andric
18180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18190b57cec5SDimitry Andric    explicit multimap(const key_compare& __comp)
18200b57cec5SDimitry Andric        _NOEXCEPT_(
18210b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
18220b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value)
18230b57cec5SDimitry Andric        : __tree_(__vc(__comp)) {}
18240b57cec5SDimitry Andric
18250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18260b57cec5SDimitry Andric    explicit multimap(const key_compare& __comp, const allocator_type& __a)
18270b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
18280b57cec5SDimitry Andric
18290b57cec5SDimitry Andric    template <class _InputIterator>
18300b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
18310b57cec5SDimitry Andric        multimap(_InputIterator __f, _InputIterator __l,
18320b57cec5SDimitry Andric            const key_compare& __comp = key_compare())
18330b57cec5SDimitry Andric        : __tree_(__vc(__comp))
18340b57cec5SDimitry Andric        {
18350b57cec5SDimitry Andric            insert(__f, __l);
18360b57cec5SDimitry Andric        }
18370b57cec5SDimitry Andric
18380b57cec5SDimitry Andric    template <class _InputIterator>
18390b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
18400b57cec5SDimitry Andric        multimap(_InputIterator __f, _InputIterator __l,
18410b57cec5SDimitry Andric            const key_compare& __comp, const allocator_type& __a)
18420b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
18430b57cec5SDimitry Andric        {
18440b57cec5SDimitry Andric            insert(__f, __l);
18450b57cec5SDimitry Andric        }
18460b57cec5SDimitry Andric
18470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
18480b57cec5SDimitry Andric    template <class _InputIterator>
18490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18500b57cec5SDimitry Andric    multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
18510b57cec5SDimitry Andric        : multimap(__f, __l, key_compare(), __a) {}
18520b57cec5SDimitry Andric#endif
18530b57cec5SDimitry Andric
18540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18550b57cec5SDimitry Andric    multimap(const multimap& __m)
18560b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(),
18570b57cec5SDimitry Andric          __alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
18580b57cec5SDimitry Andric        {
18590b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
18600b57cec5SDimitry Andric        }
18610b57cec5SDimitry Andric
18620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18630b57cec5SDimitry Andric    multimap& operator=(const multimap& __m)
18640b57cec5SDimitry Andric        {
18650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18660b57cec5SDimitry Andric            __tree_ = __m.__tree_;
18670b57cec5SDimitry Andric#else
1868349cc55cSDimitry Andric            if (this != _VSTD::addressof(__m)) {
18690b57cec5SDimitry Andric                __tree_.clear();
18700b57cec5SDimitry Andric                __tree_.value_comp() = __m.__tree_.value_comp();
18710b57cec5SDimitry Andric                __tree_.__copy_assign_alloc(__m.__tree_);
18720b57cec5SDimitry Andric                insert(__m.begin(), __m.end());
18730b57cec5SDimitry Andric            }
18740b57cec5SDimitry Andric#endif
18750b57cec5SDimitry Andric            return *this;
18760b57cec5SDimitry Andric        }
18770b57cec5SDimitry Andric
18780b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18790b57cec5SDimitry Andric
18800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18810b57cec5SDimitry Andric    multimap(multimap&& __m)
18820b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
18830b57cec5SDimitry Andric        : __tree_(_VSTD::move(__m.__tree_))
18840b57cec5SDimitry Andric        {
18850b57cec5SDimitry Andric        }
18860b57cec5SDimitry Andric
18870b57cec5SDimitry Andric    multimap(multimap&& __m, const allocator_type& __a);
18880b57cec5SDimitry Andric
18890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18900b57cec5SDimitry Andric    multimap& operator=(multimap&& __m)
18910b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
18920b57cec5SDimitry Andric        {
18930b57cec5SDimitry Andric            __tree_ = _VSTD::move(__m.__tree_);
18940b57cec5SDimitry Andric            return *this;
18950b57cec5SDimitry Andric        }
18960b57cec5SDimitry Andric
18970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18980b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
18990b57cec5SDimitry Andric        : __tree_(__vc(__comp))
19000b57cec5SDimitry Andric        {
19010b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
19020b57cec5SDimitry Andric        }
19030b57cec5SDimitry Andric
19040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19050b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
19060b57cec5SDimitry Andric        : __tree_(__vc(__comp), typename __base::allocator_type(__a))
19070b57cec5SDimitry Andric        {
19080b57cec5SDimitry Andric            insert(__il.begin(), __il.end());
19090b57cec5SDimitry Andric        }
19100b57cec5SDimitry Andric
19110b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
19120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19130b57cec5SDimitry Andric    multimap(initializer_list<value_type> __il, const allocator_type& __a)
19140b57cec5SDimitry Andric        : multimap(__il, key_compare(), __a) {}
19150b57cec5SDimitry Andric#endif
19160b57cec5SDimitry Andric
19170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19180b57cec5SDimitry Andric    multimap& operator=(initializer_list<value_type> __il)
19190b57cec5SDimitry Andric        {
19200b57cec5SDimitry Andric            __tree_.__assign_multi(__il.begin(), __il.end());
19210b57cec5SDimitry Andric            return *this;
19220b57cec5SDimitry Andric        }
19230b57cec5SDimitry Andric
19240b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
19250b57cec5SDimitry Andric
19260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19270b57cec5SDimitry Andric    explicit multimap(const allocator_type& __a)
19280b57cec5SDimitry Andric        : __tree_(typename __base::allocator_type(__a))
19290b57cec5SDimitry Andric        {
19300b57cec5SDimitry Andric        }
19310b57cec5SDimitry Andric
19320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19330b57cec5SDimitry Andric    multimap(const multimap& __m, const allocator_type& __a)
19340b57cec5SDimitry Andric        : __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
19350b57cec5SDimitry Andric        {
19360b57cec5SDimitry Andric            insert(__m.begin(), __m.end());
19370b57cec5SDimitry Andric        }
19380b57cec5SDimitry Andric
19390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19400b57cec5SDimitry Andric    ~multimap() {
19410b57cec5SDimitry Andric        static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
19420b57cec5SDimitry Andric    }
19430b57cec5SDimitry Andric
19440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19450b57cec5SDimitry Andric          iterator begin() _NOEXCEPT {return __tree_.begin();}
19460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19470b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
19480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19490b57cec5SDimitry Andric          iterator end() _NOEXCEPT {return __tree_.end();}
19500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19510b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT {return __tree_.end();}
19520b57cec5SDimitry Andric
19530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19540b57cec5SDimitry Andric          reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
19550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19560b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
19570b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
19580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19590b57cec5SDimitry Andric          reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
19600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19610b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
19620b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
19630b57cec5SDimitry Andric
19640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19650b57cec5SDimitry Andric    const_iterator cbegin()  const _NOEXCEPT {return begin();}
19660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19670b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT {return end();}
19680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19690b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
19700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19710b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT {return rend();}
19720b57cec5SDimitry Andric
19730b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
19740b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
19750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19760b57cec5SDimitry Andric    size_type size() const _NOEXCEPT {return __tree_.size();}
19770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19780b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
19790b57cec5SDimitry Andric
19800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19810b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
19820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19830b57cec5SDimitry Andric    key_compare    key_comp() const {return __tree_.value_comp().key_comp();}
19840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19850b57cec5SDimitry Andric    value_compare  value_comp() const
19860b57cec5SDimitry Andric        {return value_compare(__tree_.value_comp().key_comp());}
19870b57cec5SDimitry Andric
19880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
19890b57cec5SDimitry Andric
19900b57cec5SDimitry Andric    template <class ..._Args>
19910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19920b57cec5SDimitry Andric    iterator emplace(_Args&& ...__args) {
19930b57cec5SDimitry Andric        return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
19940b57cec5SDimitry Andric    }
19950b57cec5SDimitry Andric
19960b57cec5SDimitry Andric    template <class ..._Args>
19970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
19980b57cec5SDimitry Andric    iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
19990b57cec5SDimitry Andric        return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
20000b57cec5SDimitry Andric    }
20010b57cec5SDimitry Andric
20020b57cec5SDimitry Andric    template <class _Pp,
20030b57cec5SDimitry Andric              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
20040b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20050b57cec5SDimitry Andric        iterator insert(_Pp&& __p)
20060b57cec5SDimitry Andric            {return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
20070b57cec5SDimitry Andric
20080b57cec5SDimitry Andric    template <class _Pp,
20090b57cec5SDimitry Andric              class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
20100b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20110b57cec5SDimitry Andric        iterator insert(const_iterator __pos, _Pp&& __p)
20120b57cec5SDimitry Andric            {return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
20130b57cec5SDimitry Andric
20140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20150b57cec5SDimitry Andric    iterator insert(value_type&& __v)
20160b57cec5SDimitry Andric        {return __tree_.__insert_multi(_VSTD::move(__v));}
20170b57cec5SDimitry Andric
20180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20190b57cec5SDimitry Andric    iterator insert(const_iterator __p, value_type&& __v)
20200b57cec5SDimitry Andric        {return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
20210b57cec5SDimitry Andric
20220b57cec5SDimitry Andric
20230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20240b57cec5SDimitry Andric    void insert(initializer_list<value_type> __il)
20250b57cec5SDimitry Andric        {insert(__il.begin(), __il.end());}
20260b57cec5SDimitry Andric
20270b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
20280b57cec5SDimitry Andric
20290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20300b57cec5SDimitry Andric    iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
20310b57cec5SDimitry Andric
20320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20330b57cec5SDimitry Andric    iterator insert(const_iterator __p, const value_type& __v)
20340b57cec5SDimitry Andric            {return __tree_.__insert_multi(__p.__i_, __v);}
20350b57cec5SDimitry Andric
20360b57cec5SDimitry Andric    template <class _InputIterator>
20370b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
20380b57cec5SDimitry Andric        void insert(_InputIterator __f, _InputIterator __l)
20390b57cec5SDimitry Andric        {
20400b57cec5SDimitry Andric            for (const_iterator __e = cend(); __f != __l; ++__f)
20410b57cec5SDimitry Andric                __tree_.__insert_multi(__e.__i_, *__f);
20420b57cec5SDimitry Andric        }
20430b57cec5SDimitry Andric
20440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20450b57cec5SDimitry Andric    iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
20460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20470b57cec5SDimitry Andric    iterator erase(iterator __p)       {return __tree_.erase(__p.__i_);}
20480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20490b57cec5SDimitry Andric    size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
20500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20510b57cec5SDimitry Andric    iterator  erase(const_iterator __f, const_iterator __l)
20520b57cec5SDimitry Andric        {return __tree_.erase(__f.__i_, __l.__i_);}
20530b57cec5SDimitry Andric
20540b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
20550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20560b57cec5SDimitry Andric    iterator insert(node_type&& __nh)
20570b57cec5SDimitry Andric    {
20580b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
20590b57cec5SDimitry Andric            "node_type with incompatible allocator passed to multimap::insert()");
20600b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_multi<node_type>(
20610b57cec5SDimitry Andric            _VSTD::move(__nh));
20620b57cec5SDimitry Andric    }
20630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20640b57cec5SDimitry Andric    iterator insert(const_iterator __hint, node_type&& __nh)
20650b57cec5SDimitry Andric    {
20660b57cec5SDimitry Andric        _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
20670b57cec5SDimitry Andric            "node_type with incompatible allocator passed to multimap::insert()");
20680b57cec5SDimitry Andric        return __tree_.template __node_handle_insert_multi<node_type>(
20690b57cec5SDimitry Andric            __hint.__i_, _VSTD::move(__nh));
20700b57cec5SDimitry Andric    }
20710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20720b57cec5SDimitry Andric    node_type extract(key_type const& __key)
20730b57cec5SDimitry Andric    {
20740b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(__key);
20750b57cec5SDimitry Andric    }
20760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20770b57cec5SDimitry Andric    node_type extract(const_iterator __it)
20780b57cec5SDimitry Andric    {
20790b57cec5SDimitry Andric        return __tree_.template __node_handle_extract<node_type>(
20800b57cec5SDimitry Andric            __it.__i_);
20810b57cec5SDimitry Andric    }
20820b57cec5SDimitry Andric    template <class _Compare2>
20830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20840b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
20850b57cec5SDimitry Andric    {
20860b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
20870b57cec5SDimitry Andric                       "merging container with incompatible allocator");
20880b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
20890b57cec5SDimitry Andric    }
20900b57cec5SDimitry Andric    template <class _Compare2>
20910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20920b57cec5SDimitry Andric    void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
20930b57cec5SDimitry Andric    {
20940b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
20950b57cec5SDimitry Andric                       "merging container with incompatible allocator");
20960b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
20970b57cec5SDimitry Andric    }
20980b57cec5SDimitry Andric    template <class _Compare2>
20990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21000b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
21010b57cec5SDimitry Andric    {
21020b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
21030b57cec5SDimitry Andric                       "merging container with incompatible allocator");
21040b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
21050b57cec5SDimitry Andric    }
21060b57cec5SDimitry Andric    template <class _Compare2>
21070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21080b57cec5SDimitry Andric    void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
21090b57cec5SDimitry Andric    {
21100b57cec5SDimitry Andric        _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
21110b57cec5SDimitry Andric                       "merging container with incompatible allocator");
21120b57cec5SDimitry Andric        return __tree_.__node_handle_merge_multi(__source.__tree_);
21130b57cec5SDimitry Andric    }
21140b57cec5SDimitry Andric#endif
21150b57cec5SDimitry Andric
21160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21170b57cec5SDimitry Andric    void clear() _NOEXCEPT {__tree_.clear();}
21180b57cec5SDimitry Andric
21190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21200b57cec5SDimitry Andric    void swap(multimap& __m)
21210b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
21220b57cec5SDimitry Andric        {__tree_.swap(__m.__tree_);}
21230b57cec5SDimitry Andric
21240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21250b57cec5SDimitry Andric    iterator find(const key_type& __k)             {return __tree_.find(__k);}
21260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21270b57cec5SDimitry Andric    const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
21280b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21290b57cec5SDimitry Andric    template <typename _K2>
21300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21310b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
21320b57cec5SDimitry Andric    find(const _K2& __k)                           {return __tree_.find(__k);}
21330b57cec5SDimitry Andric    template <typename _K2>
21340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21350b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
21360b57cec5SDimitry Andric    find(const _K2& __k) const                     {return __tree_.find(__k);}
21370b57cec5SDimitry Andric#endif
21380b57cec5SDimitry Andric
21390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21400b57cec5SDimitry Andric    size_type      count(const key_type& __k) const
21410b57cec5SDimitry Andric        {return __tree_.__count_multi(__k);}
21420b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21430b57cec5SDimitry Andric    template <typename _K2>
21440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21450b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
21460b57cec5SDimitry Andric    count(const _K2& __k) const {return __tree_.__count_multi(__k);}
21470b57cec5SDimitry Andric#endif
21480b57cec5SDimitry Andric
21490b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
21500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21510b57cec5SDimitry Andric    bool contains(const key_type& __k) const {return find(__k) != end();}
2152fe6060f1SDimitry Andric    template <typename _K2>
2153fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2154fe6060f1SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
2155fe6060f1SDimitry Andric    contains(const _K2& __k) const { return find(__k) != end(); }
21560b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
21570b57cec5SDimitry Andric
21580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21590b57cec5SDimitry Andric    iterator lower_bound(const key_type& __k)
21600b57cec5SDimitry Andric        {return __tree_.lower_bound(__k);}
21610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21620b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& __k) const
21630b57cec5SDimitry Andric            {return __tree_.lower_bound(__k);}
21640b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21650b57cec5SDimitry Andric    template <typename _K2>
21660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21670b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
21680b57cec5SDimitry Andric    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
21690b57cec5SDimitry Andric
21700b57cec5SDimitry Andric    template <typename _K2>
21710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21720b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
21730b57cec5SDimitry Andric    lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
21740b57cec5SDimitry Andric#endif
21750b57cec5SDimitry Andric
21760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21770b57cec5SDimitry Andric    iterator upper_bound(const key_type& __k)
21780b57cec5SDimitry Andric            {return __tree_.upper_bound(__k);}
21790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21800b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& __k) const
21810b57cec5SDimitry Andric            {return __tree_.upper_bound(__k);}
21820b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21830b57cec5SDimitry Andric    template <typename _K2>
21840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21850b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
21860b57cec5SDimitry Andric    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
21870b57cec5SDimitry Andric    template <typename _K2>
21880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21890b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
21900b57cec5SDimitry Andric    upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
21910b57cec5SDimitry Andric#endif
21920b57cec5SDimitry Andric
21930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21940b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& __k)
21950b57cec5SDimitry Andric            {return __tree_.__equal_range_multi(__k);}
21960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21970b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
21980b57cec5SDimitry Andric            {return __tree_.__equal_range_multi(__k);}
21990b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
22000b57cec5SDimitry Andric    template <typename _K2>
22010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22020b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
22030b57cec5SDimitry Andric    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
22040b57cec5SDimitry Andric    template <typename _K2>
22050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22060b57cec5SDimitry Andric    typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
22070b57cec5SDimitry Andric    equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
22080b57cec5SDimitry Andric#endif
22090b57cec5SDimitry Andric
22100b57cec5SDimitry Andricprivate:
22110b57cec5SDimitry Andric    typedef typename __base::__node                    __node;
22120b57cec5SDimitry Andric    typedef typename __base::__node_allocator          __node_allocator;
22130b57cec5SDimitry Andric    typedef typename __base::__node_pointer            __node_pointer;
22140b57cec5SDimitry Andric
22150b57cec5SDimitry Andric    typedef __map_node_destructor<__node_allocator> _Dp;
22160b57cec5SDimitry Andric    typedef unique_ptr<__node, _Dp> __node_holder;
22170b57cec5SDimitry Andric};
22180b57cec5SDimitry Andric
2219349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
22200b57cec5SDimitry Andrictemplate<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
22210b57cec5SDimitry Andric         class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
2222349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2223349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2224349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22250b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
22260b57cec5SDimitry Andric  -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
22270b57cec5SDimitry Andric
22280b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
22290b57cec5SDimitry Andric         class _Allocator = allocator<pair<const _Key, _Tp>>,
2230349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value, void>,
2231349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22320b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
22330b57cec5SDimitry Andric  -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
22340b57cec5SDimitry Andric
22350b57cec5SDimitry Andrictemplate<class _InputIterator, class _Allocator,
2236349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
2237349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22380b57cec5SDimitry Andricmultimap(_InputIterator, _InputIterator, _Allocator)
22390b57cec5SDimitry Andric  -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
22400b57cec5SDimitry Andric         less<__iter_key_type<_InputIterator>>, _Allocator>;
22410b57cec5SDimitry Andric
22420b57cec5SDimitry Andrictemplate<class _Key, class _Tp, class _Allocator,
2243349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value, void>>
22440b57cec5SDimitry Andricmultimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
22450b57cec5SDimitry Andric  -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
22460b57cec5SDimitry Andric#endif
22470b57cec5SDimitry Andric
22480b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22490b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22500b57cec5SDimitry Andricmultimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
22510b57cec5SDimitry Andric    : __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
22520b57cec5SDimitry Andric{
22530b57cec5SDimitry Andric    if (__a != __m.get_allocator())
22540b57cec5SDimitry Andric    {
22550b57cec5SDimitry Andric        const_iterator __e = cend();
22560b57cec5SDimitry Andric        while (!__m.empty())
22570b57cec5SDimitry Andric            __tree_.__insert_multi(__e.__i_,
22580b57cec5SDimitry Andric                    _VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
22590b57cec5SDimitry Andric    }
22600b57cec5SDimitry Andric}
22610b57cec5SDimitry Andric#endif
22620b57cec5SDimitry Andric
22630b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22650b57cec5SDimitry Andricbool
22660b57cec5SDimitry Andricoperator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22670b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22680b57cec5SDimitry Andric{
22690b57cec5SDimitry Andric    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
22700b57cec5SDimitry Andric}
22710b57cec5SDimitry Andric
22720b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22740b57cec5SDimitry Andricbool
22750b57cec5SDimitry Andricoperator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22760b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22770b57cec5SDimitry Andric{
22780b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
22790b57cec5SDimitry Andric}
22800b57cec5SDimitry Andric
22810b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22820b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22830b57cec5SDimitry Andricbool
22840b57cec5SDimitry Andricoperator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22850b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22860b57cec5SDimitry Andric{
22870b57cec5SDimitry Andric    return !(__x == __y);
22880b57cec5SDimitry Andric}
22890b57cec5SDimitry Andric
22900b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
22910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
22920b57cec5SDimitry Andricbool
22930b57cec5SDimitry Andricoperator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
22940b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
22950b57cec5SDimitry Andric{
22960b57cec5SDimitry Andric    return __y < __x;
22970b57cec5SDimitry Andric}
22980b57cec5SDimitry Andric
22990b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
23000b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23010b57cec5SDimitry Andricbool
23020b57cec5SDimitry Andricoperator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23030b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23040b57cec5SDimitry Andric{
23050b57cec5SDimitry Andric    return !(__x < __y);
23060b57cec5SDimitry Andric}
23070b57cec5SDimitry Andric
23080b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
23090b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23100b57cec5SDimitry Andricbool
23110b57cec5SDimitry Andricoperator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23120b57cec5SDimitry Andric           const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23130b57cec5SDimitry Andric{
23140b57cec5SDimitry Andric    return !(__y < __x);
23150b57cec5SDimitry Andric}
23160b57cec5SDimitry Andric
23170b57cec5SDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator>
23180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23190b57cec5SDimitry Andricvoid
23200b57cec5SDimitry Andricswap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
23210b57cec5SDimitry Andric     multimap<_Key, _Tp, _Compare, _Allocator>& __y)
23220b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
23230b57cec5SDimitry Andric{
23240b57cec5SDimitry Andric    __x.swap(__y);
23250b57cec5SDimitry Andric}
23260b57cec5SDimitry Andric
23270b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
23285ffd83dbSDimitry Andrictemplate <class _Key, class _Tp, class _Compare, class _Allocator,
23295ffd83dbSDimitry Andric          class _Predicate>
23300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23315ffd83dbSDimitry Andric    typename multimap<_Key, _Tp, _Compare, _Allocator>::size_type
23325ffd83dbSDimitry Andric    erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
23335ffd83dbSDimitry Andric             _Predicate __pred) {
2334fe6060f1SDimitry Andric  return _VSTD::__libcpp_erase_if_container(__c, __pred);
23355ffd83dbSDimitry Andric}
23360b57cec5SDimitry Andric#endif
23370b57cec5SDimitry Andric
23380b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
23390b57cec5SDimitry Andric
23400b57cec5SDimitry Andric#endif // _LIBCPP_MAP
2341