xref: /freebsd/contrib/llvm-project/libcxx/include/set (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
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_SET
110b57cec5SDimitry Andric#define _LIBCPP_SET
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric    set synopsis
160b57cec5SDimitry Andric
170b57cec5SDimitry Andricnamespace std
180b57cec5SDimitry Andric{
190b57cec5SDimitry Andric
200b57cec5SDimitry Andrictemplate <class Key, class Compare = less<Key>,
210b57cec5SDimitry Andric          class Allocator = allocator<Key>>
220b57cec5SDimitry Andricclass set
230b57cec5SDimitry Andric{
240b57cec5SDimitry Andricpublic:
250b57cec5SDimitry Andric    // types:
260b57cec5SDimitry Andric    typedef Key                                      key_type;
270b57cec5SDimitry Andric    typedef key_type                                 value_type;
280b57cec5SDimitry Andric    typedef Compare                                  key_compare;
290b57cec5SDimitry Andric    typedef key_compare                              value_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::size_type       size_type;
340b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
350b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
360b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
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    // construct/copy/destroy:
460b57cec5SDimitry Andric    set()
470b57cec5SDimitry Andric        noexcept(
480b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
490b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
500b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value);
510b57cec5SDimitry Andric    explicit set(const value_compare& comp);
520b57cec5SDimitry Andric    set(const value_compare& comp, const allocator_type& a);
530b57cec5SDimitry Andric    template <class InputIterator>
540b57cec5SDimitry Andric        set(InputIterator first, InputIterator last,
550b57cec5SDimitry Andric            const value_compare& comp = value_compare());
560b57cec5SDimitry Andric    template <class InputIterator>
570b57cec5SDimitry Andric        set(InputIterator first, InputIterator last, const value_compare& comp,
580b57cec5SDimitry Andric            const allocator_type& a);
5906c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
6006c3fb27SDimitry Andric      set(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
610b57cec5SDimitry Andric    set(const set& s);
620b57cec5SDimitry Andric    set(set&& s)
630b57cec5SDimitry Andric        noexcept(
640b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
650b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
660b57cec5SDimitry Andric    explicit set(const allocator_type& a);
670b57cec5SDimitry Andric    set(const set& s, const allocator_type& a);
680b57cec5SDimitry Andric    set(set&& s, const allocator_type& a);
690b57cec5SDimitry Andric    set(initializer_list<value_type> il, const value_compare& comp = value_compare());
700b57cec5SDimitry Andric    set(initializer_list<value_type> il, const value_compare& comp,
710b57cec5SDimitry Andric        const allocator_type& a);
720b57cec5SDimitry Andric    template <class InputIterator>
730b57cec5SDimitry Andric        set(InputIterator first, InputIterator last, const allocator_type& a)
740b57cec5SDimitry Andric            : set(first, last, Compare(), a) {}  // C++14
7506c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
7606c3fb27SDimitry Andric      set(from_range_t, R&& rg, const Allocator& a))
7706c3fb27SDimitry Andric        : set(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
780b57cec5SDimitry Andric    set(initializer_list<value_type> il, const allocator_type& a)
790b57cec5SDimitry Andric        : set(il, Compare(), a) {}  // C++14
800b57cec5SDimitry Andric    ~set();
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric    set& operator=(const set& s);
830b57cec5SDimitry Andric    set& operator=(set&& s)
840b57cec5SDimitry Andric        noexcept(
850b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
860b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
870b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
880b57cec5SDimitry Andric    set& operator=(initializer_list<value_type> il);
890b57cec5SDimitry Andric
900b57cec5SDimitry Andric    // iterators:
910b57cec5SDimitry Andric          iterator begin() noexcept;
920b57cec5SDimitry Andric    const_iterator begin() const noexcept;
930b57cec5SDimitry Andric          iterator end() noexcept;
940b57cec5SDimitry Andric    const_iterator end()   const noexcept;
950b57cec5SDimitry Andric
960b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
970b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
980b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
990b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
1000b57cec5SDimitry Andric
1010b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
1020b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
1030b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
1040b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
1050b57cec5SDimitry Andric
1060b57cec5SDimitry Andric    // capacity:
1070b57cec5SDimitry Andric    bool      empty()    const noexcept;
1080b57cec5SDimitry Andric    size_type size()     const noexcept;
1090b57cec5SDimitry Andric    size_type max_size() const noexcept;
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andric    // modifiers:
1120b57cec5SDimitry Andric    template <class... Args>
1130b57cec5SDimitry Andric        pair<iterator, bool> emplace(Args&&... args);
1140b57cec5SDimitry Andric    template <class... Args>
1150b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
1160b57cec5SDimitry Andric    pair<iterator,bool> insert(const value_type& v);
1170b57cec5SDimitry Andric    pair<iterator,bool> insert(value_type&& v);
1180b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
1190b57cec5SDimitry Andric    iterator insert(const_iterator position, value_type&& v);
1200b57cec5SDimitry Andric    template <class InputIterator>
1210b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
12206c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
12306c3fb27SDimitry Andric      void insert_range(R&& rg);                                                      // C++23
1240b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
1270b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
1280b57cec5SDimitry Andric    insert_return_type insert(node_type&& nh);                                        // C++17
1290b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric    iterator  erase(const_iterator position);
1320b57cec5SDimitry Andric    iterator  erase(iterator position);  // C++14
1330b57cec5SDimitry Andric    size_type erase(const key_type& k);
1340b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
1350b57cec5SDimitry Andric    void clear() noexcept;
1360b57cec5SDimitry Andric
1370b57cec5SDimitry Andric    template<class C2>
1380b57cec5SDimitry Andric      void merge(set<Key, C2, Allocator>& source);         // C++17
1390b57cec5SDimitry Andric    template<class C2>
1400b57cec5SDimitry Andric      void merge(set<Key, C2, Allocator>&& source);        // C++17
1410b57cec5SDimitry Andric    template<class C2>
1420b57cec5SDimitry Andric      void merge(multiset<Key, C2, Allocator>& source);    // C++17
1430b57cec5SDimitry Andric    template<class C2>
1440b57cec5SDimitry Andric      void merge(multiset<Key, C2, Allocator>&& source);   // C++17
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andric    void swap(set& s)
1470b57cec5SDimitry Andric        noexcept(
1480b57cec5SDimitry Andric            __is_nothrow_swappable<key_compare>::value &&
1490b57cec5SDimitry Andric            (!allocator_type::propagate_on_container_swap::value ||
1500b57cec5SDimitry Andric             __is_nothrow_swappable<allocator_type>::value));
1510b57cec5SDimitry Andric
1520b57cec5SDimitry Andric    // observers:
1530b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
1540b57cec5SDimitry Andric    key_compare    key_comp()      const;
1550b57cec5SDimitry Andric    value_compare  value_comp()    const;
1560b57cec5SDimitry Andric
1570b57cec5SDimitry Andric    // set operations:
1580b57cec5SDimitry Andric          iterator find(const key_type& k);
1590b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
1600b57cec5SDimitry Andric    template<typename K>
1610b57cec5SDimitry Andric        iterator find(const K& x);
1620b57cec5SDimitry Andric    template<typename K>
1630b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
164fe6060f1SDimitry Andric
1650b57cec5SDimitry Andric    template<typename K>
1660b57cec5SDimitry Andric        size_type count(const K& x) const;        // C++14
1670b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
168fe6060f1SDimitry Andric
1690b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
170fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
171fe6060f1SDimitry Andric
1720b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
1730b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
1740b57cec5SDimitry Andric    template<typename K>
1750b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
1760b57cec5SDimitry Andric    template<typename K>
1770b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
1800b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
1810b57cec5SDimitry Andric    template<typename K>
1820b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
1830b57cec5SDimitry Andric    template<typename K>
1840b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
1850b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
1860b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
1870b57cec5SDimitry Andric    template<typename K>
1880b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
1890b57cec5SDimitry Andric    template<typename K>
1900b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
1910b57cec5SDimitry Andric};
1920b57cec5SDimitry Andric
193349cc55cSDimitry Andrictemplate <class InputIterator,
194349cc55cSDimitry Andric      class Compare = less<typename iterator_traits<InputIterator>::value_type>,
195349cc55cSDimitry Andric      class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
196349cc55cSDimitry Andricset(InputIterator, InputIterator,
197349cc55cSDimitry Andric    Compare = Compare(), Allocator = Allocator())
198349cc55cSDimitry Andric  -> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
199349cc55cSDimitry Andric
20006c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
20106c3fb27SDimitry Andric         class Allocator = allocator<ranges::range_value_t<R>>>
20206c3fb27SDimitry Andric  set(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
20306c3fb27SDimitry Andric    -> set<ranges::range_value_t<R>, Compare, Allocator>; // C++23
20406c3fb27SDimitry Andric
205349cc55cSDimitry Andrictemplate<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
206349cc55cSDimitry Andricset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
207349cc55cSDimitry Andric  -> set<Key, Compare, Allocator>; // C++17
208349cc55cSDimitry Andric
209349cc55cSDimitry Andrictemplate<class InputIterator, class Allocator>
210349cc55cSDimitry Andricset(InputIterator, InputIterator, Allocator)
211349cc55cSDimitry Andric  -> set<typename iterator_traits<InputIterator>::value_type,
212349cc55cSDimitry Andric          less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
213349cc55cSDimitry Andric
21406c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator>
21506c3fb27SDimitry Andric  set(from_range_t, R&&, Allocator)
21606c3fb27SDimitry Andric    -> set<ranges::range_value_t<R>, less<ranges::range_value_t<R>>, Allocator>; // C++23
21706c3fb27SDimitry Andric
218349cc55cSDimitry Andrictemplate<class Key, class Allocator>
219349cc55cSDimitry Andricset(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>; // C++17
220349cc55cSDimitry Andric
2210b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2220b57cec5SDimitry Andricbool
2230b57cec5SDimitry Andricoperator==(const set<Key, Compare, Allocator>& x,
2240b57cec5SDimitry Andric           const set<Key, Compare, Allocator>& y);
2250b57cec5SDimitry Andric
2260b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2270b57cec5SDimitry Andricbool
2280b57cec5SDimitry Andricoperator< (const set<Key, Compare, Allocator>& x,
22906c3fb27SDimitry Andric           const set<Key, Compare, Allocator>& y);                                // removed in C++20
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2320b57cec5SDimitry Andricbool
2330b57cec5SDimitry Andricoperator!=(const set<Key, Compare, Allocator>& x,
23406c3fb27SDimitry Andric           const set<Key, Compare, Allocator>& y);                                // removed in C++20
2350b57cec5SDimitry Andric
2360b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2370b57cec5SDimitry Andricbool
2380b57cec5SDimitry Andricoperator> (const set<Key, Compare, Allocator>& x,
23906c3fb27SDimitry Andric           const set<Key, Compare, Allocator>& y);                                // removed in C++20
2400b57cec5SDimitry Andric
2410b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2420b57cec5SDimitry Andricbool
2430b57cec5SDimitry Andricoperator>=(const set<Key, Compare, Allocator>& x,
24406c3fb27SDimitry Andric           const set<Key, Compare, Allocator>& y);                                // removed in C++20
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2470b57cec5SDimitry Andricbool
2480b57cec5SDimitry Andricoperator<=(const set<Key, Compare, Allocator>& x,
24906c3fb27SDimitry Andric           const set<Key, Compare, Allocator>& y);                                // removed in C++20
25006c3fb27SDimitry Andric
25106c3fb27SDimitry Andrictemplate<class Key, class Compare, class Allocator>
25206c3fb27SDimitry Andric  synth-three-way-result<Key> operator<=>(const set<Key, Compare, Allocator>& x,
25306c3fb27SDimitry Andric                                          const set<Key, Compare, Allocator>& y); // since C++20
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric// specialized algorithms:
2560b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
2570b57cec5SDimitry Andricvoid
2580b57cec5SDimitry Andricswap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
2590b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
2600b57cec5SDimitry Andric
2610b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator, class Predicate>
2625ffd83dbSDimitry Andrictypename set<Key, Compare, Allocator>::size_type
2635ffd83dbSDimitry Andricerase_if(set<Key, Compare, Allocator>& c, Predicate pred);  // C++20
2640b57cec5SDimitry Andric
2650b57cec5SDimitry Andrictemplate <class Key, class Compare = less<Key>,
2660b57cec5SDimitry Andric          class Allocator = allocator<Key>>
2670b57cec5SDimitry Andricclass multiset
2680b57cec5SDimitry Andric{
2690b57cec5SDimitry Andricpublic:
2700b57cec5SDimitry Andric    // types:
2710b57cec5SDimitry Andric    typedef Key                                      key_type;
2720b57cec5SDimitry Andric    typedef key_type                                 value_type;
2730b57cec5SDimitry Andric    typedef Compare                                  key_compare;
2740b57cec5SDimitry Andric    typedef key_compare                              value_compare;
2750b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
2760b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
2770b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
2780b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
2790b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
2800b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
2810b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
2840b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
2850b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
2860b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
2870b57cec5SDimitry Andric    typedef unspecified                              node_type;               // C++17
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric    // construct/copy/destroy:
2900b57cec5SDimitry Andric    multiset()
2910b57cec5SDimitry Andric        noexcept(
2920b57cec5SDimitry Andric            is_nothrow_default_constructible<allocator_type>::value &&
2930b57cec5SDimitry Andric            is_nothrow_default_constructible<key_compare>::value &&
2940b57cec5SDimitry Andric            is_nothrow_copy_constructible<key_compare>::value);
2950b57cec5SDimitry Andric    explicit multiset(const value_compare& comp);
2960b57cec5SDimitry Andric    multiset(const value_compare& comp, const allocator_type& a);
2970b57cec5SDimitry Andric    template <class InputIterator>
2980b57cec5SDimitry Andric        multiset(InputIterator first, InputIterator last,
2990b57cec5SDimitry Andric                 const value_compare& comp = value_compare());
3000b57cec5SDimitry Andric    template <class InputIterator>
3010b57cec5SDimitry Andric        multiset(InputIterator first, InputIterator last,
3020b57cec5SDimitry Andric                 const value_compare& comp, const allocator_type& a);
30306c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
30406c3fb27SDimitry Andric      multiset(from_range_t, R&& rg,
30506c3fb27SDimitry Andric               const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
3060b57cec5SDimitry Andric    multiset(const multiset& s);
3070b57cec5SDimitry Andric    multiset(multiset&& s)
3080b57cec5SDimitry Andric        noexcept(
3090b57cec5SDimitry Andric            is_nothrow_move_constructible<allocator_type>::value &&
3100b57cec5SDimitry Andric            is_nothrow_move_constructible<key_compare>::value);
3110b57cec5SDimitry Andric    explicit multiset(const allocator_type& a);
3120b57cec5SDimitry Andric    multiset(const multiset& s, const allocator_type& a);
3130b57cec5SDimitry Andric    multiset(multiset&& s, const allocator_type& a);
3140b57cec5SDimitry Andric    multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
3150b57cec5SDimitry Andric    multiset(initializer_list<value_type> il, const value_compare& comp,
3160b57cec5SDimitry Andric             const allocator_type& a);
3170b57cec5SDimitry Andric    template <class InputIterator>
3180b57cec5SDimitry Andric        multiset(InputIterator first, InputIterator last, const allocator_type& a)
3190b57cec5SDimitry Andric            : set(first, last, Compare(), a) {}  // C++14
32006c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
32106c3fb27SDimitry Andric      multiset(from_range_t, R&& rg, const Allocator& a))
32206c3fb27SDimitry Andric        : multiset(from_range, std::forward<R>(rg), Compare(), a) { } // C++23
3230b57cec5SDimitry Andric    multiset(initializer_list<value_type> il, const allocator_type& a)
3240b57cec5SDimitry Andric        : set(il, Compare(), a) {}  // C++14
3250b57cec5SDimitry Andric    ~multiset();
3260b57cec5SDimitry Andric
3270b57cec5SDimitry Andric    multiset& operator=(const multiset& s);
3280b57cec5SDimitry Andric    multiset& operator=(multiset&& s)
3290b57cec5SDimitry Andric        noexcept(
3300b57cec5SDimitry Andric            allocator_type::propagate_on_container_move_assignment::value &&
3310b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value &&
3320b57cec5SDimitry Andric            is_nothrow_move_assignable<key_compare>::value);
3330b57cec5SDimitry Andric    multiset& operator=(initializer_list<value_type> il);
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric    // iterators:
3360b57cec5SDimitry Andric          iterator begin() noexcept;
3370b57cec5SDimitry Andric    const_iterator begin() const noexcept;
3380b57cec5SDimitry Andric          iterator end() noexcept;
3390b57cec5SDimitry Andric    const_iterator end()   const noexcept;
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andric          reverse_iterator rbegin() noexcept;
3420b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
3430b57cec5SDimitry Andric          reverse_iterator rend() noexcept;
3440b57cec5SDimitry Andric    const_reverse_iterator rend()   const noexcept;
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
3470b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
3480b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
3490b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andric    // capacity:
3520b57cec5SDimitry Andric    bool      empty()    const noexcept;
3530b57cec5SDimitry Andric    size_type size()     const noexcept;
3540b57cec5SDimitry Andric    size_type max_size() const noexcept;
3550b57cec5SDimitry Andric
3560b57cec5SDimitry Andric    // modifiers:
3570b57cec5SDimitry Andric    template <class... Args>
3580b57cec5SDimitry Andric        iterator emplace(Args&&... args);
3590b57cec5SDimitry Andric    template <class... Args>
3600b57cec5SDimitry Andric        iterator emplace_hint(const_iterator position, Args&&... args);
3610b57cec5SDimitry Andric    iterator insert(const value_type& v);
3620b57cec5SDimitry Andric    iterator insert(value_type&& v);
3630b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& v);
3640b57cec5SDimitry Andric    iterator insert(const_iterator position, value_type&& v);
3650b57cec5SDimitry Andric    template <class InputIterator>
3660b57cec5SDimitry Andric        void insert(InputIterator first, InputIterator last);
36706c3fb27SDimitry Andric    template<container-compatible-range<value_type> R>
36806c3fb27SDimitry Andric      void insert_range(R&& rg);                                                      // C++23
3690b57cec5SDimitry Andric    void insert(initializer_list<value_type> il);
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andric    node_type extract(const_iterator position);                                       // C++17
3720b57cec5SDimitry Andric    node_type extract(const key_type& x);                                             // C++17
3730b57cec5SDimitry Andric    iterator insert(node_type&& nh);                                                  // C++17
3740b57cec5SDimitry Andric    iterator insert(const_iterator hint, node_type&& nh);                             // C++17
3750b57cec5SDimitry Andric
3760b57cec5SDimitry Andric    iterator  erase(const_iterator position);
3770b57cec5SDimitry Andric    iterator  erase(iterator position);  // C++14
3780b57cec5SDimitry Andric    size_type erase(const key_type& k);
3790b57cec5SDimitry Andric    iterator  erase(const_iterator first, const_iterator last);
3800b57cec5SDimitry Andric    void clear() noexcept;
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric    template<class C2>
3830b57cec5SDimitry Andric      void merge(multiset<Key, C2, Allocator>& source);    // C++17
3840b57cec5SDimitry Andric    template<class C2>
3850b57cec5SDimitry Andric      void merge(multiset<Key, C2, Allocator>&& source);   // C++17
3860b57cec5SDimitry Andric    template<class C2>
3870b57cec5SDimitry Andric      void merge(set<Key, C2, Allocator>& source);         // C++17
3880b57cec5SDimitry Andric    template<class C2>
3890b57cec5SDimitry Andric      void merge(set<Key, C2, Allocator>&& source);        // C++17
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric    void swap(multiset& s)
3920b57cec5SDimitry Andric        noexcept(
3930b57cec5SDimitry Andric            __is_nothrow_swappable<key_compare>::value &&
3940b57cec5SDimitry Andric            (!allocator_type::propagate_on_container_swap::value ||
3950b57cec5SDimitry Andric             __is_nothrow_swappable<allocator_type>::value));
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andric    // observers:
3980b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
3990b57cec5SDimitry Andric    key_compare    key_comp()      const;
4000b57cec5SDimitry Andric    value_compare  value_comp()    const;
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric    // set operations:
4030b57cec5SDimitry Andric          iterator find(const key_type& k);
4040b57cec5SDimitry Andric    const_iterator find(const key_type& k) const;
4050b57cec5SDimitry Andric    template<typename K>
4060b57cec5SDimitry Andric        iterator find(const K& x);
4070b57cec5SDimitry Andric    template<typename K>
4080b57cec5SDimitry Andric        const_iterator find(const K& x) const;  // C++14
409fe6060f1SDimitry Andric
4100b57cec5SDimitry Andric    template<typename K>
4110b57cec5SDimitry Andric        size_type count(const K& x) const;      // C++14
4120b57cec5SDimitry Andric    size_type      count(const key_type& k) const;
413fe6060f1SDimitry Andric
4140b57cec5SDimitry Andric    bool           contains(const key_type& x) const;  // C++20
415fe6060f1SDimitry Andric    template<class K> bool contains(const K& x) const; // C++20
416fe6060f1SDimitry Andric
4170b57cec5SDimitry Andric          iterator lower_bound(const key_type& k);
4180b57cec5SDimitry Andric    const_iterator lower_bound(const key_type& k) const;
4190b57cec5SDimitry Andric    template<typename K>
4200b57cec5SDimitry Andric        iterator lower_bound(const K& x);              // C++14
4210b57cec5SDimitry Andric    template<typename K>
4220b57cec5SDimitry Andric        const_iterator lower_bound(const K& x) const;  // C++14
4230b57cec5SDimitry Andric
4240b57cec5SDimitry Andric          iterator upper_bound(const key_type& k);
4250b57cec5SDimitry Andric    const_iterator upper_bound(const key_type& k) const;
4260b57cec5SDimitry Andric    template<typename K>
4270b57cec5SDimitry Andric        iterator upper_bound(const K& x);              // C++14
4280b57cec5SDimitry Andric    template<typename K>
4290b57cec5SDimitry Andric        const_iterator upper_bound(const K& x) const;  // C++14
4300b57cec5SDimitry Andric
4310b57cec5SDimitry Andric    pair<iterator,iterator>             equal_range(const key_type& k);
4320b57cec5SDimitry Andric    pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
4330b57cec5SDimitry Andric    template<typename K>
4340b57cec5SDimitry Andric        pair<iterator,iterator>             equal_range(const K& x);        // C++14
4350b57cec5SDimitry Andric    template<typename K>
4360b57cec5SDimitry Andric        pair<const_iterator,const_iterator> equal_range(const K& x) const;  // C++14
4370b57cec5SDimitry Andric};
4380b57cec5SDimitry Andric
439349cc55cSDimitry Andrictemplate <class InputIterator,
440349cc55cSDimitry Andric      class Compare = less<typename iterator_traits<InputIterator>::value_type>,
441349cc55cSDimitry Andric      class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
442349cc55cSDimitry Andricmultiset(InputIterator, InputIterator,
443349cc55cSDimitry Andric    Compare = Compare(), Allocator = Allocator())
444349cc55cSDimitry Andric  -> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
445349cc55cSDimitry Andric
44606c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
44706c3fb27SDimitry Andric          class Allocator = allocator<ranges::range_value_t<R>>>
44806c3fb27SDimitry Andric  multiset(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
44906c3fb27SDimitry Andric    -> multiset<ranges::range_value_t<R>, Compare, Allocator>;
45006c3fb27SDimitry Andric
451349cc55cSDimitry Andrictemplate<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
452349cc55cSDimitry Andricmultiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
453349cc55cSDimitry Andric  -> multiset<Key, Compare, Allocator>; // C++17
454349cc55cSDimitry Andric
455349cc55cSDimitry Andrictemplate<class InputIterator, class Allocator>
456349cc55cSDimitry Andricmultiset(InputIterator, InputIterator, Allocator)
457349cc55cSDimitry Andric  -> multiset<typename iterator_traits<InputIterator>::value_type,
458349cc55cSDimitry Andric          less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
459349cc55cSDimitry Andric
46006c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator>
46106c3fb27SDimitry Andric  multiset(from_range_t, R&&, Allocator)
46206c3fb27SDimitry Andric    -> multiset<ranges::range_value_t<R>, less<ranges::range_value_t<R>>, Allocator>;
46306c3fb27SDimitry Andric
464349cc55cSDimitry Andrictemplate<class Key, class Allocator>
465349cc55cSDimitry Andricmultiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>; // C++17
466349cc55cSDimitry Andric
4670b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4680b57cec5SDimitry Andricbool
4690b57cec5SDimitry Andricoperator==(const multiset<Key, Compare, Allocator>& x,
4700b57cec5SDimitry Andric           const multiset<Key, Compare, Allocator>& y);
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4730b57cec5SDimitry Andricbool
4740b57cec5SDimitry Andricoperator< (const multiset<Key, Compare, Allocator>& x,
47506c3fb27SDimitry Andric           const multiset<Key, Compare, Allocator>& y);                                // removed in C++20
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4780b57cec5SDimitry Andricbool
4790b57cec5SDimitry Andricoperator!=(const multiset<Key, Compare, Allocator>& x,
48006c3fb27SDimitry Andric           const multiset<Key, Compare, Allocator>& y);                                // removed in C++20
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4830b57cec5SDimitry Andricbool
4840b57cec5SDimitry Andricoperator> (const multiset<Key, Compare, Allocator>& x,
48506c3fb27SDimitry Andric           const multiset<Key, Compare, Allocator>& y);                                // removed in C++20
4860b57cec5SDimitry Andric
4870b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4880b57cec5SDimitry Andricbool
4890b57cec5SDimitry Andricoperator>=(const multiset<Key, Compare, Allocator>& x,
49006c3fb27SDimitry Andric           const multiset<Key, Compare, Allocator>& y);                                // removed in C++20
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
4930b57cec5SDimitry Andricbool
4940b57cec5SDimitry Andricoperator<=(const multiset<Key, Compare, Allocator>& x,
49506c3fb27SDimitry Andric           const multiset<Key, Compare, Allocator>& y);                                // removed in C++20
49606c3fb27SDimitry Andric
49706c3fb27SDimitry Andrictemplate<class Key, class Compare, class Allocator>
49806c3fb27SDimitry Andric  synth-three-way-result<Key> operator<=>(const multiset<Key, Compare, Allocator>& x,
49906c3fb27SDimitry Andric                                          const multiset<Key, Compare, Allocator>& y); // since C++20
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andric// specialized algorithms:
5020b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator>
5030b57cec5SDimitry Andricvoid
5040b57cec5SDimitry Andricswap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
5050b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
5060b57cec5SDimitry Andric
5070b57cec5SDimitry Andrictemplate <class Key, class Compare, class Allocator, class Predicate>
5085ffd83dbSDimitry Andrictypename multiset<Key, Compare, Allocator>::size_type
5095ffd83dbSDimitry Andricerase_if(multiset<Key, Compare, Allocator>& c, Predicate pred);  // C++20
5100b57cec5SDimitry Andric
5110b57cec5SDimitry Andric}  // std
5120b57cec5SDimitry Andric
5130b57cec5SDimitry Andric*/
5140b57cec5SDimitry Andric
51581ad6265SDimitry Andric#include <__algorithm/equal.h>
51681ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
51706c3fb27SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h>
51881ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
51906c3fb27SDimitry Andric#include <__availability>
5200b57cec5SDimitry Andric#include <__config>
521fe6060f1SDimitry Andric#include <__functional/is_transparent.h>
52281ad6265SDimitry Andric#include <__functional/operations.h>
52381ad6265SDimitry Andric#include <__iterator/erase_if_container.h>
524349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
52506c3fb27SDimitry Andric#include <__iterator/ranges_iterator_traits.h>
52681ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
527bdd1243dSDimitry Andric#include <__memory/allocator.h>
528bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h>
5290b57cec5SDimitry Andric#include <__node_handle>
53006c3fb27SDimitry Andric#include <__ranges/concepts.h>
53106c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h>
53206c3fb27SDimitry Andric#include <__ranges/from_range.h>
533fe6060f1SDimitry Andric#include <__tree>
534bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h>
535fe6060f1SDimitry Andric#include <__utility/forward.h>
5360b57cec5SDimitry Andric#include <version>
5370b57cec5SDimitry Andric
53881ad6265SDimitry Andric// standard-mandated includes
53981ad6265SDimitry Andric
54081ad6265SDimitry Andric// [iterator.range]
54181ad6265SDimitry Andric#include <__iterator/access.h>
54281ad6265SDimitry Andric#include <__iterator/data.h>
54381ad6265SDimitry Andric#include <__iterator/empty.h>
54481ad6265SDimitry Andric#include <__iterator/reverse_access.h>
54581ad6265SDimitry Andric#include <__iterator/size.h>
54681ad6265SDimitry Andric
54781ad6265SDimitry Andric// [associative.set.syn]
54881ad6265SDimitry Andric#include <compare>
54981ad6265SDimitry Andric#include <initializer_list>
55081ad6265SDimitry Andric
5510b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5520b57cec5SDimitry Andric#  pragma GCC system_header
5530b57cec5SDimitry Andric#endif
5540b57cec5SDimitry Andric
5550b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
5560b57cec5SDimitry Andric
5570b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
5580b57cec5SDimitry Andricclass multiset;
5590b57cec5SDimitry Andric
560cb14a3feSDimitry Andrictemplate <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
561cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS set {
5620b57cec5SDimitry Andricpublic:
5630b57cec5SDimitry Andric  // types:
5640b57cec5SDimitry Andric  typedef _Key key_type;
5650b57cec5SDimitry Andric  typedef key_type value_type;
56681ad6265SDimitry Andric  typedef __type_identity_t<_Compare> key_compare;
5670b57cec5SDimitry Andric  typedef key_compare value_compare;
56881ad6265SDimitry Andric  typedef __type_identity_t<_Allocator> allocator_type;
5690b57cec5SDimitry Andric  typedef value_type& reference;
5700b57cec5SDimitry Andric  typedef const value_type& const_reference;
5710b57cec5SDimitry Andric
5720b57cec5SDimitry Andric  static_assert((is_same<typename allocator_type::value_type, value_type>::value),
5730b57cec5SDimitry Andric                "Allocator::value_type must be same type as value_type");
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andricprivate:
5760b57cec5SDimitry Andric  typedef __tree<value_type, value_compare, allocator_type> __base;
5770b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
5780b57cec5SDimitry Andric
579bdd1243dSDimitry Andric  static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
580bdd1243dSDimitry Andric                "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
581bdd1243dSDimitry Andric                "original allocator");
582bdd1243dSDimitry Andric
5830b57cec5SDimitry Andric  __base __tree_;
5840b57cec5SDimitry Andric
5850b57cec5SDimitry Andricpublic:
5860b57cec5SDimitry Andric  typedef typename __base::pointer pointer;
5870b57cec5SDimitry Andric  typedef typename __base::const_pointer const_pointer;
5880b57cec5SDimitry Andric  typedef typename __base::size_type size_type;
5890b57cec5SDimitry Andric  typedef typename __base::difference_type difference_type;
5900b57cec5SDimitry Andric  typedef typename __base::const_iterator iterator;
5910b57cec5SDimitry Andric  typedef typename __base::const_iterator const_iterator;
5925f757f3fSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
5935f757f3fSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
5940b57cec5SDimitry Andric
59506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
5960b57cec5SDimitry Andric  typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
5970b57cec5SDimitry Andric  typedef __insert_return_type<iterator, node_type> insert_return_type;
5980b57cec5SDimitry Andric#endif
5990b57cec5SDimitry Andric
6000b57cec5SDimitry Andric  template <class _Key2, class _Compare2, class _Alloc2>
6010b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS set;
6020b57cec5SDimitry Andric  template <class _Key2, class _Compare2, class _Alloc2>
6030b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multiset;
6040b57cec5SDimitry Andric
605cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set() _NOEXCEPT_(
606cb14a3feSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
6070b57cec5SDimitry Andric          is_nothrow_copy_constructible<key_compare>::value)
6080b57cec5SDimitry Andric      : __tree_(value_compare()) {}
6090b57cec5SDimitry Andric
610cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit set(const value_compare& __comp) _NOEXCEPT_(
611cb14a3feSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
6120b57cec5SDimitry Andric      : __tree_(__comp) {}
6130b57cec5SDimitry Andric
614cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit set(const value_compare& __comp, const allocator_type& __a) : __tree_(__comp, __a) {}
6150b57cec5SDimitry Andric  template <class _InputIterator>
616cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(_InputIterator __f, _InputIterator __l, const value_compare& __comp = value_compare())
617cb14a3feSDimitry Andric      : __tree_(__comp) {
6180b57cec5SDimitry Andric    insert(__f, __l);
6190b57cec5SDimitry Andric  }
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andric  template <class _InputIterator>
6225f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
623cb14a3feSDimitry Andric  set(_InputIterator __f, _InputIterator __l, const value_compare& __comp, const allocator_type& __a)
624cb14a3feSDimitry Andric      : __tree_(__comp, __a) {
6250b57cec5SDimitry Andric    insert(__f, __l);
6260b57cec5SDimitry Andric  }
6270b57cec5SDimitry Andric
62806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
62906c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
63006c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
631cb14a3feSDimitry Andric  set(from_range_t,
632cb14a3feSDimitry Andric      _Range&& __range,
633cb14a3feSDimitry Andric      const key_compare& __comp = key_compare(),
63406c3fb27SDimitry Andric      const allocator_type& __a = allocator_type())
63506c3fb27SDimitry Andric      : __tree_(__comp, __a) {
63606c3fb27SDimitry Andric    insert_range(std::forward<_Range>(__range));
63706c3fb27SDimitry Andric  }
63806c3fb27SDimitry Andric#endif
63906c3fb27SDimitry Andric
64006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
6410b57cec5SDimitry Andric  template <class _InputIterator>
642cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
6430b57cec5SDimitry Andric      : set(__f, __l, key_compare(), __a) {}
6440b57cec5SDimitry Andric#endif
6450b57cec5SDimitry Andric
64606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
64706c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
648cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(from_range_t, _Range&& __range, const allocator_type& __a)
64906c3fb27SDimitry Andric      : set(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
65006c3fb27SDimitry Andric#endif
65106c3fb27SDimitry Andric
652cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
6530b57cec5SDimitry Andric
654cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) {
6550b57cec5SDimitry Andric    __tree_ = __s.__tree_;
6560b57cec5SDimitry Andric    return *this;
6570b57cec5SDimitry Andric  }
6580b57cec5SDimitry Andric
6590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
660cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(set&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
6615f757f3fSDimitry Andric      : __tree_(std::move(__s.__tree_)) {}
6620b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
6630b57cec5SDimitry Andric
664cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
6650b57cec5SDimitry Andric
666cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(const set& __s, const allocator_type& __a) : __tree_(__s.__tree_.value_comp(), __a) {
6670b57cec5SDimitry Andric    insert(__s.begin(), __s.end());
6680b57cec5SDimitry Andric  }
6690b57cec5SDimitry Andric
6700b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
67106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(set&& __s, const allocator_type& __a);
6720b57cec5SDimitry Andric
673cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
674cb14a3feSDimitry Andric      : __tree_(__comp) {
6750b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
6760b57cec5SDimitry Andric  }
6770b57cec5SDimitry Andric
678cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const value_compare& __comp, const allocator_type& __a)
679cb14a3feSDimitry Andric      : __tree_(__comp, __a) {
6800b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
6810b57cec5SDimitry Andric  }
6820b57cec5SDimitry Andric
68306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
684cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set(initializer_list<value_type> __il, const allocator_type& __a)
6850b57cec5SDimitry Andric      : set(__il, key_compare(), __a) {}
6860b57cec5SDimitry Andric#  endif
6870b57cec5SDimitry Andric
688cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set& operator=(initializer_list<value_type> __il) {
6890b57cec5SDimitry Andric    __tree_.__assign_unique(__il.begin(), __il.end());
6900b57cec5SDimitry Andric    return *this;
6910b57cec5SDimitry Andric  }
6920b57cec5SDimitry Andric
693cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI set& operator=(set&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
6945f757f3fSDimitry Andric    __tree_ = std::move(__s.__tree_);
6950b57cec5SDimitry Andric    return *this;
6960b57cec5SDimitry Andric  }
6970b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
6980b57cec5SDimitry Andric
699cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~set() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
7000b57cec5SDimitry Andric
701cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
702cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
703cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
704cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
7050b57cec5SDimitry Andric
706cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
707cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
708cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
709cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
7100b57cec5SDimitry Andric
711cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
712cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
713cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
714cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
7150b57cec5SDimitry Andric
716cb14a3feSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
717cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
718cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric  // modifiers:
7210b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7220b57cec5SDimitry Andric  template <class... _Args>
723cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> emplace(_Args&&... __args) {
724cb14a3feSDimitry Andric    return __tree_.__emplace_unique(std::forward<_Args>(__args)...);
725cb14a3feSDimitry Andric  }
7260b57cec5SDimitry Andric  template <class... _Args>
727cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
728cb14a3feSDimitry Andric    return __tree_.__emplace_hint_unique(__p, std::forward<_Args>(__args)...);
729cb14a3feSDimitry Andric  }
7300b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7310b57cec5SDimitry Andric
732cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
733cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
734cb14a3feSDimitry Andric    return __tree_.__insert_unique(__p, __v);
735cb14a3feSDimitry Andric  }
7360b57cec5SDimitry Andric
7370b57cec5SDimitry Andric  template <class _InputIterator>
738cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
7390b57cec5SDimitry Andric    for (const_iterator __e = cend(); __f != __l; ++__f)
7400b57cec5SDimitry Andric      __tree_.__insert_unique(__e, *__f);
7410b57cec5SDimitry Andric  }
7420b57cec5SDimitry Andric
74306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
74406c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
745cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
74606c3fb27SDimitry Andric    const_iterator __end = cend();
74706c3fb27SDimitry Andric    for (auto&& __element : __range) {
74806c3fb27SDimitry Andric      __tree_.__insert_unique(__end, std::forward<decltype(__element)>(__element));
74906c3fb27SDimitry Andric    }
75006c3fb27SDimitry Andric  }
75106c3fb27SDimitry Andric#endif
75206c3fb27SDimitry Andric
7530b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
754cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
755cb14a3feSDimitry Andric    return __tree_.__insert_unique(std::move(__v));
756cb14a3feSDimitry Andric  }
7570b57cec5SDimitry Andric
758cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
759cb14a3feSDimitry Andric    return __tree_.__insert_unique(__p, std::move(__v));
760cb14a3feSDimitry Andric  }
7610b57cec5SDimitry Andric
762cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
7630b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7640b57cec5SDimitry Andric
765cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
766cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_unique(__k); }
767cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
768cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
7690b57cec5SDimitry Andric
77006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
771cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI insert_return_type insert(node_type&& __nh) {
772*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
7730b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to set::insert()");
774cb14a3feSDimitry Andric    return __tree_.template __node_handle_insert_unique< node_type, insert_return_type>(std::move(__nh));
7750b57cec5SDimitry Andric  }
776cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
777*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
7780b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to set::insert()");
779cb14a3feSDimitry Andric    return __tree_.template __node_handle_insert_unique<node_type>(__hint, std::move(__nh));
7800b57cec5SDimitry Andric  }
781cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
7820b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__key);
7830b57cec5SDimitry Andric  }
784cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
7850b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__it);
7860b57cec5SDimitry Andric  }
7870b57cec5SDimitry Andric  template <class _Compare2>
788cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>& __source) {
789*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
790cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
7910b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
7920b57cec5SDimitry Andric  }
7930b57cec5SDimitry Andric  template <class _Compare2>
794cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>&& __source) {
795*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
796cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
7970b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
7980b57cec5SDimitry Andric  }
7990b57cec5SDimitry Andric  template <class _Compare2>
800cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>& __source) {
801*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
802cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
8030b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
8040b57cec5SDimitry Andric  }
8050b57cec5SDimitry Andric  template <class _Compare2>
806cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>&& __source) {
807*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
808cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
8090b57cec5SDimitry Andric    __tree_.__node_handle_merge_unique(__source.__tree_);
8100b57cec5SDimitry Andric  }
8110b57cec5SDimitry Andric#endif
8120b57cec5SDimitry Andric
813cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
814cb14a3feSDimitry Andric    __tree_.swap(__s.__tree_);
815cb14a3feSDimitry Andric  }
8160b57cec5SDimitry Andric
817cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return __tree_.__alloc(); }
818cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp(); }
819cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return __tree_.value_comp(); }
8200b57cec5SDimitry Andric
8210b57cec5SDimitry Andric  // set operations:
822cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
823cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
82406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
8255f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
826cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
827cb14a3feSDimitry Andric    return __tree_.find(__k);
828cb14a3feSDimitry Andric  }
8295f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
830cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
831cb14a3feSDimitry Andric    return __tree_.find(__k);
832cb14a3feSDimitry Andric  }
8330b57cec5SDimitry Andric#endif
8340b57cec5SDimitry Andric
835cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_unique(__k); }
83606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
8375f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
838cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
839cb14a3feSDimitry Andric    return __tree_.__count_multi(__k);
840cb14a3feSDimitry Andric  }
8410b57cec5SDimitry Andric#endif
8420b57cec5SDimitry Andric
84306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
844cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
8455f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
846cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
847cb14a3feSDimitry Andric    return find(__k) != end();
848cb14a3feSDimitry Andric  }
84906c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
8500b57cec5SDimitry Andric
851cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
852cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
85306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
8545f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
855cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
856cb14a3feSDimitry Andric    return __tree_.lower_bound(__k);
857cb14a3feSDimitry Andric  }
8580b57cec5SDimitry Andric
8595f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
860cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
861cb14a3feSDimitry Andric    return __tree_.lower_bound(__k);
862cb14a3feSDimitry Andric  }
8630b57cec5SDimitry Andric#endif
8640b57cec5SDimitry Andric
865cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
866cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
86706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
8685f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
869cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
870cb14a3feSDimitry Andric    return __tree_.upper_bound(__k);
871cb14a3feSDimitry Andric  }
8725f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
873cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
874cb14a3feSDimitry Andric    return __tree_.upper_bound(__k);
875cb14a3feSDimitry Andric  }
8760b57cec5SDimitry Andric#endif
8770b57cec5SDimitry Andric
878cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
879cb14a3feSDimitry Andric    return __tree_.__equal_range_unique(__k);
880cb14a3feSDimitry Andric  }
881cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
882cb14a3feSDimitry Andric    return __tree_.__equal_range_unique(__k);
883cb14a3feSDimitry Andric  }
88406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
8855f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
886cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
887cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
888cb14a3feSDimitry Andric  }
8895f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
890cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
891cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
892cb14a3feSDimitry Andric  }
8930b57cec5SDimitry Andric#endif
8940b57cec5SDimitry Andric};
8950b57cec5SDimitry Andric
896349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
8970b57cec5SDimitry Andrictemplate <class _InputIterator,
898fe6060f1SDimitry Andric          class _Compare   = less<__iter_value_type<_InputIterator>>,
899fe6060f1SDimitry Andric          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
90006c3fb27SDimitry Andric          class            = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
901349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>,
902349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>>
9030b57cec5SDimitry Andricset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
904fe6060f1SDimitry Andric    -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
9050b57cec5SDimitry Andric
90606c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
907cb14a3feSDimitry Andrictemplate <ranges::input_range _Range,
908cb14a3feSDimitry Andric          class _Compare   = less<ranges::range_value_t<_Range>>,
90906c3fb27SDimitry Andric          class _Allocator = allocator<ranges::range_value_t<_Range>>,
91006c3fb27SDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>,
91106c3fb27SDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>>
91206c3fb27SDimitry Andricset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
91306c3fb27SDimitry Andric    -> set<ranges::range_value_t<_Range>, _Compare, _Allocator>;
91406c3fb27SDimitry Andric#  endif
91506c3fb27SDimitry Andric
916cb14a3feSDimitry Andrictemplate <class _Key,
917cb14a3feSDimitry Andric          class _Compare   = less<_Key>,
9180b57cec5SDimitry Andric          class _Allocator = allocator<_Key>,
919349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>,
920349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>>
921cb14a3feSDimitry Andricset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) -> set<_Key, _Compare, _Allocator>;
9220b57cec5SDimitry Andric
923cb14a3feSDimitry Andrictemplate <class _InputIterator,
924cb14a3feSDimitry Andric          class _Allocator,
92506c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
926349cc55cSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value, void>>
9270b57cec5SDimitry Andricset(_InputIterator, _InputIterator, _Allocator)
928cb14a3feSDimitry Andric    -> set<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
9290b57cec5SDimitry Andric
93006c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
931cb14a3feSDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
93206c3fb27SDimitry Andricset(from_range_t, _Range&&, _Allocator)
93306c3fb27SDimitry Andric    -> set<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
93406c3fb27SDimitry Andric#  endif
93506c3fb27SDimitry Andric
936cb14a3feSDimitry Andrictemplate <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
937cb14a3feSDimitry Andricset(initializer_list<_Key>, _Allocator) -> set<_Key, less<_Key>, _Allocator>;
9380b57cec5SDimitry Andric#endif
9390b57cec5SDimitry Andric
9400b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9410b57cec5SDimitry Andric
9420b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
943cb14a3feSDimitry Andricset<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a) : __tree_(std::move(__s.__tree_), __a) {
944cb14a3feSDimitry Andric  if (__a != __s.get_allocator()) {
9450b57cec5SDimitry Andric    const_iterator __e = cend();
9460b57cec5SDimitry Andric    while (!__s.empty())
9475f757f3fSDimitry Andric      insert(__e, std::move(__s.__tree_.remove(__s.begin())->__value_));
9480b57cec5SDimitry Andric  }
9490b57cec5SDimitry Andric}
9500b57cec5SDimitry Andric
9510b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
9520b57cec5SDimitry Andric
9530b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
954cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
955cb14a3feSDimitry Andricoperator==(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9565f757f3fSDimitry Andric  return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
9570b57cec5SDimitry Andric}
9580b57cec5SDimitry Andric
95906c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
96006c3fb27SDimitry Andric
9610b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
962cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
963cb14a3feSDimitry Andricoperator<(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9645f757f3fSDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
9650b57cec5SDimitry Andric}
9660b57cec5SDimitry Andric
9670b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
968cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
969cb14a3feSDimitry Andricoperator!=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9700b57cec5SDimitry Andric  return !(__x == __y);
9710b57cec5SDimitry Andric}
9720b57cec5SDimitry Andric
9730b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
974cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
975cb14a3feSDimitry Andricoperator>(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9760b57cec5SDimitry Andric  return __y < __x;
9770b57cec5SDimitry Andric}
9780b57cec5SDimitry Andric
9790b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
980cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
981cb14a3feSDimitry Andricoperator>=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9820b57cec5SDimitry Andric  return !(__x < __y);
9830b57cec5SDimitry Andric}
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
986cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
987cb14a3feSDimitry Andricoperator<=(const set<_Key, _Compare, _Allocator>& __x, const set<_Key, _Compare, _Allocator>& __y) {
9880b57cec5SDimitry Andric  return !(__y < __x);
9890b57cec5SDimitry Andric}
9900b57cec5SDimitry Andric
99106c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
99206c3fb27SDimitry Andric
99306c3fb27SDimitry Andrictemplate <class _Key, class _Allocator>
99406c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
99506c3fb27SDimitry Andricoperator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y) {
99606c3fb27SDimitry Andric  return std::lexicographical_compare_three_way(
99706c3fb27SDimitry Andric      __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>);
99806c3fb27SDimitry Andric}
99906c3fb27SDimitry Andric
100006c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
100106c3fb27SDimitry Andric
10020b57cec5SDimitry Andric// specialized algorithms:
10030b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1004cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void swap(set<_Key, _Compare, _Allocator>& __x, set<_Key, _Compare, _Allocator>& __y)
1005cb14a3feSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
10060b57cec5SDimitry Andric  __x.swap(__y);
10070b57cec5SDimitry Andric}
10080b57cec5SDimitry Andric
100906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
10100b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator, class _Predicate>
1011cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename set<_Key, _Compare, _Allocator>::size_type
10125ffd83dbSDimitry Andricerase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
10135f757f3fSDimitry Andric  return std::__libcpp_erase_if_container(__c, __pred);
10145ffd83dbSDimitry Andric}
10150b57cec5SDimitry Andric#endif
10160b57cec5SDimitry Andric
1017cb14a3feSDimitry Andrictemplate <class _Key, class _Compare = less<_Key>, class _Allocator = allocator<_Key> >
1018cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS multiset {
10190b57cec5SDimitry Andricpublic:
10200b57cec5SDimitry Andric  // types:
10210b57cec5SDimitry Andric  typedef _Key key_type;
10220b57cec5SDimitry Andric  typedef key_type value_type;
102381ad6265SDimitry Andric  typedef __type_identity_t<_Compare> key_compare;
10240b57cec5SDimitry Andric  typedef key_compare value_compare;
102581ad6265SDimitry Andric  typedef __type_identity_t<_Allocator> allocator_type;
10260b57cec5SDimitry Andric  typedef value_type& reference;
10270b57cec5SDimitry Andric  typedef const value_type& const_reference;
10280b57cec5SDimitry Andric
10290b57cec5SDimitry Andric  static_assert((is_same<typename allocator_type::value_type, value_type>::value),
10300b57cec5SDimitry Andric                "Allocator::value_type must be same type as value_type");
10310b57cec5SDimitry Andric
10320b57cec5SDimitry Andricprivate:
10330b57cec5SDimitry Andric  typedef __tree<value_type, value_compare, allocator_type> __base;
10340b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
10350b57cec5SDimitry Andric
1036bdd1243dSDimitry Andric  static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
1037bdd1243dSDimitry Andric                "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
1038bdd1243dSDimitry Andric                "original allocator");
1039bdd1243dSDimitry Andric
10400b57cec5SDimitry Andric  __base __tree_;
10410b57cec5SDimitry Andric
10420b57cec5SDimitry Andricpublic:
10430b57cec5SDimitry Andric  typedef typename __base::pointer pointer;
10440b57cec5SDimitry Andric  typedef typename __base::const_pointer const_pointer;
10450b57cec5SDimitry Andric  typedef typename __base::size_type size_type;
10460b57cec5SDimitry Andric  typedef typename __base::difference_type difference_type;
10470b57cec5SDimitry Andric  typedef typename __base::const_iterator iterator;
10480b57cec5SDimitry Andric  typedef typename __base::const_iterator const_iterator;
10495f757f3fSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
10505f757f3fSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
10510b57cec5SDimitry Andric
105206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
10530b57cec5SDimitry Andric  typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
10540b57cec5SDimitry Andric#endif
10550b57cec5SDimitry Andric
10560b57cec5SDimitry Andric  template <class _Key2, class _Compare2, class _Alloc2>
10570b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS set;
10580b57cec5SDimitry Andric  template <class _Key2, class _Compare2, class _Alloc2>
10590b57cec5SDimitry Andric  friend class _LIBCPP_TEMPLATE_VIS multiset;
10600b57cec5SDimitry Andric
10610b57cec5SDimitry Andric  // construct/copy/destroy:
1062cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset() _NOEXCEPT_(
1063cb14a3feSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_default_constructible<key_compare>::value&&
10640b57cec5SDimitry Andric          is_nothrow_copy_constructible<key_compare>::value)
10650b57cec5SDimitry Andric      : __tree_(value_compare()) {}
10660b57cec5SDimitry Andric
1067cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multiset(const value_compare& __comp) _NOEXCEPT_(
1068cb14a3feSDimitry Andric      is_nothrow_default_constructible<allocator_type>::value&& is_nothrow_copy_constructible<key_compare>::value)
10690b57cec5SDimitry Andric      : __tree_(__comp) {}
10700b57cec5SDimitry Andric
1071cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multiset(const value_compare& __comp, const allocator_type& __a)
10720b57cec5SDimitry Andric      : __tree_(__comp, __a) {}
10730b57cec5SDimitry Andric  template <class _InputIterator>
1074cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(_InputIterator __f, _InputIterator __l, const value_compare& __comp = value_compare())
1075cb14a3feSDimitry Andric      : __tree_(__comp) {
10760b57cec5SDimitry Andric    insert(__f, __l);
10770b57cec5SDimitry Andric  }
10780b57cec5SDimitry Andric
107906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
10800b57cec5SDimitry Andric  template <class _InputIterator>
1081cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
10820b57cec5SDimitry Andric      : multiset(__f, __l, key_compare(), __a) {}
10830b57cec5SDimitry Andric#endif
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andric  template <class _InputIterator>
10865f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1087cb14a3feSDimitry Andric  multiset(_InputIterator __f, _InputIterator __l, const value_compare& __comp, const allocator_type& __a)
1088cb14a3feSDimitry Andric      : __tree_(__comp, __a) {
10890b57cec5SDimitry Andric    insert(__f, __l);
10900b57cec5SDimitry Andric  }
10910b57cec5SDimitry Andric
109206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
109306c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
109406c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1095cb14a3feSDimitry Andric  multiset(from_range_t,
1096cb14a3feSDimitry Andric           _Range&& __range,
1097cb14a3feSDimitry Andric           const key_compare& __comp = key_compare(),
109806c3fb27SDimitry Andric           const allocator_type& __a = allocator_type())
109906c3fb27SDimitry Andric      : __tree_(__comp, __a) {
110006c3fb27SDimitry Andric    insert_range(std::forward<_Range>(__range));
110106c3fb27SDimitry Andric  }
110206c3fb27SDimitry Andric
110306c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1104cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(from_range_t, _Range&& __range, const allocator_type& __a)
110506c3fb27SDimitry Andric      : multiset(from_range, std::forward<_Range>(__range), key_compare(), __a) {}
110606c3fb27SDimitry Andric#endif
110706c3fb27SDimitry Andric
1108cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s)
11090b57cec5SDimitry Andric      : __tree_(__s.__tree_.value_comp(),
1110cb14a3feSDimitry Andric                __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc())) {
11110b57cec5SDimitry Andric    insert(__s.begin(), __s.end());
11120b57cec5SDimitry Andric  }
11130b57cec5SDimitry Andric
1114cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) {
11150b57cec5SDimitry Andric    __tree_ = __s.__tree_;
11160b57cec5SDimitry Andric    return *this;
11170b57cec5SDimitry Andric  }
11180b57cec5SDimitry Andric
11190b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1120cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
11215f757f3fSDimitry Andric      : __tree_(std::move(__s.__tree_)) {}
11220b57cec5SDimitry Andric
112306c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
11240b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
1125cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit multiset(const allocator_type& __a) : __tree_(__a) {}
1126cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(const multiset& __s, const allocator_type& __a)
1127cb14a3feSDimitry Andric      : __tree_(__s.__tree_.value_comp(), __a) {
11280b57cec5SDimitry Andric    insert(__s.begin(), __s.end());
11290b57cec5SDimitry Andric  }
11300b57cec5SDimitry Andric
11310b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1132cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1133cb14a3feSDimitry Andric      : __tree_(__comp) {
11340b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
11350b57cec5SDimitry Andric  }
11360b57cec5SDimitry Andric
11375f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
1138cb14a3feSDimitry Andric  multiset(initializer_list<value_type> __il, const value_compare& __comp, const allocator_type& __a)
1139cb14a3feSDimitry Andric      : __tree_(__comp, __a) {
11400b57cec5SDimitry Andric    insert(__il.begin(), __il.end());
11410b57cec5SDimitry Andric  }
11420b57cec5SDimitry Andric
114306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
1144cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset(initializer_list<value_type> __il, const allocator_type& __a)
11450b57cec5SDimitry Andric      : multiset(__il, key_compare(), __a) {}
11460b57cec5SDimitry Andric#  endif
11470b57cec5SDimitry Andric
1148cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset& operator=(initializer_list<value_type> __il) {
11490b57cec5SDimitry Andric    __tree_.__assign_multi(__il.begin(), __il.end());
11500b57cec5SDimitry Andric    return *this;
11510b57cec5SDimitry Andric  }
11520b57cec5SDimitry Andric
1153cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI multiset& operator=(multiset&& __s) _NOEXCEPT_(is_nothrow_move_assignable<__base>::value) {
11545f757f3fSDimitry Andric    __tree_ = std::move(__s.__tree_);
11550b57cec5SDimitry Andric    return *this;
11560b57cec5SDimitry Andric  }
11570b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11580b57cec5SDimitry Andric
1159cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~multiset() { static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); }
11600b57cec5SDimitry Andric
1161cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __tree_.begin(); }
1162cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __tree_.begin(); }
1163cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __tree_.end(); }
1164cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __tree_.end(); }
11650b57cec5SDimitry Andric
1166cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1167cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1168cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1169cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
11700b57cec5SDimitry Andric
1171cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
1172cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
1173cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1174cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
11750b57cec5SDimitry Andric
1176cb14a3feSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __tree_.size() == 0; }
1177cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __tree_.size(); }
1178cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __tree_.max_size(); }
11790b57cec5SDimitry Andric
11800b57cec5SDimitry Andric  // modifiers:
11810b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11820b57cec5SDimitry Andric  template <class... _Args>
1183cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) {
1184cb14a3feSDimitry Andric    return __tree_.__emplace_multi(std::forward<_Args>(__args)...);
1185cb14a3feSDimitry Andric  }
11860b57cec5SDimitry Andric  template <class... _Args>
1187cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __p, _Args&&... __args) {
1188cb14a3feSDimitry Andric    return __tree_.__emplace_hint_multi(__p, std::forward<_Args>(__args)...);
1189cb14a3feSDimitry Andric  }
11900b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11910b57cec5SDimitry Andric
1192cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1193cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1194cb14a3feSDimitry Andric    return __tree_.__insert_multi(__p, __v);
1195cb14a3feSDimitry Andric  }
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andric  template <class _InputIterator>
1198cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
11990b57cec5SDimitry Andric    for (const_iterator __e = cend(); __f != __l; ++__f)
12000b57cec5SDimitry Andric      __tree_.__insert_multi(__e, *__f);
12010b57cec5SDimitry Andric  }
12020b57cec5SDimitry Andric
120306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
120406c3fb27SDimitry Andric  template <_ContainerCompatibleRange<value_type> _Range>
1205cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
120606c3fb27SDimitry Andric    const_iterator __end = cend();
120706c3fb27SDimitry Andric    for (auto&& __element : __range) {
120806c3fb27SDimitry Andric      __tree_.__insert_multi(__end, std::forward<decltype(__element)>(__element));
120906c3fb27SDimitry Andric    }
121006c3fb27SDimitry Andric  }
121106c3fb27SDimitry Andric#endif
121206c3fb27SDimitry Andric
12130b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1214cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
12150b57cec5SDimitry Andric
1216cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1217cb14a3feSDimitry Andric    return __tree_.__insert_multi(__p, std::move(__v));
1218cb14a3feSDimitry Andric  }
12190b57cec5SDimitry Andric
1220cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
12210b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
12220b57cec5SDimitry Andric
1223cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p) { return __tree_.erase(__p); }
1224cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __k) { return __tree_.__erase_multi(__k); }
1225cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l) { return __tree_.erase(__f, __l); }
1226cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __tree_.clear(); }
12270b57cec5SDimitry Andric
122806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
1229cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(node_type&& __nh) {
1230*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
12310b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to multiset::insert()");
1232cb14a3feSDimitry Andric    return __tree_.template __node_handle_insert_multi<node_type>(std::move(__nh));
12330b57cec5SDimitry Andric  }
1234cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, node_type&& __nh) {
1235*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__nh.empty() || __nh.get_allocator() == get_allocator(),
12360b57cec5SDimitry Andric                                        "node_type with incompatible allocator passed to multiset::insert()");
1237cb14a3feSDimitry Andric    return __tree_.template __node_handle_insert_multi<node_type>(__hint, std::move(__nh));
12380b57cec5SDimitry Andric  }
1239cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(key_type const& __key) {
12400b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__key);
12410b57cec5SDimitry Andric  }
1242cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI node_type extract(const_iterator __it) {
12430b57cec5SDimitry Andric    return __tree_.template __node_handle_extract<node_type>(__it);
12440b57cec5SDimitry Andric  }
12450b57cec5SDimitry Andric  template <class _Compare2>
1246cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>& __source) {
1247*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1248cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
12490b57cec5SDimitry Andric    __tree_.__node_handle_merge_multi(__source.__tree_);
12500b57cec5SDimitry Andric  }
12510b57cec5SDimitry Andric  template <class _Compare2>
1252cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(multiset<key_type, _Compare2, allocator_type>&& __source) {
1253*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1254cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
12550b57cec5SDimitry Andric    __tree_.__node_handle_merge_multi(__source.__tree_);
12560b57cec5SDimitry Andric  }
12570b57cec5SDimitry Andric  template <class _Compare2>
1258cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>& __source) {
1259*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1260cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
12610b57cec5SDimitry Andric    __tree_.__node_handle_merge_multi(__source.__tree_);
12620b57cec5SDimitry Andric  }
12630b57cec5SDimitry Andric  template <class _Compare2>
1264cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void merge(set<key_type, _Compare2, allocator_type>&& __source) {
1265*1db9f3b2SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1266cb14a3feSDimitry Andric        __source.get_allocator() == get_allocator(), "merging container with incompatible allocator");
12670b57cec5SDimitry Andric    __tree_.__node_handle_merge_multi(__source.__tree_);
12680b57cec5SDimitry Andric  }
12690b57cec5SDimitry Andric#endif
12700b57cec5SDimitry Andric
1271cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(multiset& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value) {
1272cb14a3feSDimitry Andric    __tree_.swap(__s.__tree_);
1273cb14a3feSDimitry Andric  }
12740b57cec5SDimitry Andric
1275cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return __tree_.__alloc(); }
1276cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __tree_.value_comp(); }
1277cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return __tree_.value_comp(); }
12780b57cec5SDimitry Andric
12790b57cec5SDimitry Andric  // set operations:
1280cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __k) { return __tree_.find(__k); }
1281cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __k) const { return __tree_.find(__k); }
128206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
12835f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1284cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator find(const _K2& __k) {
1285cb14a3feSDimitry Andric    return __tree_.find(__k);
1286cb14a3feSDimitry Andric  }
12875f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1288cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator find(const _K2& __k) const {
1289cb14a3feSDimitry Andric    return __tree_.find(__k);
1290cb14a3feSDimitry Andric  }
12910b57cec5SDimitry Andric#endif
12920b57cec5SDimitry Andric
1293cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __k) const { return __tree_.__count_multi(__k); }
129406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
12955f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1296cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type count(const _K2& __k) const {
1297cb14a3feSDimitry Andric    return __tree_.__count_multi(__k);
1298cb14a3feSDimitry Andric  }
12990b57cec5SDimitry Andric#endif
13000b57cec5SDimitry Andric
130106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
1302cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __k) const { return find(__k) != end(); }
13035f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1304cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool contains(const _K2& __k) const {
1305cb14a3feSDimitry Andric    return find(__k) != end();
1306cb14a3feSDimitry Andric  }
130706c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
13080b57cec5SDimitry Andric
1309cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __k) { return __tree_.lower_bound(__k); }
1310cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __k) const { return __tree_.lower_bound(__k); }
131106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
13125f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1313cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _K2& __k) {
1314cb14a3feSDimitry Andric    return __tree_.lower_bound(__k);
1315cb14a3feSDimitry Andric  }
13160b57cec5SDimitry Andric
13175f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1318cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _K2& __k) const {
1319cb14a3feSDimitry Andric    return __tree_.lower_bound(__k);
1320cb14a3feSDimitry Andric  }
13210b57cec5SDimitry Andric#endif
13220b57cec5SDimitry Andric
1323cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __k) { return __tree_.upper_bound(__k); }
1324cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __k) const { return __tree_.upper_bound(__k); }
132506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
13265f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1327cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _K2& __k) {
1328cb14a3feSDimitry Andric    return __tree_.upper_bound(__k);
1329cb14a3feSDimitry Andric  }
13305f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1331cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _K2& __k) const {
1332cb14a3feSDimitry Andric    return __tree_.upper_bound(__k);
1333cb14a3feSDimitry Andric  }
13340b57cec5SDimitry Andric#endif
13350b57cec5SDimitry Andric
1336cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const key_type& __k) {
1337cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
1338cb14a3feSDimitry Andric  }
1339cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {
1340cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
1341cb14a3feSDimitry Andric  }
134206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
13435f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1344cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<iterator, iterator> equal_range(const _K2& __k) {
1345cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
1346cb14a3feSDimitry Andric  }
13475f757f3fSDimitry Andric  template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
1348cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pair<const_iterator, const_iterator> equal_range(const _K2& __k) const {
1349cb14a3feSDimitry Andric    return __tree_.__equal_range_multi(__k);
1350cb14a3feSDimitry Andric  }
13510b57cec5SDimitry Andric#endif
13520b57cec5SDimitry Andric};
13530b57cec5SDimitry Andric
1354349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
13550b57cec5SDimitry Andrictemplate <class _InputIterator,
1356fe6060f1SDimitry Andric          class _Compare   = less<__iter_value_type<_InputIterator>>,
1357fe6060f1SDimitry Andric          class _Allocator = allocator<__iter_value_type<_InputIterator>>,
135806c3fb27SDimitry Andric          class            = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1359349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>,
1360349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>>
13610b57cec5SDimitry Andricmultiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1362fe6060f1SDimitry Andric    -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
13630b57cec5SDimitry Andric
136406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
1365cb14a3feSDimitry Andrictemplate <ranges::input_range _Range,
1366cb14a3feSDimitry Andric          class _Compare   = less<ranges::range_value_t<_Range>>,
136706c3fb27SDimitry Andric          class _Allocator = allocator<ranges::range_value_t<_Range>>,
136806c3fb27SDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>,
136906c3fb27SDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>>
137006c3fb27SDimitry Andricmultiset(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator())
137106c3fb27SDimitry Andric    -> multiset<ranges::range_value_t<_Range>, _Compare, _Allocator>;
137206c3fb27SDimitry Andric#  endif
137306c3fb27SDimitry Andric
1374cb14a3feSDimitry Andrictemplate <class _Key,
1375cb14a3feSDimitry Andric          class _Compare   = less<_Key>,
13760b57cec5SDimitry Andric          class _Allocator = allocator<_Key>,
1377349cc55cSDimitry Andric          class            = enable_if_t<__is_allocator<_Allocator>::value, void>,
1378349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value, void>>
13790b57cec5SDimitry Andricmultiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
13800b57cec5SDimitry Andric    -> multiset<_Key, _Compare, _Allocator>;
13810b57cec5SDimitry Andric
1382cb14a3feSDimitry Andrictemplate <class _InputIterator,
1383cb14a3feSDimitry Andric          class _Allocator,
138406c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value, void>,
1385349cc55cSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value, void>>
13860b57cec5SDimitry Andricmultiset(_InputIterator, _InputIterator, _Allocator)
1387cb14a3feSDimitry Andric    -> multiset<__iter_value_type<_InputIterator>, less<__iter_value_type<_InputIterator>>, _Allocator>;
13880b57cec5SDimitry Andric
138906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
1390cb14a3feSDimitry Andrictemplate <ranges::input_range _Range, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
139106c3fb27SDimitry Andricmultiset(from_range_t, _Range&&, _Allocator)
139206c3fb27SDimitry Andric    -> multiset<ranges::range_value_t<_Range>, less<ranges::range_value_t<_Range>>, _Allocator>;
139306c3fb27SDimitry Andric#  endif
139406c3fb27SDimitry Andric
1395cb14a3feSDimitry Andrictemplate <class _Key, class _Allocator, class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1396cb14a3feSDimitry Andricmultiset(initializer_list<_Key>, _Allocator) -> multiset<_Key, less<_Key>, _Allocator>;
13970b57cec5SDimitry Andric#endif
13980b57cec5SDimitry Andric
13990b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
14000b57cec5SDimitry Andric
14010b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
14020b57cec5SDimitry Andricmultiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
1403cb14a3feSDimitry Andric    : __tree_(std::move(__s.__tree_), __a) {
1404cb14a3feSDimitry Andric  if (__a != __s.get_allocator()) {
14050b57cec5SDimitry Andric    const_iterator __e = cend();
14060b57cec5SDimitry Andric    while (!__s.empty())
14075f757f3fSDimitry Andric      insert(__e, std::move(__s.__tree_.remove(__s.begin())->__value_));
14080b57cec5SDimitry Andric  }
14090b57cec5SDimitry Andric}
14100b57cec5SDimitry Andric
14110b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
14120b57cec5SDimitry Andric
14130b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1414cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1415cb14a3feSDimitry Andricoperator==(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14165f757f3fSDimitry Andric  return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
14170b57cec5SDimitry Andric}
14180b57cec5SDimitry Andric
141906c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
142006c3fb27SDimitry Andric
14210b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1422cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1423cb14a3feSDimitry Andricoperator<(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14245f757f3fSDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
14250b57cec5SDimitry Andric}
14260b57cec5SDimitry Andric
14270b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1428cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1429cb14a3feSDimitry Andricoperator!=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14300b57cec5SDimitry Andric  return !(__x == __y);
14310b57cec5SDimitry Andric}
14320b57cec5SDimitry Andric
14330b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1434cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1435cb14a3feSDimitry Andricoperator>(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14360b57cec5SDimitry Andric  return __y < __x;
14370b57cec5SDimitry Andric}
14380b57cec5SDimitry Andric
14390b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1440cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1441cb14a3feSDimitry Andricoperator>=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14420b57cec5SDimitry Andric  return !(__x < __y);
14430b57cec5SDimitry Andric}
14440b57cec5SDimitry Andric
14450b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1446cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
1447cb14a3feSDimitry Andricoperator<=(const multiset<_Key, _Compare, _Allocator>& __x, const multiset<_Key, _Compare, _Allocator>& __y) {
14480b57cec5SDimitry Andric  return !(__y < __x);
14490b57cec5SDimitry Andric}
14500b57cec5SDimitry Andric
145106c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
145206c3fb27SDimitry Andric
145306c3fb27SDimitry Andrictemplate <class _Key, class _Allocator>
145406c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key>
145506c3fb27SDimitry Andricoperator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) {
145606c3fb27SDimitry Andric  return std::lexicographical_compare_three_way(
145706c3fb27SDimitry Andric      __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>);
145806c3fb27SDimitry Andric}
145906c3fb27SDimitry Andric
146006c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
146106c3fb27SDimitry Andric
14620b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator>
1463cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
1464cb14a3feSDimitry Andricswap(multiset<_Key, _Compare, _Allocator>& __x, multiset<_Key, _Compare, _Allocator>& __y)
1465cb14a3feSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
14660b57cec5SDimitry Andric  __x.swap(__y);
14670b57cec5SDimitry Andric}
14680b57cec5SDimitry Andric
146906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
14700b57cec5SDimitry Andrictemplate <class _Key, class _Compare, class _Allocator, class _Predicate>
1471cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename multiset<_Key, _Compare, _Allocator>::size_type
14725ffd83dbSDimitry Andricerase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
14735f757f3fSDimitry Andric  return std::__libcpp_erase_if_container(__c, __pred);
14745ffd83dbSDimitry Andric}
14750b57cec5SDimitry Andric#endif
14760b57cec5SDimitry Andric
14770b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
14780b57cec5SDimitry Andric
147906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
1480bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
1481bdd1243dSDimitry Andricnamespace pmr {
1482bdd1243dSDimitry Andrictemplate <class _KeyT, class _CompareT = std::less<_KeyT>>
148306c3fb27SDimitry Andricusing set _LIBCPP_AVAILABILITY_PMR = std::set<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>;
1484bdd1243dSDimitry Andric
1485bdd1243dSDimitry Andrictemplate <class _KeyT, class _CompareT = std::less<_KeyT>>
148606c3fb27SDimitry Andricusing multiset _LIBCPP_AVAILABILITY_PMR = std::multiset<_KeyT, _CompareT, polymorphic_allocator<_KeyT>>;
1487bdd1243dSDimitry Andric} // namespace pmr
1488bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
1489bdd1243dSDimitry Andric#endif
1490bdd1243dSDimitry Andric
1491bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1492bdd1243dSDimitry Andric#  include <concepts>
149306c3fb27SDimitry Andric#  include <cstdlib>
1494bdd1243dSDimitry Andric#  include <functional>
1495bdd1243dSDimitry Andric#  include <iterator>
14965f757f3fSDimitry Andric#  include <stdexcept>
149706c3fb27SDimitry Andric#  include <type_traits>
1498bdd1243dSDimitry Andric#endif
1499bdd1243dSDimitry Andric
15000b57cec5SDimitry Andric#endif // _LIBCPP_SET
1501