blob: 81b83a7701ea9b1bae35879528abf052de8eb3d7 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-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 Hinnantc51e1022010-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 Hinnantbf438282011-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 Hinnantc51e1022010-05-11 19:42:16 +000043 explicit queue(const container_type& c);
Howard Hinnantbf438282011-06-04 21:32:33 +000044 explicit queue(container_type&& c)
Howard Hinnantc51e1022010-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 Hinnantbf438282011-06-04 21:32:33 +000052 queue(const queue& q, const Alloc& a);
53 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +000054 queue(queue&& q, const Alloc& a);
55
Howard Hinnantc51e1022010-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
Howard Hinnantbf438282011-06-04 21:32:33 +000069 void swap(queue& q) noexcept(noexcept(swap(c, q.c)));
Howard Hinnantc51e1022010-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 Hinnantbf438282011-06-04 21:32:33 +000091 void swap(queue<T, Container>& x, queue<T, Container>& y)
92 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-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 Hinnantbf438282011-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 Hinnantc51e1022010-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 Hinnantc51e1022010-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 Hinnantbf438282011-06-04 21:32:33 +0000142 priority_queue(const priority_queue& q, const Alloc& a);
143 template <class Alloc>
Howard Hinnantc51e1022010-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 Hinnantbf438282011-06-04 21:32:33 +0000155 void swap(priority_queue& q)
156 noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157};
158
159template <class T, class Container, class Compare>
160 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnantbf438282011-06-04 21:32:33 +0000161 priority_queue<T, Container, Compare>& y)
162 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-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 Hinnantaaaa52b2011-10-17 20:05:10 +0000174#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000176#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177
178_LIBCPP_BEGIN_NAMESPACE_STD
179
Marshall Clow9e1b8452015-02-18 17:51:56 +0000180template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181
182template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000183_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184bool
185operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
186
187template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000188_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189bool
190operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
191
Marshall Clow9e1b8452015-02-18 17:51:56 +0000192template <class _Tp, class _Container /*= deque<_Tp>*/>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000193class _LIBCPP_TYPE_VIS_ONLY queue
Howard Hinnantc51e1022010-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;
Marshall Clowb8825f02016-03-14 17:58:11 +0000201 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
203protected:
204 container_type c;
205
206public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000208 queue()
209 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
210 : c() {}
211
212 _LIBCPP_INLINE_VISIBILITY
213 queue(const queue& __q) : c(__q.c) {}
214
215#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
216 _LIBCPP_INLINE_VISIBILITY
217 queue(queue&& __q)
218 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000219 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000220#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
221
222 _LIBCPP_INLINE_VISIBILITY
223 queue& operator=(const queue& __q) {c = __q.c; return *this;}
224
225#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
226 _LIBCPP_INLINE_VISIBILITY
227 queue& operator=(queue&& __q)
228 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000229 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnantbf438282011-06-04 21:32:33 +0000230#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
231
Howard Hinnantf5f99992010-09-22 18:02:38 +0000232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000234#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000236 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000237#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 explicit queue(const _Alloc& __a,
241 typename enable_if<uses_allocator<container_type,
242 _Alloc>::value>::type* = 0)
243 : c(__a) {}
244 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 queue(const queue& __q, const _Alloc& __a,
247 typename enable_if<uses_allocator<container_type,
248 _Alloc>::value>::type* = 0)
249 : c(__q.c, __a) {}
250 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 queue(const container_type& __c, const _Alloc& __a,
253 typename enable_if<uses_allocator<container_type,
254 _Alloc>::value>::type* = 0)
255 : c(__c, __a) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000256#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 queue(container_type&& __c, const _Alloc& __a,
260 typename enable_if<uses_allocator<container_type,
261 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000262 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 queue(queue&& __q, const _Alloc& __a,
266 typename enable_if<uses_allocator<container_type,
267 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000268 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269
Howard Hinnant74279a52010-09-04 23:28:19 +0000270#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271
Howard Hinnantf5f99992010-09-22 18:02:38 +0000272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 size_type size() const {return c.size();}
276
Howard Hinnantf5f99992010-09-22 18:02:38 +0000277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 const_reference back() const {return c.back();}
285
Howard Hinnantf5f99992010-09-22 18:02:38 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000288#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000290 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000291#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294 void emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000295 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000296#endif // _LIBCPP_HAS_NO_VARIADICS
297#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 void pop() {c.pop_front();}
300
Howard Hinnantf5f99992010-09-22 18:02:38 +0000301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000303 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000305 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306 swap(c, __q.c);
307 }
308
309 template <class _T1, class _C1>
310 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 bool
313 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000314
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 template <class _T1, class _C1>
316 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318 bool
319 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
320};
321
322template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324bool
325operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
326{
327 return __x.c == __y.c;
328}
329
330template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332bool
333operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
334{
335 return __x.c < __y.c;
336}
337
338template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340bool
341operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
342{
343 return !(__x == __y);
344}
345
346template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348bool
349operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
350{
351 return __y < __x;
352}
353
354template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356bool
357operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
358{
359 return !(__x < __y);
360}
361
362template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364bool
365operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
366{
367 return !(__y < __x);
368}
369
370template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372void
373swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000374 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375{
376 __x.swap(__y);
377}
378
379template <class _Tp, class _Container, class _Alloc>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000380struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381 : public uses_allocator<_Container, _Alloc>
382{
383};
384
385template <class _Tp, class _Container = vector<_Tp>,
386 class _Compare = less<typename _Container::value_type> >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000387class _LIBCPP_TYPE_VIS_ONLY priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388{
389public:
390 typedef _Container container_type;
391 typedef _Compare value_compare;
392 typedef typename container_type::value_type value_type;
393 typedef typename container_type::reference reference;
394 typedef typename container_type::const_reference const_reference;
395 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000396 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397
398protected:
399 container_type c;
400 value_compare comp;
401
402public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000404 priority_queue()
405 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
406 is_nothrow_default_constructible<value_compare>::value)
407 : c(), comp() {}
408
409 _LIBCPP_INLINE_VISIBILITY
410 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
411
412#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
413 _LIBCPP_INLINE_VISIBILITY
414 priority_queue(priority_queue&& __q)
415 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
416 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000417 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000418#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
419
420 _LIBCPP_INLINE_VISIBILITY
421 priority_queue& operator=(const priority_queue& __q)
422 {c = __q.c; comp = __q.comp; return *this;}
423
424#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
425 _LIBCPP_INLINE_VISIBILITY
426 priority_queue& operator=(priority_queue&& __q)
427 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
428 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000429 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnantbf438282011-06-04 21:32:33 +0000430#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
431
432 _LIBCPP_INLINE_VISIBILITY
433 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434 : c(), comp(__comp) {}
435 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000436#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 explicit priority_queue(const value_compare& __comp, container_type&& __c);
438#endif
439 template <class _InputIter>
440 priority_queue(_InputIter __f, _InputIter __l,
441 const value_compare& __comp = value_compare());
442 template <class _InputIter>
443 priority_queue(_InputIter __f, _InputIter __l,
444 const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000445#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 template <class _InputIter>
447 priority_queue(_InputIter __f, _InputIter __l,
448 const value_compare& __comp, container_type&& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000449#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 template <class _Alloc>
451 explicit priority_queue(const _Alloc& __a,
452 typename enable_if<uses_allocator<container_type,
453 _Alloc>::value>::type* = 0);
454 template <class _Alloc>
455 priority_queue(const value_compare& __comp, const _Alloc& __a,
456 typename enable_if<uses_allocator<container_type,
457 _Alloc>::value>::type* = 0);
458 template <class _Alloc>
459 priority_queue(const value_compare& __comp, const container_type& __c,
460 const _Alloc& __a,
461 typename enable_if<uses_allocator<container_type,
462 _Alloc>::value>::type* = 0);
463 template <class _Alloc>
464 priority_queue(const priority_queue& __q, const _Alloc& __a,
465 typename enable_if<uses_allocator<container_type,
466 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 template <class _Alloc>
469 priority_queue(const value_compare& __comp, container_type&& __c,
470 const _Alloc& __a,
471 typename enable_if<uses_allocator<container_type,
472 _Alloc>::value>::type* = 0);
473 template <class _Alloc>
474 priority_queue(priority_queue&& __q, const _Alloc& __a,
475 typename enable_if<uses_allocator<container_type,
476 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000477#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478
Howard Hinnantf5f99992010-09-22 18:02:38 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 const_reference top() const {return c.front();}
485
486 void push(const value_type& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000487#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 void push(value_type&& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000489#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant74279a52010-09-04 23:28:19 +0000491#endif
492#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 void pop();
494
Howard Hinnantbf438282011-06-04 21:32:33 +0000495 void swap(priority_queue& __q)
496 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
497 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498};
499
500template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
503 const container_type& __c)
504 : c(__c),
505 comp(__comp)
506{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000507 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508}
509
Howard Hinnant74279a52010-09-04 23:28:19 +0000510#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511
512template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
515 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000516 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 comp(__comp)
518{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000519 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520}
521
Howard Hinnant74279a52010-09-04 23:28:19 +0000522#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523
524template <class _Tp, class _Container, class _Compare>
525template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
528 const value_compare& __comp)
529 : c(__f, __l),
530 comp(__comp)
531{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000532 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533}
534
535template <class _Tp, class _Container, class _Compare>
536template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000537inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
539 const value_compare& __comp,
540 const container_type& __c)
541 : c(__c),
542 comp(__comp)
543{
544 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000545 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546}
547
Howard Hinnant74279a52010-09-04 23:28:19 +0000548#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549
550template <class _Tp, class _Container, class _Compare>
551template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
554 const value_compare& __comp,
555 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000556 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 comp(__comp)
558{
559 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000560 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561}
562
Howard Hinnant74279a52010-09-04 23:28:19 +0000563#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564
565template <class _Tp, class _Container, class _Compare>
566template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
569 typename enable_if<uses_allocator<container_type,
570 _Alloc>::value>::type*)
571 : c(__a)
572{
573}
574
575template <class _Tp, class _Container, class _Compare>
576template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000577inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
579 const _Alloc& __a,
580 typename enable_if<uses_allocator<container_type,
581 _Alloc>::value>::type*)
582 : c(__a),
583 comp(__comp)
584{
585}
586
587template <class _Tp, class _Container, class _Compare>
588template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
591 const container_type& __c,
592 const _Alloc& __a,
593 typename enable_if<uses_allocator<container_type,
594 _Alloc>::value>::type*)
595 : c(__c, __a),
596 comp(__comp)
597{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000598 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599}
600
601template <class _Tp, class _Container, class _Compare>
602template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
605 const _Alloc& __a,
606 typename enable_if<uses_allocator<container_type,
607 _Alloc>::value>::type*)
608 : c(__q.c, __a),
609 comp(__q.comp)
610{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000611 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612}
613
Howard Hinnant74279a52010-09-04 23:28:19 +0000614#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615
616template <class _Tp, class _Container, class _Compare>
617template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
620 container_type&& __c,
621 const _Alloc& __a,
622 typename enable_if<uses_allocator<container_type,
623 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000624 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625 comp(__comp)
626{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000627 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628}
629
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630template <class _Tp, class _Container, class _Compare>
631template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
634 const _Alloc& __a,
635 typename enable_if<uses_allocator<container_type,
636 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000637 : c(_VSTD::move(__q.c), __a),
638 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000640 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641}
642
Howard Hinnant74279a52010-09-04 23:28:19 +0000643#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644
645template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647void
648priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
649{
650 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000651 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652}
653
Howard Hinnant74279a52010-09-04 23:28:19 +0000654#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
656template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658void
659priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
660{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000661 c.push_back(_VSTD::move(__v));
662 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663}
664
Howard Hinnant74279a52010-09-04 23:28:19 +0000665#ifndef _LIBCPP_HAS_NO_VARIADICS
666
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667template <class _Tp, class _Container, class _Compare>
668template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670void
671priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
672{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000673 c.emplace_back(_VSTD::forward<_Args>(__args)...);
674 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675}
676
Howard Hinnant74279a52010-09-04 23:28:19 +0000677#endif // _LIBCPP_HAS_NO_VARIADICS
678#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679
680template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000681inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682void
683priority_queue<_Tp, _Container, _Compare>::pop()
684{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000685 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686 c.pop_back();
687}
688
689template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691void
692priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000693 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
694 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000696 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697 swap(c, __q.c);
698 swap(comp, __q.comp);
699}
700
701template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000702inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703void
704swap(priority_queue<_Tp, _Container, _Compare>& __x,
705 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000706 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707{
708 __x.swap(__y);
709}
710
711template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000712struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 : public uses_allocator<_Container, _Alloc>
714{
715};
716
717_LIBCPP_END_NAMESPACE_STD
718
719#endif // _LIBCPP_QUEUE