blob: e05ab8f8b0ff820d5607bfe0c1348595a4600926 [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
180template <class _Tp, class _Container> class queue;
181
182template <class _Tp, class _Container>
183bool
184operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
185
186template <class _Tp, class _Container>
187bool
188operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
189
190template <class _Tp, class _Container = deque<_Tp> >
Howard Hinnantf5f99992010-09-22 18:02:38 +0000191class _LIBCPP_VISIBLE queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192{
193public:
194 typedef _Container container_type;
195 typedef typename container_type::value_type value_type;
196 typedef typename container_type::reference reference;
197 typedef typename container_type::const_reference const_reference;
198 typedef typename container_type::size_type size_type;
199
200protected:
201 container_type c;
202
203public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000205 queue()
206 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
207 : c() {}
208
209 _LIBCPP_INLINE_VISIBILITY
210 queue(const queue& __q) : c(__q.c) {}
211
212#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
213 _LIBCPP_INLINE_VISIBILITY
214 queue(queue&& __q)
215 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000216 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000217#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
218
219 _LIBCPP_INLINE_VISIBILITY
220 queue& operator=(const queue& __q) {c = __q.c; return *this;}
221
222#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
223 _LIBCPP_INLINE_VISIBILITY
224 queue& operator=(queue&& __q)
225 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000226 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnantbf438282011-06-04 21:32:33 +0000227#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
228
Howard Hinnantf5f99992010-09-22 18:02:38 +0000229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000231#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000233 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000234#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 explicit queue(const _Alloc& __a,
238 typename enable_if<uses_allocator<container_type,
239 _Alloc>::value>::type* = 0)
240 : c(__a) {}
241 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243 queue(const queue& __q, const _Alloc& __a,
244 typename enable_if<uses_allocator<container_type,
245 _Alloc>::value>::type* = 0)
246 : c(__q.c, __a) {}
247 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 queue(const container_type& __c, const _Alloc& __a,
250 typename enable_if<uses_allocator<container_type,
251 _Alloc>::value>::type* = 0)
252 : c(__c, __a) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000253#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 queue(container_type&& __c, const _Alloc& __a,
257 typename enable_if<uses_allocator<container_type,
258 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000259 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 queue(queue&& __q, const _Alloc& __a,
263 typename enable_if<uses_allocator<container_type,
264 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000265 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266
Howard Hinnant74279a52010-09-04 23:28:19 +0000267#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Howard Hinnantf5f99992010-09-22 18:02:38 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 size_type size() const {return c.size();}
273
Howard Hinnantf5f99992010-09-22 18:02:38 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 const_reference back() const {return c.back();}
282
Howard Hinnantf5f99992010-09-22 18:02:38 +0000283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000285#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000287 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000288#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 void emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000292 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000293#endif // _LIBCPP_HAS_NO_VARIADICS
294#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 void pop() {c.pop_front();}
297
Howard Hinnantf5f99992010-09-22 18:02:38 +0000298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000299 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000300 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000302 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303 swap(c, __q.c);
304 }
305
306 template <class _T1, class _C1>
307 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309 bool
310 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000311
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312 template <class _T1, class _C1>
313 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 bool
316 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
317};
318
319template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321bool
322operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
323{
324 return __x.c == __y.c;
325}
326
327template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000328inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329bool
330operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
331{
332 return __x.c < __y.c;
333}
334
335template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337bool
338operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
339{
340 return !(__x == __y);
341}
342
343template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345bool
346operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
347{
348 return __y < __x;
349}
350
351template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353bool
354operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
355{
356 return !(__x < __y);
357}
358
359template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000361bool
362operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
363{
364 return !(__y < __x);
365}
366
367template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369void
370swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000371 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372{
373 __x.swap(__y);
374}
375
376template <class _Tp, class _Container, class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000377struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378 : public uses_allocator<_Container, _Alloc>
379{
380};
381
382template <class _Tp, class _Container = vector<_Tp>,
383 class _Compare = less<typename _Container::value_type> >
Howard Hinnantf5f99992010-09-22 18:02:38 +0000384class _LIBCPP_VISIBLE priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385{
386public:
387 typedef _Container container_type;
388 typedef _Compare value_compare;
389 typedef typename container_type::value_type value_type;
390 typedef typename container_type::reference reference;
391 typedef typename container_type::const_reference const_reference;
392 typedef typename container_type::size_type size_type;
393
394protected:
395 container_type c;
396 value_compare comp;
397
398public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000400 priority_queue()
401 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
402 is_nothrow_default_constructible<value_compare>::value)
403 : c(), comp() {}
404
405 _LIBCPP_INLINE_VISIBILITY
406 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
407
408#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
409 _LIBCPP_INLINE_VISIBILITY
410 priority_queue(priority_queue&& __q)
411 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
412 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000413 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000414#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
415
416 _LIBCPP_INLINE_VISIBILITY
417 priority_queue& operator=(const priority_queue& __q)
418 {c = __q.c; comp = __q.comp; return *this;}
419
420#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
421 _LIBCPP_INLINE_VISIBILITY
422 priority_queue& operator=(priority_queue&& __q)
423 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
424 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000425 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnantbf438282011-06-04 21:32:33 +0000426#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
427
428 _LIBCPP_INLINE_VISIBILITY
429 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 : c(), comp(__comp) {}
431 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000432#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433 explicit priority_queue(const value_compare& __comp, container_type&& __c);
434#endif
435 template <class _InputIter>
436 priority_queue(_InputIter __f, _InputIter __l,
437 const value_compare& __comp = value_compare());
438 template <class _InputIter>
439 priority_queue(_InputIter __f, _InputIter __l,
440 const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000441#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442 template <class _InputIter>
443 priority_queue(_InputIter __f, _InputIter __l,
444 const value_compare& __comp, container_type&& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000445#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446 template <class _Alloc>
447 explicit priority_queue(const _Alloc& __a,
448 typename enable_if<uses_allocator<container_type,
449 _Alloc>::value>::type* = 0);
450 template <class _Alloc>
451 priority_queue(const value_compare& __comp, 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 container_type& __c,
456 const _Alloc& __a,
457 typename enable_if<uses_allocator<container_type,
458 _Alloc>::value>::type* = 0);
459 template <class _Alloc>
460 priority_queue(const priority_queue& __q, const _Alloc& __a,
461 typename enable_if<uses_allocator<container_type,
462 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000463#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 template <class _Alloc>
465 priority_queue(const value_compare& __comp, container_type&& __c,
466 const _Alloc& __a,
467 typename enable_if<uses_allocator<container_type,
468 _Alloc>::value>::type* = 0);
469 template <class _Alloc>
470 priority_queue(priority_queue&& __q, const _Alloc& __a,
471 typename enable_if<uses_allocator<container_type,
472 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000473#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474
Howard Hinnantf5f99992010-09-22 18:02:38 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 const_reference top() const {return c.front();}
481
482 void push(const value_type& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000483#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484 void push(value_type&& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000485#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant74279a52010-09-04 23:28:19 +0000487#endif
488#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 void pop();
490
Howard Hinnantbf438282011-06-04 21:32:33 +0000491 void swap(priority_queue& __q)
492 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
493 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494};
495
496template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000497inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
499 const container_type& __c)
500 : c(__c),
501 comp(__comp)
502{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000503 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504}
505
Howard Hinnant74279a52010-09-04 23:28:19 +0000506#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507
508template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000509inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
511 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000512 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 comp(__comp)
514{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000515 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516}
517
Howard Hinnant74279a52010-09-04 23:28:19 +0000518#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519
520template <class _Tp, class _Container, class _Compare>
521template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
524 const value_compare& __comp)
525 : c(__f, __l),
526 comp(__comp)
527{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000528 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529}
530
531template <class _Tp, class _Container, class _Compare>
532template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
535 const value_compare& __comp,
536 const container_type& __c)
537 : c(__c),
538 comp(__comp)
539{
540 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000541 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542}
543
Howard Hinnant74279a52010-09-04 23:28:19 +0000544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545
546template <class _Tp, class _Container, class _Compare>
547template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
550 const value_compare& __comp,
551 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000552 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 comp(__comp)
554{
555 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000556 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557}
558
Howard Hinnant74279a52010-09-04 23:28:19 +0000559#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
561template <class _Tp, class _Container, class _Compare>
562template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
565 typename enable_if<uses_allocator<container_type,
566 _Alloc>::value>::type*)
567 : c(__a)
568{
569}
570
571template <class _Tp, class _Container, class _Compare>
572template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
575 const _Alloc& __a,
576 typename enable_if<uses_allocator<container_type,
577 _Alloc>::value>::type*)
578 : c(__a),
579 comp(__comp)
580{
581}
582
583template <class _Tp, class _Container, class _Compare>
584template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
587 const container_type& __c,
588 const _Alloc& __a,
589 typename enable_if<uses_allocator<container_type,
590 _Alloc>::value>::type*)
591 : c(__c, __a),
592 comp(__comp)
593{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000594 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595}
596
597template <class _Tp, class _Container, class _Compare>
598template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
601 const _Alloc& __a,
602 typename enable_if<uses_allocator<container_type,
603 _Alloc>::value>::type*)
604 : c(__q.c, __a),
605 comp(__q.comp)
606{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000607 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608}
609
Howard Hinnant74279a52010-09-04 23:28:19 +0000610#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611
612template <class _Tp, class _Container, class _Compare>
613template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
616 container_type&& __c,
617 const _Alloc& __a,
618 typename enable_if<uses_allocator<container_type,
619 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000620 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 comp(__comp)
622{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000623 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624}
625
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626template <class _Tp, class _Container, class _Compare>
627template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
630 const _Alloc& __a,
631 typename enable_if<uses_allocator<container_type,
632 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000633 : c(_VSTD::move(__q.c), __a),
634 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000636 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637}
638
Howard Hinnant74279a52010-09-04 23:28:19 +0000639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
641template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643void
644priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
645{
646 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000647 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648}
649
Howard Hinnant74279a52010-09-04 23:28:19 +0000650#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651
652template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654void
655priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
656{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000657 c.push_back(_VSTD::move(__v));
658 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659}
660
Howard Hinnant74279a52010-09-04 23:28:19 +0000661#ifndef _LIBCPP_HAS_NO_VARIADICS
662
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663template <class _Tp, class _Container, class _Compare>
664template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000665inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666void
667priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
668{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000669 c.emplace_back(_VSTD::forward<_Args>(__args)...);
670 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671}
672
Howard Hinnant74279a52010-09-04 23:28:19 +0000673#endif // _LIBCPP_HAS_NO_VARIADICS
674#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675
676template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678void
679priority_queue<_Tp, _Container, _Compare>::pop()
680{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000681 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682 c.pop_back();
683}
684
685template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000687void
688priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000689 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
690 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000692 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 swap(c, __q.c);
694 swap(comp, __q.comp);
695}
696
697template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699void
700swap(priority_queue<_Tp, _Container, _Compare>& __x,
701 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000702 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703{
704 __x.swap(__y);
705}
706
707template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000708struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709 : public uses_allocator<_Container, _Alloc>
710{
711};
712
713_LIBCPP_END_NAMESPACE_STD
714
715#endif // _LIBCPP_QUEUE