blob: 9470a75102a672cf55205af0b4bd63cedcc29fd8 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_QUEUE
11#define _LIBCPP_QUEUE
12
13/*
14 queue synopsis
15
16namespace std
17{
18
19template <class T, class Container = deque<T>>
20class queue
21{
22public:
23 typedef Container container_type;
24 typedef typename container_type::value_type value_type;
25 typedef typename container_type::reference reference;
26 typedef typename container_type::const_reference const_reference;
27 typedef typename container_type::size_type size_type;
28
29protected:
30 container_type c;
31
32public:
Howard Hinnantbf438282011-06-04 21:32:33 +000033 queue() = default;
34 ~queue() = default;
35
36 queue(const queue& q) = default;
37 queue(queue&& q) = default;
38
39 queue& operator=(const queue& q) = default;
40 queue& operator=(queue&& q) = default;
41
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 explicit queue(const container_type& c);
Howard Hinnantbf438282011-06-04 21:32:33 +000043 explicit queue(container_type&& c)
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
45 explicit queue(const Alloc& a);
46 template <class Alloc>
47 queue(const container_type& c, const Alloc& a);
48 template <class Alloc>
49 queue(container_type&& c, const Alloc& a);
50 template <class Alloc>
Howard Hinnantbf438282011-06-04 21:32:33 +000051 queue(const queue& q, const Alloc& a);
52 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +000053 queue(queue&& q, const Alloc& a);
54
Howard Hinnantc51e1022010-05-11 19:42:16 +000055 bool empty() const;
56 size_type size() const;
57
58 reference front();
59 const_reference front() const;
60 reference back();
61 const_reference back() const;
62
63 void push(const value_type& v);
64 void push(value_type&& v);
Marshall Clowea52cc42017-01-24 23:09:12 +000065 template <class... Args> reference emplace(Args&&... args); // reference in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000066 void pop();
67
Eric Fiselier6bfed252016-04-21 23:38:59 +000068 void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
Howard Hinnantc51e1022010-05-11 19:42:16 +000069};
70
Marshall Clow592d9952018-05-22 01:57:53 +000071template<class Container>
72 queue(Container) -> queue<typename Container::value_type, Container>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +000073
74template<class Container, class Allocator>
Marshall Clow592d9952018-05-22 01:57:53 +000075 queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
76
Howard Hinnantc51e1022010-05-11 19:42:16 +000077template <class T, class Container>
78 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
79
80template <class T, class Container>
81 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
82
83template <class T, class Container>
84 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
85
86template <class T, class Container>
87 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
88
89template <class T, class Container>
90 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
91
92template <class T, class Container>
93 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
94
95template <class T, class Container>
Howard Hinnantbf438282011-06-04 21:32:33 +000096 void swap(queue<T, Container>& x, queue<T, Container>& y)
97 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +000098
99template <class T, class Container = vector<T>,
100 class Compare = less<typename Container::value_type>>
101class priority_queue
102{
103public:
104 typedef Container container_type;
105 typedef typename container_type::value_type value_type;
106 typedef typename container_type::reference reference;
107 typedef typename container_type::const_reference const_reference;
108 typedef typename container_type::size_type size_type;
109
110protected:
111 container_type c;
112 Compare comp;
113
114public:
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100115 priority_queue() : priority_queue(Compare()) {} // C++20
116 explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
117 priority_queue(const Compare& x, const Container&);
118 explicit priority_queue(const Compare& x = Compare(), Container&&= Container()); // before C++20
119 priority_queue(const Compare& x, Container&&); // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 template <class InputIterator>
121 priority_queue(InputIterator first, InputIterator last,
122 const Compare& comp = Compare());
123 template <class InputIterator>
124 priority_queue(InputIterator first, InputIterator last,
125 const Compare& comp, const container_type& c);
126 template <class InputIterator>
127 priority_queue(InputIterator first, InputIterator last,
128 const Compare& comp, container_type&& c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129 template <class Alloc>
130 explicit priority_queue(const Alloc& a);
131 template <class Alloc>
132 priority_queue(const Compare& comp, const Alloc& a);
133 template <class Alloc>
134 priority_queue(const Compare& comp, const container_type& c,
135 const Alloc& a);
136 template <class Alloc>
137 priority_queue(const Compare& comp, container_type&& c,
138 const Alloc& a);
139 template <class Alloc>
Howard Hinnantbf438282011-06-04 21:32:33 +0000140 priority_queue(const priority_queue& q, const Alloc& a);
141 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142 priority_queue(priority_queue&& q, const Alloc& a);
143
144 bool empty() const;
145 size_type size() const;
146 const_reference top() const;
147
148 void push(const value_type& v);
149 void push(value_type&& v);
150 template <class... Args> void emplace(Args&&... args);
151 void pop();
152
Howard Hinnantbf438282011-06-04 21:32:33 +0000153 void swap(priority_queue& q)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000154 noexcept(is_nothrow_swappable_v<Container> &&
155 is_nothrow_swappable_v<Comp>)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156};
157
Marshall Clow592d9952018-05-22 01:57:53 +0000158template <class Compare, class Container>
159priority_queue(Compare, Container)
160 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000161
162template<class InputIterator,
Marshall Clow592d9952018-05-22 01:57:53 +0000163 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
164 class Container = vector<typename iterator_traits<InputIterator>::value_type>>
165priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
166 -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000167
Marshall Clow592d9952018-05-22 01:57:53 +0000168template<class Compare, class Container, class Allocator>
169priority_queue(Compare, Container, Allocator)
170 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172template <class T, class Container, class Compare>
173 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnantbf438282011-06-04 21:32:33 +0000174 priority_queue<T, Container, Compare>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176
177} // std
178
179*/
180
181#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400182#include <algorithm>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400183#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184#include <deque>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185#include <functional>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400186#include <vector>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000188#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000190#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191
192_LIBCPP_BEGIN_NAMESPACE_STD
193
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000194template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195
196template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000197_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000198bool
199operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
200
201template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000202_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203bool
204operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
205
Marshall Clow9e1b8452015-02-18 17:51:56 +0000206template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000207class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208{
209public:
210 typedef _Container container_type;
211 typedef typename container_type::value_type value_type;
212 typedef typename container_type::reference reference;
213 typedef typename container_type::const_reference const_reference;
214 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000215 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216
217protected:
218 container_type c;
219
220public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000222 queue()
223 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
224 : c() {}
225
226 _LIBCPP_INLINE_VISIBILITY
227 queue(const queue& __q) : c(__q.c) {}
228
Eric Fiselier26081dd2017-04-18 21:23:18 +0000229 _LIBCPP_INLINE_VISIBILITY
230 queue& operator=(const queue& __q) {c = __q.c; return *this;}
231
232#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000233 _LIBCPP_INLINE_VISIBILITY
234 queue(queue&& __q)
235 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000236 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000237
238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000239 queue& operator=(queue&& __q)
240 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000241 {c = _VSTD::move(__q.c); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400242#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000243
Howard Hinnantf5f99992010-09-22 18:02:38 +0000244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000246#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000248 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400249#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 explicit queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500253 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 : c(__a) {}
255 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 queue(const queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500258 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 : c(__q.c, __a) {}
260 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 queue(const container_type& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500263 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000265#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 queue(container_type&& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500269 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000270 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 queue(queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500274 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000275 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400277#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278
Marshall Clow425f5752017-11-15 05:51:26 +0000279 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 size_type size() const {return c.size();}
283
Howard Hinnantf5f99992010-09-22 18:02:38 +0000284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000285 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 const_reference back() const {return c.back();}
292
Howard Hinnantf5f99992010-09-22 18:02:38 +0000293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000295#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000297 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000299 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000300#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000301 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000302 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000303#else
304 void emplace(_Args&&... __args)
305 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
306#endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400307#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309 void pop() {c.pop_front();}
310
Howard Hinnantf5f99992010-09-22 18:02:38 +0000311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000313 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000315 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 swap(c, __q.c);
317 }
318
319 template <class _T1, class _C1>
320 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000321 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 bool
323 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 template <class _T1, class _C1>
326 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328 bool
329 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
330};
331
Marshall Clow592d9952018-05-22 01:57:53 +0000332#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
333template<class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500334 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000335>
336queue(_Container)
337 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000338
Marshall Clow592d9952018-05-22 01:57:53 +0000339template<class _Container,
340 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500341 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500342 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000343>
344queue(_Container, _Alloc)
345 -> queue<typename _Container::value_type, _Container>;
346#endif
347
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000349inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350bool
351operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
352{
353 return __x.c == __y.c;
354}
355
356template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358bool
359operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
360{
361 return __x.c < __y.c;
362}
363
364template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000365inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366bool
367operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
368{
369 return !(__x == __y);
370}
371
372template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000373inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374bool
375operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
376{
377 return __y < __x;
378}
379
380template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000381inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382bool
383operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
384{
385 return !(__x < __y);
386}
387
388template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390bool
391operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
392{
393 return !(__y < __x);
394}
395
396template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000397inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500398_EnableIf<__is_swappable<_Container>::value, void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000400 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401{
402 __x.swap(__y);
403}
404
405template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000406struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407 : public uses_allocator<_Container, _Alloc>
408{
409};
410
411template <class _Tp, class _Container = vector<_Tp>,
412 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000413class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414{
415public:
416 typedef _Container container_type;
417 typedef _Compare value_compare;
418 typedef typename container_type::value_type value_type;
419 typedef typename container_type::reference reference;
420 typedef typename container_type::const_reference const_reference;
421 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000422 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
424protected:
425 container_type c;
426 value_compare comp;
427
428public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000430 priority_queue()
431 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
432 is_nothrow_default_constructible<value_compare>::value)
433 : c(), comp() {}
434
435 _LIBCPP_INLINE_VISIBILITY
436 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
437
Eric Fiselier26081dd2017-04-18 21:23:18 +0000438 _LIBCPP_INLINE_VISIBILITY
439 priority_queue& operator=(const priority_queue& __q)
440 {c = __q.c; comp = __q.comp; return *this;}
441
442#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000443 _LIBCPP_INLINE_VISIBILITY
444 priority_queue(priority_queue&& __q)
445 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
446 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000447 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000448
449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000450 priority_queue& operator=(priority_queue&& __q)
451 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
452 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000453 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400454#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000455
456 _LIBCPP_INLINE_VISIBILITY
457 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000461#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000462 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100463 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464#endif
465 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 priority_queue(_InputIter __f, _InputIter __l,
468 const value_compare& __comp = value_compare());
469 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471 priority_queue(_InputIter __f, _InputIter __l,
472 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000473#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 priority_queue(_InputIter __f, _InputIter __l,
477 const value_compare& __comp, container_type&& __c);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400478#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000479 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481 explicit priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500482 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 priority_queue(const value_compare& __comp, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500486 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 priority_queue(const value_compare& __comp, const container_type& __c,
490 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500491 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 priority_queue(const priority_queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500495 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000496#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499 priority_queue(const value_compare& __comp, container_type&& __c,
500 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500501 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 priority_queue(priority_queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500505 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400506#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507
Marshall Clow425f5752017-11-15 05:51:26 +0000508 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 const_reference top() const {return c.front();}
514
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000517#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000520 template <class... _Args>
521 _LIBCPP_INLINE_VISIBILITY
522 void emplace(_Args&&... __args);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400523#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525 void pop();
526
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000528 void swap(priority_queue& __q)
529 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
530 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531};
532
Marshall Clow592d9952018-05-22 01:57:53 +0000533#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
534template <class _Compare,
535 class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500536 class = _EnableIf<!__is_allocator<_Compare>::value>,
537 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000538>
539priority_queue(_Compare, _Container)
540 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000541
542template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500543 class _Compare = less<__iter_value_type<_InputIterator>>,
544 class _Container = vector<__iter_value_type<_InputIterator>>,
545 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
546 class = _EnableIf<!__is_allocator<_Compare>::value>,
547 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000548>
549priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500550 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000551
552template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000553 class _Container,
554 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500555 class = _EnableIf<!__is_allocator<_Compare>::value>,
556 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500557 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000558>
559priority_queue(_Compare, _Container, _Alloc)
560 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
561#endif
562
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000564inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
566 const container_type& __c)
567 : c(__c),
568 comp(__comp)
569{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000570 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571}
572
Eric Fiselier26081dd2017-04-18 21:23:18 +0000573#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574
575template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000576inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
578 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000579 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 comp(__comp)
581{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000582 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583}
584
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400585#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586
587template <class _Tp, class _Container, class _Compare>
588template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000589inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
591 const value_compare& __comp)
592 : c(__f, __l),
593 comp(__comp)
594{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000595 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596}
597
598template <class _Tp, class _Container, class _Compare>
599template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000600inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
602 const value_compare& __comp,
603 const container_type& __c)
604 : c(__c),
605 comp(__comp)
606{
607 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000608 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609}
610
Eric Fiselier26081dd2017-04-18 21:23:18 +0000611#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612
613template <class _Tp, class _Container, class _Compare>
614template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000615inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
617 const value_compare& __comp,
618 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000619 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620 comp(__comp)
621{
622 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000623 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624}
625
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400626#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627
628template <class _Tp, class _Container, class _Compare>
629template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000630inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500632 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 : c(__a)
634{
635}
636
637template <class _Tp, class _Container, class _Compare>
638template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000639inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
641 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500642 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 : c(__a),
644 comp(__comp)
645{
646}
647
648template <class _Tp, class _Container, class _Compare>
649template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000650inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
652 const container_type& __c,
653 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500654 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655 : c(__c, __a),
656 comp(__comp)
657{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000658 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659}
660
661template <class _Tp, class _Container, class _Compare>
662template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000663inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
665 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500666 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667 : c(__q.c, __a),
668 comp(__q.comp)
669{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000670 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671}
672
Eric Fiselier26081dd2017-04-18 21:23:18 +0000673#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674
675template <class _Tp, class _Container, class _Compare>
676template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000677inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
679 container_type&& __c,
680 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500681 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000682 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 comp(__comp)
684{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000685 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686}
687
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688template <class _Tp, class _Container, class _Compare>
689template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000690inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
692 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500693 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000694 : c(_VSTD::move(__q.c), __a),
695 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000697 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698}
699
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400700#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701
702template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000703inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704void
705priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
706{
707 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000708 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709}
710
Eric Fiselier26081dd2017-04-18 21:23:18 +0000711#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712
713template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000714inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715void
716priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
717{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000718 c.push_back(_VSTD::move(__v));
719 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720}
721
722template <class _Tp, class _Container, class _Compare>
723template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000724inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725void
726priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
727{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000728 c.emplace_back(_VSTD::forward<_Args>(__args)...);
729 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000730}
731
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400732#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733
734template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000735inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736void
737priority_queue<_Tp, _Container, _Compare>::pop()
738{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000739 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740 c.pop_back();
741}
742
743template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000744inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745void
746priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000747 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
748 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000750 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751 swap(c, __q.c);
752 swap(comp, __q.comp);
753}
754
755template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000756inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500757_EnableIf<
758 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
Eric Fiselier6bfed252016-04-21 23:38:59 +0000759 void
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500760>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761swap(priority_queue<_Tp, _Container, _Compare>& __x,
762 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000763 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764{
765 __x.swap(__y);
766}
767
768template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000769struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 : public uses_allocator<_Container, _Alloc>
771{
772};
773
774_LIBCPP_END_NAMESPACE_STD
775
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400776#endif // _LIBCPP_QUEUE