blob: 896c68265ac067ec29ee80c43bf94da98e43d985 [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
Howard Hinnant6a094412011-06-04 21:32:33 +000069 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)
156 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
174#pragma GCC system_header
175
176_LIBCPP_BEGIN_NAMESPACE_STD
177
178template <class _Tp, class _Container> class queue;
179
180template <class _Tp, class _Container>
181bool
182operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
183
184template <class _Tp, class _Container>
185bool
186operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
187
188template <class _Tp, class _Container = deque<_Tp> >
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000189class _LIBCPP_VISIBLE queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190{
191public:
192 typedef _Container container_type;
193 typedef typename container_type::value_type value_type;
194 typedef typename container_type::reference reference;
195 typedef typename container_type::const_reference const_reference;
196 typedef typename container_type::size_type size_type;
197
198protected:
199 container_type c;
200
201public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000203 queue()
204 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
205 : c() {}
206
207 _LIBCPP_INLINE_VISIBILITY
208 queue(const queue& __q) : c(__q.c) {}
209
210#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
211 _LIBCPP_INLINE_VISIBILITY
212 queue(queue&& __q)
213 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
214 : c(_STD::move(__q.c)) {}
215#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
216
217 _LIBCPP_INLINE_VISIBILITY
218 queue& operator=(const queue& __q) {c = __q.c; return *this;}
219
220#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
221 _LIBCPP_INLINE_VISIBILITY
222 queue& operator=(queue&& __q)
223 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
224 {c = _STD::move(__q.c); return *this;}
225#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
226
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000229#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231 explicit queue(container_type&& __c) : c(_STD::move(__c)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000232#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000233 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235 explicit queue(const _Alloc& __a,
236 typename enable_if<uses_allocator<container_type,
237 _Alloc>::value>::type* = 0)
238 : c(__a) {}
239 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241 queue(const queue& __q, const _Alloc& __a,
242 typename enable_if<uses_allocator<container_type,
243 _Alloc>::value>::type* = 0)
244 : c(__q.c, __a) {}
245 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247 queue(const container_type& __c, const _Alloc& __a,
248 typename enable_if<uses_allocator<container_type,
249 _Alloc>::value>::type* = 0)
250 : c(__c, __a) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000251#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254 queue(container_type&& __c, const _Alloc& __a,
255 typename enable_if<uses_allocator<container_type,
256 _Alloc>::value>::type* = 0)
257 : c(_STD::move(__c), __a) {}
258 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260 queue(queue&& __q, const _Alloc& __a,
261 typename enable_if<uses_allocator<container_type,
262 _Alloc>::value>::type* = 0)
263 : c(_STD::move(__q.c), __a) {}
264
Howard Hinnant73d21a42010-09-04 23:28:19 +0000265#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270 size_type size() const {return c.size();}
271
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000275 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279 const_reference back() const {return c.back();}
280
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000283#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285 void push(value_type&& __v) {c.push_back(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000286#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000287 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289 void emplace(_Args&&... __args)
290 {c.emplace_back(_STD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000291#endif // _LIBCPP_HAS_NO_VARIADICS
292#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294 void pop() {c.pop_front();}
295
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000298 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299 {
300 using _STD::swap;
301 swap(c, __q.c);
302 }
303
304 template <class _T1, class _C1>
305 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307 bool
308 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43 +0000309
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310 template <class _T1, class _C1>
311 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000313 bool
314 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
315};
316
317template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000318inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319bool
320operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
321{
322 return __x.c == __y.c;
323}
324
325template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000326inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327bool
328operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
329{
330 return __x.c < __y.c;
331}
332
333template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335bool
336operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
337{
338 return !(__x == __y);
339}
340
341template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000342inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343bool
344operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
345{
346 return __y < __x;
347}
348
349template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000350inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351bool
352operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
353{
354 return !(__x < __y);
355}
356
357template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359bool
360operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
361{
362 return !(__y < __x);
363}
364
365template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000366inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367void
368swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000369 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370{
371 __x.swap(__y);
372}
373
374template <class _Tp, class _Container, class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000375struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 : public uses_allocator<_Container, _Alloc>
377{
378};
379
380template <class _Tp, class _Container = vector<_Tp>,
381 class _Compare = less<typename _Container::value_type> >
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000382class _LIBCPP_VISIBLE priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383{
384public:
385 typedef _Container container_type;
386 typedef _Compare value_compare;
387 typedef typename container_type::value_type value_type;
388 typedef typename container_type::reference reference;
389 typedef typename container_type::const_reference const_reference;
390 typedef typename container_type::size_type size_type;
391
392protected:
393 container_type c;
394 value_compare comp;
395
396public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000398 priority_queue()
399 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
400 is_nothrow_default_constructible<value_compare>::value)
401 : c(), comp() {}
402
403 _LIBCPP_INLINE_VISIBILITY
404 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
405
406#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
407 _LIBCPP_INLINE_VISIBILITY
408 priority_queue(priority_queue&& __q)
409 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
410 is_nothrow_move_constructible<value_compare>::value)
411 : c(_STD::move(__q.c)), comp(_STD::move(__q.comp)) {}
412#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
413
414 _LIBCPP_INLINE_VISIBILITY
415 priority_queue& operator=(const priority_queue& __q)
416 {c = __q.c; comp = __q.comp; return *this;}
417
418#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
419 _LIBCPP_INLINE_VISIBILITY
420 priority_queue& operator=(priority_queue&& __q)
421 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
422 is_nothrow_move_assignable<value_compare>::value)
423 {c = _STD::move(__q.c); comp = _STD::move(__q.comp); return *this;}
424#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
425
426 _LIBCPP_INLINE_VISIBILITY
427 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 : c(), comp(__comp) {}
429 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000430#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431 explicit priority_queue(const value_compare& __comp, container_type&& __c);
432#endif
433 template <class _InputIter>
434 priority_queue(_InputIter __f, _InputIter __l,
435 const value_compare& __comp = value_compare());
436 template <class _InputIter>
437 priority_queue(_InputIter __f, _InputIter __l,
438 const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000439#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440 template <class _InputIter>
441 priority_queue(_InputIter __f, _InputIter __l,
442 const value_compare& __comp, container_type&& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000443#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 template <class _Alloc>
445 explicit priority_queue(const _Alloc& __a,
446 typename enable_if<uses_allocator<container_type,
447 _Alloc>::value>::type* = 0);
448 template <class _Alloc>
449 priority_queue(const value_compare& __comp, 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 container_type& __c,
454 const _Alloc& __a,
455 typename enable_if<uses_allocator<container_type,
456 _Alloc>::value>::type* = 0);
457 template <class _Alloc>
458 priority_queue(const priority_queue& __q, const _Alloc& __a,
459 typename enable_if<uses_allocator<container_type,
460 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000461#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462 template <class _Alloc>
463 priority_queue(const value_compare& __comp, container_type&& __c,
464 const _Alloc& __a,
465 typename enable_if<uses_allocator<container_type,
466 _Alloc>::value>::type* = 0);
467 template <class _Alloc>
468 priority_queue(priority_queue&& __q, const _Alloc& __a,
469 typename enable_if<uses_allocator<container_type,
470 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000471#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 const_reference top() const {return c.front();}
479
480 void push(const value_type& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000481#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 void push(value_type&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000483#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000485#endif
486#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487 void pop();
488
Howard Hinnant6a094412011-06-04 21:32:33 +0000489 void swap(priority_queue& __q)
490 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
491 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492};
493
494template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
497 const container_type& __c)
498 : c(__c),
499 comp(__comp)
500{
501 _STD::make_heap(c.begin(), c.end(), comp);
502}
503
Howard Hinnant73d21a42010-09-04 23:28:19 +0000504#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505
506template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000508priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
509 container_type&& __c)
510 : c(_STD::move(__c)),
511 comp(__comp)
512{
513 _STD::make_heap(c.begin(), c.end(), comp);
514}
515
Howard Hinnant73d21a42010-09-04 23:28:19 +0000516#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517
518template <class _Tp, class _Container, class _Compare>
519template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000520inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
522 const value_compare& __comp)
523 : c(__f, __l),
524 comp(__comp)
525{
526 _STD::make_heap(c.begin(), c.end(), comp);
527}
528
529template <class _Tp, class _Container, class _Compare>
530template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
533 const value_compare& __comp,
534 const container_type& __c)
535 : c(__c),
536 comp(__comp)
537{
538 c.insert(c.end(), __f, __l);
539 _STD::make_heap(c.begin(), c.end(), comp);
540}
541
Howard Hinnant73d21a42010-09-04 23:28:19 +0000542#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543
544template <class _Tp, class _Container, class _Compare>
545template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000546inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
548 const value_compare& __comp,
549 container_type&& __c)
550 : c(_STD::move(__c)),
551 comp(__comp)
552{
553 c.insert(c.end(), __f, __l);
554 _STD::make_heap(c.begin(), c.end(), comp);
555}
556
Howard Hinnant73d21a42010-09-04 23:28:19 +0000557#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558
559template <class _Tp, class _Container, class _Compare>
560template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
563 typename enable_if<uses_allocator<container_type,
564 _Alloc>::value>::type*)
565 : c(__a)
566{
567}
568
569template <class _Tp, class _Container, class _Compare>
570template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000571inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
573 const _Alloc& __a,
574 typename enable_if<uses_allocator<container_type,
575 _Alloc>::value>::type*)
576 : c(__a),
577 comp(__comp)
578{
579}
580
581template <class _Tp, class _Container, class _Compare>
582template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
585 const container_type& __c,
586 const _Alloc& __a,
587 typename enable_if<uses_allocator<container_type,
588 _Alloc>::value>::type*)
589 : c(__c, __a),
590 comp(__comp)
591{
592 _STD::make_heap(c.begin(), c.end(), comp);
593}
594
595template <class _Tp, class _Container, class _Compare>
596template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
599 const _Alloc& __a,
600 typename enable_if<uses_allocator<container_type,
601 _Alloc>::value>::type*)
602 : c(__q.c, __a),
603 comp(__q.comp)
604{
605 _STD::make_heap(c.begin(), c.end(), comp);
606}
607
Howard Hinnant73d21a42010-09-04 23:28:19 +0000608#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609
610template <class _Tp, class _Container, class _Compare>
611template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
614 container_type&& __c,
615 const _Alloc& __a,
616 typename enable_if<uses_allocator<container_type,
617 _Alloc>::value>::type*)
618 : c(_STD::move(__c), __a),
619 comp(__comp)
620{
621 _STD::make_heap(c.begin(), c.end(), comp);
622}
623
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624template <class _Tp, class _Container, class _Compare>
625template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
628 const _Alloc& __a,
629 typename enable_if<uses_allocator<container_type,
630 _Alloc>::value>::type*)
631 : c(_STD::move(__q.c), __a),
632 comp(_STD::move(__q.comp))
633{
634 _STD::make_heap(c.begin(), c.end(), comp);
635}
636
Howard Hinnant73d21a42010-09-04 23:28:19 +0000637#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638
639template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000640inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641void
642priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
643{
644 c.push_back(__v);
645 _STD::push_heap(c.begin(), c.end(), comp);
646}
647
Howard Hinnant73d21a42010-09-04 23:28:19 +0000648#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649
650template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652void
653priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
654{
655 c.push_back(_STD::move(__v));
656 _STD::push_heap(c.begin(), c.end(), comp);
657}
658
Howard Hinnant73d21a42010-09-04 23:28:19 +0000659#ifndef _LIBCPP_HAS_NO_VARIADICS
660
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661template <class _Tp, class _Container, class _Compare>
662template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664void
665priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
666{
667 c.emplace_back(_STD::forward<_Args>(__args)...);
668 _STD::push_heap(c.begin(), c.end(), comp);
669}
670
Howard Hinnant73d21a42010-09-04 23:28:19 +0000671#endif // _LIBCPP_HAS_NO_VARIADICS
672#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673
674template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676void
677priority_queue<_Tp, _Container, _Compare>::pop()
678{
679 _STD::pop_heap(c.begin(), c.end(), comp);
680 c.pop_back();
681}
682
683template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685void
686priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000687 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
688 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689{
690 using _STD::swap;
691 swap(c, __q.c);
692 swap(comp, __q.comp);
693}
694
695template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000696inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697void
698swap(priority_queue<_Tp, _Container, _Compare>& __x,
699 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000700 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701{
702 __x.swap(__y);
703}
704
705template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000706struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707 : public uses_allocator<_Container, _Alloc>
708{
709};
710
711_LIBCPP_END_NAMESPACE_STD
712
713#endif // _LIBCPP_QUEUE