blob: 97ec6f633c5153231a38696d23a5f675635de906 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Chandler Carruth7c3769d2019-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 Hinnantbc8d3f92010-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 Hinnant6a094412011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000042 explicit queue(const container_type& c);
Howard Hinnant6a094412011-06-04 21:32:33 +000043 explicit queue(container_type&& c)
Howard Hinnantbc8d3f92010-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 Hinnant6a094412011-06-04 21:32:33 +000051 queue(const queue& q, const Alloc& a);
52 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 queue(queue&& q, const Alloc& a);
54
Howard Hinnantbc8d3f92010-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 Clow4e42dc92017-01-24 23:09:12 +000065 template <class... Args> reference emplace(Args&&... args); // reference in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066 void pop();
67
Eric Fiselier8f1e73d2016-04-21 23:38:59 +000068 void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
Marshall Clow0e5d7072018-05-22 01:57:53 +000071template<class Container>
72 queue(Container) -> queue<typename Container::value_type, Container>; // C++17
Louis Dionnec30e2d92019-05-29 16:01:36 +000073
74template<class Container, class Allocator>
Marshall Clow0e5d7072018-05-22 01:57:53 +000075 queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
76
Howard Hinnantbc8d3f92010-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 Hinnant6a094412011-06-04 21:32:33 +000096 void swap(queue<T, Container>& x, queue<T, Container>& y)
97 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-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:
Howard Hinnant6a094412011-06-04 21:32:33 +0000115 priority_queue() = default;
116 ~priority_queue() = default;
117
118 priority_queue(const priority_queue& q) = default;
119 priority_queue(priority_queue&& q) = default;
120
121 priority_queue& operator=(const priority_queue& q) = default;
122 priority_queue& operator=(priority_queue&& q) = default;
123
124 explicit priority_queue(const Compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000125 priority_queue(const Compare& comp, const container_type& c);
126 explicit priority_queue(const Compare& comp, container_type&& c);
127 template <class InputIterator>
128 priority_queue(InputIterator first, InputIterator last,
129 const Compare& comp = Compare());
130 template <class InputIterator>
131 priority_queue(InputIterator first, InputIterator last,
132 const Compare& comp, const container_type& c);
133 template <class InputIterator>
134 priority_queue(InputIterator first, InputIterator last,
135 const Compare& comp, container_type&& c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136 template <class Alloc>
137 explicit priority_queue(const Alloc& a);
138 template <class Alloc>
139 priority_queue(const Compare& comp, const Alloc& a);
140 template <class Alloc>
141 priority_queue(const Compare& comp, const container_type& c,
142 const Alloc& a);
143 template <class Alloc>
144 priority_queue(const Compare& comp, container_type&& c,
145 const Alloc& a);
146 template <class Alloc>
Howard Hinnant6a094412011-06-04 21:32:33 +0000147 priority_queue(const priority_queue& q, const Alloc& a);
148 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149 priority_queue(priority_queue&& q, const Alloc& a);
150
151 bool empty() const;
152 size_type size() const;
153 const_reference top() const;
154
155 void push(const value_type& v);
156 void push(value_type&& v);
157 template <class... Args> void emplace(Args&&... args);
158 void pop();
159
Howard Hinnant6a094412011-06-04 21:32:33 +0000160 void swap(priority_queue& q)
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000161 noexcept(is_nothrow_swappable_v<Container> &&
162 is_nothrow_swappable_v<Comp>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163};
164
Marshall Clow0e5d7072018-05-22 01:57:53 +0000165template <class Compare, class Container>
166priority_queue(Compare, Container)
167 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
Louis Dionnec30e2d92019-05-29 16:01:36 +0000168
169template<class InputIterator,
Marshall Clow0e5d7072018-05-22 01:57:53 +0000170 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
171 class Container = vector<typename iterator_traits<InputIterator>::value_type>>
172priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
173 -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
Louis Dionnec30e2d92019-05-29 16:01:36 +0000174
Marshall Clow0e5d7072018-05-22 01:57:53 +0000175template<class Compare, class Container, class Allocator>
176priority_queue(Compare, Container, Allocator)
177 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
178
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179template <class T, class Container, class Compare>
180 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnant6a094412011-06-04 21:32:33 +0000181 priority_queue<T, Container, Compare>& y)
182 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000183
184} // std
185
186*/
187
188#include <__config>
189#include <deque>
190#include <vector>
191#include <functional>
192#include <algorithm>
193
Howard Hinnant08e17472011-10-17 20:05:10 +0000194#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000196#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197
198_LIBCPP_BEGIN_NAMESPACE_STD
199
Eric Fiselierc3589a82017-01-04 23:56:00 +0000200template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201
202template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000203_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204bool
205operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
206
207template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000208_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209bool
210operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
211
Marshall Clowa46f5ce2015-02-18 17:51:56 +0000212template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000213class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214{
215public:
216 typedef _Container container_type;
217 typedef typename container_type::value_type value_type;
218 typedef typename container_type::reference reference;
219 typedef typename container_type::const_reference const_reference;
220 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11 +0000221 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222
223protected:
224 container_type c;
225
226public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000228 queue()
229 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
230 : c() {}
231
232 _LIBCPP_INLINE_VISIBILITY
233 queue(const queue& __q) : c(__q.c) {}
234
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000235 _LIBCPP_INLINE_VISIBILITY
236 queue& operator=(const queue& __q) {c = __q.c; return *this;}
237
238#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000239 _LIBCPP_INLINE_VISIBILITY
240 queue(queue&& __q)
241 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000242 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000243
244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000245 queue& operator=(queue&& __q)
246 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000247 {c = _VSTD::move(__q.c); return *this;}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000248#endif // _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000249
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000252#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000254 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000255#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 explicit queue(const _Alloc& __a,
259 typename enable_if<uses_allocator<container_type,
260 _Alloc>::value>::type* = 0)
261 : c(__a) {}
262 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264 queue(const queue& __q, const _Alloc& __a,
265 typename enable_if<uses_allocator<container_type,
266 _Alloc>::value>::type* = 0)
267 : c(__q.c, __a) {}
268 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 queue(const container_type& __c, const _Alloc& __a,
271 typename enable_if<uses_allocator<container_type,
272 _Alloc>::value>::type* = 0)
273 : c(__c, __a) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000274#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277 queue(container_type&& __c, const _Alloc& __a,
278 typename enable_if<uses_allocator<container_type,
279 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000280 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283 queue(queue&& __q, const _Alloc& __a,
284 typename enable_if<uses_allocator<container_type,
285 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000286 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000288#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289
Marshall Clow88626bf2017-11-15 05:51:26 +0000290 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 size_type size() const {return c.size();}
294
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302 const_reference back() const {return c.back();}
303
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000306#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000308 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000310 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4e42dc92017-01-24 23:09:12 +0000311#if _LIBCPP_STD_VER > 14
Marshall Clowcc704882018-01-24 22:42:25 +0000312 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier3816ef92016-07-21 03:20:17 +0000313 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clow4e42dc92017-01-24 23:09:12 +0000314#else
315 void emplace(_Args&&... __args)
316 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
317#endif
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000318#endif // _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320 void pop() {c.pop_front();}
321
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000324 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000326 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327 swap(c, __q.c);
328 }
329
330 template <class _T1, class _C1>
331 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 bool
334 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43 +0000335
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 template <class _T1, class _C1>
337 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339 bool
340 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
341};
342
Marshall Clow0e5d7072018-05-22 01:57:53 +0000343#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
344template<class _Container,
345 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
346>
347queue(_Container)
348 -> queue<typename _Container::value_type, _Container>;
Louis Dionnec30e2d92019-05-29 16:01:36 +0000349
Marshall Clow0e5d7072018-05-22 01:57:53 +0000350template<class _Container,
351 class _Alloc,
352 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
353 class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
354>
355queue(_Container, _Alloc)
356 -> queue<typename _Container::value_type, _Container>;
357#endif
358
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361bool
362operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
363{
364 return __x.c == __y.c;
365}
366
367template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369bool
370operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
371{
372 return __x.c < __y.c;
373}
374
375template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377bool
378operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
379{
380 return !(__x == __y);
381}
382
383template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385bool
386operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
387{
388 return __y < __x;
389}
390
391template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393bool
394operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
395{
396 return !(__x < __y);
397}
398
399template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000400inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401bool
402operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
403{
404 return !(__y < __x);
405}
406
407template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000408inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000409typename enable_if<
410 __is_swappable<_Container>::value,
411 void
412>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000414 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415{
416 __x.swap(__y);
417}
418
419template <class _Tp, class _Container, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000420struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 : public uses_allocator<_Container, _Alloc>
422{
423};
424
425template <class _Tp, class _Container = vector<_Tp>,
426 class _Compare = less<typename _Container::value_type> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000427class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428{
429public:
430 typedef _Container container_type;
431 typedef _Compare value_compare;
432 typedef typename container_type::value_type value_type;
433 typedef typename container_type::reference reference;
434 typedef typename container_type::const_reference const_reference;
435 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11 +0000436 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437
438protected:
439 container_type c;
440 value_compare comp;
441
442public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000444 priority_queue()
445 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
446 is_nothrow_default_constructible<value_compare>::value)
447 : c(), comp() {}
448
449 _LIBCPP_INLINE_VISIBILITY
450 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
451
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000452 _LIBCPP_INLINE_VISIBILITY
453 priority_queue& operator=(const priority_queue& __q)
454 {c = __q.c; comp = __q.comp; return *this;}
455
456#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000457 _LIBCPP_INLINE_VISIBILITY
458 priority_queue(priority_queue&& __q)
459 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
460 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000461 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000462
463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000464 priority_queue& operator=(priority_queue&& __q)
465 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
466 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000467 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000468#endif // _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000469
470 _LIBCPP_INLINE_VISIBILITY
471 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472 : c(), comp(__comp) {}
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000475#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477 explicit priority_queue(const value_compare& __comp, container_type&& __c);
478#endif
479 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481 priority_queue(_InputIter __f, _InputIter __l,
482 const value_compare& __comp = value_compare());
483 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485 priority_queue(_InputIter __f, _InputIter __l,
486 const value_compare& __comp, const container_type& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000487#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 priority_queue(_InputIter __f, _InputIter __l,
491 const value_compare& __comp, container_type&& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000492#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495 explicit priority_queue(const _Alloc& __a,
496 typename enable_if<uses_allocator<container_type,
497 _Alloc>::value>::type* = 0);
498 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 priority_queue(const value_compare& __comp, const _Alloc& __a,
501 typename enable_if<uses_allocator<container_type,
502 _Alloc>::value>::type* = 0);
503 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 priority_queue(const value_compare& __comp, const container_type& __c,
506 const _Alloc& __a,
507 typename enable_if<uses_allocator<container_type,
508 _Alloc>::value>::type* = 0);
509 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 priority_queue(const priority_queue& __q, const _Alloc& __a,
512 typename enable_if<uses_allocator<container_type,
513 _Alloc>::value>::type* = 0);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000514#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 priority_queue(const value_compare& __comp, container_type&& __c,
518 const _Alloc& __a,
519 typename enable_if<uses_allocator<container_type,
520 _Alloc>::value>::type* = 0);
521 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 priority_queue(priority_queue&& __q, const _Alloc& __a,
524 typename enable_if<uses_allocator<container_type,
525 _Alloc>::value>::type* = 0);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000526#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527
Marshall Clow88626bf2017-11-15 05:51:26 +0000528 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 const_reference top() const {return c.front();}
534
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 void push(const value_type& __v);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000537#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 void push(value_type&& __v);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000540 template <class... _Args>
541 _LIBCPP_INLINE_VISIBILITY
542 void emplace(_Args&&... __args);
543#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 void pop();
546
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000548 void swap(priority_queue& __q)
549 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
550 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551};
552
Marshall Clow0e5d7072018-05-22 01:57:53 +0000553#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
554template <class _Compare,
555 class _Container,
556 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
557 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
558>
559priority_queue(_Compare, _Container)
560 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionnec30e2d92019-05-29 16:01:36 +0000561
562template<class _InputIterator,
Marshall Clow0e5d7072018-05-22 01:57:53 +0000563 class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
564 class _Container = vector<typename iterator_traits<_InputIterator>::value_type>,
565 class = typename enable_if< __is_input_iterator<_InputIterator>::value, nullptr_t>::type,
566 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
567 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
568>
569priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
570 -> priority_queue<typename iterator_traits<_InputIterator>::value_type, _Container, _Compare>;
Louis Dionnec30e2d92019-05-29 16:01:36 +0000571
572template<class _Compare,
Marshall Clow0e5d7072018-05-22 01:57:53 +0000573 class _Container,
574 class _Alloc,
575 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
576 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
577 class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
578>
579priority_queue(_Compare, _Container, _Alloc)
580 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
581#endif
582
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000584inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
586 const container_type& __c)
587 : c(__c),
588 comp(__comp)
589{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000590 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591}
592
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000593#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594
595template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000596inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
598 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000599 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 comp(__comp)
601{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000602 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603}
604
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000605#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606
607template <class _Tp, class _Container, class _Compare>
608template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000609inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
611 const value_compare& __comp)
612 : c(__f, __l),
613 comp(__comp)
614{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000615 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616}
617
618template <class _Tp, class _Container, class _Compare>
619template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000620inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
622 const value_compare& __comp,
623 const container_type& __c)
624 : c(__c),
625 comp(__comp)
626{
627 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000628 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629}
630
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000631#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632
633template <class _Tp, class _Container, class _Compare>
634template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000635inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
637 const value_compare& __comp,
638 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000639 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 comp(__comp)
641{
642 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000643 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644}
645
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000646#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647
648template <class _Tp, class _Container, class _Compare>
649template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000650inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
652 typename enable_if<uses_allocator<container_type,
653 _Alloc>::value>::type*)
654 : c(__a)
655{
656}
657
658template <class _Tp, class _Container, class _Compare>
659template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000660inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
662 const _Alloc& __a,
663 typename enable_if<uses_allocator<container_type,
664 _Alloc>::value>::type*)
665 : c(__a),
666 comp(__comp)
667{
668}
669
670template <class _Tp, class _Container, class _Compare>
671template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000672inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
674 const container_type& __c,
675 const _Alloc& __a,
676 typename enable_if<uses_allocator<container_type,
677 _Alloc>::value>::type*)
678 : c(__c, __a),
679 comp(__comp)
680{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000681 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682}
683
684template <class _Tp, class _Container, class _Compare>
685template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000686inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
688 const _Alloc& __a,
689 typename enable_if<uses_allocator<container_type,
690 _Alloc>::value>::type*)
691 : c(__q.c, __a),
692 comp(__q.comp)
693{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000694 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695}
696
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000697#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698
699template <class _Tp, class _Container, class _Compare>
700template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000701inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
703 container_type&& __c,
704 const _Alloc& __a,
705 typename enable_if<uses_allocator<container_type,
706 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000707 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 comp(__comp)
709{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000710 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711}
712
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713template <class _Tp, class _Container, class _Compare>
714template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000715inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
717 const _Alloc& __a,
718 typename enable_if<uses_allocator<container_type,
719 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000720 : c(_VSTD::move(__q.c), __a),
721 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000723 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724}
725
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000726#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727
728template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000729inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730void
731priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
732{
733 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000734 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735}
736
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000737#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738
739template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000740inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741void
742priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
743{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000744 c.push_back(_VSTD::move(__v));
745 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746}
747
748template <class _Tp, class _Container, class _Compare>
749template <class... _Args>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000750inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751void
752priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
753{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000754 c.emplace_back(_VSTD::forward<_Args>(__args)...);
755 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756}
757
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000758#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759
760template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000761inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000762void
763priority_queue<_Tp, _Container, _Compare>::pop()
764{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000765 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 c.pop_back();
767}
768
769template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000770inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771void
772priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000773 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
774 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000776 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 swap(c, __q.c);
778 swap(comp, __q.comp);
779}
780
781template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000782inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000783typename enable_if<
784 __is_swappable<_Container>::value
785 && __is_swappable<_Compare>::value,
786 void
787>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788swap(priority_queue<_Tp, _Container, _Compare>& __x,
789 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000790 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791{
792 __x.swap(__y);
793}
794
795template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000796struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797 : public uses_allocator<_Container, _Alloc>
798{
799};
800
801_LIBCPP_END_NAMESPACE_STD
802
803#endif // _LIBCPP_QUEUE