blob: 42470e3a102243aea2dae6ba3d7c548ba6cc12bf [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 Bella55d7a822021-07-01 09:25:35 -0400182#include <__memory/uses_allocator.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000183#include <__utility/forward.h>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400184#include <algorithm>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400185#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186#include <deque>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187#include <functional>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400188#include <vector>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000190#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000192#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000193
194_LIBCPP_BEGIN_NAMESPACE_STD
195
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000196template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197
198template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000199_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200bool
201operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
202
203template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000204_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205bool
206operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
207
Marshall Clow9e1b8452015-02-18 17:51:56 +0000208template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000209class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210{
211public:
212 typedef _Container container_type;
213 typedef typename container_type::value_type value_type;
214 typedef typename container_type::reference reference;
215 typedef typename container_type::const_reference const_reference;
216 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000217 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218
219protected:
220 container_type c;
221
222public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000224 queue()
225 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
226 : c() {}
227
228 _LIBCPP_INLINE_VISIBILITY
229 queue(const queue& __q) : c(__q.c) {}
230
Eric Fiselier26081dd2017-04-18 21:23:18 +0000231 _LIBCPP_INLINE_VISIBILITY
232 queue& operator=(const queue& __q) {c = __q.c; return *this;}
233
234#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000235 _LIBCPP_INLINE_VISIBILITY
236 queue(queue&& __q)
237 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000238 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000239
240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000241 queue& operator=(queue&& __q)
242 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000243 {c = _VSTD::move(__q.c); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400244#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000245
Howard Hinnantf5f99992010-09-22 18:02:38 +0000246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000248#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000250 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400251#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 explicit queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500255 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 : c(__a) {}
257 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 queue(const queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500260 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000261 : c(__q.c, __a) {}
262 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 queue(const container_type& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500265 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000267#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 queue(container_type&& __c, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500271 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000272 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 queue(queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500276 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000277 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400279#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280
Marshall Clow425f5752017-11-15 05:51:26 +0000281 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 size_type size() const {return c.size();}
285
Howard Hinnantf5f99992010-09-22 18:02:38 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 const_reference back() const {return c.back();}
294
Howard Hinnantf5f99992010-09-22 18:02:38 +0000295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000297#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000299 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000301 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000302#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000303 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000304 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000305#else
306 void emplace(_Args&&... __args)
307 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
308#endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400309#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311 void pop() {c.pop_front();}
312
Howard Hinnantf5f99992010-09-22 18:02:38 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000315 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000317 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318 swap(c, __q.c);
319 }
320
321 template <class _T1, class _C1>
322 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 bool
325 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000326
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 template <class _T1, class _C1>
328 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 bool
331 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
332};
333
Marshall Clow592d9952018-05-22 01:57:53 +0000334#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
335template<class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500336 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000337>
338queue(_Container)
339 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000340
Marshall Clow592d9952018-05-22 01:57:53 +0000341template<class _Container,
342 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500343 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500344 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000345>
346queue(_Container, _Alloc)
347 -> queue<typename _Container::value_type, _Container>;
348#endif
349
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352bool
353operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
354{
355 return __x.c == __y.c;
356}
357
358template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360bool
361operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
362{
363 return __x.c < __y.c;
364}
365
366template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368bool
369operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
370{
371 return !(__x == __y);
372}
373
374template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000375inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376bool
377operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
378{
379 return __y < __x;
380}
381
382template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000383inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384bool
385operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
386{
387 return !(__x < __y);
388}
389
390template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392bool
393operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
394{
395 return !(__y < __x);
396}
397
398template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000399inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500400_EnableIf<__is_swappable<_Container>::value, void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000402 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403{
404 __x.swap(__y);
405}
406
407template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000408struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 : public uses_allocator<_Container, _Alloc>
410{
411};
412
413template <class _Tp, class _Container = vector<_Tp>,
414 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000415class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416{
417public:
418 typedef _Container container_type;
419 typedef _Compare value_compare;
420 typedef typename container_type::value_type value_type;
421 typedef typename container_type::reference reference;
422 typedef typename container_type::const_reference const_reference;
423 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000424 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425
426protected:
427 container_type c;
428 value_compare comp;
429
430public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000432 priority_queue()
433 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
434 is_nothrow_default_constructible<value_compare>::value)
435 : c(), comp() {}
436
437 _LIBCPP_INLINE_VISIBILITY
438 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
439
Eric Fiselier26081dd2017-04-18 21:23:18 +0000440 _LIBCPP_INLINE_VISIBILITY
441 priority_queue& operator=(const priority_queue& __q)
442 {c = __q.c; comp = __q.comp; return *this;}
443
444#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000445 _LIBCPP_INLINE_VISIBILITY
446 priority_queue(priority_queue&& __q)
447 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
448 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000449 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000450
451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000452 priority_queue& operator=(priority_queue&& __q)
453 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
454 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000455 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400456#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000457
458 _LIBCPP_INLINE_VISIBILITY
459 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000463#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000464 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100465 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466#endif
467 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469 priority_queue(_InputIter __f, _InputIter __l,
470 const value_compare& __comp = value_compare());
471 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 priority_queue(_InputIter __f, _InputIter __l,
474 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000475#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 priority_queue(_InputIter __f, _InputIter __l,
479 const value_compare& __comp, container_type&& __c);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400480#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483 explicit priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500484 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 priority_queue(const value_compare& __comp, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500488 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 priority_queue(const value_compare& __comp, const container_type& __c,
492 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500493 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 priority_queue(const priority_queue& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500497 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000498#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 priority_queue(const value_compare& __comp, container_type&& __c,
502 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500503 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 priority_queue(priority_queue&& __q, const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500507 _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400508#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509
Marshall Clow425f5752017-11-15 05:51:26 +0000510 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 const_reference top() const {return c.front();}
516
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000519#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000522 template <class... _Args>
523 _LIBCPP_INLINE_VISIBILITY
524 void emplace(_Args&&... __args);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400525#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527 void pop();
528
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000530 void swap(priority_queue& __q)
531 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
532 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533};
534
Marshall Clow592d9952018-05-22 01:57:53 +0000535#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
536template <class _Compare,
537 class _Container,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500538 class = _EnableIf<!__is_allocator<_Compare>::value>,
539 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000540>
541priority_queue(_Compare, _Container)
542 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000543
544template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500545 class _Compare = less<__iter_value_type<_InputIterator>>,
546 class _Container = vector<__iter_value_type<_InputIterator>>,
547 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
548 class = _EnableIf<!__is_allocator<_Compare>::value>,
549 class = _EnableIf<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000550>
551priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500552 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000553
554template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000555 class _Container,
556 class _Alloc,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500557 class = _EnableIf<!__is_allocator<_Compare>::value>,
558 class = _EnableIf<!__is_allocator<_Container>::value>,
Arthur O'Dwyer9b9662f2021-03-01 17:08:24 -0500559 class = _EnableIf<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000560>
561priority_queue(_Compare, _Container, _Alloc)
562 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
563#endif
564
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000566inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
568 const container_type& __c)
569 : c(__c),
570 comp(__comp)
571{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000572 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573}
574
Eric Fiselier26081dd2017-04-18 21:23:18 +0000575#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576
577template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000578inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
580 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000581 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582 comp(__comp)
583{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000584 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585}
586
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400587#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588
589template <class _Tp, class _Container, class _Compare>
590template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000591inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
593 const value_compare& __comp)
594 : c(__f, __l),
595 comp(__comp)
596{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000597 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598}
599
600template <class _Tp, class _Container, class _Compare>
601template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000602inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
604 const value_compare& __comp,
605 const container_type& __c)
606 : c(__c),
607 comp(__comp)
608{
609 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000610 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611}
612
Eric Fiselier26081dd2017-04-18 21:23:18 +0000613#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614
615template <class _Tp, class _Container, class _Compare>
616template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000617inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
619 const value_compare& __comp,
620 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000621 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 comp(__comp)
623{
624 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000625 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626}
627
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400628#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
630template <class _Tp, class _Container, class _Compare>
631template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000632inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500634 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635 : c(__a)
636{
637}
638
639template <class _Tp, class _Container, class _Compare>
640template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000641inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
643 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500644 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 : c(__a),
646 comp(__comp)
647{
648}
649
650template <class _Tp, class _Container, class _Compare>
651template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000652inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
654 const container_type& __c,
655 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500656 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 : c(__c, __a),
658 comp(__comp)
659{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000660 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661}
662
663template <class _Tp, class _Container, class _Compare>
664template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000665inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
667 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500668 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 : c(__q.c, __a),
670 comp(__q.comp)
671{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000672 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673}
674
Eric Fiselier26081dd2017-04-18 21:23:18 +0000675#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676
677template <class _Tp, class _Container, class _Compare>
678template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000679inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
681 container_type&& __c,
682 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500683 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000684 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 comp(__comp)
686{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000687 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688}
689
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690template <class _Tp, class _Container, class _Compare>
691template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000692inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
694 const _Alloc& __a,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500695 _EnableIf<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000696 : c(_VSTD::move(__q.c), __a),
697 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000699 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700}
701
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400702#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703
704template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000705inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706void
707priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
708{
709 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000710 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711}
712
Eric Fiselier26081dd2017-04-18 21:23:18 +0000713#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714
715template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000716inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717void
718priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
719{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000720 c.push_back(_VSTD::move(__v));
721 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722}
723
724template <class _Tp, class _Container, class _Compare>
725template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000726inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727void
728priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
729{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000730 c.emplace_back(_VSTD::forward<_Args>(__args)...);
731 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732}
733
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400734#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735
736template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000737inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738void
739priority_queue<_Tp, _Container, _Compare>::pop()
740{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000741 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742 c.pop_back();
743}
744
745template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000746inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747void
748priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000749 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
750 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000752 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 swap(c, __q.c);
754 swap(comp, __q.comp);
755}
756
757template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000758inline _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500759_EnableIf<
760 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
Eric Fiselier6bfed252016-04-21 23:38:59 +0000761 void
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500762>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763swap(priority_queue<_Tp, _Container, _Compare>& __x,
764 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000765 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766{
767 __x.swap(__y);
768}
769
770template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000771struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772 : public uses_allocator<_Container, _Alloc>
773{
774};
775
776_LIBCPP_END_NAMESPACE_STD
777
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400778#endif // _LIBCPP_QUEUE