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
460b57cec5SDimitry Andric    template <class Alloc>
470b57cec5SDimitry Andric        explicit queue(const Alloc& a);
480b57cec5SDimitry Andric    template <class Alloc>
490b57cec5SDimitry Andric        queue(const container_type& c, const Alloc& a);
500b57cec5SDimitry Andric    template <class Alloc>
510b57cec5SDimitry Andric        queue(container_type&& c, const Alloc& a);
520b57cec5SDimitry Andric    template <class Alloc>
530b57cec5SDimitry Andric        queue(const queue& q, const Alloc& a);
540b57cec5SDimitry Andric    template <class Alloc>
550b57cec5SDimitry Andric        queue(queue&& q, const Alloc& a);
5604eeddc0SDimitry Andric    template <class InputIterator, class Alloc>
5704eeddc0SDimitry Andric        queue(InputIterator first, InputIterator last, const Alloc&); // since C++23
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    bool      empty() const;
600b57cec5SDimitry Andric    size_type size() const;
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric    reference       front();
630b57cec5SDimitry Andric    const_reference front() const;
640b57cec5SDimitry Andric    reference       back();
650b57cec5SDimitry Andric    const_reference back() const;
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric    void push(const value_type& v);
680b57cec5SDimitry Andric    void push(value_type&& v);
690b57cec5SDimitry Andric    template <class... Args> reference emplace(Args&&... args); // reference in C++17
700b57cec5SDimitry Andric    void pop();
710b57cec5SDimitry Andric
720b57cec5SDimitry Andric    void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
730b57cec5SDimitry Andric};
740b57cec5SDimitry Andric
750b57cec5SDimitry Andrictemplate<class Container>
760b57cec5SDimitry Andric  queue(Container) -> queue<typename Container::value_type, Container>; // C++17
770b57cec5SDimitry Andric
7804eeddc0SDimitry Andrictemplate<class InputIterator>
7904eeddc0SDimitry Andric  queue(InputIterator, InputIterator) -> queue<iter-value-type<InputIterator>>; // since C++23
8004eeddc0SDimitry Andric
810b57cec5SDimitry Andrictemplate<class Container, class Allocator>
820b57cec5SDimitry Andric  queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
830b57cec5SDimitry Andric
8404eeddc0SDimitry Andrictemplate<class InputIterator, class Allocator>
8504eeddc0SDimitry Andric  queue(InputIterator, InputIterator, Allocator)
8604eeddc0SDimitry Andric  -> queue<iter-value-type<InputIterator>,
8704eeddc0SDimitry Andric           deque<iter-value-type<InputIterator>, Allocator>>; // since C++23
8804eeddc0SDimitry Andric
890b57cec5SDimitry Andrictemplate <class T, class Container>
900b57cec5SDimitry Andric  bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
910b57cec5SDimitry Andric
920b57cec5SDimitry Andrictemplate <class T, class Container>
930b57cec5SDimitry Andric  bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
940b57cec5SDimitry Andric
950b57cec5SDimitry Andrictemplate <class T, class Container>
960b57cec5SDimitry Andric  bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
970b57cec5SDimitry Andric
980b57cec5SDimitry Andrictemplate <class T, class Container>
990b57cec5SDimitry Andric  bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
1000b57cec5SDimitry 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  void swap(queue<T, Container>& x, queue<T, Container>& y)
1090b57cec5SDimitry Andric  noexcept(noexcept(x.swap(y)));
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andrictemplate <class T, class Container = vector<T>,
1120b57cec5SDimitry Andric          class Compare = less<typename Container::value_type>>
1130b57cec5SDimitry Andricclass priority_queue
1140b57cec5SDimitry Andric{
1150b57cec5SDimitry Andricpublic:
1160b57cec5SDimitry Andric    typedef Container                                container_type;
1170b57cec5SDimitry Andric    typedef typename container_type::value_type      value_type;
1180b57cec5SDimitry Andric    typedef typename container_type::reference       reference;
1190b57cec5SDimitry Andric    typedef typename container_type::const_reference const_reference;
1200b57cec5SDimitry Andric    typedef typename container_type::size_type       size_type;
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andricprotected:
1230b57cec5SDimitry Andric    container_type c;
1240b57cec5SDimitry Andric    Compare comp;
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andricpublic:
127e8d8bef9SDimitry Andric    priority_queue() : priority_queue(Compare()) {} // C++20
128e8d8bef9SDimitry Andric    explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
129e8d8bef9SDimitry Andric    priority_queue(const Compare& x, const Container&);
130e8d8bef9SDimitry Andric    explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
131e8d8bef9SDimitry Andric    priority_queue(const Compare& x, Container&&); // C++20
1320b57cec5SDimitry Andric    template <class InputIterator>
1330b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
1340b57cec5SDimitry Andric                       const Compare& comp = Compare());
1350b57cec5SDimitry Andric    template <class InputIterator>
1360b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
137349cc55cSDimitry Andric                       const Compare& comp, const Container& c);
1380b57cec5SDimitry Andric    template <class InputIterator>
1390b57cec5SDimitry Andric        priority_queue(InputIterator first, InputIterator last,
140349cc55cSDimitry Andric                       const Compare& comp, Container&& c);
1410b57cec5SDimitry Andric    template <class Alloc>
1420b57cec5SDimitry Andric        explicit priority_queue(const Alloc& a);
1430b57cec5SDimitry Andric    template <class Alloc>
1440b57cec5SDimitry Andric        priority_queue(const Compare& comp, const Alloc& a);
1450b57cec5SDimitry Andric    template <class Alloc>
146349cc55cSDimitry Andric        priority_queue(const Compare& comp, const Container& c,
1470b57cec5SDimitry Andric                       const Alloc& a);
1480b57cec5SDimitry Andric    template <class Alloc>
149349cc55cSDimitry Andric        priority_queue(const Compare& comp, Container&& c,
1500b57cec5SDimitry Andric                       const Alloc& a);
151349cc55cSDimitry Andric    template <class InputIterator>
152349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
153349cc55cSDimitry Andric                       const Alloc& a);
154349cc55cSDimitry Andric    template <class InputIterator>
155349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
156349cc55cSDimitry Andric                       const Compare& comp, const Alloc& a);
157349cc55cSDimitry Andric    template <class InputIterator>
158349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
159349cc55cSDimitry Andric                       const Compare& comp, const Container& c, const Alloc& a);
160349cc55cSDimitry Andric    template <class InputIterator>
161349cc55cSDimitry Andric        priority_queue(InputIterator first, InputIterator last,
162349cc55cSDimitry Andric                       const Compare& comp, Container&& c, const Alloc& a);
1630b57cec5SDimitry Andric    template <class Alloc>
1640b57cec5SDimitry Andric        priority_queue(const priority_queue& q, const Alloc& a);
1650b57cec5SDimitry Andric    template <class Alloc>
1660b57cec5SDimitry Andric        priority_queue(priority_queue&& q, const Alloc& a);
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric    bool            empty() const;
1690b57cec5SDimitry Andric    size_type       size() const;
1700b57cec5SDimitry Andric    const_reference top() const;
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andric    void push(const value_type& v);
1730b57cec5SDimitry Andric    void push(value_type&& v);
1740b57cec5SDimitry Andric    template <class... Args> void emplace(Args&&... args);
1750b57cec5SDimitry Andric    void pop();
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric    void swap(priority_queue& q)
1780b57cec5SDimitry Andric        noexcept(is_nothrow_swappable_v<Container> &&
1790b57cec5SDimitry Andric                 is_nothrow_swappable_v<Comp>)
1800b57cec5SDimitry Andric};
1810b57cec5SDimitry Andric
1820b57cec5SDimitry Andrictemplate <class Compare, class Container>
1830b57cec5SDimitry Andricpriority_queue(Compare, Container)
1840b57cec5SDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andrictemplate<class InputIterator,
187349cc55cSDimitry Andric         class Compare = less<iter-value-type<InputIterator>>,
188349cc55cSDimitry Andric         class Container = vector<iter-value-type<InputIterator>>>
1890b57cec5SDimitry Andricpriority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
190349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andrictemplate<class Compare, class Container, class Allocator>
1930b57cec5SDimitry Andricpriority_queue(Compare, Container, Allocator)
1940b57cec5SDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
1950b57cec5SDimitry Andric
196349cc55cSDimitry Andrictemplate<class InputIterator, class Allocator>
197349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Allocator)
198349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>,
199349cc55cSDimitry Andric                      vector<iter-value-type<InputIterator>, Allocator>,
200349cc55cSDimitry Andric                      less<iter-value-type<InputIterator>>>; // C++17
201349cc55cSDimitry Andric
202349cc55cSDimitry Andrictemplate<class InputIterator, class Compare, class Allocator>
203349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Compare, Allocator)
204349cc55cSDimitry Andric    -> priority_queue<iter-value-type<InputIterator>,
205349cc55cSDimitry Andric                      vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
206349cc55cSDimitry Andric
207349cc55cSDimitry Andrictemplate<class InputIterator, class Compare, class Container, class Allocator>
208349cc55cSDimitry Andricpriority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
209349cc55cSDimitry Andric    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
210349cc55cSDimitry Andric
2110b57cec5SDimitry Andrictemplate <class T, class Container, class Compare>
2120b57cec5SDimitry Andric  void swap(priority_queue<T, Container, Compare>& x,
2130b57cec5SDimitry Andric            priority_queue<T, Container, Compare>& y)
2140b57cec5SDimitry Andric            noexcept(noexcept(x.swap(y)));
2150b57cec5SDimitry Andric
2160b57cec5SDimitry Andric}  // std
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andric*/
2190b57cec5SDimitry Andric
22081ad6265SDimitry Andric#include <__algorithm/make_heap.h>
22181ad6265SDimitry Andric#include <__algorithm/pop_heap.h>
22281ad6265SDimitry Andric#include <__algorithm/push_heap.h>
22381ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
2240b57cec5SDimitry Andric#include <__config>
22581ad6265SDimitry Andric#include <__functional/operations.h>
22604eeddc0SDimitry Andric#include <__iterator/iterator_traits.h>
227fe6060f1SDimitry Andric#include <__memory/uses_allocator.h>
228fe6060f1SDimitry Andric#include <__utility/forward.h>
229fe6060f1SDimitry Andric#include <deque>
23004eeddc0SDimitry Andric#include <type_traits>
231fe6060f1SDimitry Andric#include <vector>
23204eeddc0SDimitry Andric#include <version>
2330b57cec5SDimitry Andric
23481ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
23581ad6265SDimitry Andric#  include <functional>
23681ad6265SDimitry Andric#endif
23781ad6265SDimitry Andric
23881ad6265SDimitry Andric// standard-mandated includes
23981ad6265SDimitry Andric#include <compare>
24081ad6265SDimitry Andric#include <initializer_list>
24181ad6265SDimitry Andric
2420b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2430b57cec5SDimitry Andric#  pragma GCC system_header
2440b57cec5SDimitry Andric#endif
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andrictemplate <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
2510b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
2520b57cec5SDimitry Andricbool
2530b57cec5SDimitry Andricoperator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
2560b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
2570b57cec5SDimitry Andricbool
2580b57cec5SDimitry Andricoperator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
2590b57cec5SDimitry Andric
2600b57cec5SDimitry Andrictemplate <class _Tp, class _Container /*= deque<_Tp>*/>
2610b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS queue
2620b57cec5SDimitry Andric{
2630b57cec5SDimitry Andricpublic:
2640b57cec5SDimitry Andric    typedef _Container                               container_type;
2650b57cec5SDimitry Andric    typedef typename container_type::value_type      value_type;
2660b57cec5SDimitry Andric    typedef typename container_type::reference       reference;
2670b57cec5SDimitry Andric    typedef typename container_type::const_reference const_reference;
2680b57cec5SDimitry Andric    typedef typename container_type::size_type       size_type;
2690b57cec5SDimitry Andric    static_assert((is_same<_Tp, value_type>::value), "" );
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andricprotected:
2720b57cec5SDimitry Andric    container_type c;
2730b57cec5SDimitry Andric
2740b57cec5SDimitry Andricpublic:
2750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2760b57cec5SDimitry Andric    queue()
2770b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
2780b57cec5SDimitry Andric        : c() {}
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2810b57cec5SDimitry Andric    queue(const queue& __q) : c(__q.c) {}
2820b57cec5SDimitry Andric
28304eeddc0SDimitry Andric#if _LIBCPP_STD_VER > 20
28404eeddc0SDimitry Andric    template <class _InputIterator,
28504eeddc0SDimitry Andric              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
28604eeddc0SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
28704eeddc0SDimitry Andric    queue(_InputIterator __first, _InputIterator __last) : c(__first, __last) {}
28804eeddc0SDimitry Andric
28904eeddc0SDimitry Andric    template <class _InputIterator,
29004eeddc0SDimitry Andric              class _Alloc,
29104eeddc0SDimitry Andric              class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
29204eeddc0SDimitry Andric              class = __enable_if_t<uses_allocator<container_type, _Alloc>::value>>
29304eeddc0SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
29404eeddc0SDimitry Andric    queue(_InputIterator __first, _InputIterator __second, const _Alloc& __alloc) : c(__first, __second, __alloc) {}
29504eeddc0SDimitry Andric#endif
29604eeddc0SDimitry Andric
2970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2980b57cec5SDimitry Andric    queue& operator=(const queue& __q) {c = __q.c; return *this;}
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3020b57cec5SDimitry Andric    queue(queue&& __q)
3030b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
3040b57cec5SDimitry Andric        : c(_VSTD::move(__q.c)) {}
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3070b57cec5SDimitry Andric    queue& operator=(queue&& __q)
3080b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
3090b57cec5SDimitry Andric        {c = _VSTD::move(__q.c); return *this;}
3100b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3130b57cec5SDimitry Andric    explicit queue(const container_type& __c)  : c(__c) {}
3140b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3160b57cec5SDimitry Andric    explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
3170b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
3180b57cec5SDimitry Andric    template <class _Alloc>
3190b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3200b57cec5SDimitry Andric        explicit queue(const _Alloc& __a,
321349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
3220b57cec5SDimitry Andric            : c(__a) {}
3230b57cec5SDimitry Andric    template <class _Alloc>
3240b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3250b57cec5SDimitry Andric        queue(const queue& __q, const _Alloc& __a,
326349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
3270b57cec5SDimitry Andric            : c(__q.c, __a) {}
3280b57cec5SDimitry Andric    template <class _Alloc>
3290b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3300b57cec5SDimitry Andric        queue(const container_type& __c, const _Alloc& __a,
331349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
3320b57cec5SDimitry Andric            : c(__c, __a) {}
3330b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3340b57cec5SDimitry Andric    template <class _Alloc>
3350b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3360b57cec5SDimitry Andric        queue(container_type&& __c, const _Alloc& __a,
337349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
3380b57cec5SDimitry Andric            : c(_VSTD::move(__c), __a) {}
3390b57cec5SDimitry Andric    template <class _Alloc>
3400b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3410b57cec5SDimitry Andric        queue(queue&& __q, const _Alloc& __a,
342349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
3430b57cec5SDimitry Andric            : c(_VSTD::move(__q.c), __a) {}
3440b57cec5SDimitry Andric
3450b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
3480b57cec5SDimitry Andric    bool      empty() const {return c.empty();}
3490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3500b57cec5SDimitry Andric    size_type size() const  {return c.size();}
3510b57cec5SDimitry Andric
3520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3530b57cec5SDimitry Andric    reference       front()       {return c.front();}
3540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3550b57cec5SDimitry Andric    const_reference front() const {return c.front();}
3560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3570b57cec5SDimitry Andric    reference       back()        {return c.back();}
3580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3590b57cec5SDimitry Andric    const_reference back() const  {return c.back();}
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3620b57cec5SDimitry Andric    void push(const value_type& __v) {c.push_back(__v);}
3630b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3650b57cec5SDimitry Andric    void push(value_type&& __v)      {c.push_back(_VSTD::move(__v));}
3660b57cec5SDimitry Andric    template <class... _Args>
3670b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
3680b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
3690b57cec5SDimitry Andric        decltype(auto) emplace(_Args&&... __args)
3700b57cec5SDimitry Andric            { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
3710b57cec5SDimitry Andric#else
3720b57cec5SDimitry Andric        void     emplace(_Args&&... __args)
3730b57cec5SDimitry Andric            {        c.emplace_back(_VSTD::forward<_Args>(__args)...);}
3740b57cec5SDimitry Andric#endif
3750b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
3760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3770b57cec5SDimitry Andric    void pop() {c.pop_front();}
3780b57cec5SDimitry Andric
3790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3800b57cec5SDimitry Andric    void swap(queue& __q)
3810b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
3820b57cec5SDimitry Andric    {
3830b57cec5SDimitry Andric        using _VSTD::swap;
3840b57cec5SDimitry Andric        swap(c, __q.c);
3850b57cec5SDimitry Andric    }
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andric    template <class _T1, class _C1>
3880b57cec5SDimitry Andric    friend
3890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3900b57cec5SDimitry Andric    bool
3910b57cec5SDimitry Andric    operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
3920b57cec5SDimitry Andric
3930b57cec5SDimitry Andric    template <class _T1, class _C1>
3940b57cec5SDimitry Andric    friend
3950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3960b57cec5SDimitry Andric    bool
3970b57cec5SDimitry Andric    operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
3980b57cec5SDimitry Andric};
3990b57cec5SDimitry Andric
40004eeddc0SDimitry Andric#if _LIBCPP_STD_VER > 14
4010b57cec5SDimitry Andrictemplate<class _Container,
402349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Container>::value>
4030b57cec5SDimitry Andric>
4040b57cec5SDimitry Andricqueue(_Container)
4050b57cec5SDimitry Andric    -> queue<typename _Container::value_type, _Container>;
4060b57cec5SDimitry Andric
4070b57cec5SDimitry Andrictemplate<class _Container,
4080b57cec5SDimitry Andric         class _Alloc,
409349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Container>::value>,
410349cc55cSDimitry Andric         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
4110b57cec5SDimitry Andric>
4120b57cec5SDimitry Andricqueue(_Container, _Alloc)
4130b57cec5SDimitry Andric    -> queue<typename _Container::value_type, _Container>;
4140b57cec5SDimitry Andric#endif
4150b57cec5SDimitry Andric
41604eeddc0SDimitry Andric#if _LIBCPP_STD_VER > 20
41704eeddc0SDimitry Andrictemplate <class _InputIterator,
41804eeddc0SDimitry Andric          class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>>
41904eeddc0SDimitry Andricqueue(_InputIterator, _InputIterator)
42004eeddc0SDimitry Andric    -> queue<__iter_value_type<_InputIterator>>;
42104eeddc0SDimitry Andric
42204eeddc0SDimitry Andrictemplate <class _InputIterator,
42304eeddc0SDimitry Andric          class _Alloc,
42404eeddc0SDimitry Andric          class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
42504eeddc0SDimitry Andric          class = __enable_if_t<__is_allocator<_Alloc>::value>>
42604eeddc0SDimitry Andricqueue(_InputIterator, _InputIterator, _Alloc)
42704eeddc0SDimitry Andric    -> queue<__iter_value_type<_InputIterator>, deque<__iter_value_type<_InputIterator>, _Alloc>>;
42804eeddc0SDimitry Andric#endif
42904eeddc0SDimitry Andric
4300b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4320b57cec5SDimitry Andricbool
4330b57cec5SDimitry Andricoperator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4340b57cec5SDimitry Andric{
4350b57cec5SDimitry Andric    return __x.c == __y.c;
4360b57cec5SDimitry Andric}
4370b57cec5SDimitry Andric
4380b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4400b57cec5SDimitry Andricbool
4410b57cec5SDimitry Andricoperator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4420b57cec5SDimitry Andric{
4430b57cec5SDimitry Andric    return __x.c < __y.c;
4440b57cec5SDimitry Andric}
4450b57cec5SDimitry Andric
4460b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4480b57cec5SDimitry Andricbool
4490b57cec5SDimitry Andricoperator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4500b57cec5SDimitry Andric{
4510b57cec5SDimitry Andric    return !(__x == __y);
4520b57cec5SDimitry Andric}
4530b57cec5SDimitry Andric
4540b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4560b57cec5SDimitry Andricbool
4570b57cec5SDimitry Andricoperator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4580b57cec5SDimitry Andric{
4590b57cec5SDimitry Andric    return __y < __x;
4600b57cec5SDimitry Andric}
4610b57cec5SDimitry Andric
4620b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4640b57cec5SDimitry Andricbool
4650b57cec5SDimitry Andricoperator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4660b57cec5SDimitry Andric{
4670b57cec5SDimitry Andric    return !(__x < __y);
4680b57cec5SDimitry Andric}
4690b57cec5SDimitry Andric
4700b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4720b57cec5SDimitry Andricbool
4730b57cec5SDimitry Andricoperator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4740b57cec5SDimitry Andric{
4750b57cec5SDimitry Andric    return !(__y < __x);
4760b57cec5SDimitry Andric}
4770b57cec5SDimitry Andric
4780b57cec5SDimitry Andrictemplate <class _Tp, class _Container>
4790b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
480349cc55cSDimitry Andric__enable_if_t<__is_swappable<_Container>::value, void>
4810b57cec5SDimitry Andricswap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
4820b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
4830b57cec5SDimitry Andric{
4840b57cec5SDimitry Andric    __x.swap(__y);
4850b57cec5SDimitry Andric}
4860b57cec5SDimitry Andric
4870b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Alloc>
4880b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
4890b57cec5SDimitry Andric    : public uses_allocator<_Container, _Alloc>
4900b57cec5SDimitry Andric{
4910b57cec5SDimitry Andric};
4920b57cec5SDimitry Andric
4930b57cec5SDimitry Andrictemplate <class _Tp, class _Container = vector<_Tp>,
4940b57cec5SDimitry Andric          class _Compare = less<typename _Container::value_type> >
4950b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS priority_queue
4960b57cec5SDimitry Andric{
4970b57cec5SDimitry Andricpublic:
4980b57cec5SDimitry Andric    typedef _Container                               container_type;
4990b57cec5SDimitry Andric    typedef _Compare                                 value_compare;
5000b57cec5SDimitry Andric    typedef typename container_type::value_type      value_type;
5010b57cec5SDimitry Andric    typedef typename container_type::reference       reference;
5020b57cec5SDimitry Andric    typedef typename container_type::const_reference const_reference;
5030b57cec5SDimitry Andric    typedef typename container_type::size_type       size_type;
5040b57cec5SDimitry Andric    static_assert((is_same<_Tp, value_type>::value), "" );
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andricprotected:
5070b57cec5SDimitry Andric    container_type c;
5080b57cec5SDimitry Andric    value_compare comp;
5090b57cec5SDimitry Andric
5100b57cec5SDimitry Andricpublic:
5110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5120b57cec5SDimitry Andric    priority_queue()
5130b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
5140b57cec5SDimitry Andric                   is_nothrow_default_constructible<value_compare>::value)
5150b57cec5SDimitry Andric        : c(), comp() {}
5160b57cec5SDimitry Andric
5170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5180b57cec5SDimitry Andric    priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
5190b57cec5SDimitry Andric
5200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5210b57cec5SDimitry Andric    priority_queue& operator=(const priority_queue& __q)
5220b57cec5SDimitry Andric        {c = __q.c; comp = __q.comp; return *this;}
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5260b57cec5SDimitry Andric    priority_queue(priority_queue&& __q)
5270b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
5280b57cec5SDimitry Andric                   is_nothrow_move_constructible<value_compare>::value)
5290b57cec5SDimitry Andric        : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
5300b57cec5SDimitry Andric
5310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5320b57cec5SDimitry Andric    priority_queue& operator=(priority_queue&& __q)
5330b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
5340b57cec5SDimitry Andric                   is_nothrow_move_assignable<value_compare>::value)
5350b57cec5SDimitry Andric        {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
5360b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
5370b57cec5SDimitry Andric
5380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5390b57cec5SDimitry Andric    explicit priority_queue(const value_compare& __comp)
5400b57cec5SDimitry Andric        : c(), comp(__comp) {}
5410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5420b57cec5SDimitry Andric    priority_queue(const value_compare& __comp, const container_type& __c);
5430b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
545e8d8bef9SDimitry Andric    priority_queue(const value_compare& __comp, container_type&& __c);
5460b57cec5SDimitry Andric#endif
547349cc55cSDimitry Andric    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5480b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5490b57cec5SDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
5500b57cec5SDimitry Andric                       const value_compare& __comp = value_compare());
551349cc55cSDimitry Andric    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5520b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5530b57cec5SDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
5540b57cec5SDimitry Andric                       const value_compare& __comp, const container_type& __c);
5550b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
556349cc55cSDimitry Andric    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5570b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5580b57cec5SDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
5590b57cec5SDimitry Andric                       const value_compare& __comp, container_type&& __c);
5600b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
5610b57cec5SDimitry Andric    template <class _Alloc>
5620b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5630b57cec5SDimitry Andric        explicit priority_queue(const _Alloc& __a,
564349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5650b57cec5SDimitry Andric    template <class _Alloc>
5660b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5670b57cec5SDimitry Andric        priority_queue(const value_compare& __comp, const _Alloc& __a,
568349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5690b57cec5SDimitry Andric    template <class _Alloc>
5700b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5710b57cec5SDimitry Andric        priority_queue(const value_compare& __comp, const container_type& __c,
5720b57cec5SDimitry Andric                       const _Alloc& __a,
573349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5740b57cec5SDimitry Andric    template <class _Alloc>
5750b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5760b57cec5SDimitry Andric        priority_queue(const priority_queue& __q, const _Alloc& __a,
577349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5780b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5790b57cec5SDimitry Andric    template <class _Alloc>
5800b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5810b57cec5SDimitry Andric        priority_queue(const value_compare& __comp, container_type&& __c,
5820b57cec5SDimitry Andric                       const _Alloc& __a,
583349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5840b57cec5SDimitry Andric    template <class _Alloc>
5850b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
5860b57cec5SDimitry Andric        priority_queue(priority_queue&& __q, const _Alloc& __a,
587349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
588349cc55cSDimitry Andric#endif // _LIBCPP_CXX03_LANG
589349cc55cSDimitry Andric
590349cc55cSDimitry Andric    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
591349cc55cSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
592349cc55cSDimitry Andric        priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a,
593349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
594349cc55cSDimitry Andric
595349cc55cSDimitry Andric    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
596349cc55cSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
597349cc55cSDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
598349cc55cSDimitry Andric                       const value_compare& __comp, const _Alloc& __a,
599349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
600349cc55cSDimitry Andric
601349cc55cSDimitry Andric    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
602349cc55cSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
603349cc55cSDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
604349cc55cSDimitry Andric                       const value_compare& __comp, const container_type& __c, const _Alloc& __a,
605349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
606349cc55cSDimitry Andric
607349cc55cSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
608349cc55cSDimitry Andric    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
609349cc55cSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
610349cc55cSDimitry Andric        priority_queue(_InputIter __f, _InputIter __l,
611349cc55cSDimitry Andric                       const value_compare& __comp, container_type&& __c, const _Alloc& __a,
612349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
6130b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
6140b57cec5SDimitry Andric
6150b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
6160b57cec5SDimitry Andric    bool            empty() const {return c.empty();}
6170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6180b57cec5SDimitry Andric    size_type       size() const  {return c.size();}
6190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6200b57cec5SDimitry Andric    const_reference top() const   {return c.front();}
6210b57cec5SDimitry Andric
6220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6230b57cec5SDimitry Andric    void push(const value_type& __v);
6240b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
6250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6260b57cec5SDimitry Andric    void push(value_type&& __v);
6270b57cec5SDimitry Andric    template <class... _Args>
6280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6290b57cec5SDimitry Andric    void emplace(_Args&&... __args);
6300b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
6310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6320b57cec5SDimitry Andric    void pop();
6330b57cec5SDimitry Andric
6340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6350b57cec5SDimitry Andric    void swap(priority_queue& __q)
6360b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
6370b57cec5SDimitry Andric                   __is_nothrow_swappable<value_compare>::value);
6380b57cec5SDimitry Andric};
6390b57cec5SDimitry Andric
640349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
6410b57cec5SDimitry Andrictemplate <class _Compare,
6420b57cec5SDimitry Andric          class _Container,
643349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Compare>::value>,
644349cc55cSDimitry Andric          class = enable_if_t<!__is_allocator<_Container>::value>
6450b57cec5SDimitry Andric>
6460b57cec5SDimitry Andricpriority_queue(_Compare, _Container)
6470b57cec5SDimitry Andric    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
6480b57cec5SDimitry Andric
6490b57cec5SDimitry Andrictemplate<class _InputIterator,
650fe6060f1SDimitry Andric         class _Compare = less<__iter_value_type<_InputIterator>>,
651fe6060f1SDimitry Andric         class _Container = vector<__iter_value_type<_InputIterator>>,
652349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
653349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value>,
654349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Container>::value>
6550b57cec5SDimitry Andric>
6560b57cec5SDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
657fe6060f1SDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
6580b57cec5SDimitry Andric
6590b57cec5SDimitry Andrictemplate<class _Compare,
6600b57cec5SDimitry Andric         class _Container,
6610b57cec5SDimitry Andric         class _Alloc,
662349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value>,
663349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Container>::value>,
664349cc55cSDimitry Andric         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
6650b57cec5SDimitry Andric>
6660b57cec5SDimitry Andricpriority_queue(_Compare, _Container, _Alloc)
6670b57cec5SDimitry Andric    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
668349cc55cSDimitry Andric
669349cc55cSDimitry Andrictemplate<class _InputIterator, class _Allocator,
670349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
671349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value>
672349cc55cSDimitry Andric>
673349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Allocator)
674349cc55cSDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>,
675349cc55cSDimitry Andric                      vector<__iter_value_type<_InputIterator>, _Allocator>,
676349cc55cSDimitry Andric                      less<__iter_value_type<_InputIterator>>>;
677349cc55cSDimitry Andric
678349cc55cSDimitry Andrictemplate<class _InputIterator, class _Compare, class _Allocator,
679349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
680349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value>,
681349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value>
682349cc55cSDimitry Andric>
683349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
684349cc55cSDimitry Andric    -> priority_queue<__iter_value_type<_InputIterator>,
685349cc55cSDimitry Andric                      vector<__iter_value_type<_InputIterator>, _Allocator>, _Compare>;
686349cc55cSDimitry Andric
687349cc55cSDimitry Andrictemplate<class _InputIterator, class _Compare, class _Container, class _Alloc,
688349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
689349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Compare>::value>,
690349cc55cSDimitry Andric         class = enable_if_t<!__is_allocator<_Container>::value>,
691349cc55cSDimitry Andric         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
692349cc55cSDimitry Andric>
693349cc55cSDimitry Andricpriority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
694349cc55cSDimitry Andric    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
6950b57cec5SDimitry Andric#endif
6960b57cec5SDimitry Andric
6970b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
6980b57cec5SDimitry Andricinline
6990b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
7000b57cec5SDimitry Andric                                                          const container_type& __c)
7010b57cec5SDimitry Andric    : c(__c),
7020b57cec5SDimitry Andric      comp(__comp)
7030b57cec5SDimitry Andric{
7040b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7050b57cec5SDimitry Andric}
7060b57cec5SDimitry Andric
7070b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7080b57cec5SDimitry Andric
7090b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7100b57cec5SDimitry Andricinline
7110b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7120b57cec5SDimitry Andric                                                          container_type&& __c)
7130b57cec5SDimitry Andric    : c(_VSTD::move(__c)),
7140b57cec5SDimitry Andric      comp(__comp)
7150b57cec5SDimitry Andric{
7160b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7170b57cec5SDimitry Andric}
7180b57cec5SDimitry Andric
7190b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7200b57cec5SDimitry Andric
7210b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
722349cc55cSDimitry Andrictemplate <class _InputIter, class>
7230b57cec5SDimitry Andricinline
7240b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
7250b57cec5SDimitry Andric                                                          const value_compare& __comp)
7260b57cec5SDimitry Andric    : c(__f, __l),
7270b57cec5SDimitry Andric      comp(__comp)
7280b57cec5SDimitry Andric{
7290b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7300b57cec5SDimitry Andric}
7310b57cec5SDimitry Andric
7320b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
733349cc55cSDimitry Andrictemplate <class _InputIter, class>
7340b57cec5SDimitry Andricinline
7350b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
7360b57cec5SDimitry Andric                                                          const value_compare& __comp,
7370b57cec5SDimitry Andric                                                          const container_type& __c)
7380b57cec5SDimitry Andric    : c(__c),
7390b57cec5SDimitry Andric      comp(__comp)
7400b57cec5SDimitry Andric{
7410b57cec5SDimitry Andric    c.insert(c.end(), __f, __l);
7420b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7430b57cec5SDimitry Andric}
7440b57cec5SDimitry Andric
7450b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
748349cc55cSDimitry Andrictemplate <class _InputIter, class>
7490b57cec5SDimitry Andricinline
7500b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
7510b57cec5SDimitry Andric                                                          const value_compare& __comp,
7520b57cec5SDimitry Andric                                                          container_type&& __c)
7530b57cec5SDimitry Andric    : c(_VSTD::move(__c)),
7540b57cec5SDimitry Andric      comp(__comp)
7550b57cec5SDimitry Andric{
7560b57cec5SDimitry Andric    c.insert(c.end(), __f, __l);
7570b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7580b57cec5SDimitry Andric}
7590b57cec5SDimitry Andric
7600b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7610b57cec5SDimitry Andric
7620b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7630b57cec5SDimitry Andrictemplate <class _Alloc>
7640b57cec5SDimitry Andricinline
7650b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
766349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7670b57cec5SDimitry Andric    : c(__a)
7680b57cec5SDimitry Andric{
7690b57cec5SDimitry Andric}
7700b57cec5SDimitry Andric
7710b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7720b57cec5SDimitry Andrictemplate <class _Alloc>
7730b57cec5SDimitry Andricinline
7740b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7750b57cec5SDimitry Andric                                                          const _Alloc& __a,
776349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7770b57cec5SDimitry Andric    : c(__a),
7780b57cec5SDimitry Andric      comp(__comp)
7790b57cec5SDimitry Andric{
7800b57cec5SDimitry Andric}
7810b57cec5SDimitry Andric
7820b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7830b57cec5SDimitry Andrictemplate <class _Alloc>
7840b57cec5SDimitry Andricinline
7850b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7860b57cec5SDimitry Andric                                                          const container_type& __c,
7870b57cec5SDimitry Andric                                                          const _Alloc& __a,
788349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7890b57cec5SDimitry Andric    : c(__c, __a),
7900b57cec5SDimitry Andric      comp(__comp)
7910b57cec5SDimitry Andric{
7920b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
7930b57cec5SDimitry Andric}
7940b57cec5SDimitry Andric
7950b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
7960b57cec5SDimitry Andrictemplate <class _Alloc>
7970b57cec5SDimitry Andricinline
7980b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
7990b57cec5SDimitry Andric                                                          const _Alloc& __a,
800349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8010b57cec5SDimitry Andric    : c(__q.c, __a),
8020b57cec5SDimitry Andric      comp(__q.comp)
8030b57cec5SDimitry Andric{
8040b57cec5SDimitry Andric}
8050b57cec5SDimitry Andric
8060b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8070b57cec5SDimitry Andric
8080b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8090b57cec5SDimitry Andrictemplate <class _Alloc>
8100b57cec5SDimitry Andricinline
8110b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
8120b57cec5SDimitry Andric                                                          container_type&& __c,
8130b57cec5SDimitry Andric                                                          const _Alloc& __a,
814349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8150b57cec5SDimitry Andric    : c(_VSTD::move(__c), __a),
8160b57cec5SDimitry Andric      comp(__comp)
8170b57cec5SDimitry Andric{
8180b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
8190b57cec5SDimitry Andric}
8200b57cec5SDimitry Andric
8210b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8220b57cec5SDimitry Andrictemplate <class _Alloc>
8230b57cec5SDimitry Andricinline
8240b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
8250b57cec5SDimitry Andric                                                          const _Alloc& __a,
826349cc55cSDimitry Andric                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8270b57cec5SDimitry Andric    : c(_VSTD::move(__q.c), __a),
8280b57cec5SDimitry Andric      comp(_VSTD::move(__q.comp))
8290b57cec5SDimitry Andric{
830349cc55cSDimitry Andric}
831349cc55cSDimitry Andric
832349cc55cSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
833349cc55cSDimitry Andric
834349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
835349cc55cSDimitry Andrictemplate <class _InputIter, class _Alloc, class>
836349cc55cSDimitry Andricinline
837349cc55cSDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(
838349cc55cSDimitry Andric        _InputIter __f, _InputIter __l, const _Alloc& __a,
839349cc55cSDimitry Andric        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
840349cc55cSDimitry Andric    : c(__f, __l, __a),
841349cc55cSDimitry Andric      comp()
842349cc55cSDimitry Andric{
8430b57cec5SDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
8440b57cec5SDimitry Andric}
8450b57cec5SDimitry Andric
846349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
847349cc55cSDimitry Andrictemplate <class _InputIter, class _Alloc, class>
848349cc55cSDimitry Andricinline
849349cc55cSDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(
850349cc55cSDimitry Andric        _InputIter __f, _InputIter __l,
851349cc55cSDimitry Andric        const value_compare& __comp, const _Alloc& __a,
852349cc55cSDimitry Andric        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
853349cc55cSDimitry Andric    : c(__f, __l, __a),
854349cc55cSDimitry Andric      comp(__comp)
855349cc55cSDimitry Andric{
856349cc55cSDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
857349cc55cSDimitry Andric}
858349cc55cSDimitry Andric
859349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
860349cc55cSDimitry Andrictemplate <class _InputIter, class _Alloc, class>
861349cc55cSDimitry Andricinline
862349cc55cSDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(
863349cc55cSDimitry Andric        _InputIter __f, _InputIter __l,
864349cc55cSDimitry Andric        const value_compare& __comp, const container_type& __c, const _Alloc& __a,
865349cc55cSDimitry Andric        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
866349cc55cSDimitry Andric    : c(__c, __a),
867349cc55cSDimitry Andric      comp(__comp)
868349cc55cSDimitry Andric{
869349cc55cSDimitry Andric    c.insert(c.end(), __f, __l);
870349cc55cSDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
871349cc55cSDimitry Andric}
872349cc55cSDimitry Andric
873349cc55cSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
874349cc55cSDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
875349cc55cSDimitry Andrictemplate <class _InputIter, class _Alloc, class>
876349cc55cSDimitry Andricinline
877349cc55cSDimitry Andricpriority_queue<_Tp, _Container, _Compare>::priority_queue(
878349cc55cSDimitry Andric        _InputIter __f, _InputIter __l, const value_compare& __comp,
879349cc55cSDimitry Andric        container_type&& __c, const _Alloc& __a,
880349cc55cSDimitry Andric        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
881349cc55cSDimitry Andric    : c(_VSTD::move(__c), __a),
882349cc55cSDimitry Andric      comp(__comp)
883349cc55cSDimitry Andric{
884349cc55cSDimitry Andric    c.insert(c.end(), __f, __l);
885349cc55cSDimitry Andric    _VSTD::make_heap(c.begin(), c.end(), comp);
886349cc55cSDimitry Andric}
8870b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8880b57cec5SDimitry Andric
8890b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
8900b57cec5SDimitry Andricinline
8910b57cec5SDimitry Andricvoid
8920b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
8930b57cec5SDimitry Andric{
8940b57cec5SDimitry Andric    c.push_back(__v);
8950b57cec5SDimitry Andric    _VSTD::push_heap(c.begin(), c.end(), comp);
8960b57cec5SDimitry Andric}
8970b57cec5SDimitry Andric
8980b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8990b57cec5SDimitry Andric
9000b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9010b57cec5SDimitry Andricinline
9020b57cec5SDimitry Andricvoid
9030b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
9040b57cec5SDimitry Andric{
9050b57cec5SDimitry Andric    c.push_back(_VSTD::move(__v));
9060b57cec5SDimitry Andric    _VSTD::push_heap(c.begin(), c.end(), comp);
9070b57cec5SDimitry Andric}
9080b57cec5SDimitry Andric
9090b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9100b57cec5SDimitry Andrictemplate <class... _Args>
9110b57cec5SDimitry Andricinline
9120b57cec5SDimitry Andricvoid
9130b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
9140b57cec5SDimitry Andric{
9150b57cec5SDimitry Andric    c.emplace_back(_VSTD::forward<_Args>(__args)...);
9160b57cec5SDimitry Andric    _VSTD::push_heap(c.begin(), c.end(), comp);
9170b57cec5SDimitry Andric}
9180b57cec5SDimitry Andric
9190b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
9200b57cec5SDimitry Andric
9210b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9220b57cec5SDimitry Andricinline
9230b57cec5SDimitry Andricvoid
9240b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::pop()
9250b57cec5SDimitry Andric{
9260b57cec5SDimitry Andric    _VSTD::pop_heap(c.begin(), c.end(), comp);
9270b57cec5SDimitry Andric    c.pop_back();
9280b57cec5SDimitry Andric}
9290b57cec5SDimitry Andric
9300b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9310b57cec5SDimitry Andricinline
9320b57cec5SDimitry Andricvoid
9330b57cec5SDimitry Andricpriority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
9340b57cec5SDimitry Andric        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
9350b57cec5SDimitry Andric                   __is_nothrow_swappable<value_compare>::value)
9360b57cec5SDimitry Andric{
9370b57cec5SDimitry Andric    using _VSTD::swap;
9380b57cec5SDimitry Andric    swap(c, __q.c);
9390b57cec5SDimitry Andric    swap(comp, __q.comp);
9400b57cec5SDimitry Andric}
9410b57cec5SDimitry Andric
9420b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare>
9430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
944349cc55cSDimitry Andric__enable_if_t<
945fe6060f1SDimitry Andric    __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
9460b57cec5SDimitry Andric    void
947fe6060f1SDimitry Andric>
9480b57cec5SDimitry Andricswap(priority_queue<_Tp, _Container, _Compare>& __x,
9490b57cec5SDimitry Andric     priority_queue<_Tp, _Container, _Compare>& __y)
9500b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
9510b57cec5SDimitry Andric{
9520b57cec5SDimitry Andric    __x.swap(__y);
9530b57cec5SDimitry Andric}
9540b57cec5SDimitry Andric
9550b57cec5SDimitry Andrictemplate <class _Tp, class _Container, class _Compare, class _Alloc>
9560b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
9570b57cec5SDimitry Andric    : public uses_allocator<_Container, _Alloc>
9580b57cec5SDimitry Andric{
9590b57cec5SDimitry Andric};
9600b57cec5SDimitry Andric
9610b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
9620b57cec5SDimitry Andric
9630b57cec5SDimitry Andric#endif // _LIBCPP_QUEUE
964