blob: 05cc2466baa40c3d10d9beaaa3fa047d97d414d5 [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>
182#include <deque>
183#include <vector>
184#include <functional>
185#include <algorithm>
186
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000187#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000189#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190
191_LIBCPP_BEGIN_NAMESPACE_STD
192
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000193template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194
195template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000196_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197bool
198operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
199
200template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000201_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202bool
203operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
204
Marshall Clow9e1b8452015-02-18 17:51:56 +0000205template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000206class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207{
208public:
209 typedef _Container container_type;
210 typedef typename container_type::value_type value_type;
211 typedef typename container_type::reference reference;
212 typedef typename container_type::const_reference const_reference;
213 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000214 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215
216protected:
217 container_type c;
218
219public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000221 queue()
222 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
223 : c() {}
224
225 _LIBCPP_INLINE_VISIBILITY
226 queue(const queue& __q) : c(__q.c) {}
227
Eric Fiselier26081dd2017-04-18 21:23:18 +0000228 _LIBCPP_INLINE_VISIBILITY
229 queue& operator=(const queue& __q) {c = __q.c; return *this;}
230
231#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000232 _LIBCPP_INLINE_VISIBILITY
233 queue(queue&& __q)
234 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000235 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000236
237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000238 queue& operator=(queue&& __q)
239 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000240 {c = _VSTD::move(__q.c); return *this;}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000241#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000242
Howard Hinnantf5f99992010-09-22 18:02:38 +0000243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000245#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000247 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000248#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 explicit queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500252 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 : c(__a) {}
254 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 queue(const queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500257 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258 : c(__q.c, __a) {}
259 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 queue(const container_type& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500262 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000264#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267 queue(container_type&& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500268 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000269 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 queue(queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500273 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000274 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275
Eric Fiselier26081dd2017-04-18 21:23:18 +0000276#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277
Marshall Clow425f5752017-11-15 05:51:26 +0000278 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 size_type size() const {return c.size();}
282
Howard Hinnantf5f99992010-09-22 18:02:38 +0000283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 const_reference back() const {return c.back();}
291
Howard Hinnantf5f99992010-09-22 18:02:38 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000294#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000296 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000297 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000298 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000299#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000300 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000301 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000302#else
303 void emplace(_Args&&... __args)
304 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
305#endif
Eric Fiselier26081dd2017-04-18 21:23:18 +0000306#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308 void pop() {c.pop_front();}
309
Howard Hinnantf5f99992010-09-22 18:02:38 +0000310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000312 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000314 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 swap(c, __q.c);
316 }
317
318 template <class _T1, class _C1>
319 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 bool
322 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000323
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 template <class _T1, class _C1>
325 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 bool
328 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
329};
330
Marshall Clow592d9952018-05-22 01:57:53 +0000331#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
332template<class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500333 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000334>
335queue(_Container)
336 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000337
Marshall Clow592d9952018-05-22 01:57:53 +0000338template<class _Container,
339 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500340 class = _EnableIf<!__is_allocator<_Container>::value>,
341 class = _EnableIf<__is_allocator<_Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000342>
343queue(_Container, _Alloc)
344 -> queue<typename _Container::value_type, _Container>;
345#endif
346
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349bool
350operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
351{
352 return __x.c == __y.c;
353}
354
355template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357bool
358operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
359{
360 return __x.c < __y.c;
361}
362
363template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365bool
366operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
367{
368 return !(__x == __y);
369}
370
371template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373bool
374operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
375{
376 return __y < __x;
377}
378
379template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000380inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381bool
382operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
383{
384 return !(__x < __y);
385}
386
387template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389bool
390operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
391{
392 return !(__y < __x);
393}
394
395template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000396inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500397_EnableIf<__is_swappable<_Container>::value, void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000399 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400{
401 __x.swap(__y);
402}
403
404template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000405struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406 : public uses_allocator<_Container, _Alloc>
407{
408};
409
410template <class _Tp, class _Container = vector<_Tp>,
411 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000412class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413{
414public:
415 typedef _Container container_type;
416 typedef _Compare value_compare;
417 typedef typename container_type::value_type value_type;
418 typedef typename container_type::reference reference;
419 typedef typename container_type::const_reference const_reference;
420 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000421 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
423protected:
424 container_type c;
425 value_compare comp;
426
427public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000429 priority_queue()
430 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
431 is_nothrow_default_constructible<value_compare>::value)
432 : c(), comp() {}
433
434 _LIBCPP_INLINE_VISIBILITY
435 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
436
Eric Fiselier26081dd2017-04-18 21:23:18 +0000437 _LIBCPP_INLINE_VISIBILITY
438 priority_queue& operator=(const priority_queue& __q)
439 {c = __q.c; comp = __q.comp; return *this;}
440
441#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000442 _LIBCPP_INLINE_VISIBILITY
443 priority_queue(priority_queue&& __q)
444 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
445 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000446 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000447
448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000449 priority_queue& operator=(priority_queue&& __q)
450 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
451 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000452 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000453#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000454
455 _LIBCPP_INLINE_VISIBILITY
456 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000460#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000461 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100462 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463#endif
464 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 priority_queue(_InputIter __f, _InputIter __l,
467 const value_compare& __comp = value_compare());
468 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470 priority_queue(_InputIter __f, _InputIter __l,
471 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000472#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 priority_queue(_InputIter __f, _InputIter __l,
476 const value_compare& __comp, container_type&& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000477#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 explicit priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500481 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 priority_queue(const value_compare& __comp, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500485 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 priority_queue(const value_compare& __comp, const container_type& __c,
489 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500490 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 priority_queue(const priority_queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500494 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000495#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 priority_queue(const value_compare& __comp, container_type&& __c,
499 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500500 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 priority_queue(priority_queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500504 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000505#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506
Marshall Clow425f5752017-11-15 05:51:26 +0000507 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 const_reference top() const {return c.front();}
513
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000516#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000519 template <class... _Args>
520 _LIBCPP_INLINE_VISIBILITY
521 void emplace(_Args&&... __args);
522#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 void pop();
525
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000527 void swap(priority_queue& __q)
528 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
529 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530};
531
Marshall Clow592d9952018-05-22 01:57:53 +0000532#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
533template <class _Compare,
534 class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500535 class = _EnableIf<!__is_allocator<_Compare>::value>,
536 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000537>
538priority_queue(_Compare, _Container)
539 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000540
541template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500542 class _Compare = less<__iter_value_type<_InputIterator>>,
543 class _Container = vector<__iter_value_type<_InputIterator>>,
544 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
545 class = _EnableIf<!__is_allocator<_Compare>::value>,
546 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000547>
548priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500549 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000550
551template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000552 class _Container,
553 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500554 class = _EnableIf<!__is_allocator<_Compare>::value>,
555 class = _EnableIf<!__is_allocator<_Container>::value>,
556 class = _EnableIf<__is_allocator<_Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000557>
558priority_queue(_Compare, _Container, _Alloc)
559 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
560#endif
561
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000563inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
565 const container_type& __c)
566 : c(__c),
567 comp(__comp)
568{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000569 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570}
571
Eric Fiselier26081dd2017-04-18 21:23:18 +0000572#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573
574template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000575inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
577 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000578 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 comp(__comp)
580{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000581 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582}
583
Eric Fiselier26081dd2017-04-18 21:23:18 +0000584#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585
586template <class _Tp, class _Container, class _Compare>
587template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000588inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
590 const value_compare& __comp)
591 : c(__f, __l),
592 comp(__comp)
593{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000594 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595}
596
597template <class _Tp, class _Container, class _Compare>
598template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000599inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
601 const value_compare& __comp,
602 const container_type& __c)
603 : c(__c),
604 comp(__comp)
605{
606 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000607 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608}
609
Eric Fiselier26081dd2017-04-18 21:23:18 +0000610#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611
612template <class _Tp, class _Container, class _Compare>
613template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000614inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
616 const value_compare& __comp,
617 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000618 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619 comp(__comp)
620{
621 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000622 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623}
624
Eric Fiselier26081dd2017-04-18 21:23:18 +0000625#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626
627template <class _Tp, class _Container, class _Compare>
628template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000629inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500631 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 : c(__a)
633{
634}
635
636template <class _Tp, class _Container, class _Compare>
637template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000638inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
640 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500641 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 : c(__a),
643 comp(__comp)
644{
645}
646
647template <class _Tp, class _Container, class _Compare>
648template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000649inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
651 const container_type& __c,
652 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500653 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 : c(__c, __a),
655 comp(__comp)
656{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000657 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658}
659
660template <class _Tp, class _Container, class _Compare>
661template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000662inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
664 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500665 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 : c(__q.c, __a),
667 comp(__q.comp)
668{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000669 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670}
671
Eric Fiselier26081dd2017-04-18 21:23:18 +0000672#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673
674template <class _Tp, class _Container, class _Compare>
675template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000676inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
678 container_type&& __c,
679 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500680 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000681 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682 comp(__comp)
683{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000684 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685}
686
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687template <class _Tp, class _Container, class _Compare>
688template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000689inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
691 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500692 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000693 : c(_VSTD::move(__q.c), __a),
694 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000696 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697}
698
Eric Fiselier26081dd2017-04-18 21:23:18 +0000699#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700
701template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000702inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703void
704priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
705{
706 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000707 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708}
709
Eric Fiselier26081dd2017-04-18 21:23:18 +0000710#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711
712template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000713inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714void
715priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
716{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000717 c.push_back(_VSTD::move(__v));
718 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719}
720
721template <class _Tp, class _Container, class _Compare>
722template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000723inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724void
725priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
726{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000727 c.emplace_back(_VSTD::forward<_Args>(__args)...);
728 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729}
730
Eric Fiselier26081dd2017-04-18 21:23:18 +0000731#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732
733template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000734inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735void
736priority_queue<_Tp, _Container, _Compare>::pop()
737{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000738 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739 c.pop_back();
740}
741
742template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000743inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744void
745priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000746 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
747 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000749 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750 swap(c, __q.c);
751 swap(comp, __q.comp);
752}
753
754template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000755inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500756_EnableIf<
757 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
Eric Fiselier6bfed252016-04-21 23:38:59 +0000758 void
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500759>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760swap(priority_queue<_Tp, _Container, _Compare>& __x,
761 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000762 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763{
764 __x.swap(__y);
765}
766
767template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000768struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 : public uses_allocator<_Container, _Alloc>
770{
771};
772
773_LIBCPP_END_NAMESPACE_STD
774
775#endif // _LIBCPP_QUEUE