blob: f2e5d30034dfb8153cd29f874fbd70acc8482d63 [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:
34 queue();
35 explicit queue(const container_type& c);
36 explicit queue(container_type&& c);
37 queue(queue&& q);
38 template <class Alloc>
39 explicit queue(const Alloc& a);
40 template <class Alloc>
41 queue(const container_type& c, const Alloc& a);
42 template <class Alloc>
43 queue(container_type&& c, const Alloc& a);
44 template <class Alloc>
45 queue(queue&& q, const Alloc& a);
46
47 queue& operator=(queue&& q);
48
49 bool empty() const;
50 size_type size() const;
51
52 reference front();
53 const_reference front() const;
54 reference back();
55 const_reference back() const;
56
57 void push(const value_type& v);
58 void push(value_type&& v);
59 template <class... Args> void emplace(Args&&... args);
60 void pop();
61
62 void swap(queue& q);
63};
64
65template <class T, class Container>
66 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
67
68template <class T, class Container>
69 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
70
71template <class T, class Container>
72 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
73
74template <class T, class Container>
75 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
76
77template <class T, class Container>
78 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
79
80template <class T, class Container>
81 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
82
83template <class T, class Container>
84 void swap(queue<T, Container>& x, queue<T, Container>& y);
85
86template <class T, class Container = vector<T>,
87 class Compare = less<typename Container::value_type>>
88class priority_queue
89{
90public:
91 typedef Container container_type;
92 typedef typename container_type::value_type value_type;
93 typedef typename container_type::reference reference;
94 typedef typename container_type::const_reference const_reference;
95 typedef typename container_type::size_type size_type;
96
97protected:
98 container_type c;
99 Compare comp;
100
101public:
102 explicit priority_queue(const Compare& comp = Compare());
103 priority_queue(const Compare& comp, const container_type& c);
104 explicit priority_queue(const Compare& comp, container_type&& c);
105 template <class InputIterator>
106 priority_queue(InputIterator first, InputIterator last,
107 const Compare& comp = Compare());
108 template <class InputIterator>
109 priority_queue(InputIterator first, InputIterator last,
110 const Compare& comp, const container_type& c);
111 template <class InputIterator>
112 priority_queue(InputIterator first, InputIterator last,
113 const Compare& comp, container_type&& c);
114 priority_queue(priority_queue&& q);
115 priority_queue& operator=(priority_queue&& q);
116 template <class Alloc>
117 explicit priority_queue(const Alloc& a);
118 template <class Alloc>
119 priority_queue(const Compare& comp, const Alloc& a);
120 template <class Alloc>
121 priority_queue(const Compare& comp, const container_type& c,
122 const Alloc& a);
123 template <class Alloc>
124 priority_queue(const Compare& comp, container_type&& c,
125 const Alloc& a);
126 template <class Alloc>
127 priority_queue(priority_queue&& q, const Alloc& a);
128
129 bool empty() const;
130 size_type size() const;
131 const_reference top() const;
132
133 void push(const value_type& v);
134 void push(value_type&& v);
135 template <class... Args> void emplace(Args&&... args);
136 void pop();
137
138 void swap(priority_queue& q);
139};
140
141template <class T, class Container, class Compare>
142 void swap(priority_queue<T, Container, Compare>& x,
143 priority_queue<T, Container, Compare>& y);
144
145} // std
146
147*/
148
149#include <__config>
150#include <deque>
151#include <vector>
152#include <functional>
153#include <algorithm>
154
155#pragma GCC system_header
156
157_LIBCPP_BEGIN_NAMESPACE_STD
158
159template <class _Tp, class _Container> class queue;
160
161template <class _Tp, class _Container>
162bool
163operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
164
165template <class _Tp, class _Container>
166bool
167operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
168
169template <class _Tp, class _Container = deque<_Tp> >
Howard Hinnantf5f99992010-09-22 18:02:38 +0000170class _LIBCPP_VISIBLE queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171{
172public:
173 typedef _Container container_type;
174 typedef typename container_type::value_type value_type;
175 typedef typename container_type::reference reference;
176 typedef typename container_type::const_reference const_reference;
177 typedef typename container_type::size_type size_type;
178
179protected:
180 container_type c;
181
182public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184 queue() : c() {}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000187#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189 explicit queue(container_type&& __c) : c(_STD::move(__c)) {}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191 queue(queue&& __q) : c(_STD::move(__q.c)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000192#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000193 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195 explicit queue(const _Alloc& __a,
196 typename enable_if<uses_allocator<container_type,
197 _Alloc>::value>::type* = 0)
198 : c(__a) {}
199 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201 queue(const queue& __q, const _Alloc& __a,
202 typename enable_if<uses_allocator<container_type,
203 _Alloc>::value>::type* = 0)
204 : c(__q.c, __a) {}
205 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207 queue(const container_type& __c, const _Alloc& __a,
208 typename enable_if<uses_allocator<container_type,
209 _Alloc>::value>::type* = 0)
210 : c(__c, __a) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000211#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214 queue(container_type&& __c, const _Alloc& __a,
215 typename enable_if<uses_allocator<container_type,
216 _Alloc>::value>::type* = 0)
217 : c(_STD::move(__c), __a) {}
218 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000219 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220 queue(queue&& __q, const _Alloc& __a,
221 typename enable_if<uses_allocator<container_type,
222 _Alloc>::value>::type* = 0)
223 : c(_STD::move(__q.c), __a) {}
224
Howard Hinnantf5f99992010-09-22 18:02:38 +0000225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226 queue& operator=(queue&& __q)
227 {
228 c = _STD::move(__q.c);
229 return *this;
230 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000231#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232
Howard Hinnantf5f99992010-09-22 18:02:38 +0000233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236 size_type size() const {return c.size();}
237
Howard Hinnantf5f99992010-09-22 18:02:38 +0000238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 const_reference back() const {return c.back();}
246
Howard Hinnantf5f99992010-09-22 18:02:38 +0000247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000248 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000249#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 void push(value_type&& __v) {c.push_back(_STD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000252#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255 void emplace(_Args&&... __args)
256 {c.emplace_back(_STD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000257#endif // _LIBCPP_HAS_NO_VARIADICS
258#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantf5f99992010-09-22 18:02:38 +0000259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260 void pop() {c.pop_front();}
261
Howard Hinnantf5f99992010-09-22 18:02:38 +0000262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 void swap(queue& __q)
264 {
265 using _STD::swap;
266 swap(c, __q.c);
267 }
268
269 template <class _T1, class _C1>
270 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 bool
273 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000274
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 template <class _T1, class _C1>
276 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278 bool
279 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
280};
281
282template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000283inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284bool
285operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
286{
287 return __x.c == __y.c;
288}
289
290template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292bool
293operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
294{
295 return __x.c < __y.c;
296}
297
298template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000299inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300bool
301operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
302{
303 return !(__x == __y);
304}
305
306template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000307inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308bool
309operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
310{
311 return __y < __x;
312}
313
314template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316bool
317operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
318{
319 return !(__x < __y);
320}
321
322template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324bool
325operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
326{
327 return !(__y < __x);
328}
329
330template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332void
333swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
334{
335 __x.swap(__y);
336}
337
338template <class _Tp, class _Container, class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000339struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 : public uses_allocator<_Container, _Alloc>
341{
342};
343
344template <class _Tp, class _Container = vector<_Tp>,
345 class _Compare = less<typename _Container::value_type> >
Howard Hinnantf5f99992010-09-22 18:02:38 +0000346class _LIBCPP_VISIBLE priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347{
348public:
349 typedef _Container container_type;
350 typedef _Compare value_compare;
351 typedef typename container_type::value_type value_type;
352 typedef typename container_type::reference reference;
353 typedef typename container_type::const_reference const_reference;
354 typedef typename container_type::size_type size_type;
355
356protected:
357 container_type c;
358 value_compare comp;
359
360public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 explicit priority_queue(const value_compare& __comp = value_compare())
363 : c(), comp(__comp) {}
364 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000365#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 explicit priority_queue(const value_compare& __comp, container_type&& __c);
367#endif
368 template <class _InputIter>
369 priority_queue(_InputIter __f, _InputIter __l,
370 const value_compare& __comp = value_compare());
371 template <class _InputIter>
372 priority_queue(_InputIter __f, _InputIter __l,
373 const value_compare& __comp, const container_type& __c);
Howard Hinnant74279a52010-09-04 23:28:19 +0000374#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375 template <class _InputIter>
376 priority_queue(_InputIter __f, _InputIter __l,
377 const value_compare& __comp, container_type&& __c);
378 priority_queue(priority_queue&& __q);
379 priority_queue& operator=(priority_queue&& __q);
Howard Hinnant74279a52010-09-04 23:28:19 +0000380#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381 template <class _Alloc>
382 explicit priority_queue(const _Alloc& __a,
383 typename enable_if<uses_allocator<container_type,
384 _Alloc>::value>::type* = 0);
385 template <class _Alloc>
386 priority_queue(const value_compare& __comp, const _Alloc& __a,
387 typename enable_if<uses_allocator<container_type,
388 _Alloc>::value>::type* = 0);
389 template <class _Alloc>
390 priority_queue(const value_compare& __comp, const container_type& __c,
391 const _Alloc& __a,
392 typename enable_if<uses_allocator<container_type,
393 _Alloc>::value>::type* = 0);
394 template <class _Alloc>
395 priority_queue(const priority_queue& __q, const _Alloc& __a,
396 typename enable_if<uses_allocator<container_type,
397 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000398#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 template <class _Alloc>
400 priority_queue(const value_compare& __comp, container_type&& __c,
401 const _Alloc& __a,
402 typename enable_if<uses_allocator<container_type,
403 _Alloc>::value>::type* = 0);
404 template <class _Alloc>
405 priority_queue(priority_queue&& __q, const _Alloc& __a,
406 typename enable_if<uses_allocator<container_type,
407 _Alloc>::value>::type* = 0);
Howard Hinnant74279a52010-09-04 23:28:19 +0000408#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409
Howard Hinnantf5f99992010-09-22 18:02:38 +0000410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415 const_reference top() const {return c.front();}
416
417 void push(const value_type& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000418#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 void push(value_type&& __v);
Howard Hinnant74279a52010-09-04 23:28:19 +0000420#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant74279a52010-09-04 23:28:19 +0000422#endif
423#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 void pop();
425
426 void swap(priority_queue& __q);
427};
428
429template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000430inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
432 const container_type& __c)
433 : c(__c),
434 comp(__comp)
435{
436 _STD::make_heap(c.begin(), c.end(), comp);
437}
438
Howard Hinnant74279a52010-09-04 23:28:19 +0000439#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440
441template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000442inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
444 container_type&& __c)
445 : c(_STD::move(__c)),
446 comp(__comp)
447{
448 _STD::make_heap(c.begin(), c.end(), comp);
449}
450
Howard Hinnant74279a52010-09-04 23:28:19 +0000451#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452
453template <class _Tp, class _Container, class _Compare>
454template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000455inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
457 const value_compare& __comp)
458 : c(__f, __l),
459 comp(__comp)
460{
461 _STD::make_heap(c.begin(), c.end(), comp);
462}
463
464template <class _Tp, class _Container, class _Compare>
465template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
468 const value_compare& __comp,
469 const container_type& __c)
470 : c(__c),
471 comp(__comp)
472{
473 c.insert(c.end(), __f, __l);
474 _STD::make_heap(c.begin(), c.end(), comp);
475}
476
Howard Hinnant74279a52010-09-04 23:28:19 +0000477#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478
479template <class _Tp, class _Container, class _Compare>
480template <class _InputIter>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
483 const value_compare& __comp,
484 container_type&& __c)
485 : c(_STD::move(__c)),
486 comp(__comp)
487{
488 c.insert(c.end(), __f, __l);
489 _STD::make_heap(c.begin(), c.end(), comp);
490}
491
492template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000493inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q)
495 : c(_STD::move(__q.c)),
496 comp(_STD::move(__q.comp))
497{
498}
499
500template <class _Tp, class _Container, class _Compare>
501priority_queue<_Tp, _Container, _Compare>&
502priority_queue<_Tp, _Container, _Compare>::operator=(priority_queue&& __q)
503{
504 c = _STD::move(__q.c);
505 comp = _STD::move(__q.comp);
506 return *this;
507}
508
Howard Hinnant74279a52010-09-04 23:28:19 +0000509#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510
511template <class _Tp, class _Container, class _Compare>
512template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
515 typename enable_if<uses_allocator<container_type,
516 _Alloc>::value>::type*)
517 : c(__a)
518{
519}
520
521template <class _Tp, class _Container, class _Compare>
522template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000523inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
525 const _Alloc& __a,
526 typename enable_if<uses_allocator<container_type,
527 _Alloc>::value>::type*)
528 : c(__a),
529 comp(__comp)
530{
531}
532
533template <class _Tp, class _Container, class _Compare>
534template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
537 const container_type& __c,
538 const _Alloc& __a,
539 typename enable_if<uses_allocator<container_type,
540 _Alloc>::value>::type*)
541 : c(__c, __a),
542 comp(__comp)
543{
544 _STD::make_heap(c.begin(), c.end(), comp);
545}
546
547template <class _Tp, class _Container, class _Compare>
548template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000549inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
551 const _Alloc& __a,
552 typename enable_if<uses_allocator<container_type,
553 _Alloc>::value>::type*)
554 : c(__q.c, __a),
555 comp(__q.comp)
556{
557 _STD::make_heap(c.begin(), c.end(), comp);
558}
559
Howard Hinnant74279a52010-09-04 23:28:19 +0000560#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561
562template <class _Tp, class _Container, class _Compare>
563template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
566 container_type&& __c,
567 const _Alloc& __a,
568 typename enable_if<uses_allocator<container_type,
569 _Alloc>::value>::type*)
570 : c(_STD::move(__c), __a),
571 comp(__comp)
572{
573 _STD::make_heap(c.begin(), c.end(), comp);
574}
575
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576template <class _Tp, class _Container, class _Compare>
577template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
580 const _Alloc& __a,
581 typename enable_if<uses_allocator<container_type,
582 _Alloc>::value>::type*)
583 : c(_STD::move(__q.c), __a),
584 comp(_STD::move(__q.comp))
585{
586 _STD::make_heap(c.begin(), c.end(), comp);
587}
588
Howard Hinnant74279a52010-09-04 23:28:19 +0000589#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590
591template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593void
594priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
595{
596 c.push_back(__v);
597 _STD::push_heap(c.begin(), c.end(), comp);
598}
599
Howard Hinnant74279a52010-09-04 23:28:19 +0000600#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601
602template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604void
605priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
606{
607 c.push_back(_STD::move(__v));
608 _STD::push_heap(c.begin(), c.end(), comp);
609}
610
Howard Hinnant74279a52010-09-04 23:28:19 +0000611#ifndef _LIBCPP_HAS_NO_VARIADICS
612
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613template <class _Tp, class _Container, class _Compare>
614template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000615inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616void
617priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
618{
619 c.emplace_back(_STD::forward<_Args>(__args)...);
620 _STD::push_heap(c.begin(), c.end(), comp);
621}
622
Howard Hinnant74279a52010-09-04 23:28:19 +0000623#endif // _LIBCPP_HAS_NO_VARIADICS
624#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625
626template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000627inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628void
629priority_queue<_Tp, _Container, _Compare>::pop()
630{
631 _STD::pop_heap(c.begin(), c.end(), comp);
632 c.pop_back();
633}
634
635template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000636inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637void
638priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
639{
640 using _STD::swap;
641 swap(c, __q.c);
642 swap(comp, __q.comp);
643}
644
645template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647void
648swap(priority_queue<_Tp, _Container, _Compare>& __x,
649 priority_queue<_Tp, _Container, _Compare>& __y)
650{
651 __x.swap(__y);
652}
653
654template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000655struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656 : public uses_allocator<_Container, _Alloc>
657{
658};
659
660_LIBCPP_END_NAMESPACE_STD
661
662#endif // _LIBCPP_QUEUE