xref: /freebsd/contrib/llvm-project/libcxx/include/queue (revision 700637cbb5e582861067a11aaca4d053546871d2)
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_QUEUE
110b57cec5SDimitry Andric#define _LIBCPP_QUEUE
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    queue synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class T, class Container = deque<T>>
200b57cec5SDimitry Andricclass queue
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricpublic:
230b57cec5SDimitry Andric    typedef Container                                container_type;
240b57cec5SDimitry Andric    typedef typename container_type::value_type      value_type;
250b57cec5SDimitry Andric    typedef typename container_type::reference       reference;
260b57cec5SDimitry Andric    typedef typename container_type::const_reference const_reference;
270b57cec5SDimitry Andric    typedef typename container_type::size_type       size_type;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andricprotected:
300b57cec5SDimitry Andric    container_type c;
310b57cec5SDimitry Andric
320b57cec5SDimitry Andricpublic:
330b57cec5SDimitry Andric    queue() = default;
340b57cec5SDimitry Andric    ~queue() = default;
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric    queue(const queue& q) = default;
370b57cec5SDimitry Andric    queue(queue&& q) = default;
380b57cec5SDimitry Andric
390b57cec5SDimitry Andric    queue& operator=(const queue& q) = default;
400b57cec5SDimitry Andric    queue& operator=(queue&& q) = default;
410b57cec5SDimitry Andric
420b57cec5SDimitry Andric    explicit queue(const container_type& c);
430b57cec5SDimitry Andric    explicit queue(container_type&& c)
4404eeddc0SDimitry Andric    template<class InputIterator>
4504eeddc0SDimitry Andric        queue(InputIterator first, InputIterator last); // since C++23
4606c3fb27SDimitry Andric    template<container-compatible-range<T> R> queue(from_range_t, R&& rg); // since C++23
470b57cec5SDimitry Andric    template <class Alloc>
480b57cec5SDimitry Andric        explicit queue(const Alloc& a);
490b57cec5SDimitry Andric    template <class Alloc>
500b57cec5SDimitry Andric        queue(const container_type& c, const Alloc& a);
510b57cec5SDimitry Andric    template <class Alloc>
520b57cec5SDimitry Andric        queue(container_type&& c, const Alloc& a);
530b57cec5SDimitry Andric    template <class Alloc>
540b57cec5SDimitry Andric        queue(const queue& q, const Alloc& a);
550b57cec5SDimitry Andric    template <class Alloc>
560b57cec5SDimitry Andric        queue(queue&& q, const Alloc& a);
5704eeddc0SDimitry Andric    template <class InputIterator, class Alloc>
5804eeddc0SDimitry Andric        queue(InputIterator first, InputIterator last, const Alloc&); // since C++23
5906c3fb27SDimitry Andric    template<container-compatible-range<T> R, class Alloc>
6006c3fb27SDimitry Andric        queue(from_range_t, R&& rg, const Alloc&); // since C++23
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric    bool      empty() const;
630b57cec5SDimitry Andric    size_type size() const;
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric    reference       front();
660b57cec5SDimitry Andric    const_reference front() const;
670b57cec5SDimitry Andric    reference       back();
680b57cec5SDimitry Andric    const_reference back() const;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric    void push(const value_type& v);
710b57cec5SDimitry Andric    void push(value_type&& v);
7206c3fb27SDimitry Andric    template<container-compatible-range<T> R>
7306c3fb27SDimitry Andric      void push_range(R&& rg); // C++23
740b57cec5SDimitry Andric    template <class... Args> reference emplace(Args&&... args); // reference in C++17
750b57cec5SDimitry Andric    void pop();
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric    void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
780b57cec5SDimitry Andric};
790b57cec5SDimitry Andric
800b57cec5SDimitry Andrictemplate<class Container>
810b57cec5SDimitry Andric  queue(Container) -> queue<typename Container::value_type, Container>; // C++17
820b57cec5SDimitry Andric
8304eeddc0SDimitry Andrictemplate<class InputIterator>
8404eeddc0SDimitry Andric  queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23
8504eeddc0SDimitry Andric
8606c3fb27SDimitry Andrictemplate<ranges::input_range R>
8706c3fb27SDimitry Andric  queue(from_range_t, R&&) -> queue<ranges::range_value_t<R>>; // since C++23
8806c3fb27SDimitry Andric
890b57cec5SDimitry Andrictemplate<class Container, class Allocator>
900b57cec5SDimitry Andric  queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
910b57cec5SDimitry Andric
9204eeddc0SDimitry Andrictemplate<class InputIterator, class Allocator>
9304eeddc0SDimitry Andric  queue(InputIterator, InputIterator, Allocator)
9404eeddc0SDimitry Andric  -> queue<iter-value-type<InputIterator>,
9504eeddc0SDimitry Andric           deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
9604eeddc0SDimitry Andric
9706c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator>
9806c3fb27SDimitry Andric    queue(from_range_t, R&&, Allocator)
9906c3fb27SDimitry Andric      -> queue<ranges::range_value_t<R>, deque<ranges::range_value_t<R>, Allocator>>; // since C++23
10006c3fb27SDimitry Andric
1010b57cec5SDimitry Andrictemplate <class T, class Container>
1020b57cec5SDimitry Andric  bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andrictemplate <class T, class Container>
1050b57cec5SDimitry Andric  bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
1060b57cec5SDimitry Andric
1070b57cec5SDimitry Andrictemplate <class T, class Container>
1080b57cec5SDimitry Andric  bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andrictemplate <class T, class Container>
1110b57cec5SDimitry Andric  bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andrictemplate <class T, class Container>
1140b57cec5SDimitry Andric  bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andrictemplate <class T, class Container>
1170b57cec5SDimitry Andric  bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
1180b57cec5SDimitry Andric
11906c3fb27SDimitry Andrictemplate<class T, three_way_comparable Container>
12006c3fb27SDimitry Andric  compare_three_way_result_t<Container>
12106c3fb27SDimitry Andric    operator<=>(const queue<T, Container>& x, const queue<T, Container>& y);  // since C++20
12206c3fb27SDimitry Andric
1230b57cec5SDimitry Andrictemplate <class T, class Container>
1240b57cec5SDimitry Andric  void swap(queue<T, Container>& x, queue<T, Container>& y)
1250b57cec5SDimitry Andric  noexcept(noexcept(x.swap(y)));
1260b57cec5SDimitry Andric
1270b57cec5SDimitry Andrictemplate <class T, class Container = vector<T>,
1280b57cec5SDimitry Andric          class Compare = less<typename Container::value_type>>
1290b57cec5SDimitry Andricclass priority_queue
1300b57cec5SDimitry Andric{
1310b57cec5SDimitry Andricpublic:
1320b57cec5SDimitry Andric    typedef Container                                container_type;
1330b57cec5SDimitry Andric    typedef typename container_type::value_type      value_type;
1340b57cec5SDimitry Andric    typedef typename container_type::reference       reference;
1350b57cec5SDimitry Andric    typedef typename container_type::const_reference const_reference;
1360b57cec5SDimitry Andric    typedef typename container_type::size_type       size_type;
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andricprotected:
1390b57cec5SDimitry Andric    container_type c;
1400b57cec5SDimitry Andric    Compare comp;
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andricpublic:
143e8d8bef9SDimitry Andric    priority_queue() : priority_queue(Compare()) {} // C++20
144e8d8bef9SDimitry Andric    explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
145e8d8bef9SDimitry Andric    priority_queue(const Compare& x, const Container&);
146e8d8bef9SDimitry Andric    explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
147e8d8bef9SDimitry Andric    priority_queue(const Compare& x, Container&&); // C++20
1480b57cec5SDimitry Andric    template <class InputIterator>
1490b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
1500b57cec5SDimitry Andric                       const Compare& comp = Compare());
1510b57cec5SDimitry Andric    template <class InputIterator>
1520b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
153349cc55cSDimitry Andric                       const Compare& comp, const Container& c);
1540b57cec5SDimitry Andric    template <class InputIterator>
1550b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
156349cc55cSDimitry Andric                       const Compare& comp, Container&& c);
15706c3fb27SDimitry Andric    template <container-compatible-range<T> R>
15806c3fb27SDimitry Andric        priority_queue(from_range_t, R&& rg, const Compare& x = Compare()); // since C++23
1590b57cec5SDimitry Andric    template <class Alloc>
1600b57cec5SDimitry Andric        explicit priority_queue(const Alloc& a);
1610b57cec5SDimitry Andric    template <class Alloc>
1620b57cec5SDimitry Andric        priority_queue(const Compare& comp, const Alloc& a);
1630b57cec5SDimitry Andric    template <class Alloc>
164349cc55cSDimitry Andric        priority_queue(const Compare& comp, const Container& c,
1650b57cec5SDimitry Andric                       const Alloc& a);
1660b57cec5SDimitry Andric    template <class Alloc>
167349cc55cSDimitry Andric        priority_queue(const Compare& comp, Container&& c,
1680b57cec5SDimitry Andric                       const Alloc& a);
169349cc55cSDimitry Andric    template <class InputIterator>
170349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
171349cc55cSDimitry Andric                       const Alloc& a);
172349cc55cSDimitry Andric    template <class InputIterator>
173349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
174349cc55cSDimitry Andric                       const Compare& comp, const Alloc& a);
175349cc55cSDimitry Andric    template <class InputIterator>
176349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
177349cc55cSDimitry Andric                       const Compare& comp, const Container& c, const Alloc& a);
178349cc55cSDimitry Andric    template <class InputIterator>
179349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
180349cc55cSDimitry Andric                       const Compare& comp, Container&& c, const Alloc& a);
18106c3fb27SDimitry Andric    template <container-compatible-range<T> R, class Alloc>
18206c3fb27SDimitry Andric      priority_queue(from_range_t, R&& rg, const Compare&, const Alloc&); // since C++23
18306c3fb27SDimitry Andric    template <container-compatible-range<T> R, class Alloc>
18406c3fb27SDimitry Andric      priority_queue(from_range_t, R&& rg, const Alloc&); // since C++23
1850b57cec5SDimitry Andric    template <class Alloc>
1860b57cec5SDimitry Andric        priority_queue(const priority_queue& q, const Alloc& a);
1870b57cec5SDimitry Andric    template <class Alloc>
1880b57cec5SDimitry Andric        priority_queue(priority_queue&& q, const Alloc& a);
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andric    bool            empty() const;
1910b57cec5SDimitry Andric    size_type       size() const;
1920b57cec5SDimitry Andric    const_reference top() const;
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric    void push(const value_type& v);
1950b57cec5SDimitry Andric    void push(value_type&& v);
19606c3fb27SDimitry Andric    template<container-compatible-range<T> R>
19706c3fb27SDimitry Andric      void push_range(R&& rg); // C++23
1980b57cec5SDimitry Andric    template <class... Args> void emplace(Args&&... args);
1990b57cec5SDimitry Andric    void pop();
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric    void swap(priority_queue& q)
2020b57cec5SDimitry Andric        noexcept(is_nothrow_swappable_v<Container> &&
2030b57cec5SDimitry Andric                 is_nothrow_swappable_v<Comp>)
2040b57cec5SDimitry Andric};
2050b57cec5SDimitry Andric
2060b57cec5SDimitry Andrictemplate <class Compare, class Container>
2070b57cec5SDimitry Andricpriority_queue(Compare, Container)
2080b57cec5SDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
2090b57cec5SDimitry Andric
2100b57cec5SDimitry Andrictemplate<class InputIterator,
211349cc55cSDimitry Andric         class Compare = less<iter-value-type<InputIterator>>,
212349cc55cSDimitry Andric         class Container = vector<iter-value-type<InputIterator>>>
2130b57cec5SDimitry Andricpriority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
214349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
2150b57cec5SDimitry Andric
21606c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>>
21706c3fb27SDimitry Andric  priority_queue(from_range_t, R&&, Compare = Compare())
21806c3fb27SDimitry Andric    -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>>, Compare>; // C++23
21906c3fb27SDimitry Andric
2200b57cec5SDimitry Andrictemplate<class Compare, class Container, class Allocator>
2210b57cec5SDimitry Andricpriority_queue(Compare, Container, Allocator)
2220b57cec5SDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
2230b57cec5SDimitry Andric
224349cc55cSDimitry Andrictemplate<class InputIterator, class Allocator>
225349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Allocator)
226349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>,
227349cc55cSDimitry Andric                      vector<iter-value-type<InputIterator>, Allocator>,
228349cc55cSDimitry Andric                      less<iter-value-type<InputIterator>>>; // C++17
229349cc55cSDimitry Andric
230349cc55cSDimitry Andrictemplate<class InputIterator, class Compare, class Allocator>
231349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Compare, Allocator)
232349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>,
233349cc55cSDimitry Andric                      vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
234349cc55cSDimitry Andric
235349cc55cSDimitry Andrictemplate<class InputIterator, class Compare, class Container, class Allocator>
236349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
237349cc55cSDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
238349cc55cSDimitry Andric
23906c3fb27SDimitry Andrictemplate<ranges::input_range R, class Compare, class Allocator>
24006c3fb27SDimitry Andric  priority_queue(from_range_t, R&&, Compare, Allocator)
24106c3fb27SDimitry Andric    -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>,
24206c3fb27SDimitry Andric                        Compare>; // C++23
24306c3fb27SDimitry Andric
24406c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator>
24506c3fb27SDimitry Andric  priority_queue(from_range_t, R&&, Allocator)
24606c3fb27SDimitry Andric    -> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>>; // C++23
24706c3fb27SDimitry Andric
2480b57cec5SDimitry Andrictemplate <class T, class Container, class Compare>
2490b57cec5SDimitry Andric  void swap(priority_queue<T, Container, Compare>& x,
2500b57cec5SDimitry Andric            priority_queue<T, Container, Compare>& y)
2510b57cec5SDimitry Andric            noexcept(noexcept(x.swap(y)));
2520b57cec5SDimitry Andric
2530b57cec5SDimitry Andric}  // std
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric*/
2560b57cec5SDimitry Andric
257*700637cbSDimitry Andric#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
258*700637cbSDimitry Andric#  include <__cxx03/queue>
259*700637cbSDimitry Andric#else
26081ad6265SDimitry Andric#  include <__algorithm/make_heap.h>
26181ad6265SDimitry Andric#  include <__algorithm/pop_heap.h>
26281ad6265SDimitry Andric#  include <__algorithm/push_heap.h>
26306c3fb27SDimitry Andric#  include <__algorithm/ranges_copy.h>
2640b57cec5SDimitry Andric#  include <__config>
26581ad6265SDimitry Andric#  include <__functional/operations.h>
2660fca6ea1SDimitry Andric#  include <__fwd/deque.h>
2670fca6ea1SDimitry Andric#  include <__fwd/queue.h>
26806c3fb27SDimitry Andric#  include <__iterator/back_insert_iterator.h>
26904eeddc0SDimitry Andric#  include <__iterator/iterator_traits.h>
270fe6060f1SDimitry Andric#  include <__memory/uses_allocator.h>
27106c3fb27SDimitry Andric#  include <__ranges/access.h>
27206c3fb27SDimitry Andric#  include <__ranges/concepts.h>
27306c3fb27SDimitry Andric#  include <__ranges/container_compatible_range.h>
27406c3fb27SDimitry Andric#  include <__ranges/from_range.h>
275fe6060f1SDimitry Andric#  include <__utility/forward.h>
276fe6060f1SDimitry Andric#  include <deque>
277fe6060f1SDimitry Andric#  include <vector>
27804eeddc0SDimitry Andric#  include <version>
2790b57cec5SDimitry Andric
28081ad6265SDimitry Andric// standard-mandated includes
281bdd1243dSDimitry Andric
282bdd1243dSDimitry Andric// [queue.syn]
28381ad6265SDimitry Andric#  include <compare>
28481ad6265SDimitry Andric#  include <initializer_list>
28581ad6265SDimitry Andric
2860b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2870b57cec5SDimitry Andric#    pragma GCC system_header
2880b57cec5SDimitry Andric#  endif
2890b57cec5SDimitry Andric
290b3edf446SDimitry Andric_LIBCPP_PUSH_MACROS
291b3edf446SDimitry Andric#  include <__undef_macros>
292b3edf446SDimitry Andric
2930b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2940b57cec5SDimitry Andric
2950b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
296cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
299cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y);
3000b57cec5SDimitry Andric
3010b57cec5SDimitry Andrictemplate <class _Tp, class _Container /*= deque<_Tp>*/>
302*700637cbSDimitry Andricclass queue {
3030b57cec5SDimitry Andricpublic:
3040b57cec5SDimitry Andric  typedef _Container container_type;
3050b57cec5SDimitry Andric  typedef typename container_type::value_type value_type;
3060b57cec5SDimitry Andric  typedef typename container_type::reference reference;
3070b57cec5SDimitry Andric  typedef typename container_type::const_reference const_reference;
3080b57cec5SDimitry Andric  typedef typename container_type::size_type size_type;
3090fca6ea1SDimitry Andric  static_assert(is_same<_Tp, value_type>::value, "");
3100b57cec5SDimitry Andric
3110b57cec5SDimitry Andricprotected:
3120b57cec5SDimitry Andric  container_type c;
3130b57cec5SDimitry Andric
3140b57cec5SDimitry Andricpublic:
315cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue() _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) : c() {}
3160b57cec5SDimitry Andric
317cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(const queue& __q) : c(__q.c) {}
3180b57cec5SDimitry Andric
31906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
3200fca6ea1SDimitry Andric  template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
321cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
32204eeddc0SDimitry Andric
32306c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
324cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range) : c(from_range, std::forward<_Range>(__range)) {}
32506c3fb27SDimitry Andric
32604eeddc0SDimitry Andric  template <class _InputIterator,
32704eeddc0SDimitry Andric            class _Alloc,
3280fca6ea1SDimitry Andric            __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
3290fca6ea1SDimitry Andric            __enable_if_t<uses_allocator<container_type, _Alloc>::value, int>        = 0>
330cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc)
331cb14a3feSDimitry Andric      : c(__first, __second, __alloc) {}
33206c3fb27SDimitry Andric
33306c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range,
33406c3fb27SDimitry Andric            class _Alloc,
3350fca6ea1SDimitry Andric            __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
336cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(from_range_t, _Range&& __range, const _Alloc& __alloc)
33706c3fb27SDimitry Andric      : c(from_range, std::forward<_Range>(__range), __alloc) {}
33806c3fb27SDimitry Andric
33904eeddc0SDimitry Andric#  endif
34004eeddc0SDimitry Andric
341cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue& operator=(const queue& __q) {
342cb14a3feSDimitry Andric    c = __q.c;
343cb14a3feSDimitry Andric    return *this;
344cb14a3feSDimitry Andric  }
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
3470fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(queue&& __q) noexcept(is_nothrow_move_constructible<container_type>::value)
3485f757f3fSDimitry Andric      : c(std::move(__q.c)) {}
3490b57cec5SDimitry Andric
3500fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue& operator=(queue&& __q) noexcept(is_nothrow_move_assignable<container_type>::value) {
351cb14a3feSDimitry Andric    c = std::move(__q.c);
352cb14a3feSDimitry Andric    return *this;
353cb14a3feSDimitry Andric  }
3540b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
3550b57cec5SDimitry Andric
356cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit queue(const container_type& __c) : c(__c) {}
3570b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
358cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit queue(container_type&& __c) : c(std::move(__c)) {}
3590b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
3600b57cec5SDimitry Andric
3610fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
3620fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit queue(const _Alloc& __a) : c(__a) {}
3630fca6ea1SDimitry Andric
3640fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
3650fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(const queue& __q, const _Alloc& __a) : c(__q.c, __a) {}
3660fca6ea1SDimitry Andric
3670fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
3680fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(const container_type& __c, const _Alloc& __a) : c(__c, __a) {}
3690fca6ea1SDimitry Andric
3700fca6ea1SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
3710fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
3720fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(container_type&& __c, const _Alloc& __a) : c(std::move(__c), __a) {}
3730fca6ea1SDimitry Andric
3740fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
3750fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI queue(queue&& __q, const _Alloc& __a) : c(std::move(__q.c), __a) {}
3760b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
3770b57cec5SDimitry Andric
378*700637cbSDimitry Andric  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
379cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
3800b57cec5SDimitry Andric
381cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference front() { return c.front(); }
382cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference front() const { return c.front(); }
383cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference back() { return c.back(); }
384cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference back() const { return c.back(); }
3850b57cec5SDimitry Andric
386cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v) { c.push_back(__v); }
3870b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
388cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v) { c.push_back(std::move(__v)); }
38906c3fb27SDimitry Andric
39006c3fb27SDimitry Andric#    if _LIBCPP_STD_VER >= 23
39106c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
392cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
393cb14a3feSDimitry Andric    if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
39406c3fb27SDimitry Andric      c.append_range(std::forward<_Range>(__range));
39506c3fb27SDimitry Andric    } else {
39606c3fb27SDimitry Andric      ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
39706c3fb27SDimitry Andric    }
39806c3fb27SDimitry Andric  }
39906c3fb27SDimitry Andric#    endif
40006c3fb27SDimitry Andric
4010b57cec5SDimitry Andric  template <class... _Args>
4025f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
40306c3fb27SDimitry Andric#    if _LIBCPP_STD_VER >= 17
404cb14a3feSDimitry Andric  decltype(auto)
405cb14a3feSDimitry Andric  emplace(_Args&&... __args) {
406cb14a3feSDimitry Andric    return c.emplace_back(std::forward<_Args>(__args)...);
407cb14a3feSDimitry Andric  }
4080b57cec5SDimitry Andric#    else
409cb14a3feSDimitry Andric  void
410cb14a3feSDimitry Andric  emplace(_Args&&... __args) {
411cb14a3feSDimitry Andric    c.emplace_back(std::forward<_Args>(__args)...);
412cb14a3feSDimitry Andric  }
4130b57cec5SDimitry Andric#    endif
4140b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
415cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void pop() { c.pop_front(); }
4160b57cec5SDimitry Andric
4170fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(queue& __q) _NOEXCEPT_(__is_nothrow_swappable_v<container_type>) {
4185f757f3fSDimitry Andric    using std::swap;
4190b57cec5SDimitry Andric    swap(c, __q.c);
4200b57cec5SDimitry Andric  }
4210b57cec5SDimitry Andric
422*700637cbSDimitry Andric  [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const { return c; }
423bdd1243dSDimitry Andric
42406c3fb27SDimitry Andric  template <class _T1, class _OtherContainer>
425cb14a3feSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool
42606c3fb27SDimitry Andric  operator==(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
4270b57cec5SDimitry Andric
42806c3fb27SDimitry Andric  template <class _T1, class _OtherContainer>
429cb14a3feSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI bool
43006c3fb27SDimitry Andric  operator<(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
431*700637cbSDimitry Andric
432*700637cbSDimitry Andric#  if _LIBCPP_STD_VER >= 20
433*700637cbSDimitry Andric  template <class _T1, three_way_comparable _OtherContainer>
434*700637cbSDimitry Andric  friend _LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_OtherContainer>
435*700637cbSDimitry Andric  operator<=>(const queue<_T1, _OtherContainer>& __x, const queue<_T1, _OtherContainer>& __y);
436*700637cbSDimitry Andric#  endif
4370b57cec5SDimitry Andric};
4380b57cec5SDimitry Andric
43906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
440cb14a3feSDimitry Andrictemplate <class _Container, class = enable_if_t<!__is_allocator<_Container>::value> >
441cb14a3feSDimitry Andricqueue(_Container) -> queue<typename _Container::value_type, _Container>;
4420b57cec5SDimitry Andric
4430b57cec5SDimitry Andrictemplate <class _Container,
4440b57cec5SDimitry Andric          class _Alloc,
445349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Container>::value>,
446cb14a3feSDimitry Andric          class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
447cb14a3feSDimitry Andricqueue(_Container, _Alloc) -> queue<typename _Container::value_type, _Container>;
4480b57cec5SDimitry Andric#  endif
4490b57cec5SDimitry Andric
45006c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
4510fca6ea1SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
452cb14a3feSDimitry Andricqueue(_InputIterator, _InputIterator) -> queue<__iter_value_type<_InputIterator>>;
45304eeddc0SDimitry Andric
45406c3fb27SDimitry Andrictemplate <ranges::input_range _Range>
455cb14a3feSDimitry Andricqueue(from_range_t, _Range&&) -> queue<ranges::range_value_t<_Range>>;
45606c3fb27SDimitry Andric
45704eeddc0SDimitry Andrictemplate <class _InputIterator,
45804eeddc0SDimitry Andric          class _Alloc,
4590fca6ea1SDimitry Andric          __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0,
4600fca6ea1SDimitry Andric          __enable_if_t<__is_allocator<_Alloc>::value, int>                        = 0>
461*700637cbSDimitry Andricqueue(_InputIterator, _InputIterator, _Alloc)
462*700637cbSDimitry Andric    -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
46306c3fb27SDimitry Andric
4640fca6ea1SDimitry Andrictemplate <ranges::input_range _Range, class _Alloc, __enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
465*700637cbSDimitry Andricqueue(from_range_t, _Range&&, _Alloc)
466*700637cbSDimitry Andric    -> queue<ranges::range_value_t<_Range>, deque<ranges::range_value_t<_Range>, _Alloc>>;
46704eeddc0SDimitry Andric#  endif
46804eeddc0SDimitry Andric
4690b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
470cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator==(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4710b57cec5SDimitry Andric  return __x.c == __y.c;
4720b57cec5SDimitry Andric}
4730b57cec5SDimitry Andric
4740b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
475cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4760b57cec5SDimitry Andric  return __x.c < __y.c;
4770b57cec5SDimitry Andric}
4780b57cec5SDimitry Andric
4790b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
480cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4810b57cec5SDimitry Andric  return !(__x == __y);
4820b57cec5SDimitry Andric}
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
485cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4860b57cec5SDimitry Andric  return __y < __x;
4870b57cec5SDimitry Andric}
4880b57cec5SDimitry Andric
4890b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
490cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4910b57cec5SDimitry Andric  return !(__x < __y);
4920b57cec5SDimitry Andric}
4930b57cec5SDimitry Andric
4940b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
495cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
4960b57cec5SDimitry Andric  return !(__y < __x);
4970b57cec5SDimitry Andric}
4980b57cec5SDimitry Andric
49906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
50006c3fb27SDimitry Andric
50106c3fb27SDimitry Andrictemplate <class _Tp, three_way_comparable _Container>
50206c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
50306c3fb27SDimitry Andricoperator<=>(const queue<_Tp, _Container>& __x, const queue<_Tp, _Container>& __y) {
504*700637cbSDimitry Andric  return __x.c <=> __y.c;
50506c3fb27SDimitry Andric}
50606c3fb27SDimitry Andric
50706c3fb27SDimitry Andric#  endif
50806c3fb27SDimitry Andric
5090fca6ea1SDimitry Andrictemplate <class _Tp, class _Container, __enable_if_t<__is_swappable_v<_Container>, int> = 0>
510cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
511cb14a3feSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
5120b57cec5SDimitry Andric  __x.swap(__y);
5130b57cec5SDimitry Andric}
5140b57cec5SDimitry Andric
5150b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Alloc>
516*700637cbSDimitry Andricstruct uses_allocator<queue<_Tp, _Container>, _Alloc> : public uses_allocator<_Container, _Alloc> {};
5170b57cec5SDimitry Andric
5180fca6ea1SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
519*700637cbSDimitry Andricclass priority_queue {
5200b57cec5SDimitry Andricpublic:
5210b57cec5SDimitry Andric  typedef _Container container_type;
5220b57cec5SDimitry Andric  typedef _Compare value_compare;
5230b57cec5SDimitry Andric  typedef typename container_type::value_type value_type;
5240b57cec5SDimitry Andric  typedef typename container_type::reference reference;
5250b57cec5SDimitry Andric  typedef typename container_type::const_reference const_reference;
5260b57cec5SDimitry Andric  typedef typename container_type::size_type size_type;
5270fca6ea1SDimitry Andric  static_assert(is_same<_Tp, value_type>::value, "");
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andricprotected:
5300b57cec5SDimitry Andric  container_type c;
5310b57cec5SDimitry Andric  value_compare comp;
5320b57cec5SDimitry Andric
5330b57cec5SDimitry Andricpublic:
534*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue() _NOEXCEPT_(
535cb14a3feSDimitry Andric      is_nothrow_default_constructible<container_type>::value&& is_nothrow_default_constructible<value_compare>::value)
5360b57cec5SDimitry Andric      : c(), comp() {}
5370b57cec5SDimitry Andric
538*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q)
539*700637cbSDimitry Andric      : c(__q.c), comp(__q.comp) {}
5400b57cec5SDimitry Andric
541*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(const priority_queue& __q) {
542cb14a3feSDimitry Andric    c    = __q.c;
543cb14a3feSDimitry Andric    comp = __q.comp;
544cb14a3feSDimitry Andric    return *this;
545cb14a3feSDimitry Andric  }
5460b57cec5SDimitry Andric
5470b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
548*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q) noexcept(
549cb14a3feSDimitry Andric      is_nothrow_move_constructible<container_type>::value && is_nothrow_move_constructible<value_compare>::value)
5505f757f3fSDimitry Andric      : c(std::move(__q.c)), comp(std::move(__q.comp)) {}
5510b57cec5SDimitry Andric
552*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue& operator=(priority_queue&& __q) noexcept(
5530fca6ea1SDimitry Andric      is_nothrow_move_assignable<container_type>::value && is_nothrow_move_assignable<value_compare>::value) {
554cb14a3feSDimitry Andric    c    = std::move(__q.c);
555cb14a3feSDimitry Andric    comp = std::move(__q.comp);
556cb14a3feSDimitry Andric    return *this;
557cb14a3feSDimitry Andric  }
5580b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
5590b57cec5SDimitry Andric
560*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const value_compare& __comp)
561*700637cbSDimitry Andric      : c(), comp(__comp) {}
562*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
563*700637cbSDimitry Andric  priority_queue(const value_compare& __comp, const container_type& __c);
5640b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
565*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, container_type&& __c);
5660b57cec5SDimitry Andric#  endif
5670fca6ea1SDimitry Andric  template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
568*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
569*700637cbSDimitry Andric  priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp = value_compare());
5700fca6ea1SDimitry Andric
5710fca6ea1SDimitry Andric  template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
572*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
573cb14a3feSDimitry Andric  priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c);
5740fca6ea1SDimitry Andric
5750b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
5760fca6ea1SDimitry Andric  template <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> = 0>
577*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
578cb14a3feSDimitry Andric  priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c);
5790b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
58006c3fb27SDimitry Andric
58106c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
58206c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
583*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
584*700637cbSDimitry Andric  priority_queue(from_range_t, _Range&& __range, const value_compare& __comp = value_compare())
585cb14a3feSDimitry Andric      : c(from_range, std::forward<_Range>(__range)), comp(__comp) {
58606c3fb27SDimitry Andric    std::make_heap(c.begin(), c.end(), comp);
58706c3fb27SDimitry Andric  }
58806c3fb27SDimitry Andric#  endif
58906c3fb27SDimitry Andric
5900fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
591*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI explicit priority_queue(const _Alloc& __a);
5920fca6ea1SDimitry Andric
5930fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
594*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const value_compare& __comp, const _Alloc& __a);
5950fca6ea1SDimitry Andric
5960fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
597*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
598*700637cbSDimitry Andric  priority_queue(const value_compare& __comp, const container_type& __c, const _Alloc& __a);
5990fca6ea1SDimitry Andric
6000fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
601*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(const priority_queue& __q, const _Alloc& __a);
6020fca6ea1SDimitry Andric
6030b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
6040fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
605*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
606*700637cbSDimitry Andric  priority_queue(const value_compare& __comp, container_type&& __c, const _Alloc& __a);
6070fca6ea1SDimitry Andric
6080fca6ea1SDimitry Andric  template <class _Alloc, __enable_if_t<uses_allocator<container_type, _Alloc>::value, int> = 0>
609*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(priority_queue&& __q, const _Alloc& __a);
610349cc55cSDimitry Andric#  endif // _LIBCPP_CXX03_LANG
611349cc55cSDimitry Andric
6120fca6ea1SDimitry Andric  template <
6130fca6ea1SDimitry Andric      class _InputIter,
6140fca6ea1SDimitry Andric      class _Alloc,
6150fca6ea1SDimitry Andric      __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
6160fca6ea1SDimitry Andric                    int> = 0>
617*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a);
618349cc55cSDimitry Andric
6190fca6ea1SDimitry Andric  template <
6200fca6ea1SDimitry Andric      class _InputIter,
6210fca6ea1SDimitry Andric      class _Alloc,
6220fca6ea1SDimitry Andric      __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
6230fca6ea1SDimitry Andric                    int> = 0>
624*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
625*700637cbSDimitry Andric  priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a);
626349cc55cSDimitry Andric
6270fca6ea1SDimitry Andric  template <
6280fca6ea1SDimitry Andric      class _InputIter,
6290fca6ea1SDimitry Andric      class _Alloc,
6300fca6ea1SDimitry Andric      __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
6310fca6ea1SDimitry Andric                    int> = 0>
632*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(
6330fca6ea1SDimitry Andric      _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a);
634349cc55cSDimitry Andric
635349cc55cSDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
6360fca6ea1SDimitry Andric  template <
6370fca6ea1SDimitry Andric      class _InputIter,
6380fca6ea1SDimitry Andric      class _Alloc,
6390fca6ea1SDimitry Andric      __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<container_type, _Alloc>::value,
6400fca6ea1SDimitry Andric                    int> = 0>
641*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
6420fca6ea1SDimitry Andric  priority_queue(_InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a);
6430b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
6440b57cec5SDimitry Andric
64506c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
64606c3fb27SDimitry Andric
64706c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range,
64806c3fb27SDimitry Andric            class _Alloc,
64906c3fb27SDimitry Andric            class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
650*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI
651*700637cbSDimitry Andric  priority_queue(from_range_t, _Range&& __range, const value_compare& __comp, const _Alloc& __a)
652cb14a3feSDimitry Andric      : c(from_range, std::forward<_Range>(__range), __a), comp(__comp) {
65306c3fb27SDimitry Andric    std::make_heap(c.begin(), c.end(), comp);
65406c3fb27SDimitry Andric  }
65506c3fb27SDimitry Andric
65606c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range,
65706c3fb27SDimitry Andric            class _Alloc,
65806c3fb27SDimitry Andric            class = enable_if_t<uses_allocator<_Container, _Alloc>::value>>
659*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI priority_queue(from_range_t, _Range&& __range, const _Alloc& __a)
660cb14a3feSDimitry Andric      : c(from_range, std::forward<_Range>(__range), __a), comp() {
66106c3fb27SDimitry Andric    std::make_heap(c.begin(), c.end(), comp);
66206c3fb27SDimitry Andric  }
66306c3fb27SDimitry Andric
66406c3fb27SDimitry Andric#  endif
66506c3fb27SDimitry Andric
666*700637cbSDimitry Andric  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI bool empty() const { return c.empty(); }
667*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI size_type size() const { return c.size(); }
668*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const_reference top() const { return c.front(); }
6690b57cec5SDimitry Andric
670*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push(const value_type& __v);
6710b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
672*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push(value_type&& __v);
67306c3fb27SDimitry Andric
67406c3fb27SDimitry Andric#    if _LIBCPP_STD_VER >= 23
67506c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
676*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void push_range(_Range&& __range) {
677cb14a3feSDimitry Andric    if constexpr (requires(container_type& __c) { __c.append_range(std::forward<_Range>(__range)); }) {
67806c3fb27SDimitry Andric      c.append_range(std::forward<_Range>(__range));
67906c3fb27SDimitry Andric    } else {
68006c3fb27SDimitry Andric      ranges::copy(std::forward<_Range>(__range), std::back_inserter(c));
68106c3fb27SDimitry Andric    }
68206c3fb27SDimitry Andric
68306c3fb27SDimitry Andric    std::make_heap(c.begin(), c.end(), comp);
68406c3fb27SDimitry Andric  }
68506c3fb27SDimitry Andric#    endif
68606c3fb27SDimitry Andric
6870b57cec5SDimitry Andric  template <class... _Args>
688*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void emplace(_Args&&... __args);
6890b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
690*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void pop();
6910b57cec5SDimitry Andric
692*700637cbSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI void swap(priority_queue& __q)
6930fca6ea1SDimitry Andric      _NOEXCEPT_(__is_nothrow_swappable_v<container_type>&& __is_nothrow_swappable_v<value_compare>);
694bdd1243dSDimitry Andric
695*700637cbSDimitry Andric  [[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX26 _LIBCPP_HIDE_FROM_ABI const _Container& __get_container() const {
696*700637cbSDimitry Andric    return c;
697*700637cbSDimitry Andric  }
6980b57cec5SDimitry Andric};
6990b57cec5SDimitry Andric
700349cc55cSDimitry Andric#  if _LIBCPP_STD_VER >= 17
7010b57cec5SDimitry Andrictemplate <class _Compare,
7020b57cec5SDimitry Andric          class _Container,
703349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
704cb14a3feSDimitry Andric          class = enable_if_t<!__is_allocator<_Container>::value> >
705cb14a3feSDimitry Andricpriority_queue(_Compare, _Container) -> priority_queue<typename _Container::value_type, _Container, _Compare>;
7060b57cec5SDimitry Andric
7070b57cec5SDimitry Andrictemplate <class _InputIterator,
708fe6060f1SDimitry Andric          class _Compare   = less<__iter_value_type<_InputIterator>>,
709fe6060f1SDimitry Andric          class _Container = vector<__iter_value_type<_InputIterator>>,
71006c3fb27SDimitry Andric          class            = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
711349cc55cSDimitry Andric          class            = enable_if_t<!__is_allocator<_Compare>::value>,
712cb14a3feSDimitry Andric          class            = enable_if_t<!__is_allocator<_Container>::value> >
7130b57cec5SDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
714fe6060f1SDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
7150b57cec5SDimitry Andric
7160b57cec5SDimitry Andrictemplate <class _Compare,
7170b57cec5SDimitry Andric          class _Container,
7180b57cec5SDimitry Andric          class _Alloc,
719349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
720349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Container>::value>,
721cb14a3feSDimitry Andric          class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
722cb14a3feSDimitry Andricpriority_queue(_Compare, _Container, _Alloc) -> priority_queue<typename _Container::value_type, _Container, _Compare>;
723349cc55cSDimitry Andric
724cb14a3feSDimitry Andrictemplate <class _InputIterator,
725cb14a3feSDimitry Andric          class _Allocator,
72606c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
727cb14a3feSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value> >
728349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Allocator)
729349cc55cSDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>,
730349cc55cSDimitry Andric                      vector<__iter_value_type<_InputIterator>, _Allocator>,
731349cc55cSDimitry Andric                      less<__iter_value_type<_InputIterator>>>;
732349cc55cSDimitry Andric
733cb14a3feSDimitry Andrictemplate <class _InputIterator,
734cb14a3feSDimitry Andric          class _Compare,
735cb14a3feSDimitry Andric          class _Allocator,
73606c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
737349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
738cb14a3feSDimitry Andric          class = enable_if_t<__is_allocator<_Allocator>::value> >
739349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
740349cc55cSDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>,
741cb14a3feSDimitry Andric                      vector<__iter_value_type<_InputIterator>, _Allocator>,
742cb14a3feSDimitry Andric                      _Compare>;
743349cc55cSDimitry Andric
744cb14a3feSDimitry Andrictemplate <class _InputIterator,
745cb14a3feSDimitry Andric          class _Compare,
746cb14a3feSDimitry Andric          class _Container,
747cb14a3feSDimitry Andric          class _Alloc,
74806c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
749349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
750349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Container>::value>,
751cb14a3feSDimitry Andric          class = enable_if_t<uses_allocator<_Container, _Alloc>::value> >
752349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
753349cc55cSDimitry Andric    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
7540b57cec5SDimitry Andric#  endif
7550b57cec5SDimitry Andric
75606c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
75706c3fb27SDimitry Andric
75806c3fb27SDimitry Andrictemplate <ranges::input_range _Range,
75906c3fb27SDimitry Andric          class _Compare = less<ranges::range_value_t<_Range>>,
76006c3fb27SDimitry Andric          class          = enable_if_t<!__is_allocator<_Compare>::value>>
76106c3fb27SDimitry Andricpriority_queue(from_range_t, _Range&&, _Compare = _Compare())
76206c3fb27SDimitry Andric    -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>>, _Compare>;
76306c3fb27SDimitry Andric
76406c3fb27SDimitry Andrictemplate <ranges::input_range _Range,
76506c3fb27SDimitry Andric          class _Compare,
76606c3fb27SDimitry Andric          class _Alloc,
76706c3fb27SDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
76806c3fb27SDimitry Andric          class = enable_if_t<__is_allocator<_Alloc>::value>>
76906c3fb27SDimitry Andricpriority_queue(from_range_t, _Range&&, _Compare, _Alloc)
770cb14a3feSDimitry Andric    -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>, _Compare>;
77106c3fb27SDimitry Andric
772cb14a3feSDimitry Andrictemplate <ranges::input_range _Range, class _Alloc, class = enable_if_t<__is_allocator<_Alloc>::value>>
77306c3fb27SDimitry Andricpriority_queue(from_range_t, _Range&&, _Alloc)
77406c3fb27SDimitry Andric    -> priority_queue<ranges::range_value_t<_Range>, vector<ranges::range_value_t<_Range>, _Alloc>>;
77506c3fb27SDimitry Andric
77606c3fb27SDimitry Andric#  endif
77706c3fb27SDimitry Andric
7780b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
779*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
780*700637cbSDimitry Andric    const _Compare& __comp, const container_type& __c)
781cb14a3feSDimitry Andric    : c(__c), comp(__comp) {
7825f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
7830b57cec5SDimitry Andric}
7840b57cec5SDimitry Andric
7850b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
7860b57cec5SDimitry Andric
7870b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
788*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
789*700637cbSDimitry Andric    const value_compare& __comp, container_type&& __c)
790cb14a3feSDimitry Andric    : c(std::move(__c)), comp(__comp) {
7915f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
7920b57cec5SDimitry Andric}
7930b57cec5SDimitry Andric
7940b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
7950b57cec5SDimitry Andric
7960b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7970fca6ea1SDimitry Andrictemplate <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
798*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
799cb14a3feSDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp)
800cb14a3feSDimitry Andric    : c(__f, __l), comp(__comp) {
8015f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8020b57cec5SDimitry Andric}
8030b57cec5SDimitry Andric
8040b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8050fca6ea1SDimitry Andrictemplate <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
806*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
807cb14a3feSDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c)
808cb14a3feSDimitry Andric    : c(__c), comp(__comp) {
8090b57cec5SDimitry Andric  c.insert(c.end(), __f, __l);
8105f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8110b57cec5SDimitry Andric}
8120b57cec5SDimitry Andric
8130b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
8140b57cec5SDimitry Andric
8150b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8160fca6ea1SDimitry Andrictemplate <class _InputIter, __enable_if_t<__has_input_iterator_category<_InputIter>::value, int> >
817*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
818cb14a3feSDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c)
819cb14a3feSDimitry Andric    : c(std::move(__c)), comp(__comp) {
8200b57cec5SDimitry Andric  c.insert(c.end(), __f, __l);
8215f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8220b57cec5SDimitry Andric}
8230b57cec5SDimitry Andric
8240b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
8250b57cec5SDimitry Andric
8260b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8270fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
828*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a)
829*700637cbSDimitry Andric    : c(__a) {}
8300b57cec5SDimitry Andric
8310b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8320fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
833*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
834*700637cbSDimitry Andric    const value_compare& __comp, const _Alloc& __a)
835cb14a3feSDimitry Andric    : c(__a), comp(__comp) {}
8360b57cec5SDimitry Andric
8370b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8380fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
839*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
8400fca6ea1SDimitry Andric    const value_compare& __comp, const container_type& __c, const _Alloc& __a)
841cb14a3feSDimitry Andric    : c(__c, __a), comp(__comp) {
8425f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8430b57cec5SDimitry Andric}
8440b57cec5SDimitry Andric
8450b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8460fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
847*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
848*700637cbSDimitry Andric    const priority_queue& __q, const _Alloc& __a)
849cb14a3feSDimitry Andric    : c(__q.c, __a), comp(__q.comp) {}
8500b57cec5SDimitry Andric
8510b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
8520b57cec5SDimitry Andric
8530b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8540fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
855*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
8560fca6ea1SDimitry Andric    const value_compare& __comp, container_type&& __c, const _Alloc& __a)
857cb14a3feSDimitry Andric    : c(std::move(__c), __a), comp(__comp) {
8585f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8590b57cec5SDimitry Andric}
8600b57cec5SDimitry Andric
8610b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8620fca6ea1SDimitry Andrictemplate <class _Alloc, __enable_if_t<uses_allocator<_Container, _Alloc>::value, int> >
863*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
864*700637cbSDimitry Andric    priority_queue&& __q, const _Alloc& __a)
865cb14a3feSDimitry Andric    : c(std::move(__q.c), __a), comp(std::move(__q.comp)) {}
866349cc55cSDimitry Andric
867349cc55cSDimitry Andric#  endif // _LIBCPP_CXX03_LANG
868349cc55cSDimitry Andric
869349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8700fca6ea1SDimitry Andrictemplate <
8710fca6ea1SDimitry Andric    class _InputIter,
8720fca6ea1SDimitry Andric    class _Alloc,
8730fca6ea1SDimitry Andric    __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
874*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
875*700637cbSDimitry Andric    _InputIter __f, _InputIter __l, const _Alloc& __a)
876cb14a3feSDimitry Andric    : c(__f, __l, __a), comp() {
8775f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
8780b57cec5SDimitry Andric}
8790b57cec5SDimitry Andric
880349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8810fca6ea1SDimitry Andrictemplate <
8820fca6ea1SDimitry Andric    class _InputIter,
8830fca6ea1SDimitry Andric    class _Alloc,
8840fca6ea1SDimitry Andric    __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
885*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
8860fca6ea1SDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp, const _Alloc& __a)
887cb14a3feSDimitry Andric    : c(__f, __l, __a), comp(__comp) {
8885f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
889349cc55cSDimitry Andric}
890349cc55cSDimitry Andric
891349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8920fca6ea1SDimitry Andrictemplate <
8930fca6ea1SDimitry Andric    class _InputIter,
8940fca6ea1SDimitry Andric    class _Alloc,
8950fca6ea1SDimitry Andric    __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
896*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
8970fca6ea1SDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp, const container_type& __c, const _Alloc& __a)
898cb14a3feSDimitry Andric    : c(__c, __a), comp(__comp) {
899349cc55cSDimitry Andric  c.insert(c.end(), __f, __l);
9005f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
901349cc55cSDimitry Andric}
902349cc55cSDimitry Andric
903349cc55cSDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
904349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9050fca6ea1SDimitry Andrictemplate <
9060fca6ea1SDimitry Andric    class _InputIter,
9070fca6ea1SDimitry Andric    class _Alloc,
9080fca6ea1SDimitry Andric    __enable_if_t<__has_input_iterator_category<_InputIter>::value && uses_allocator<_Container, _Alloc>::value, int> >
909*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline priority_queue<_Tp, _Container, _Compare>::priority_queue(
9100fca6ea1SDimitry Andric    _InputIter __f, _InputIter __l, const value_compare& __comp, container_type&& __c, const _Alloc& __a)
911cb14a3feSDimitry Andric    : c(std::move(__c), __a), comp(__comp) {
912349cc55cSDimitry Andric  c.insert(c.end(), __f, __l);
9135f757f3fSDimitry Andric  std::make_heap(c.begin(), c.end(), comp);
914349cc55cSDimitry Andric}
9150b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
9160b57cec5SDimitry Andric
9170b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
918*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) {
9190b57cec5SDimitry Andric  c.push_back(__v);
9205f757f3fSDimitry Andric  std::push_heap(c.begin(), c.end(), comp);
9210b57cec5SDimitry Andric}
9220b57cec5SDimitry Andric
9230b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
9240b57cec5SDimitry Andric
9250b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
926*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) {
9275f757f3fSDimitry Andric  c.push_back(std::move(__v));
9285f757f3fSDimitry Andric  std::push_heap(c.begin(), c.end(), comp);
9290b57cec5SDimitry Andric}
9300b57cec5SDimitry Andric
9310b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9320b57cec5SDimitry Andrictemplate <class... _Args>
933*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) {
9345f757f3fSDimitry Andric  c.emplace_back(std::forward<_Args>(__args)...);
9355f757f3fSDimitry Andric  std::push_heap(c.begin(), c.end(), comp);
9360b57cec5SDimitry Andric}
9370b57cec5SDimitry Andric
9380b57cec5SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
9390b57cec5SDimitry Andric
9400b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
941*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::pop() {
9425f757f3fSDimitry Andric  std::pop_heap(c.begin(), c.end(), comp);
9430b57cec5SDimitry Andric  c.pop_back();
9440b57cec5SDimitry Andric}
9450b57cec5SDimitry Andric
9460b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
947*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline void priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
9480fca6ea1SDimitry Andric    _NOEXCEPT_(__is_nothrow_swappable_v<container_type>&& __is_nothrow_swappable_v<value_compare>) {
9495f757f3fSDimitry Andric  using std::swap;
9500b57cec5SDimitry Andric  swap(c, __q.c);
9510b57cec5SDimitry Andric  swap(comp, __q.comp);
9520b57cec5SDimitry Andric}
9530b57cec5SDimitry Andric
954cb14a3feSDimitry Andrictemplate <class _Tp,
955cb14a3feSDimitry Andric          class _Container,
956cb14a3feSDimitry Andric          class _Compare,
9570fca6ea1SDimitry Andric          __enable_if_t<__is_swappable_v<_Container> && __is_swappable_v<_Compare>, int> = 0>
958*700637cbSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX26 inline _LIBCPP_HIDE_FROM_ABI void
959cb14a3feSDimitry Andricswap(priority_queue<_Tp, _Container, _Compare>& __x, priority_queue<_Tp, _Container, _Compare>& __y)
960cb14a3feSDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
9610b57cec5SDimitry Andric  __x.swap(__y);
9620b57cec5SDimitry Andric}
9630b57cec5SDimitry Andric
9640b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare, class _Alloc>
965*700637cbSDimitry Andricstruct uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> : public uses_allocator<_Container, _Alloc> {};
9660b57cec5SDimitry Andric
9670b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
9680b57cec5SDimitry Andric
969b3edf446SDimitry Andric_LIBCPP_POP_MACROS
970b3edf446SDimitry Andric
971bdd1243dSDimitry Andric#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
972bdd1243dSDimitry Andric#    include <concepts>
97306c3fb27SDimitry Andric#    include <cstdlib>
974bdd1243dSDimitry Andric#    include <functional>
97506c3fb27SDimitry Andric#    include <type_traits>
976bdd1243dSDimitry Andric#  endif
977*700637cbSDimitry Andric#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
978bdd1243dSDimitry Andric
9790b57cec5SDimitry Andric#endif // _LIBCPP_QUEUE
980