blob: 81b83a7701ea9b1bae35879528abf052de8eb3d7 [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
Marshall Clowa46f5ce2015-02-18 17:51:56180template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY queue;
Howard Hinnantbc8d3f92010-05-11 19:42:16181
182template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16183_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16184bool
185operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
186
187template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16188_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16189bool
190operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
191
Marshall Clowa46f5ce2015-02-18 17:51:56192template <class _Tp, class _Container /*= deque<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34193class _LIBCPP_TYPE_VIS_ONLY queue
Howard Hinnantbc8d3f92010-05-11 19:42:16194{
195public:
196 typedef _Container container_type;
197 typedef typename container_type::value_type value_type;
198 typedef typename container_type::reference reference;
199 typedef typename container_type::const_reference const_reference;
200 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11201 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16202
203protected:
204 container_type c;
205
206public:
Howard Hinnantb9af2ea2010-09-22 18:02:38207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33208 queue()
209 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
210 : c() {}
211
212 _LIBCPP_INLINE_VISIBILITY
213 queue(const queue& __q) : c(__q.c) {}
214
215#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
216 _LIBCPP_INLINE_VISIBILITY
217 queue(queue&& __q)
218 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19219 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33220#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
221
222 _LIBCPP_INLINE_VISIBILITY
223 queue& operator=(const queue& __q) {c = __q.c; return *this;}
224
225#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
226 _LIBCPP_INLINE_VISIBILITY
227 queue& operator=(queue&& __q)
228 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19229 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33230#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
231
Howard Hinnantb9af2ea2010-09-22 18:02:38232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16233 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant73d21a42010-09-04 23:28:19234#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19236 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant73d21a42010-09-04 23:28:19237#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16238 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16240 explicit queue(const _Alloc& __a,
241 typename enable_if<uses_allocator<container_type,
242 _Alloc>::value>::type* = 0)
243 : c(__a) {}
244 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16246 queue(const queue& __q, const _Alloc& __a,
247 typename enable_if<uses_allocator<container_type,
248 _Alloc>::value>::type* = 0)
249 : c(__q.c, __a) {}
250 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16252 queue(const container_type& __c, const _Alloc& __a,
253 typename enable_if<uses_allocator<container_type,
254 _Alloc>::value>::type* = 0)
255 : c(__c, __a) {}
Howard Hinnant73d21a42010-09-04 23:28:19256#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16257 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16259 queue(container_type&& __c, const _Alloc& __a,
260 typename enable_if<uses_allocator<container_type,
261 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19262 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16263 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16265 queue(queue&& __q, const _Alloc& __a,
266 typename enable_if<uses_allocator<container_type,
267 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19268 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16269
Howard Hinnant73d21a42010-09-04 23:28:19270#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16271
Howard Hinnantb9af2ea2010-09-22 18:02:38272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16273 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16275 size_type size() const {return c.size();}
276
Howard Hinnantb9af2ea2010-09-22 18:02:38277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16278 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16280 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16282 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16284 const_reference back() const {return c.back();}
285
Howard Hinnantb9af2ea2010-09-22 18:02:38286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16287 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19288#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19290 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19291#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16292 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16294 void emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19295 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19296#endif // _LIBCPP_HAS_NO_VARIADICS
297#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16299 void pop() {c.pop_front();}
300
Howard Hinnantb9af2ea2010-09-22 18:02:38301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16302 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33303 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16304 {
Howard Hinnant0949eed2011-06-30 21:18:19305 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16306 swap(c, __q.c);
307 }
308
309 template <class _T1, class _C1>
310 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16312 bool
313 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43314
Howard Hinnantbc8d3f92010-05-11 19:42:16315 template <class _T1, class _C1>
316 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16318 bool
319 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
320};
321
322template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16324bool
325operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
326{
327 return __x.c == __y.c;
328}
329
330template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16332bool
333operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
334{
335 return __x.c < __y.c;
336}
337
338template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16340bool
341operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
342{
343 return !(__x == __y);
344}
345
346template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16348bool
349operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
350{
351 return __y < __x;
352}
353
354template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16356bool
357operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
358{
359 return !(__x < __y);
360}
361
362template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16364bool
365operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
366{
367 return !(__y < __x);
368}
369
370template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16372void
373swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33374 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16375{
376 __x.swap(__y);
377}
378
379template <class _Tp, class _Container, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34380struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16381 : public uses_allocator<_Container, _Alloc>
382{
383};
384
385template <class _Tp, class _Container = vector<_Tp>,
386 class _Compare = less<typename _Container::value_type> >
Howard Hinnant0f678bd2013-08-12 18:38:34387class _LIBCPP_TYPE_VIS_ONLY priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16388{
389public:
390 typedef _Container container_type;
391 typedef _Compare value_compare;
392 typedef typename container_type::value_type value_type;
393 typedef typename container_type::reference reference;
394 typedef typename container_type::const_reference const_reference;
395 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11396 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16397
398protected:
399 container_type c;
400 value_compare comp;
401
402public:
Howard Hinnantb9af2ea2010-09-22 18:02:38403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33404 priority_queue()
405 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
406 is_nothrow_default_constructible<value_compare>::value)
407 : c(), comp() {}
408
409 _LIBCPP_INLINE_VISIBILITY
410 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
411
412#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
413 _LIBCPP_INLINE_VISIBILITY
414 priority_queue(priority_queue&& __q)
415 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
416 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19417 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33418#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
419
420 _LIBCPP_INLINE_VISIBILITY
421 priority_queue& operator=(const priority_queue& __q)
422 {c = __q.c; comp = __q.comp; return *this;}
423
424#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
425 _LIBCPP_INLINE_VISIBILITY
426 priority_queue& operator=(priority_queue&& __q)
427 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
428 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19429 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33430#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
431
432 _LIBCPP_INLINE_VISIBILITY
433 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16434 : c(), comp(__comp) {}
435 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19436#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16437 explicit priority_queue(const value_compare& __comp, container_type&& __c);
438#endif
439 template <class _InputIter>
440 priority_queue(_InputIter __f, _InputIter __l,
441 const value_compare& __comp = value_compare());
442 template <class _InputIter>
443 priority_queue(_InputIter __f, _InputIter __l,
444 const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19445#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16446 template <class _InputIter>
447 priority_queue(_InputIter __f, _InputIter __l,
448 const value_compare& __comp, container_type&& __c);
Howard Hinnant73d21a42010-09-04 23:28:19449#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16450 template <class _Alloc>
451 explicit priority_queue(const _Alloc& __a,
452 typename enable_if<uses_allocator<container_type,
453 _Alloc>::value>::type* = 0);
454 template <class _Alloc>
455 priority_queue(const value_compare& __comp, const _Alloc& __a,
456 typename enable_if<uses_allocator<container_type,
457 _Alloc>::value>::type* = 0);
458 template <class _Alloc>
459 priority_queue(const value_compare& __comp, const container_type& __c,
460 const _Alloc& __a,
461 typename enable_if<uses_allocator<container_type,
462 _Alloc>::value>::type* = 0);
463 template <class _Alloc>
464 priority_queue(const priority_queue& __q, const _Alloc& __a,
465 typename enable_if<uses_allocator<container_type,
466 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16468 template <class _Alloc>
469 priority_queue(const value_compare& __comp, container_type&& __c,
470 const _Alloc& __a,
471 typename enable_if<uses_allocator<container_type,
472 _Alloc>::value>::type* = 0);
473 template <class _Alloc>
474 priority_queue(priority_queue&& __q, const _Alloc& __a,
475 typename enable_if<uses_allocator<container_type,
476 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19477#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16478
Howard Hinnantb9af2ea2010-09-22 18:02:38479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16480 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16482 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16484 const_reference top() const {return c.front();}
485
486 void push(const value_type& __v);
Howard Hinnant73d21a42010-09-04 23:28:19487#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16488 void push(value_type&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19489#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16490 template <class... _Args> void emplace(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19491#endif
492#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16493 void pop();
494
Howard Hinnant6a094412011-06-04 21:32:33495 void swap(priority_queue& __q)
496 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
497 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16498};
499
500template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16502priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
503 const container_type& __c)
504 : c(__c),
505 comp(__comp)
506{
Howard Hinnant0949eed2011-06-30 21:18:19507 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16508}
509
Howard Hinnant73d21a42010-09-04 23:28:19510#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16511
512template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16514priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
515 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19516 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16517 comp(__comp)
518{
Howard Hinnant0949eed2011-06-30 21:18:19519 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16520}
521
Howard Hinnant73d21a42010-09-04 23:28:19522#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16523
524template <class _Tp, class _Container, class _Compare>
525template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16527priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
528 const value_compare& __comp)
529 : c(__f, __l),
530 comp(__comp)
531{
Howard Hinnant0949eed2011-06-30 21:18:19532 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16533}
534
535template <class _Tp, class _Container, class _Compare>
536template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38537inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16538priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
539 const value_compare& __comp,
540 const container_type& __c)
541 : c(__c),
542 comp(__comp)
543{
544 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19545 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16546}
547
Howard Hinnant73d21a42010-09-04 23:28:19548#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16549
550template <class _Tp, class _Container, class _Compare>
551template <class _InputIter>
Howard Hinnantb9af2ea2010-09-22 18:02:38552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16553priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
554 const value_compare& __comp,
555 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19556 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16557 comp(__comp)
558{
559 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19560 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16561}
562
Howard Hinnant73d21a42010-09-04 23:28:19563#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16564
565template <class _Tp, class _Container, class _Compare>
566template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38567inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16568priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
569 typename enable_if<uses_allocator<container_type,
570 _Alloc>::value>::type*)
571 : c(__a)
572{
573}
574
575template <class _Tp, class _Container, class _Compare>
576template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38577inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16578priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
579 const _Alloc& __a,
580 typename enable_if<uses_allocator<container_type,
581 _Alloc>::value>::type*)
582 : c(__a),
583 comp(__comp)
584{
585}
586
587template <class _Tp, class _Container, class _Compare>
588template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16590priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
591 const container_type& __c,
592 const _Alloc& __a,
593 typename enable_if<uses_allocator<container_type,
594 _Alloc>::value>::type*)
595 : c(__c, __a),
596 comp(__comp)
597{
Howard Hinnant0949eed2011-06-30 21:18:19598 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16599}
600
601template <class _Tp, class _Container, class _Compare>
602template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16604priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
605 const _Alloc& __a,
606 typename enable_if<uses_allocator<container_type,
607 _Alloc>::value>::type*)
608 : c(__q.c, __a),
609 comp(__q.comp)
610{
Howard Hinnant0949eed2011-06-30 21:18:19611 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16612}
613
Howard Hinnant73d21a42010-09-04 23:28:19614#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16615
616template <class _Tp, class _Container, class _Compare>
617template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16619priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
620 container_type&& __c,
621 const _Alloc& __a,
622 typename enable_if<uses_allocator<container_type,
623 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19624 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16625 comp(__comp)
626{
Howard Hinnant0949eed2011-06-30 21:18:19627 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16628}
629
Howard Hinnantbc8d3f92010-05-11 19:42:16630template <class _Tp, class _Container, class _Compare>
631template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16633priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
634 const _Alloc& __a,
635 typename enable_if<uses_allocator<container_type,
636 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19637 : c(_VSTD::move(__q.c), __a),
638 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16639{
Howard Hinnant0949eed2011-06-30 21:18:19640 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16641}
642
Howard Hinnant73d21a42010-09-04 23:28:19643#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16644
645template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38646inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16647void
648priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
649{
650 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19651 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16652}
653
Howard Hinnant73d21a42010-09-04 23:28:19654#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16655
656template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16658void
659priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
660{
Howard Hinnant0949eed2011-06-30 21:18:19661 c.push_back(_VSTD::move(__v));
662 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16663}
664
Howard Hinnant73d21a42010-09-04 23:28:19665#ifndef _LIBCPP_HAS_NO_VARIADICS
666
Howard Hinnantbc8d3f92010-05-11 19:42:16667template <class _Tp, class _Container, class _Compare>
668template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16670void
671priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
672{
Howard Hinnant0949eed2011-06-30 21:18:19673 c.emplace_back(_VSTD::forward<_Args>(__args)...);
674 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16675}
676
Howard Hinnant73d21a42010-09-04 23:28:19677#endif // _LIBCPP_HAS_NO_VARIADICS
678#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16679
680template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38681inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16682void
683priority_queue<_Tp, _Container, _Compare>::pop()
684{
Howard Hinnant0949eed2011-06-30 21:18:19685 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16686 c.pop_back();
687}
688
689template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16691void
692priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33693 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
694 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16695{
Howard Hinnant0949eed2011-06-30 21:18:19696 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16697 swap(c, __q.c);
698 swap(comp, __q.comp);
699}
700
701template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38702inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16703void
704swap(priority_queue<_Tp, _Container, _Compare>& __x,
705 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33706 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16707{
708 __x.swap(__y);
709}
710
711template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34712struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16713 : public uses_allocator<_Container, _Alloc>
714{
715};
716
717_LIBCPP_END_NAMESPACE_STD
718
719#endif // _LIBCPP_QUEUE