xref: /llvm-project-15.0.7/libcxx/include/queue (revision bd6e6846)
13e519524SHoward Hinnant// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_QUEUE
113e519524SHoward Hinnant#define _LIBCPP_QUEUE
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    queue synopsis
153e519524SHoward Hinnant
163e519524SHoward Hinnantnamespace std
173e519524SHoward Hinnant{
183e519524SHoward Hinnant
193e519524SHoward Hinnanttemplate <class T, class Container = deque<T>>
203e519524SHoward Hinnantclass queue
213e519524SHoward Hinnant{
223e519524SHoward Hinnantpublic:
233e519524SHoward Hinnant    typedef Container                                container_type;
243e519524SHoward Hinnant    typedef typename container_type::value_type      value_type;
253e519524SHoward Hinnant    typedef typename container_type::reference       reference;
263e519524SHoward Hinnant    typedef typename container_type::const_reference const_reference;
273e519524SHoward Hinnant    typedef typename container_type::size_type       size_type;
283e519524SHoward Hinnant
293e519524SHoward Hinnantprotected:
303e519524SHoward Hinnant    container_type c;
313e519524SHoward Hinnant
323e519524SHoward Hinnantpublic:
336971d826SHoward Hinnant    queue() = default;
346971d826SHoward Hinnant    ~queue() = default;
356971d826SHoward Hinnant
366971d826SHoward Hinnant    queue(const queue& q) = default;
376971d826SHoward Hinnant    queue(queue&& q) = default;
386971d826SHoward Hinnant
396971d826SHoward Hinnant    queue& operator=(const queue& q) = default;
406971d826SHoward Hinnant    queue& operator=(queue&& q) = default;
416971d826SHoward Hinnant
423e519524SHoward Hinnant    explicit queue(const container_type& c);
436971d826SHoward Hinnant    explicit queue(container_type&& c)
443e519524SHoward Hinnant    template <class Alloc>
453e519524SHoward Hinnant        explicit queue(const Alloc& a);
463e519524SHoward Hinnant    template <class Alloc>
473e519524SHoward Hinnant        queue(const container_type& c, const Alloc& a);
483e519524SHoward Hinnant    template <class Alloc>
493e519524SHoward Hinnant        queue(container_type&& c, const Alloc& a);
503e519524SHoward Hinnant    template <class Alloc>
516971d826SHoward Hinnant        queue(const queue& q, const Alloc& a);
526971d826SHoward Hinnant    template <class Alloc>
533e519524SHoward Hinnant        queue(queue&& q, const Alloc& a);
543e519524SHoward Hinnant
553e519524SHoward Hinnant    bool      empty() const;
563e519524SHoward Hinnant    size_type size() const;
573e519524SHoward Hinnant
583e519524SHoward Hinnant    reference       front();
593e519524SHoward Hinnant    const_reference front() const;
603e519524SHoward Hinnant    reference       back();
613e519524SHoward Hinnant    const_reference back() const;
623e519524SHoward Hinnant
633e519524SHoward Hinnant    void push(const value_type& v);
643e519524SHoward Hinnant    void push(value_type&& v);
6563b560beSMarshall Clow    template <class... Args> reference emplace(Args&&... args); // reference in C++17
663e519524SHoward Hinnant    void pop();
673e519524SHoward Hinnant
68f07dd8d0SEric Fiselier    void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
693e519524SHoward Hinnant};
703e519524SHoward Hinnant
715b8b8b5dSMarshall Clowtemplate<class Container>
725b8b8b5dSMarshall Clow  queue(Container) -> queue<typename Container::value_type, Container>; // C++17
735b8b8b5dSMarshall Clow
745b8b8b5dSMarshall Clowtemplate<class Container, class Allocator>
755b8b8b5dSMarshall Clow  queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
765b8b8b5dSMarshall Clow
773e519524SHoward Hinnanttemplate <class T, class Container>
783e519524SHoward Hinnant  bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
793e519524SHoward Hinnant
803e519524SHoward Hinnanttemplate <class T, class Container>
813e519524SHoward Hinnant  bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
823e519524SHoward Hinnant
833e519524SHoward Hinnanttemplate <class T, class Container>
843e519524SHoward Hinnant  bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
853e519524SHoward Hinnant
863e519524SHoward Hinnanttemplate <class T, class Container>
873e519524SHoward Hinnant  bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
883e519524SHoward Hinnant
893e519524SHoward Hinnanttemplate <class T, class Container>
903e519524SHoward Hinnant  bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
913e519524SHoward Hinnant
923e519524SHoward Hinnanttemplate <class T, class Container>
933e519524SHoward Hinnant  bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
943e519524SHoward Hinnant
953e519524SHoward Hinnanttemplate <class T, class Container>
966971d826SHoward Hinnant  void swap(queue<T, Container>& x, queue<T, Container>& y)
976971d826SHoward Hinnant  noexcept(noexcept(x.swap(y)));
983e519524SHoward Hinnant
993e519524SHoward Hinnanttemplate <class T, class Container = vector<T>,
1003e519524SHoward Hinnant          class Compare = less<typename Container::value_type>>
1013e519524SHoward Hinnantclass priority_queue
1023e519524SHoward Hinnant{
1033e519524SHoward Hinnantpublic:
1043e519524SHoward Hinnant    typedef Container                                container_type;
1053e519524SHoward Hinnant    typedef typename container_type::value_type      value_type;
1063e519524SHoward Hinnant    typedef typename container_type::reference       reference;
1073e519524SHoward Hinnant    typedef typename container_type::const_reference const_reference;
1083e519524SHoward Hinnant    typedef typename container_type::size_type       size_type;
1093e519524SHoward Hinnant
1103e519524SHoward Hinnantprotected:
1113e519524SHoward Hinnant    container_type c;
1123e519524SHoward Hinnant    Compare comp;
1133e519524SHoward Hinnant
1143e519524SHoward Hinnantpublic:
115a11f8b1aSMarek Kurdej    priority_queue() : priority_queue(Compare()) {} // C++20
116a11f8b1aSMarek Kurdej    explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
117a11f8b1aSMarek Kurdej    priority_queue(const Compare& x, const Container&);
118a11f8b1aSMarek Kurdej    explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
119a11f8b1aSMarek Kurdej    priority_queue(const Compare& x, Container&&); // C++20
1203e519524SHoward Hinnant    template <class InputIterator>
1213e519524SHoward Hinnant        priority_queue(InputIterator first, InputIterator last,
1223e519524SHoward Hinnant                       const Compare& comp = Compare());
1233e519524SHoward Hinnant    template <class InputIterator>
1243e519524SHoward Hinnant        priority_queue(InputIterator first, InputIterator last,
1253894a8a4SArthur O'Dwyer                       const Compare& comp, const Container& c);
1263e519524SHoward Hinnant    template <class InputIterator>
1273e519524SHoward Hinnant        priority_queue(InputIterator first, InputIterator last,
1283894a8a4SArthur O'Dwyer                       const Compare& comp, Container&& c);
1293e519524SHoward Hinnant    template <class Alloc>
1303e519524SHoward Hinnant        explicit priority_queue(const Alloc& a);
1313e519524SHoward Hinnant    template <class Alloc>
1323e519524SHoward Hinnant        priority_queue(const Compare& comp, const Alloc& a);
1333e519524SHoward Hinnant    template <class Alloc>
1343894a8a4SArthur O'Dwyer        priority_queue(const Compare& comp, const Container& c,
1353e519524SHoward Hinnant                       const Alloc& a);
1363e519524SHoward Hinnant    template <class Alloc>
1373894a8a4SArthur O'Dwyer        priority_queue(const Compare& comp, Container&& c,
1383e519524SHoward Hinnant                       const Alloc& a);
1393894a8a4SArthur O'Dwyer    template <class InputIterator>
1403894a8a4SArthur O'Dwyer        priority_queue(InputIterator first, InputIterator last,
1413894a8a4SArthur O'Dwyer                       const Alloc& a);
1423894a8a4SArthur O'Dwyer    template <class InputIterator>
1433894a8a4SArthur O'Dwyer        priority_queue(InputIterator first, InputIterator last,
1443894a8a4SArthur O'Dwyer                       const Compare& comp, const Alloc& a);
1453894a8a4SArthur O'Dwyer    template <class InputIterator>
1463894a8a4SArthur O'Dwyer        priority_queue(InputIterator first, InputIterator last,
1473894a8a4SArthur O'Dwyer                       const Compare& comp, const Container& c, const Alloc& a);
1483894a8a4SArthur O'Dwyer    template <class InputIterator>
1493894a8a4SArthur O'Dwyer        priority_queue(InputIterator first, InputIterator last,
1503894a8a4SArthur O'Dwyer                       const Compare& comp, Container&& c, const Alloc& a);
1513e519524SHoward Hinnant    template <class Alloc>
1526971d826SHoward Hinnant        priority_queue(const priority_queue& q, const Alloc& a);
1536971d826SHoward Hinnant    template <class Alloc>
1543e519524SHoward Hinnant        priority_queue(priority_queue&& q, const Alloc& a);
1553e519524SHoward Hinnant
1563e519524SHoward Hinnant    bool            empty() const;
1573e519524SHoward Hinnant    size_type       size() const;
1583e519524SHoward Hinnant    const_reference top() const;
1593e519524SHoward Hinnant
1603e519524SHoward Hinnant    void push(const value_type& v);
1613e519524SHoward Hinnant    void push(value_type&& v);
1623e519524SHoward Hinnant    template <class... Args> void emplace(Args&&... args);
1633e519524SHoward Hinnant    void pop();
1643e519524SHoward Hinnant
1656971d826SHoward Hinnant    void swap(priority_queue& q)
166f07dd8d0SEric Fiselier        noexcept(is_nothrow_swappable_v<Container> &&
167f07dd8d0SEric Fiselier                 is_nothrow_swappable_v<Comp>)
1683e519524SHoward Hinnant};
1693e519524SHoward Hinnant
1705b8b8b5dSMarshall Clowtemplate <class Compare, class Container>
1715b8b8b5dSMarshall Clowpriority_queue(Compare, Container)
1725b8b8b5dSMarshall Clow    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
1735b8b8b5dSMarshall Clow
1745b8b8b5dSMarshall Clowtemplate<class InputIterator,
1753894a8a4SArthur O'Dwyer         class Compare = less<iter-value-type<InputIterator>>,
1763894a8a4SArthur O'Dwyer         class Container = vector<iter-value-type<InputIterator>>>
1775b8b8b5dSMarshall Clowpriority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
1783894a8a4SArthur O'Dwyer    -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
1795b8b8b5dSMarshall Clow
1805b8b8b5dSMarshall Clowtemplate<class Compare, class Container, class Allocator>
1815b8b8b5dSMarshall Clowpriority_queue(Compare, Container, Allocator)
1825b8b8b5dSMarshall Clow    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
1835b8b8b5dSMarshall Clow
1843894a8a4SArthur O'Dwyertemplate<class InputIterator, class Allocator>
1853894a8a4SArthur O'Dwyerpriority_queue(InputIterator, InputIterator, Allocator)
1863894a8a4SArthur O'Dwyer    -> priority_queue<iter-value-type<InputIterator>,
1873894a8a4SArthur O'Dwyer                      vector<iter-value-type<InputIterator>, Allocator>,
18868072a71SKonstantin Varlamov                      less<iter-value-type<InputIterator>>>; // C++17
1893894a8a4SArthur O'Dwyer
1903894a8a4SArthur O'Dwyertemplate<class InputIterator, class Compare, class Allocator>
1913894a8a4SArthur O'Dwyerpriority_queue(InputIterator, InputIterator, Compare, Allocator)
1923894a8a4SArthur O'Dwyer    -> priority_queue<iter-value-type<InputIterator>,
19368072a71SKonstantin Varlamov                      vector<iter-value-type<InputIterator>, Allocator>, Compare>; // C++17
1943894a8a4SArthur O'Dwyer
1953894a8a4SArthur O'Dwyertemplate<class InputIterator, class Compare, class Container, class Allocator>
1963894a8a4SArthur O'Dwyerpriority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
19768072a71SKonstantin Varlamov    -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
1983894a8a4SArthur O'Dwyer
1993e519524SHoward Hinnanttemplate <class T, class Container, class Compare>
2003e519524SHoward Hinnant  void swap(priority_queue<T, Container, Compare>& x,
2016971d826SHoward Hinnant            priority_queue<T, Container, Compare>& y)
2026971d826SHoward Hinnant            noexcept(noexcept(x.swap(y)));
2033e519524SHoward Hinnant
2043e519524SHoward Hinnant}  // std
2053e519524SHoward Hinnant
2063e519524SHoward Hinnant*/
2073e519524SHoward Hinnant
2083e519524SHoward Hinnant#include <__config>
209050b064fSChristopher Di Bella#include <__memory/uses_allocator.h>
2106adbc83eSChristopher Di Bella#include <__utility/forward.h>
211bfbd73f8SArthur O'Dwyer#include <algorithm>
2122d0f1fa4SArthur O'Dwyer#include <compare>
2133e519524SHoward Hinnant#include <deque>
2143e519524SHoward Hinnant#include <functional>
215bfbd73f8SArthur O'Dwyer#include <vector>
216*bd6e6846SMark de Wever#include <version>
2173e519524SHoward Hinnant
218073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2193e519524SHoward Hinnant#pragma GCC system_header
220073458b1SHoward Hinnant#endif
2213e519524SHoward Hinnant
2223e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
2233e519524SHoward Hinnant
224e2f2d1edSEric Fiseliertemplate <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
2253e519524SHoward Hinnant
2263e519524SHoward Hinnanttemplate <class _Tp, class _Container>
227aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
2283e519524SHoward Hinnantbool
2293e519524SHoward Hinnantoperator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
2303e519524SHoward Hinnant
2313e519524SHoward Hinnanttemplate <class _Tp, class _Container>
232aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
2333e519524SHoward Hinnantbool
2343e519524SHoward Hinnantoperator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
2353e519524SHoward Hinnant
2363afa22a3SMarshall Clowtemplate <class _Tp, class _Container /*= deque<_Tp>*/>
237e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS queue
2383e519524SHoward Hinnant{
2393e519524SHoward Hinnantpublic:
2403e519524SHoward Hinnant    typedef _Container                               container_type;
2413e519524SHoward Hinnant    typedef typename container_type::value_type      value_type;
2423e519524SHoward Hinnant    typedef typename container_type::reference       reference;
2433e519524SHoward Hinnant    typedef typename container_type::const_reference const_reference;
2443e519524SHoward Hinnant    typedef typename container_type::size_type       size_type;
245c1fe2c43SMarshall Clow    static_assert((is_same<_Tp, value_type>::value), "" );
2463e519524SHoward Hinnant
2473e519524SHoward Hinnantprotected:
2483e519524SHoward Hinnant    container_type c;
2493e519524SHoward Hinnant
2503e519524SHoward Hinnantpublic:
251392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
2526971d826SHoward Hinnant    queue()
2536971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
2546971d826SHoward Hinnant        : c() {}
2556971d826SHoward Hinnant
2566971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
2576971d826SHoward Hinnant    queue(const queue& __q) : c(__q.c) {}
2586971d826SHoward Hinnant
259f5427b26SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
260f5427b26SEric Fiselier    queue& operator=(const queue& __q) {c = __q.c; return *this;}
261f5427b26SEric Fiselier
262f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
2636971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
2646971d826SHoward Hinnant    queue(queue&& __q)
2656971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
266ce48a113SHoward Hinnant        : c(_VSTD::move(__q.c)) {}
2676971d826SHoward Hinnant
2686971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
2696971d826SHoward Hinnant    queue& operator=(queue&& __q)
2706971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
271ce48a113SHoward Hinnant        {c = _VSTD::move(__q.c); return *this;}
272f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
2736971d826SHoward Hinnant
274392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
2753e519524SHoward Hinnant    explicit queue(const container_type& __c)  : c(__c) {}
276f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
277392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
278ce48a113SHoward Hinnant    explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
279f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
2803e519524SHoward Hinnant    template <class _Alloc>
281392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2823e519524SHoward Hinnant        explicit queue(const _Alloc& __a,
283b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
2843e519524SHoward Hinnant            : c(__a) {}
2853e519524SHoward Hinnant    template <class _Alloc>
286392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2873e519524SHoward Hinnant        queue(const queue& __q, const _Alloc& __a,
288b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
2893e519524SHoward Hinnant            : c(__q.c, __a) {}
2903e519524SHoward Hinnant    template <class _Alloc>
291392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2923e519524SHoward Hinnant        queue(const container_type& __c, const _Alloc& __a,
293b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
2943e519524SHoward Hinnant            : c(__c, __a) {}
295f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
2963e519524SHoward Hinnant    template <class _Alloc>
297392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2983e519524SHoward Hinnant        queue(container_type&& __c, const _Alloc& __a,
299b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
300ce48a113SHoward Hinnant            : c(_VSTD::move(__c), __a) {}
3013e519524SHoward Hinnant    template <class _Alloc>
302392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
3033e519524SHoward Hinnant        queue(queue&& __q, const _Alloc& __a,
304b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
305ce48a113SHoward Hinnant            : c(_VSTD::move(__q.c), __a) {}
3063e519524SHoward Hinnant
307f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
3083e519524SHoward Hinnant
30972c8fad4SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
3103e519524SHoward Hinnant    bool      empty() const {return c.empty();}
311392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3123e519524SHoward Hinnant    size_type size() const  {return c.size();}
3133e519524SHoward Hinnant
314392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3153e519524SHoward Hinnant    reference       front()       {return c.front();}
316392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3173e519524SHoward Hinnant    const_reference front() const {return c.front();}
318392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3193e519524SHoward Hinnant    reference       back()        {return c.back();}
320392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3213e519524SHoward Hinnant    const_reference back() const  {return c.back();}
3223e519524SHoward Hinnant
323392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3243e519524SHoward Hinnant    void push(const value_type& __v) {c.push_back(__v);}
325f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
326392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
327ce48a113SHoward Hinnant    void push(value_type&& __v)      {c.push_back(_VSTD::move(__v));}
3283e519524SHoward Hinnant    template <class... _Args>
329392183f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
33063b560beSMarshall Clow#if _LIBCPP_STD_VER > 14
331e34f5ffeSMarshall Clow        decltype(auto) emplace(_Args&&... __args)
3320e411641SEric Fiselier            { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
33363b560beSMarshall Clow#else
33463b560beSMarshall Clow        void     emplace(_Args&&... __args)
33563b560beSMarshall Clow            {        c.emplace_back(_VSTD::forward<_Args>(__args)...);}
33663b560beSMarshall Clow#endif
337f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
338392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3393e519524SHoward Hinnant    void pop() {c.pop_front();}
3403e519524SHoward Hinnant
341392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3423e519524SHoward Hinnant    void swap(queue& __q)
3436971d826SHoward Hinnant        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
3443e519524SHoward Hinnant    {
345ce48a113SHoward Hinnant        using _VSTD::swap;
3463e519524SHoward Hinnant        swap(c, __q.c);
3473e519524SHoward Hinnant    }
3483e519524SHoward Hinnant
3493e519524SHoward Hinnant    template <class _T1, class _C1>
3503e519524SHoward Hinnant    friend
351392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3523e519524SHoward Hinnant    bool
3533e519524SHoward Hinnant    operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
3543e519524SHoward Hinnant
3553e519524SHoward Hinnant    template <class _T1, class _C1>
3563e519524SHoward Hinnant    friend
357392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
3583e519524SHoward Hinnant    bool
3593e519524SHoward Hinnant    operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
3603e519524SHoward Hinnant};
3613e519524SHoward Hinnant
36201666904SLouis Dionne#if _LIBCPP_STD_VER >= 17
3635b8b8b5dSMarshall Clowtemplate<class _Container,
3644e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Container>::value>
3655b8b8b5dSMarshall Clow>
3665b8b8b5dSMarshall Clowqueue(_Container)
3675b8b8b5dSMarshall Clow    -> queue<typename _Container::value_type, _Container>;
3685b8b8b5dSMarshall Clow
3695b8b8b5dSMarshall Clowtemplate<class _Container,
3705b8b8b5dSMarshall Clow         class _Alloc,
3714e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Container>::value>,
3724e0ea2cfSLouis Dionne         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
3735b8b8b5dSMarshall Clow>
3745b8b8b5dSMarshall Clowqueue(_Container, _Alloc)
3755b8b8b5dSMarshall Clow    -> queue<typename _Container::value_type, _Container>;
3765b8b8b5dSMarshall Clow#endif
3775b8b8b5dSMarshall Clow
3783e519524SHoward Hinnanttemplate <class _Tp, class _Container>
379392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3803e519524SHoward Hinnantbool
3813e519524SHoward Hinnantoperator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
3823e519524SHoward Hinnant{
3833e519524SHoward Hinnant    return __x.c == __y.c;
3843e519524SHoward Hinnant}
3853e519524SHoward Hinnant
3863e519524SHoward Hinnanttemplate <class _Tp, class _Container>
387392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3883e519524SHoward Hinnantbool
3893e519524SHoward Hinnantoperator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
3903e519524SHoward Hinnant{
3913e519524SHoward Hinnant    return __x.c < __y.c;
3923e519524SHoward Hinnant}
3933e519524SHoward Hinnant
3943e519524SHoward Hinnanttemplate <class _Tp, class _Container>
395392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
3963e519524SHoward Hinnantbool
3973e519524SHoward Hinnantoperator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
3983e519524SHoward Hinnant{
3993e519524SHoward Hinnant    return !(__x == __y);
4003e519524SHoward Hinnant}
4013e519524SHoward Hinnant
4023e519524SHoward Hinnanttemplate <class _Tp, class _Container>
403392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4043e519524SHoward Hinnantbool
4053e519524SHoward Hinnantoperator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4063e519524SHoward Hinnant{
4073e519524SHoward Hinnant    return __y < __x;
4083e519524SHoward Hinnant}
4093e519524SHoward Hinnant
4103e519524SHoward Hinnanttemplate <class _Tp, class _Container>
411392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4123e519524SHoward Hinnantbool
4133e519524SHoward Hinnantoperator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4143e519524SHoward Hinnant{
4153e519524SHoward Hinnant    return !(__x < __y);
4163e519524SHoward Hinnant}
4173e519524SHoward Hinnant
4183e519524SHoward Hinnanttemplate <class _Tp, class _Container>
419392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
4203e519524SHoward Hinnantbool
4213e519524SHoward Hinnantoperator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
4223e519524SHoward Hinnant{
4233e519524SHoward Hinnant    return !(__y < __x);
4243e519524SHoward Hinnant}
4253e519524SHoward Hinnant
4263e519524SHoward Hinnanttemplate <class _Tp, class _Container>
427392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
428b4e88d4dSLouis Dionne__enable_if_t<__is_swappable<_Container>::value, void>
4293e519524SHoward Hinnantswap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
4306971d826SHoward Hinnant    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
4313e519524SHoward Hinnant{
4323e519524SHoward Hinnant    __x.swap(__y);
4333e519524SHoward Hinnant}
4343e519524SHoward Hinnant
4353e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Alloc>
436e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
4373e519524SHoward Hinnant    : public uses_allocator<_Container, _Alloc>
4383e519524SHoward Hinnant{
4393e519524SHoward Hinnant};
4403e519524SHoward Hinnant
4413e519524SHoward Hinnanttemplate <class _Tp, class _Container = vector<_Tp>,
4423e519524SHoward Hinnant          class _Compare = less<typename _Container::value_type> >
443e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS priority_queue
4443e519524SHoward Hinnant{
4453e519524SHoward Hinnantpublic:
4463e519524SHoward Hinnant    typedef _Container                               container_type;
4473e519524SHoward Hinnant    typedef _Compare                                 value_compare;
4483e519524SHoward Hinnant    typedef typename container_type::value_type      value_type;
4493e519524SHoward Hinnant    typedef typename container_type::reference       reference;
4503e519524SHoward Hinnant    typedef typename container_type::const_reference const_reference;
4513e519524SHoward Hinnant    typedef typename container_type::size_type       size_type;
452c1fe2c43SMarshall Clow    static_assert((is_same<_Tp, value_type>::value), "" );
4533e519524SHoward Hinnant
4543e519524SHoward Hinnantprotected:
4553e519524SHoward Hinnant    container_type c;
4563e519524SHoward Hinnant    value_compare comp;
4573e519524SHoward Hinnant
4583e519524SHoward Hinnantpublic:
459392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
4606971d826SHoward Hinnant    priority_queue()
4616971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
4626971d826SHoward Hinnant                   is_nothrow_default_constructible<value_compare>::value)
4636971d826SHoward Hinnant        : c(), comp() {}
4646971d826SHoward Hinnant
4656971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
4666971d826SHoward Hinnant    priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
4676971d826SHoward Hinnant
468f5427b26SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
469f5427b26SEric Fiselier    priority_queue& operator=(const priority_queue& __q)
470f5427b26SEric Fiselier        {c = __q.c; comp = __q.comp; return *this;}
471f5427b26SEric Fiselier
472f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
4736971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
4746971d826SHoward Hinnant    priority_queue(priority_queue&& __q)
4756971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
4766971d826SHoward Hinnant                   is_nothrow_move_constructible<value_compare>::value)
477ce48a113SHoward Hinnant        : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
4786971d826SHoward Hinnant
4796971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
4806971d826SHoward Hinnant    priority_queue& operator=(priority_queue&& __q)
4816971d826SHoward Hinnant        _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
4826971d826SHoward Hinnant                   is_nothrow_move_assignable<value_compare>::value)
483ce48a113SHoward Hinnant        {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
484f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
4856971d826SHoward Hinnant
4866971d826SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
4876971d826SHoward Hinnant    explicit priority_queue(const value_compare& __comp)
4883e519524SHoward Hinnant        : c(), comp(__comp) {}
489cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
4903e519524SHoward Hinnant    priority_queue(const value_compare& __comp, const container_type& __c);
491f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
492cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
493a11f8b1aSMarek Kurdej    priority_queue(const value_compare& __comp, container_type&& __c);
4943e519524SHoward Hinnant#endif
495b4e88d4dSLouis Dionne    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
496cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
4973e519524SHoward Hinnant        priority_queue(_InputIter __f, _InputIter __l,
4983e519524SHoward Hinnant                       const value_compare& __comp = value_compare());
499b4e88d4dSLouis Dionne    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
500cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5013e519524SHoward Hinnant        priority_queue(_InputIter __f, _InputIter __l,
5023e519524SHoward Hinnant                       const value_compare& __comp, const container_type& __c);
503f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
504b4e88d4dSLouis Dionne    template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
505cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5063e519524SHoward Hinnant        priority_queue(_InputIter __f, _InputIter __l,
5073e519524SHoward Hinnant                       const value_compare& __comp, container_type&& __c);
508f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
5093e519524SHoward Hinnant    template <class _Alloc>
510cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5113e519524SHoward Hinnant        explicit priority_queue(const _Alloc& __a,
512b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5133e519524SHoward Hinnant    template <class _Alloc>
514cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5153e519524SHoward Hinnant        priority_queue(const value_compare& __comp, const _Alloc& __a,
516b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5173e519524SHoward Hinnant    template <class _Alloc>
518cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5193e519524SHoward Hinnant        priority_queue(const value_compare& __comp, const container_type& __c,
5203e519524SHoward Hinnant                       const _Alloc& __a,
521b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5223e519524SHoward Hinnant    template <class _Alloc>
523cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5243e519524SHoward Hinnant        priority_queue(const priority_queue& __q, const _Alloc& __a,
525b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
526f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
5273e519524SHoward Hinnant    template <class _Alloc>
528cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5293e519524SHoward Hinnant        priority_queue(const value_compare& __comp, container_type&& __c,
5303e519524SHoward Hinnant                       const _Alloc& __a,
531b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5323e519524SHoward Hinnant    template <class _Alloc>
533cd31b434SEvgeniy Stepanov        _LIBCPP_INLINE_VISIBILITY
5343e519524SHoward Hinnant        priority_queue(priority_queue&& __q, const _Alloc& __a,
535b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
536f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
5373e519524SHoward Hinnant
538b4e88d4dSLouis Dionne    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5393894a8a4SArthur O'Dwyer        _LIBCPP_INLINE_VISIBILITY
5403894a8a4SArthur O'Dwyer        priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a,
541b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5423894a8a4SArthur O'Dwyer
543b4e88d4dSLouis Dionne    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5443894a8a4SArthur O'Dwyer        _LIBCPP_INLINE_VISIBILITY
5453894a8a4SArthur O'Dwyer        priority_queue(_InputIter __f, _InputIter __l,
5463894a8a4SArthur O'Dwyer                       const value_compare& __comp, const _Alloc& __a,
547b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5483894a8a4SArthur O'Dwyer
549b4e88d4dSLouis Dionne    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5503894a8a4SArthur O'Dwyer        _LIBCPP_INLINE_VISIBILITY
5513894a8a4SArthur O'Dwyer        priority_queue(_InputIter __f, _InputIter __l,
5523894a8a4SArthur O'Dwyer                       const value_compare& __comp, const container_type& __c, const _Alloc& __a,
553b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5543894a8a4SArthur O'Dwyer
5553894a8a4SArthur O'Dwyer#ifndef _LIBCPP_CXX03_LANG
556b4e88d4dSLouis Dionne    template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
5573894a8a4SArthur O'Dwyer        _LIBCPP_INLINE_VISIBILITY
5583894a8a4SArthur O'Dwyer        priority_queue(_InputIter __f, _InputIter __l,
5593894a8a4SArthur O'Dwyer                       const value_compare& __comp, container_type&& __c, const _Alloc& __a,
560b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
5613894a8a4SArthur O'Dwyer#endif  // _LIBCPP_CXX03_LANG
5623894a8a4SArthur O'Dwyer
56372c8fad4SMarshall Clow    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5643e519524SHoward Hinnant    bool            empty() const {return c.empty();}
565392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
5663e519524SHoward Hinnant    size_type       size() const  {return c.size();}
567392183f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
5683e519524SHoward Hinnant    const_reference top() const   {return c.front();}
5693e519524SHoward Hinnant
570cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
5713e519524SHoward Hinnant    void push(const value_type& __v);
572f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
573cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
5743e519524SHoward Hinnant    void push(value_type&& __v);
575f5427b26SEric Fiselier    template <class... _Args>
576f5427b26SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
577f5427b26SEric Fiselier    void emplace(_Args&&... __args);
578f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
579cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
5803e519524SHoward Hinnant    void pop();
5813e519524SHoward Hinnant
582cd31b434SEvgeniy Stepanov    _LIBCPP_INLINE_VISIBILITY
5836971d826SHoward Hinnant    void swap(priority_queue& __q)
5846971d826SHoward Hinnant        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
5856971d826SHoward Hinnant                   __is_nothrow_swappable<value_compare>::value);
5863e519524SHoward Hinnant};
5873e519524SHoward Hinnant
58801666904SLouis Dionne#if _LIBCPP_STD_VER >= 17
5895b8b8b5dSMarshall Clowtemplate <class _Compare,
5905b8b8b5dSMarshall Clow          class _Container,
5914e0ea2cfSLouis Dionne          class = enable_if_t<!__is_allocator<_Compare>::value>,
5924e0ea2cfSLouis Dionne          class = enable_if_t<!__is_allocator<_Container>::value>
5935b8b8b5dSMarshall Clow>
5945b8b8b5dSMarshall Clowpriority_queue(_Compare, _Container)
5955b8b8b5dSMarshall Clow    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
5965b8b8b5dSMarshall Clow
5975b8b8b5dSMarshall Clowtemplate<class _InputIterator,
598199d2ebeSArthur O'Dwyer         class _Compare = less<__iter_value_type<_InputIterator>>,
599199d2ebeSArthur O'Dwyer         class _Container = vector<__iter_value_type<_InputIterator>>,
6004e0ea2cfSLouis Dionne         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
6014e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Compare>::value>,
6024e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Container>::value>
6035b8b8b5dSMarshall Clow>
6045b8b8b5dSMarshall Clowpriority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
605199d2ebeSArthur O'Dwyer    -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
6065b8b8b5dSMarshall Clow
6075b8b8b5dSMarshall Clowtemplate<class _Compare,
6085b8b8b5dSMarshall Clow         class _Container,
6095b8b8b5dSMarshall Clow         class _Alloc,
6104e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Compare>::value>,
6114e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Container>::value>,
6124e0ea2cfSLouis Dionne         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
6135b8b8b5dSMarshall Clow>
6145b8b8b5dSMarshall Clowpriority_queue(_Compare, _Container, _Alloc)
6155b8b8b5dSMarshall Clow    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
6163894a8a4SArthur O'Dwyer
6173894a8a4SArthur O'Dwyertemplate<class _InputIterator, class _Allocator,
6184e0ea2cfSLouis Dionne         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
6194e0ea2cfSLouis Dionne         class = enable_if_t<__is_allocator<_Allocator>::value>
6203894a8a4SArthur O'Dwyer>
6213894a8a4SArthur O'Dwyerpriority_queue(_InputIterator, _InputIterator, _Allocator)
6223894a8a4SArthur O'Dwyer    -> priority_queue<__iter_value_type<_InputIterator>,
6233894a8a4SArthur O'Dwyer                      vector<__iter_value_type<_InputIterator>, _Allocator>,
6243894a8a4SArthur O'Dwyer                      less<__iter_value_type<_InputIterator>>>;
6253894a8a4SArthur O'Dwyer
6263894a8a4SArthur O'Dwyertemplate<class _InputIterator, class _Compare, class _Allocator,
6274e0ea2cfSLouis Dionne         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
6284e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Compare>::value>,
6294e0ea2cfSLouis Dionne         class = enable_if_t<__is_allocator<_Allocator>::value>
6303894a8a4SArthur O'Dwyer>
6313894a8a4SArthur O'Dwyerpriority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
6323894a8a4SArthur O'Dwyer    -> priority_queue<__iter_value_type<_InputIterator>,
6333894a8a4SArthur O'Dwyer                      vector<__iter_value_type<_InputIterator>, _Allocator>, _Compare>;
6343894a8a4SArthur O'Dwyer
6353894a8a4SArthur O'Dwyertemplate<class _InputIterator, class _Compare, class _Container, class _Alloc,
6364e0ea2cfSLouis Dionne         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
6374e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Compare>::value>,
6384e0ea2cfSLouis Dionne         class = enable_if_t<!__is_allocator<_Container>::value>,
6394e0ea2cfSLouis Dionne         class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
6403894a8a4SArthur O'Dwyer>
6413894a8a4SArthur O'Dwyerpriority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
6423894a8a4SArthur O'Dwyer    -> priority_queue<typename _Container::value_type, _Container, _Compare>;
6435b8b8b5dSMarshall Clow#endif
6445b8b8b5dSMarshall Clow
6453e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
646cd31b434SEvgeniy Stepanovinline
6473e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
6483e519524SHoward Hinnant                                                          const container_type& __c)
6493e519524SHoward Hinnant    : c(__c),
6503e519524SHoward Hinnant      comp(__comp)
6513e519524SHoward Hinnant{
652ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
6533e519524SHoward Hinnant}
6543e519524SHoward Hinnant
655f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
6563e519524SHoward Hinnant
6573e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
658cd31b434SEvgeniy Stepanovinline
6593e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
6603e519524SHoward Hinnant                                                          container_type&& __c)
661ce48a113SHoward Hinnant    : c(_VSTD::move(__c)),
6623e519524SHoward Hinnant      comp(__comp)
6633e519524SHoward Hinnant{
664ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
6653e519524SHoward Hinnant}
6663e519524SHoward Hinnant
667f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
6683e519524SHoward Hinnant
6693e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
6703894a8a4SArthur O'Dwyertemplate <class _InputIter, class>
671cd31b434SEvgeniy Stepanovinline
6723e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
6733e519524SHoward Hinnant                                                          const value_compare& __comp)
6743e519524SHoward Hinnant    : c(__f, __l),
6753e519524SHoward Hinnant      comp(__comp)
6763e519524SHoward Hinnant{
677ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
6783e519524SHoward Hinnant}
6793e519524SHoward Hinnant
6803e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
6813894a8a4SArthur O'Dwyertemplate <class _InputIter, class>
682cd31b434SEvgeniy Stepanovinline
6833e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
6843e519524SHoward Hinnant                                                          const value_compare& __comp,
6853e519524SHoward Hinnant                                                          const container_type& __c)
6863e519524SHoward Hinnant    : c(__c),
6873e519524SHoward Hinnant      comp(__comp)
6883e519524SHoward Hinnant{
6893e519524SHoward Hinnant    c.insert(c.end(), __f, __l);
690ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
6913e519524SHoward Hinnant}
6923e519524SHoward Hinnant
693f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
6943e519524SHoward Hinnant
6953e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
6963894a8a4SArthur O'Dwyertemplate <class _InputIter, class>
697cd31b434SEvgeniy Stepanovinline
6983e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
6993e519524SHoward Hinnant                                                          const value_compare& __comp,
7003e519524SHoward Hinnant                                                          container_type&& __c)
701ce48a113SHoward Hinnant    : c(_VSTD::move(__c)),
7023e519524SHoward Hinnant      comp(__comp)
7033e519524SHoward Hinnant{
7043e519524SHoward Hinnant    c.insert(c.end(), __f, __l);
705ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
7063e519524SHoward Hinnant}
7073e519524SHoward Hinnant
708f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
7093e519524SHoward Hinnant
7103e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7113e519524SHoward Hinnanttemplate <class _Alloc>
712cd31b434SEvgeniy Stepanovinline
7133e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
714b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7153e519524SHoward Hinnant    : c(__a)
7163e519524SHoward Hinnant{
7173e519524SHoward Hinnant}
7183e519524SHoward Hinnant
7193e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7203e519524SHoward Hinnanttemplate <class _Alloc>
721cd31b434SEvgeniy Stepanovinline
7223e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7233e519524SHoward Hinnant                                                          const _Alloc& __a,
724b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7253e519524SHoward Hinnant    : c(__a),
7263e519524SHoward Hinnant      comp(__comp)
7273e519524SHoward Hinnant{
7283e519524SHoward Hinnant}
7293e519524SHoward Hinnant
7303e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7313e519524SHoward Hinnanttemplate <class _Alloc>
732cd31b434SEvgeniy Stepanovinline
7333e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7343e519524SHoward Hinnant                                                          const container_type& __c,
7353e519524SHoward Hinnant                                                          const _Alloc& __a,
736b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7373e519524SHoward Hinnant    : c(__c, __a),
7383e519524SHoward Hinnant      comp(__comp)
7393e519524SHoward Hinnant{
740ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
7413e519524SHoward Hinnant}
7423e519524SHoward Hinnant
7433e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7443e519524SHoward Hinnanttemplate <class _Alloc>
745cd31b434SEvgeniy Stepanovinline
7463e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
7473e519524SHoward Hinnant                                                          const _Alloc& __a,
748b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7493e519524SHoward Hinnant    : c(__q.c, __a),
7503e519524SHoward Hinnant      comp(__q.comp)
7513e519524SHoward Hinnant{
7523e519524SHoward Hinnant}
7533e519524SHoward Hinnant
754f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
7553e519524SHoward Hinnant
7563e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7573e519524SHoward Hinnanttemplate <class _Alloc>
758cd31b434SEvgeniy Stepanovinline
7593e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
7603e519524SHoward Hinnant                                                          container_type&& __c,
7613e519524SHoward Hinnant                                                          const _Alloc& __a,
762b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
763ce48a113SHoward Hinnant    : c(_VSTD::move(__c), __a),
7643e519524SHoward Hinnant      comp(__comp)
7653e519524SHoward Hinnant{
766ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
7673e519524SHoward Hinnant}
7683e519524SHoward Hinnant
7693e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
7703e519524SHoward Hinnanttemplate <class _Alloc>
771cd31b434SEvgeniy Stepanovinline
7723e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
7733e519524SHoward Hinnant                                                          const _Alloc& __a,
774b4e88d4dSLouis Dionne                       __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
775ce48a113SHoward Hinnant    : c(_VSTD::move(__q.c), __a),
776ce48a113SHoward Hinnant      comp(_VSTD::move(__q.comp))
7773e519524SHoward Hinnant{
7783894a8a4SArthur O'Dwyer}
7793894a8a4SArthur O'Dwyer
7803894a8a4SArthur O'Dwyer#endif  // _LIBCPP_CXX03_LANG
7813894a8a4SArthur O'Dwyer
7823894a8a4SArthur O'Dwyertemplate <class _Tp, class _Container, class _Compare>
7833894a8a4SArthur O'Dwyertemplate <class _InputIter, class _Alloc, class>
7843894a8a4SArthur O'Dwyerinline
7853894a8a4SArthur O'Dwyerpriority_queue<_Tp, _Container, _Compare>::priority_queue(
7863894a8a4SArthur O'Dwyer        _InputIter __f, _InputIter __l, const _Alloc& __a,
787b4e88d4dSLouis Dionne        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
7883894a8a4SArthur O'Dwyer    : c(__f, __l, __a),
7893894a8a4SArthur O'Dwyer      comp()
7903894a8a4SArthur O'Dwyer{
791ce48a113SHoward Hinnant    _VSTD::make_heap(c.begin(), c.end(), comp);
7923e519524SHoward Hinnant}
7933e519524SHoward Hinnant
7943894a8a4SArthur O'Dwyertemplate <class _Tp, class _Container, class _Compare>
7953894a8a4SArthur O'Dwyertemplate <class _InputIter, class _Alloc, class>
7963894a8a4SArthur O'Dwyerinline
7973894a8a4SArthur O'Dwyerpriority_queue<_Tp, _Container, _Compare>::priority_queue(
7983894a8a4SArthur O'Dwyer        _InputIter __f, _InputIter __l,
7993894a8a4SArthur O'Dwyer        const value_compare& __comp, const _Alloc& __a,
800b4e88d4dSLouis Dionne        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8013894a8a4SArthur O'Dwyer    : c(__f, __l, __a),
8023894a8a4SArthur O'Dwyer      comp(__comp)
8033894a8a4SArthur O'Dwyer{
8043894a8a4SArthur O'Dwyer    _VSTD::make_heap(c.begin(), c.end(), comp);
8053894a8a4SArthur O'Dwyer}
8063894a8a4SArthur O'Dwyer
8073894a8a4SArthur O'Dwyertemplate <class _Tp, class _Container, class _Compare>
8083894a8a4SArthur O'Dwyertemplate <class _InputIter, class _Alloc, class>
8093894a8a4SArthur O'Dwyerinline
8103894a8a4SArthur O'Dwyerpriority_queue<_Tp, _Container, _Compare>::priority_queue(
8113894a8a4SArthur O'Dwyer        _InputIter __f, _InputIter __l,
8123894a8a4SArthur O'Dwyer        const value_compare& __comp, const container_type& __c, const _Alloc& __a,
813b4e88d4dSLouis Dionne        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8143894a8a4SArthur O'Dwyer    : c(__c, __a),
8153894a8a4SArthur O'Dwyer      comp(__comp)
8163894a8a4SArthur O'Dwyer{
8173894a8a4SArthur O'Dwyer    c.insert(c.end(), __f, __l);
8183894a8a4SArthur O'Dwyer    _VSTD::make_heap(c.begin(), c.end(), comp);
8193894a8a4SArthur O'Dwyer}
8203894a8a4SArthur O'Dwyer
8213894a8a4SArthur O'Dwyer#ifndef _LIBCPP_CXX03_LANG
8223894a8a4SArthur O'Dwyertemplate <class _Tp, class _Container, class _Compare>
8233894a8a4SArthur O'Dwyertemplate <class _InputIter, class _Alloc, class>
8243894a8a4SArthur O'Dwyerinline
8253894a8a4SArthur O'Dwyerpriority_queue<_Tp, _Container, _Compare>::priority_queue(
8263894a8a4SArthur O'Dwyer        _InputIter __f, _InputIter __l, const value_compare& __comp,
8273894a8a4SArthur O'Dwyer        container_type&& __c, const _Alloc& __a,
828b4e88d4dSLouis Dionne        __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
8293894a8a4SArthur O'Dwyer    : c(_VSTD::move(__c), __a),
8303894a8a4SArthur O'Dwyer      comp(__comp)
8313894a8a4SArthur O'Dwyer{
8323894a8a4SArthur O'Dwyer    c.insert(c.end(), __f, __l);
8333894a8a4SArthur O'Dwyer    _VSTD::make_heap(c.begin(), c.end(), comp);
8343894a8a4SArthur O'Dwyer}
835f5427b26SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
8363e519524SHoward Hinnant
8373e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
838cd31b434SEvgeniy Stepanovinline
8393e519524SHoward Hinnantvoid
8403e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
8413e519524SHoward Hinnant{
8423e519524SHoward Hinnant    c.push_back(__v);
843ce48a113SHoward Hinnant    _VSTD::push_heap(c.begin(), c.end(), comp);
8443e519524SHoward Hinnant}
8453e519524SHoward Hinnant
846f5427b26SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
8473e519524SHoward Hinnant
8483e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
849cd31b434SEvgeniy Stepanovinline
8503e519524SHoward Hinnantvoid
8513e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
8523e519524SHoward Hinnant{
853ce48a113SHoward Hinnant    c.push_back(_VSTD::move(__v));
854ce48a113SHoward Hinnant    _VSTD::push_heap(c.begin(), c.end(), comp);
8553e519524SHoward Hinnant}
8563e519524SHoward Hinnant
8573e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
8583e519524SHoward Hinnanttemplate <class... _Args>
859cd31b434SEvgeniy Stepanovinline
8603e519524SHoward Hinnantvoid
8613e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
8623e519524SHoward Hinnant{
863ce48a113SHoward Hinnant    c.emplace_back(_VSTD::forward<_Args>(__args)...);
864ce48a113SHoward Hinnant    _VSTD::push_heap(c.begin(), c.end(), comp);
8653e519524SHoward Hinnant}
8663e519524SHoward Hinnant
867f5427b26SEric Fiselier#endif // _LIBCPP_CXX03_LANG
8683e519524SHoward Hinnant
8693e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
870cd31b434SEvgeniy Stepanovinline
8713e519524SHoward Hinnantvoid
8723e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::pop()
8733e519524SHoward Hinnant{
874ce48a113SHoward Hinnant    _VSTD::pop_heap(c.begin(), c.end(), comp);
8753e519524SHoward Hinnant    c.pop_back();
8763e519524SHoward Hinnant}
8773e519524SHoward Hinnant
8783e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
879cd31b434SEvgeniy Stepanovinline
8803e519524SHoward Hinnantvoid
8813e519524SHoward Hinnantpriority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
8826971d826SHoward Hinnant        _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
8836971d826SHoward Hinnant                   __is_nothrow_swappable<value_compare>::value)
8843e519524SHoward Hinnant{
885ce48a113SHoward Hinnant    using _VSTD::swap;
8863e519524SHoward Hinnant    swap(c, __q.c);
8873e519524SHoward Hinnant    swap(comp, __q.comp);
8883e519524SHoward Hinnant}
8893e519524SHoward Hinnant
8903e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare>
891392183f9SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
892b4e88d4dSLouis Dionne__enable_if_t<
893199d2ebeSArthur O'Dwyer    __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
8943e519524SHoward Hinnant    void
895199d2ebeSArthur O'Dwyer>
8963e519524SHoward Hinnantswap(priority_queue<_Tp, _Container, _Compare>& __x,
8973e519524SHoward Hinnant     priority_queue<_Tp, _Container, _Compare>& __y)
8986971d826SHoward Hinnant    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
8993e519524SHoward Hinnant{
9003e519524SHoward Hinnant    __x.swap(__y);
9013e519524SHoward Hinnant}
9023e519524SHoward Hinnant
9033e519524SHoward Hinnanttemplate <class _Tp, class _Container, class _Compare, class _Alloc>
904e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
9053e519524SHoward Hinnant    : public uses_allocator<_Container, _Alloc>
9063e519524SHoward Hinnant{
9073e519524SHoward Hinnant};
9083e519524SHoward Hinnant
9093e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
9103e519524SHoward Hinnant
9113e519524SHoward Hinnant#endif // _LIBCPP_QUEUE
912