blob: 6f49c87acdc56cde6d0b33a80ac429aee5f6317e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_QUEUE
12#define _LIBCPP_QUEUE
13
14/*
15 queue synopsis
16
17namespace std
18{
19
20template <class T, class Container = deque<T>>
21class queue
22{
23public:
24 typedef Container container_type;
25 typedef typename container_type::value_type value_type;
26 typedef typename container_type::reference reference;
27 typedef typename container_type::const_reference const_reference;
28 typedef typename container_type::size_type size_type;
29
30protected:
31 container_type c;
32
33public:
Howard Hinnant6a094412011-06-04 21:32:33 +000034 queue() = default;
35 ~queue() = default;
36
37 queue(const queue& q) = default;
38 queue(queue&& q) = default;
39
40 queue& operator=(const queue& q) = default;
41 queue& operator=(queue&& q) = default;
42
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 explicit queue(const container_type& c);
Howard Hinnant6a094412011-06-04 21:32:33 +000044 explicit queue(container_type&& c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 template <class Alloc>
46 explicit queue(const Alloc& a);
47 template <class Alloc>
48 queue(const container_type& c, const Alloc& a);
49 template <class Alloc>
50 queue(container_type&& c, const Alloc& a);
51 template <class Alloc>
Howard Hinnant6a094412011-06-04 21:32:33 +000052 queue(const queue& q, const Alloc& a);
53 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 queue(queue&& q, const Alloc& a);
55
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056 bool empty() const;
57 size_type size() const;
58
59 reference front();
60 const_reference front() const;
61 reference back();
62 const_reference back() const;
63
64 void push(const value_type& v);
65 void push(value_type&& v);
66 template <class... Args> void emplace(Args&&... args);
67 void pop();
68
Dan Albert1d4a1ed2016-05-25 22:36:09 -070069 void swap(queue& q) noexcept(noexcept(swap(c, q.c)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070};
71
72template <class T, class Container>
73 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
74
75template <class T, class Container>
76 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
77
78template <class T, class Container>
79 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
80
81template <class T, class Container>
82 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
83
84template <class T, class Container>
85 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
86
87template <class T, class Container>
88 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
89
90template <class T, class Container>
Howard Hinnant6a094412011-06-04 21:32:33 +000091 void swap(queue<T, Container>& x, queue<T, Container>& y)
92 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093
94template <class T, class Container = vector<T>,
95 class Compare = less<typename Container::value_type>>
96class priority_queue
97{
98public:
99 typedef Container container_type;
100 typedef typename container_type::value_type value_type;
101 typedef typename container_type::reference reference;
102 typedef typename container_type::const_reference const_reference;
103 typedef typename container_type::size_type size_type;
104
105protected:
106 container_type c;
107 Compare comp;
108
109public:
Howard Hinnant6a094412011-06-04 21:32:33 +0000110 priority_queue() = default;
111 ~priority_queue() = default;
112
113 priority_queue(const priority_queue& q) = default;
114 priority_queue(priority_queue&& q) = default;
115
116 priority_queue& operator=(const priority_queue& q) = default;
117 priority_queue& operator=(priority_queue&& q) = default;
118
119 explicit priority_queue(const Compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 priority_queue(const Compare& comp, const container_type& c);
121 explicit priority_queue(const Compare& comp, container_type&& c);
122 template <class InputIterator>
123 priority_queue(InputIterator first, InputIterator last,
124 const Compare& comp = Compare());
125 template <class InputIterator>
126 priority_queue(InputIterator first, InputIterator last,
127 const Compare& comp, const container_type& c);
128 template <class InputIterator>
129 priority_queue(InputIterator first, InputIterator last,
130 const Compare& comp, container_type&& c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 template <class Alloc>
132 explicit priority_queue(const Alloc& a);
133 template <class Alloc>
134 priority_queue(const Compare& comp, const Alloc& a);
135 template <class Alloc>
136 priority_queue(const Compare& comp, const container_type& c,
137 const Alloc& a);
138 template <class Alloc>
139 priority_queue(const Compare& comp, container_type&& c,
140 const Alloc& a);
141 template <class Alloc>
Howard Hinnant6a094412011-06-04 21:32:33 +0000142 priority_queue(const priority_queue& q, const Alloc& a);
143 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144 priority_queue(priority_queue&& q, const Alloc& a);
145
146 bool empty() const;
147 size_type size() const;
148 const_reference top() const;
149
150 void push(const value_type& v);
151 void push(value_type&& v);
152 template <class... Args> void emplace(Args&&... args);
153 void pop();
154
Howard Hinnant6a094412011-06-04 21:32:33 +0000155 void swap(priority_queue& q)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700156 noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157};
158
159template <class T, class Container, class Compare>
160 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnant6a094412011-06-04 21:32:33 +0000161 priority_queue<T, Container, Compare>& y)
162 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000163
164} // std
165
166*/
167
168#include <__config>
169#include <deque>
170#include <vector>
171#include <functional>
172#include <algorithm>
173
Howard Hinnant08e17472011-10-17 20:05:10 +0000174#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000175#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000176#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177
178_LIBCPP_BEGIN_NAMESPACE_STD
179
Marshall Clowa46f5ce2015-02-18 17:51:56 +0000180template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY queue;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000181
182template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000183_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184bool
185operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
186
187template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000188_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000189bool
190operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
191
Marshall Clowa46f5ce2015-02-18 17:51:56 +0000192template <class _Tp, class _Container /*= deque<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000193class _LIBCPP_TYPE_VIS_ONLY queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000194{
195public:
196 typedef _Container container_type;
197 typedef typename container_type::value_type value_type;
198 typedef typename container_type::reference reference;
199 typedef typename container_type::const_reference const_reference;
200 typedef typename container_type::size_type size_type;
201
202protected:
203 container_type c;
204
205public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000207 queue()
208 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
209 : c() {}
210
211 _LIBCPP_INLINE_VISIBILITY
212 queue(const queue& __q) : c(__q.c) {}
213
214#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
215 _LIBCPP_INLINE_VISIBILITY
216 queue(queue&& __q)
217 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000218 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000219#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
220
221 _LIBCPP_INLINE_VISIBILITY
222 queue& operator=(const queue& __q) {c = __q.c; return *this;}
223
224#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
225 _LIBCPP_INLINE_VISIBILITY
226 queue& operator=(queue&& __q)
227 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000228 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33 +0000229#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
230
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000233#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000235 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000236#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 explicit queue(const _Alloc& __a,
240 typename enable_if<uses_allocator<container_type,
241 _Alloc>::value>::type* = 0)
242 : c(__a) {}
243 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245 queue(const queue& __q, const _Alloc& __a,
246 typename enable_if<uses_allocator<container_type,
247 _Alloc>::value>::type* = 0)
248 : c(__q.c, __a) {}
249 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 queue(const container_type& __c, const _Alloc& __a,
252 typename enable_if<uses_allocator<container_type,
253 _Alloc>::value>::type* = 0)
254 : c(__c, __a) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000255#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 queue(container_type&& __c, const _Alloc& __a,
259 typename enable_if<uses_allocator<container_type,
260 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000261 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264 queue(queue&& __q, const _Alloc& __a,
265 typename enable_if<uses_allocator<container_type,
266 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000267 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
Howard Hinnant73d21a42010-09-04 23:28:19 +0000269#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274 size_type size() const {return c.size();}
275
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283 const_reference back() const {return c.back();}
284
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000287#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000289 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000290#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 void emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000294 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000295#endif // _LIBCPP_HAS_NO_VARIADICS
296#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000298 void pop() {c.pop_front();}
299
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000302 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000304 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305 swap(c, __q.c);
306 }
307
308 template <class _T1, class _C1>
309 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000311 bool
312 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43 +0000313
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 template <class _T1, class _C1>
315 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317 bool
318 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
319};
320
321template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000322inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323bool
324operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
325{
326 return __x.c == __y.c;
327}
328
329template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000330inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331bool
332operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
333{
334 return __x.c < __y.c;
335}
336
337template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000338inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339bool
340operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
341{
342 return !(__x == __y);
343}
344
345template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347bool
348operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
349{
350 return __y < __x;
351}
352
353template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355bool
356operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
357{
358 return !(__x < __y);
359}
360
361template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363bool
364operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
365{
366 return !(__y < __x);
367}
368
369template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000370inline _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700371void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000373 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374{
375 __x.swap(__y);
376}
377
378template <class _Tp, class _Container, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000379struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380 : public uses_allocator<_Container, _Alloc>
381{
382};
383
384template <class _Tp, class _Container = vector<_Tp>,
385 class _Compare = less<typename _Container::value_type> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000386class _LIBCPP_TYPE_VIS_ONLY priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387{
388public:
389 typedef _Container container_type;
390 typedef _Compare value_compare;
391 typedef typename container_type::value_type value_type;
392 typedef typename container_type::reference reference;
393 typedef typename container_type::const_reference const_reference;
394 typedef typename container_type::size_type size_type;
395
396protected:
397 container_type c;
398 value_compare comp;
399
400public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000402 priority_queue()
403 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
404 is_nothrow_default_constructible<value_compare>::value)
405 : c(), comp() {}
406
407 _LIBCPP_INLINE_VISIBILITY
408 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
409
410#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
411 _LIBCPP_INLINE_VISIBILITY
412 priority_queue(priority_queue&& __q)
413 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
414 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000415 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000416#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
417
418 _LIBCPP_INLINE_VISIBILITY
419 priority_queue& operator=(const priority_queue& __q)
420 {c = __q.c; comp = __q.comp; return *this;}
421
422#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
423 _LIBCPP_INLINE_VISIBILITY
424 priority_queue& operator=(priority_queue&& __q)
425 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
426 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000427 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33 +0000428#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
429
430 _LIBCPP_INLINE_VISIBILITY
431 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 : c(), comp(__comp) {}
433 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000434#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 explicit priority_queue(const value_compare& __comp, container_type&& __c);
436#endif
437 template <class _InputIter>
438 priority_queue(_InputIter __f, _InputIter __l,
439 const value_compare& __comp = value_compare());
440 template <class _InputIter>
441 priority_queue(_InputIter __f, _InputIter __l,
442 const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000443#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 template <class _InputIter>
445 priority_queue(_InputIter __f, _InputIter __l,
446 const value_compare& __comp, container_type&& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000447#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 template <class _Alloc>
449 explicit priority_queue(const _Alloc& __a,
450 typename enable_if<uses_allocator<container_type,
451 _Alloc>::value>::type* = 0);
452 template <class _Alloc>
453 priority_queue(const value_compare& __comp, const _Alloc& __a,
454 typename enable_if<uses_allocator<container_type,
455 _Alloc>::value>::type* = 0);
456 template <class _Alloc>
457 priority_queue(const value_compare& __comp, const container_type& __c,
458 const _Alloc& __a,
459 typename enable_if<uses_allocator<container_type,
460 _Alloc>::value>::type* = 0);
461 template <class _Alloc>
462 priority_queue(const priority_queue& __q, const _Alloc& __a,
463 typename enable_if<uses_allocator<container_type,
464 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000465#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 template <class _Alloc>
467 priority_queue(const value_compare& __comp, container_type&& __c,
468 const _Alloc& __a,
469 typename enable_if<uses_allocator<container_type,
470 _Alloc>::value>::type* = 0);
471 template <class _Alloc>
472 priority_queue(priority_queue&& __q, const _Alloc& __a,
473 typename enable_if<uses_allocator<container_type,
474 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000475#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 const_reference top() const {return c.front();}
483
484 void push(const value_type& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000485#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486 void push(value_type&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000487#ifndef _LIBCPP_HAS_NO_VARIADICS
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700488 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000489#endif
490#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 void pop();
492
Howard Hinnant6a094412011-06-04 21:32:33 +0000493 void swap(priority_queue& __q)
494 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
495 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496};
497
498template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
501 const container_type& __c)
502 : c(__c),
503 comp(__comp)
504{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000505 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506}
507
Howard Hinnant73d21a42010-09-04 23:28:19 +0000508#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000509
510template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000512priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
513 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000514 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 comp(__comp)
516{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000517 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518}
519
Howard Hinnant73d21a42010-09-04 23:28:19 +0000520#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521
522template <class _Tp, class _Container, class _Compare>
523template <class _InputIter>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700524inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
526 const value_compare& __comp)
527 : c(__f, __l),
528 comp(__comp)
529{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000530 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531}
532
533template <class _Tp, class _Container, class _Compare>
534template <class _InputIter>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
537 const value_compare& __comp,
538 const container_type& __c)
539 : c(__c),
540 comp(__comp)
541{
542 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000543 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544}
545
Howard Hinnant73d21a42010-09-04 23:28:19 +0000546#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547
548template <class _Tp, class _Container, class _Compare>
549template <class _InputIter>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
552 const value_compare& __comp,
553 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000554 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555 comp(__comp)
556{
557 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000558 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559}
560
Howard Hinnant73d21a42010-09-04 23:28:19 +0000561#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562
563template <class _Tp, class _Container, class _Compare>
564template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700565inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
567 typename enable_if<uses_allocator<container_type,
568 _Alloc>::value>::type*)
569 : c(__a)
570{
571}
572
573template <class _Tp, class _Container, class _Compare>
574template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
577 const _Alloc& __a,
578 typename enable_if<uses_allocator<container_type,
579 _Alloc>::value>::type*)
580 : c(__a),
581 comp(__comp)
582{
583}
584
585template <class _Tp, class _Container, class _Compare>
586template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
589 const container_type& __c,
590 const _Alloc& __a,
591 typename enable_if<uses_allocator<container_type,
592 _Alloc>::value>::type*)
593 : c(__c, __a),
594 comp(__comp)
595{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000596 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597}
598
599template <class _Tp, class _Container, class _Compare>
600template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
603 const _Alloc& __a,
604 typename enable_if<uses_allocator<container_type,
605 _Alloc>::value>::type*)
606 : c(__q.c, __a),
607 comp(__q.comp)
608{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000609 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610}
611
Howard Hinnant73d21a42010-09-04 23:28:19 +0000612#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613
614template <class _Tp, class _Container, class _Compare>
615template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700616inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
618 container_type&& __c,
619 const _Alloc& __a,
620 typename enable_if<uses_allocator<container_type,
621 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000622 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 comp(__comp)
624{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000625 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626}
627
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628template <class _Tp, class _Container, class _Compare>
629template <class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
632 const _Alloc& __a,
633 typename enable_if<uses_allocator<container_type,
634 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000635 : c(_VSTD::move(__q.c), __a),
636 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000638 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639}
640
Howard Hinnant73d21a42010-09-04 23:28:19 +0000641#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642
643template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700644inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645void
646priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
647{
648 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000649 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650}
651
Howard Hinnant73d21a42010-09-04 23:28:19 +0000652#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653
654template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656void
657priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
658{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000659 c.push_back(_VSTD::move(__v));
660 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661}
662
Howard Hinnant73d21a42010-09-04 23:28:19 +0000663#ifndef _LIBCPP_HAS_NO_VARIADICS
664
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665template <class _Tp, class _Container, class _Compare>
666template <class... _Args>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668void
669priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
670{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000671 c.emplace_back(_VSTD::forward<_Args>(__args)...);
672 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673}
674
Howard Hinnant73d21a42010-09-04 23:28:19 +0000675#endif // _LIBCPP_HAS_NO_VARIADICS
676#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677
678template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680void
681priority_queue<_Tp, _Container, _Compare>::pop()
682{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000683 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 c.pop_back();
685}
686
687template <class _Tp, class _Container, class _Compare>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700688inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689void
690priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000691 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
692 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000694 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 swap(c, __q.c);
696 swap(comp, __q.comp);
697}
698
699template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000700inline _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700701void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702swap(priority_queue<_Tp, _Container, _Compare>& __x,
703 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000704 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705{
706 __x.swap(__y);
707}
708
709template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000710struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 : public uses_allocator<_Container, _Alloc>
712{
713};
714
715_LIBCPP_END_NAMESPACE_STD
716
717#endif // _LIBCPP_QUEUE