blob: e05ab8f8b0ff820d5607bfe0c1348595a4600926 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:3334 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:1643 explicit queue(const container_type& c);
Howard Hinnant6a094412011-06-04 21:32:3344 explicit queue(container_type&& c)
Howard Hinnantbc8d3f92010-05-11 19:42:1645 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:3352 queue(const queue& q, const Alloc& a);
53 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:1654 queue(queue&& q, const Alloc& a);
55
Howard Hinnantbc8d3f92010-05-11 19:42:1656 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:3369 void swap(queue& q) noexcept(noexcept(swap(c, q.c)));
Howard Hinnantbc8d3f92010-05-11 19:42:1670};
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:3391 void swap(queue<T, Container>& x, queue<T, Container>& y)
92 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:1693
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:33110 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:16120 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:16131 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:33142 priority_queue(const priority_queue& q, const Alloc& a);
143 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16144 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:33155 void swap(priority_queue& q)
156 noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp)));
Howard Hinnantbc8d3f92010-05-11 19:42:16157};
158
159template <class T, class Container, class Compare>
160 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnant6a094412011-06-04 21:32:33161 priority_queue<T, Container, Compare>& y)
162 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16163
164} // std
165
166*/
167
168#include <__config>
169#include <deque>
170#include <vector>
171#include <functional>
172#include <algorithm>
173
Howard Hinnant08e17472011-10-17 20:05:10174#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16175#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10176#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16177
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 Hinnantb9af2ea2010-09-22 18:02:38191class _LIBCPP_VISIBLE queue
Howard Hinnantbc8d3f92010-05-11 19:42:16192{
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 Hinnantb9af2ea2010-09-22 18:02:38204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33205 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 Hinnant0949eed2011-06-30 21:18:19216 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33217#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 Hinnant0949eed2011-06-30 21:18:19226 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33227#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
228
Howard Hinnantb9af2ea2010-09-22 18:02:38229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16230 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant73d21a42010-09-04 23:28:19231#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19233 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant73d21a42010-09-04 23:28:19234#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16235 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16237 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 Hinnantb9af2ea2010-09-22 18:02:38242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16243 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 Hinnantb9af2ea2010-09-22 18:02:38248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16249 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 Hinnant73d21a42010-09-04 23:28:19253#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16254 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16256 queue(container_type&& __c, const _Alloc& __a,
257 typename enable_if<uses_allocator<container_type,
258 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19259 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16260 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16262 queue(queue&& __q, const _Alloc& __a,
263 typename enable_if<uses_allocator<container_type,
264 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19265 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16266
Howard Hinnant73d21a42010-09-04 23:28:19267#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16268
Howard Hinnantb9af2ea2010-09-22 18:02:38269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16270 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16272 size_type size() const {return c.size();}
273
Howard Hinnantb9af2ea2010-09-22 18:02:38274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16275 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16277 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16279 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16281 const_reference back() const {return c.back();}
282
Howard Hinnantb9af2ea2010-09-22 18:02:38283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16284 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19285#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19287 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19288#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16289 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16291 void emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19292 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19293#endif // _LIBCPP_HAS_NO_VARIADICS
294#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16296 void pop() {c.pop_front();}
297
Howard Hinnantb9af2ea2010-09-22 18:02:38298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16299 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33300 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16301 {
Howard Hinnant0949eed2011-06-30 21:18:19302 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16303 swap(c, __q.c);
304 }
305
306 template <class _T1, class _C1>
307 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16309 bool
310 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43311
Howard Hinnantbc8d3f92010-05-11 19:42:16312 template <class _T1, class _C1>
313 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16315 bool
316 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
317};
318
319template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16321bool
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 Hinnantb9af2ea2010-09-22 18:02:38328inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16329bool
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 Hinnantb9af2ea2010-09-22 18:02:38336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16337bool
338operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
339{
340 return !(__x == __y);
341}
342
343template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16345bool
346operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
347{
348 return __y < __x;
349}
350
351template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16353bool
354operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
355{
356 return !(__x < __y);
357}
358
359template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16361bool
362operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
363{
364 return !(__y < __x);
365}
366
367template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16369void
370swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33371 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16372{
373 __x.swap(__y);
374}
375
376template <class _Tp, class _Container, class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38377struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16378 : public uses_allocator<_Container, _Alloc>
379{
380};
381
382template <class _Tp, class _Container = vector<_Tp>,
383 class _Compare = less<typename _Container::value_type> >
Howard Hinnantb9af2ea2010-09-22 18:02:38384class _LIBCPP_VISIBLE priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16385{
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 Hinnantb9af2ea2010-09-22 18:02:38399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33400 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 Hinnant0949eed2011-06-30 21:18:19413 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33414#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 Hinnant0949eed2011-06-30 21:18:19425 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33426#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
427
428 _LIBCPP_INLINE_VISIBILITY
429 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16430 : c(), comp(__comp) {}
431 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19432#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16433 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 Hinnant73d21a42010-09-04 23:28:19441#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16442 template <class _InputIter>
443 priority_queue(_InputIter __f, _InputIter __l,
444 const value_compare& __comp, container_type&& __c);
Howard Hinnant73d21a42010-09-04 23:28:19445#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16446 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 Hinnant73d21a42010-09-04 23:28:19463#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16464 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 Hinnant73d21a42010-09-04 23:28:19473#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16474
Howard Hinnantb9af2ea2010-09-22 18:02:38475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16476 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16478 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16480 const_reference top() const {return c.front();}
481
482 void push(const value_type& __v);
Howard Hinnant73d21a42010-09-04 23:28:19483#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16484 void push(value_type&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19485#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16486 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19487#endif
488#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16489 void pop();
490
Howard Hinnant6a094412011-06-04 21:32:33491 void swap(priority_queue& __q)
492 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
493 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16494};
495
496template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38497inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16498priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
499 const container_type& __c)
500 : c(__c),
501 comp(__comp)
502{
Howard Hinnant0949eed2011-06-30 21:18:19503 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16504}
505
Howard Hinnant73d21a42010-09-04 23:28:19506#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16507
508template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38509inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16510priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
511 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19512 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16513 comp(__comp)
514{
Howard Hinnant0949eed2011-06-30 21:18:19515 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16516}
517
Howard Hinnant73d21a42010-09-04 23:28:19518#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16519
520template <class _Tp, class _Container, class _Compare>
521template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16523priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
524 const value_compare& __comp)
525 : c(__f, __l),
526 comp(__comp)
527{
Howard Hinnant0949eed2011-06-30 21:18:19528 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16529}
530
531template <class _Tp, class _Container, class _Compare>
532template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16534priority_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 Hinnant0949eed2011-06-30 21:18:19541 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16542}
543
Howard Hinnant73d21a42010-09-04 23:28:19544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16545
546template <class _Tp, class _Container, class _Compare>
547template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38548inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16549priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
550 const value_compare& __comp,
551 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19552 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16553 comp(__comp)
554{
555 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19556 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16557}
558
Howard Hinnant73d21a42010-09-04 23:28:19559#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16560
561template <class _Tp, class _Container, class _Compare>
562template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16564priority_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 Hinnantb9af2ea2010-09-22 18:02:38573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16574priority_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 Hinnantb9af2ea2010-09-22 18:02:38585inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16586priority_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 Hinnant0949eed2011-06-30 21:18:19594 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16595}
596
597template <class _Tp, class _Container, class _Compare>
598template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38599inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16600priority_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 Hinnant0949eed2011-06-30 21:18:19607 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16608}
609
Howard Hinnant73d21a42010-09-04 23:28:19610#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16611
612template <class _Tp, class _Container, class _Compare>
613template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16615priority_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 Hinnant0949eed2011-06-30 21:18:19620 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16621 comp(__comp)
622{
Howard Hinnant0949eed2011-06-30 21:18:19623 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16624}
625
Howard Hinnantbc8d3f92010-05-11 19:42:16626template <class _Tp, class _Container, class _Compare>
627template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38628inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16629priority_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 Hinnant0949eed2011-06-30 21:18:19633 : c(_VSTD::move(__q.c), __a),
634 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16635{
Howard Hinnant0949eed2011-06-30 21:18:19636 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16637}
638
Howard Hinnant73d21a42010-09-04 23:28:19639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16640
641template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16643void
644priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
645{
646 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19647 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16648}
649
Howard Hinnant73d21a42010-09-04 23:28:19650#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16651
652template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16654void
655priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
656{
Howard Hinnant0949eed2011-06-30 21:18:19657 c.push_back(_VSTD::move(__v));
658 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16659}
660
Howard Hinnant73d21a42010-09-04 23:28:19661#ifndef _LIBCPP_HAS_NO_VARIADICS
662
Howard Hinnantbc8d3f92010-05-11 19:42:16663template <class _Tp, class _Container, class _Compare>
664template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38665inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16666void
667priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
668{
Howard Hinnant0949eed2011-06-30 21:18:19669 c.emplace_back(_VSTD::forward<_Args>(__args)...);
670 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16671}
672
Howard Hinnant73d21a42010-09-04 23:28:19673#endif // _LIBCPP_HAS_NO_VARIADICS
674#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16675
676template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16678void
679priority_queue<_Tp, _Container, _Compare>::pop()
680{
Howard Hinnant0949eed2011-06-30 21:18:19681 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16682 c.pop_back();
683}
684
685template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38686inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16687void
688priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33689 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
690 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16691{
Howard Hinnant0949eed2011-06-30 21:18:19692 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16693 swap(c, __q.c);
694 swap(comp, __q.comp);
695}
696
697template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16699void
700swap(priority_queue<_Tp, _Container, _Compare>& __x,
701 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33702 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16703{
704 __x.swap(__y);
705}
706
707template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38708struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16709 : public uses_allocator<_Container, _Alloc>
710{
711};
712
713_LIBCPP_END_NAMESPACE_STD
714
715#endif // _LIBCPP_QUEUE