blob: 3c7bbf2f6adb79f8d41e254b60206bb9f247c993 [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>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000182#include <__utility/forward.h>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400183#include <algorithm>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400184#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185#include <deque>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186#include <functional>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400187#include <vector>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000189#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000191#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192
193_LIBCPP_BEGIN_NAMESPACE_STD
194
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000195template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196
197template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000198_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199bool
200operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
201
202template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000203_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204bool
205operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
206
Marshall Clow9e1b8452015-02-18 17:51:56 +0000207template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000208class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209{
210public:
211 typedef _Container container_type;
212 typedef typename container_type::value_type value_type;
213 typedef typename container_type::reference reference;
214 typedef typename container_type::const_reference const_reference;
215 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000216 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
218protected:
219 container_type c;
220
221public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000223 queue()
224 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
225 : c() {}
226
227 _LIBCPP_INLINE_VISIBILITY
228 queue(const queue& __q) : c(__q.c) {}
229
Eric Fiselier26081dd2017-04-18 21:23:18 +0000230 _LIBCPP_INLINE_VISIBILITY
231 queue& operator=(const queue& __q) {c = __q.c; return *this;}
232
233#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000234 _LIBCPP_INLINE_VISIBILITY
235 queue(queue&& __q)
236 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000237 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000238
239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000240 queue& operator=(queue&& __q)
241 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000242 {c = _VSTD::move(__q.c); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400243#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000244
Howard Hinnantf5f99992010-09-22 18:02:38 +0000245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000247#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000249 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400250#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 explicit queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500254 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 : c(__a) {}
256 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258 queue(const queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500259 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 : c(__q.c, __a) {}
261 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 queue(const container_type& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500264 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000266#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000267 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269 queue(container_type&& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500270 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000271 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274 queue(queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500275 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000276 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400278#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
Marshall Clow425f5752017-11-15 05:51:26 +0000280 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 size_type size() const {return c.size();}
284
Howard Hinnantf5f99992010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 const_reference back() const {return c.back();}
293
Howard Hinnantf5f99992010-09-22 18:02:38 +0000294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000296#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000298 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000300 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000301#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000302 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000303 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000304#else
305 void emplace(_Args&&... __args)
306 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
307#endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400308#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310 void pop() {c.pop_front();}
311
Howard Hinnantf5f99992010-09-22 18:02:38 +0000312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000314 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000316 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000317 swap(c, __q.c);
318 }
319
320 template <class _T1, class _C1>
321 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 bool
324 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000325
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 template <class _T1, class _C1>
327 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 bool
330 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
331};
332
Marshall Clow592d9952018-05-22 01:57:53 +0000333#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
334template<class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500335 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000336>
337queue(_Container)
338 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000339
Marshall Clow592d9952018-05-22 01:57:53 +0000340template<class _Container,
341 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500342 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500343 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000344>
345queue(_Container, _Alloc)
346 -> queue<typename _Container::value_type, _Container>;
347#endif
348
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000350inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351bool
352operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
353{
354 return __x.c == __y.c;
355}
356
357template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359bool
360operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
361{
362 return __x.c < __y.c;
363}
364
365template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000366inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367bool
368operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
369{
370 return !(__x == __y);
371}
372
373template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375bool
376operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
377{
378 return __y < __x;
379}
380
381template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000382inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383bool
384operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
385{
386 return !(__x < __y);
387}
388
389template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000390inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391bool
392operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
393{
394 return !(__y < __x);
395}
396
397template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000398inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500399_EnableIf<__is_swappable<_Container>::value, void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000401 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402{
403 __x.swap(__y);
404}
405
406template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000407struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 : public uses_allocator<_Container, _Alloc>
409{
410};
411
412template <class _Tp, class _Container = vector<_Tp>,
413 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000414class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415{
416public:
417 typedef _Container container_type;
418 typedef _Compare value_compare;
419 typedef typename container_type::value_type value_type;
420 typedef typename container_type::reference reference;
421 typedef typename container_type::const_reference const_reference;
422 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000423 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424
425protected:
426 container_type c;
427 value_compare comp;
428
429public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000431 priority_queue()
432 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
433 is_nothrow_default_constructible<value_compare>::value)
434 : c(), comp() {}
435
436 _LIBCPP_INLINE_VISIBILITY
437 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
438
Eric Fiselier26081dd2017-04-18 21:23:18 +0000439 _LIBCPP_INLINE_VISIBILITY
440 priority_queue& operator=(const priority_queue& __q)
441 {c = __q.c; comp = __q.comp; return *this;}
442
443#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000444 _LIBCPP_INLINE_VISIBILITY
445 priority_queue(priority_queue&& __q)
446 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
447 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000448 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000449
450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000451 priority_queue& operator=(priority_queue&& __q)
452 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
453 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000454 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400455#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000456
457 _LIBCPP_INLINE_VISIBILITY
458 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000462#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000463 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100464 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465#endif
466 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 priority_queue(_InputIter __f, _InputIter __l,
469 const value_compare& __comp = value_compare());
470 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472 priority_queue(_InputIter __f, _InputIter __l,
473 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000474#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 priority_queue(_InputIter __f, _InputIter __l,
478 const value_compare& __comp, container_type&& __c);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400479#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 explicit priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500483 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 priority_queue(const value_compare& __comp, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500487 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 priority_queue(const value_compare& __comp, const container_type& __c,
491 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500492 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495 priority_queue(const priority_queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500496 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000497#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 priority_queue(const value_compare& __comp, container_type&& __c,
501 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500502 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 priority_queue(priority_queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500506 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400507#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508
Marshall Clow425f5752017-11-15 05:51:26 +0000509 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 const_reference top() const {return c.front();}
515
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000518#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000521 template <class... _Args>
522 _LIBCPP_INLINE_VISIBILITY
523 void emplace(_Args&&... __args);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400524#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 void pop();
527
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000529 void swap(priority_queue& __q)
530 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
531 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532};
533
Marshall Clow592d9952018-05-22 01:57:53 +0000534#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
535template <class _Compare,
536 class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500537 class = _EnableIf<!__is_allocator<_Compare>::value>,
538 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000539>
540priority_queue(_Compare, _Container)
541 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000542
543template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500544 class _Compare = less<__iter_value_type<_InputIterator>>,
545 class _Container = vector<__iter_value_type<_InputIterator>>,
546 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
547 class = _EnableIf<!__is_allocator<_Compare>::value>,
548 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000549>
550priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500551 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000552
553template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000554 class _Container,
555 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500556 class = _EnableIf<!__is_allocator<_Compare>::value>,
557 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500558 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000559>
560priority_queue(_Compare, _Container, _Alloc)
561 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
562#endif
563
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000565inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
567 const container_type& __c)
568 : c(__c),
569 comp(__comp)
570{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000571 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572}
573
Eric Fiselier26081dd2017-04-18 21:23:18 +0000574#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575
576template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000577inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
579 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000580 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581 comp(__comp)
582{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000583 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584}
585
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400586#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587
588template <class _Tp, class _Container, class _Compare>
589template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000590inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
592 const value_compare& __comp)
593 : c(__f, __l),
594 comp(__comp)
595{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000596 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597}
598
599template <class _Tp, class _Container, class _Compare>
600template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000601inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
603 const value_compare& __comp,
604 const container_type& __c)
605 : c(__c),
606 comp(__comp)
607{
608 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000609 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610}
611
Eric Fiselier26081dd2017-04-18 21:23:18 +0000612#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613
614template <class _Tp, class _Container, class _Compare>
615template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000616inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
618 const value_compare& __comp,
619 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000620 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 comp(__comp)
622{
623 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000624 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625}
626
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400627#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628
629template <class _Tp, class _Container, class _Compare>
630template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000631inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500633 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 : c(__a)
635{
636}
637
638template <class _Tp, class _Container, class _Compare>
639template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000640inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
642 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500643 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 : c(__a),
645 comp(__comp)
646{
647}
648
649template <class _Tp, class _Container, class _Compare>
650template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000651inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
653 const container_type& __c,
654 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500655 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656 : c(__c, __a),
657 comp(__comp)
658{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000659 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660}
661
662template <class _Tp, class _Container, class _Compare>
663template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000664inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
666 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500667 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668 : c(__q.c, __a),
669 comp(__q.comp)
670{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000671 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672}
673
Eric Fiselier26081dd2017-04-18 21:23:18 +0000674#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675
676template <class _Tp, class _Container, class _Compare>
677template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000678inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
680 container_type&& __c,
681 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500682 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000683 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684 comp(__comp)
685{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000686 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687}
688
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689template <class _Tp, class _Container, class _Compare>
690template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000691inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
693 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500694 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000695 : c(_VSTD::move(__q.c), __a),
696 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000698 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699}
700
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400701#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702
703template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000704inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705void
706priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
707{
708 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000709 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710}
711
Eric Fiselier26081dd2017-04-18 21:23:18 +0000712#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713
714template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000715inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716void
717priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
718{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000719 c.push_back(_VSTD::move(__v));
720 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721}
722
723template <class _Tp, class _Container, class _Compare>
724template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000725inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726void
727priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
728{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000729 c.emplace_back(_VSTD::forward<_Args>(__args)...);
730 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731}
732
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400733#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734
735template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000736inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737void
738priority_queue<_Tp, _Container, _Compare>::pop()
739{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000740 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 c.pop_back();
742}
743
744template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000745inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746void
747priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000748 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
749 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000751 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752 swap(c, __q.c);
753 swap(comp, __q.comp);
754}
755
756template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000757inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500758_EnableIf<
759 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
Eric Fiselier6bfed252016-04-21 23:38:59 +0000760 void
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500761>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762swap(priority_queue<_Tp, _Container, _Compare>& __x,
763 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000764 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765{
766 __x.swap(__y);
767}
768
769template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000770struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 : public uses_allocator<_Container, _Alloc>
772{
773};
774
775_LIBCPP_END_NAMESPACE_STD
776
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400777#endif // _LIBCPP_QUEUE