blob: 01247a29da2b1b22685ffdd3b82f4ff111fa6f09 [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);
Eric Fiselier3816ef92016-07-21 03:20:1766 template <class... Args> reference emplace(Args&&... args);
Howard Hinnantbc8d3f92010-05-11 19:42:1667 void pop();
68
Eric Fiselier8f1e73d2016-04-21 23:38:5969 void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
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)
Eric Fiselier8f1e73d2016-04-21 23:38:59156 noexcept(is_nothrow_swappable_v<Container> &&
157 is_nothrow_swappable_v<Comp>)
Howard Hinnantbc8d3f92010-05-11 19:42:16158};
159
160template <class T, class Container, class Compare>
161 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnant6a094412011-06-04 21:32:33162 priority_queue<T, Container, Compare>& y)
163 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16164
165} // std
166
167*/
168
169#include <__config>
170#include <deque>
171#include <vector>
172#include <functional>
173#include <algorithm>
174
Howard Hinnant08e17472011-10-17 20:05:10175#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16176#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10177#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16178
179_LIBCPP_BEGIN_NAMESPACE_STD
180
Marshall Clowa46f5ce2015-02-18 17:51:56181template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TYPE_VIS_ONLY queue;
Howard Hinnantbc8d3f92010-05-11 19:42:16182
183template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16184_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16185bool
186operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
187
188template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16189_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16190bool
191operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
192
Marshall Clowa46f5ce2015-02-18 17:51:56193template <class _Tp, class _Container /*= deque<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34194class _LIBCPP_TYPE_VIS_ONLY queue
Howard Hinnantbc8d3f92010-05-11 19:42:16195{
196public:
197 typedef _Container container_type;
198 typedef typename container_type::value_type value_type;
199 typedef typename container_type::reference reference;
200 typedef typename container_type::const_reference const_reference;
201 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11202 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16203
204protected:
205 container_type c;
206
207public:
Howard Hinnantb9af2ea2010-09-22 18:02:38208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33209 queue()
210 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
211 : c() {}
212
213 _LIBCPP_INLINE_VISIBILITY
214 queue(const queue& __q) : c(__q.c) {}
215
216#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
217 _LIBCPP_INLINE_VISIBILITY
218 queue(queue&& __q)
219 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19220 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33221#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
222
223 _LIBCPP_INLINE_VISIBILITY
224 queue& operator=(const queue& __q) {c = __q.c; return *this;}
225
226#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
227 _LIBCPP_INLINE_VISIBILITY
228 queue& operator=(queue&& __q)
229 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19230 {c = _VSTD::move(__q.c); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33231#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
232
Howard Hinnantb9af2ea2010-09-22 18:02:38233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16234 explicit queue(const container_type& __c) : c(__c) {}
Howard Hinnant73d21a42010-09-04 23:28:19235#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19237 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Howard Hinnant73d21a42010-09-04 23:28:19238#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16239 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16241 explicit queue(const _Alloc& __a,
242 typename enable_if<uses_allocator<container_type,
243 _Alloc>::value>::type* = 0)
244 : c(__a) {}
245 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16247 queue(const queue& __q, const _Alloc& __a,
248 typename enable_if<uses_allocator<container_type,
249 _Alloc>::value>::type* = 0)
250 : c(__q.c, __a) {}
251 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16253 queue(const container_type& __c, const _Alloc& __a,
254 typename enable_if<uses_allocator<container_type,
255 _Alloc>::value>::type* = 0)
256 : c(__c, __a) {}
Howard Hinnant73d21a42010-09-04 23:28:19257#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16258 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16260 queue(container_type&& __c, const _Alloc& __a,
261 typename enable_if<uses_allocator<container_type,
262 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19263 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16264 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16266 queue(queue&& __q, const _Alloc& __a,
267 typename enable_if<uses_allocator<container_type,
268 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19269 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16270
Howard Hinnant73d21a42010-09-04 23:28:19271#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16272
Howard Hinnantb9af2ea2010-09-22 18:02:38273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16274 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16276 size_type size() const {return c.size();}
277
Howard Hinnantb9af2ea2010-09-22 18:02:38278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16279 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16281 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16283 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16285 const_reference back() const {return c.back();}
286
Howard Hinnantb9af2ea2010-09-22 18:02:38287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16288 void push(const value_type& __v) {c.push_back(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19289#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19291 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19292#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16293 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38294 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3816ef92016-07-21 03:20:17295 reference emplace(_Args&&... __args)
296 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19297#endif // _LIBCPP_HAS_NO_VARIADICS
298#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb9af2ea2010-09-22 18:02:38299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16300 void pop() {c.pop_front();}
301
Howard Hinnantb9af2ea2010-09-22 18:02:38302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16303 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33304 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16305 {
Howard Hinnant0949eed2011-06-30 21:18:19306 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16307 swap(c, __q.c);
308 }
309
310 template <class _T1, class _C1>
311 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16313 bool
314 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43315
Howard Hinnantbc8d3f92010-05-11 19:42:16316 template <class _T1, class _C1>
317 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16319 bool
320 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
321};
322
323template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16325bool
326operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
327{
328 return __x.c == __y.c;
329}
330
331template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16333bool
334operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
335{
336 return __x.c < __y.c;
337}
338
339template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16341bool
342operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
343{
344 return !(__x == __y);
345}
346
347template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16349bool
350operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
351{
352 return __y < __x;
353}
354
355template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38356inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16357bool
358operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
359{
360 return !(__x < __y);
361}
362
363template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38364inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16365bool
366operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
367{
368 return !(__y < __x);
369}
370
371template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38372inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59373typename enable_if<
374 __is_swappable<_Container>::value,
375 void
376>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16377swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33378 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16379{
380 __x.swap(__y);
381}
382
383template <class _Tp, class _Container, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34384struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16385 : public uses_allocator<_Container, _Alloc>
386{
387};
388
389template <class _Tp, class _Container = vector<_Tp>,
390 class _Compare = less<typename _Container::value_type> >
Howard Hinnant0f678bd2013-08-12 18:38:34391class _LIBCPP_TYPE_VIS_ONLY priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16392{
393public:
394 typedef _Container container_type;
395 typedef _Compare value_compare;
396 typedef typename container_type::value_type value_type;
397 typedef typename container_type::reference reference;
398 typedef typename container_type::const_reference const_reference;
399 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11400 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16401
402protected:
403 container_type c;
404 value_compare comp;
405
406public:
Howard Hinnantb9af2ea2010-09-22 18:02:38407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33408 priority_queue()
409 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
410 is_nothrow_default_constructible<value_compare>::value)
411 : c(), comp() {}
412
413 _LIBCPP_INLINE_VISIBILITY
414 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
415
416#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
417 _LIBCPP_INLINE_VISIBILITY
418 priority_queue(priority_queue&& __q)
419 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
420 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19421 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33422#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
423
424 _LIBCPP_INLINE_VISIBILITY
425 priority_queue& operator=(const priority_queue& __q)
426 {c = __q.c; comp = __q.comp; return *this;}
427
428#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
429 _LIBCPP_INLINE_VISIBILITY
430 priority_queue& operator=(priority_queue&& __q)
431 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
432 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19433 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Howard Hinnant6a094412011-06-04 21:32:33434#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
435
436 _LIBCPP_INLINE_VISIBILITY
437 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16438 : c(), comp(__comp) {}
Evgeniy Stepanov9341a8a2016-04-22 01:04:55439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16440 priority_queue(const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19441#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16443 explicit priority_queue(const value_compare& __comp, container_type&& __c);
444#endif
445 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16447 priority_queue(_InputIter __f, _InputIter __l,
448 const value_compare& __comp = value_compare());
449 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16451 priority_queue(_InputIter __f, _InputIter __l,
452 const value_compare& __comp, const container_type& __c);
Howard Hinnant73d21a42010-09-04 23:28:19453#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16454 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16456 priority_queue(_InputIter __f, _InputIter __l,
457 const value_compare& __comp, container_type&& __c);
Howard Hinnant73d21a42010-09-04 23:28:19458#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16459 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16461 explicit priority_queue(const _Alloc& __a,
462 typename enable_if<uses_allocator<container_type,
463 _Alloc>::value>::type* = 0);
464 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16466 priority_queue(const value_compare& __comp, const _Alloc& __a,
467 typename enable_if<uses_allocator<container_type,
468 _Alloc>::value>::type* = 0);
469 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16471 priority_queue(const value_compare& __comp, const container_type& __c,
472 const _Alloc& __a,
473 typename enable_if<uses_allocator<container_type,
474 _Alloc>::value>::type* = 0);
475 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16477 priority_queue(const priority_queue& __q, const _Alloc& __a,
478 typename enable_if<uses_allocator<container_type,
479 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19480#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16481 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16483 priority_queue(const value_compare& __comp, container_type&& __c,
484 const _Alloc& __a,
485 typename enable_if<uses_allocator<container_type,
486 _Alloc>::value>::type* = 0);
487 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16489 priority_queue(priority_queue&& __q, const _Alloc& __a,
490 typename enable_if<uses_allocator<container_type,
491 _Alloc>::value>::type* = 0);
Howard Hinnant73d21a42010-09-04 23:28:19492#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16493
Howard Hinnantb9af2ea2010-09-22 18:02:38494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16495 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16497 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16499 const_reference top() const {return c.front();}
500
Evgeniy Stepanov9341a8a2016-04-22 01:04:55501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16502 void push(const value_type& __v);
Howard Hinnant73d21a42010-09-04 23:28:19503#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16505 void push(value_type&& __v);
Howard Hinnant73d21a42010-09-04 23:28:19506#ifndef _LIBCPP_HAS_NO_VARIADICS
Evgeniy Stepanov9341a8a2016-04-22 01:04:55507 template <class... _Args> _LIBCPP_INLINE_VISIBILITY void emplace(_Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19508#endif
509#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16511 void pop();
512
Evgeniy Stepanov9341a8a2016-04-22 01:04:55513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33514 void swap(priority_queue& __q)
515 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
516 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16517};
518
519template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55520inline
Howard Hinnantbc8d3f92010-05-11 19:42:16521priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
522 const container_type& __c)
523 : c(__c),
524 comp(__comp)
525{
Howard Hinnant0949eed2011-06-30 21:18:19526 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16527}
528
Howard Hinnant73d21a42010-09-04 23:28:19529#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16530
531template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55532inline
Howard Hinnantbc8d3f92010-05-11 19:42:16533priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
534 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19535 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16536 comp(__comp)
537{
Howard Hinnant0949eed2011-06-30 21:18:19538 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16539}
540
Howard Hinnant73d21a42010-09-04 23:28:19541#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16542
543template <class _Tp, class _Container, class _Compare>
544template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55545inline
Howard Hinnantbc8d3f92010-05-11 19:42:16546priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
547 const value_compare& __comp)
548 : c(__f, __l),
549 comp(__comp)
550{
Howard Hinnant0949eed2011-06-30 21:18:19551 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16552}
553
554template <class _Tp, class _Container, class _Compare>
555template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55556inline
Howard Hinnantbc8d3f92010-05-11 19:42:16557priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
558 const value_compare& __comp,
559 const container_type& __c)
560 : c(__c),
561 comp(__comp)
562{
563 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19564 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16565}
566
Howard Hinnant73d21a42010-09-04 23:28:19567#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16568
569template <class _Tp, class _Container, class _Compare>
570template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55571inline
Howard Hinnantbc8d3f92010-05-11 19:42:16572priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
573 const value_compare& __comp,
574 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19575 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16576 comp(__comp)
577{
578 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19579 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16580}
581
Howard Hinnant73d21a42010-09-04 23:28:19582#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16583
584template <class _Tp, class _Container, class _Compare>
585template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55586inline
Howard Hinnantbc8d3f92010-05-11 19:42:16587priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
588 typename enable_if<uses_allocator<container_type,
589 _Alloc>::value>::type*)
590 : c(__a)
591{
592}
593
594template <class _Tp, class _Container, class _Compare>
595template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55596inline
Howard Hinnantbc8d3f92010-05-11 19:42:16597priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
598 const _Alloc& __a,
599 typename enable_if<uses_allocator<container_type,
600 _Alloc>::value>::type*)
601 : c(__a),
602 comp(__comp)
603{
604}
605
606template <class _Tp, class _Container, class _Compare>
607template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55608inline
Howard Hinnantbc8d3f92010-05-11 19:42:16609priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
610 const container_type& __c,
611 const _Alloc& __a,
612 typename enable_if<uses_allocator<container_type,
613 _Alloc>::value>::type*)
614 : c(__c, __a),
615 comp(__comp)
616{
Howard Hinnant0949eed2011-06-30 21:18:19617 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16618}
619
620template <class _Tp, class _Container, class _Compare>
621template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55622inline
Howard Hinnantbc8d3f92010-05-11 19:42:16623priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
624 const _Alloc& __a,
625 typename enable_if<uses_allocator<container_type,
626 _Alloc>::value>::type*)
627 : c(__q.c, __a),
628 comp(__q.comp)
629{
Howard Hinnant0949eed2011-06-30 21:18:19630 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16631}
632
Howard Hinnant73d21a42010-09-04 23:28:19633#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16634
635template <class _Tp, class _Container, class _Compare>
636template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55637inline
Howard Hinnantbc8d3f92010-05-11 19:42:16638priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
639 container_type&& __c,
640 const _Alloc& __a,
641 typename enable_if<uses_allocator<container_type,
642 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19643 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16644 comp(__comp)
645{
Howard Hinnant0949eed2011-06-30 21:18:19646 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16647}
648
Howard Hinnantbc8d3f92010-05-11 19:42:16649template <class _Tp, class _Container, class _Compare>
650template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55651inline
Howard Hinnantbc8d3f92010-05-11 19:42:16652priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
653 const _Alloc& __a,
654 typename enable_if<uses_allocator<container_type,
655 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19656 : c(_VSTD::move(__q.c), __a),
657 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16658{
Howard Hinnant0949eed2011-06-30 21:18:19659 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16660}
661
Howard Hinnant73d21a42010-09-04 23:28:19662#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16663
664template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55665inline
Howard Hinnantbc8d3f92010-05-11 19:42:16666void
667priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
668{
669 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19670 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16671}
672
Howard Hinnant73d21a42010-09-04 23:28:19673#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16674
675template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55676inline
Howard Hinnantbc8d3f92010-05-11 19:42:16677void
678priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
679{
Howard Hinnant0949eed2011-06-30 21:18:19680 c.push_back(_VSTD::move(__v));
681 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16682}
683
Howard Hinnant73d21a42010-09-04 23:28:19684#ifndef _LIBCPP_HAS_NO_VARIADICS
685
Howard Hinnantbc8d3f92010-05-11 19:42:16686template <class _Tp, class _Container, class _Compare>
687template <class... _Args>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55688inline
Howard Hinnantbc8d3f92010-05-11 19:42:16689void
690priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
691{
Howard Hinnant0949eed2011-06-30 21:18:19692 c.emplace_back(_VSTD::forward<_Args>(__args)...);
693 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16694}
695
Howard Hinnant73d21a42010-09-04 23:28:19696#endif // _LIBCPP_HAS_NO_VARIADICS
697#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16698
699template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55700inline
Howard Hinnantbc8d3f92010-05-11 19:42:16701void
702priority_queue<_Tp, _Container, _Compare>::pop()
703{
Howard Hinnant0949eed2011-06-30 21:18:19704 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16705 c.pop_back();
706}
707
708template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55709inline
Howard Hinnantbc8d3f92010-05-11 19:42:16710void
711priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33712 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
713 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16714{
Howard Hinnant0949eed2011-06-30 21:18:19715 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16716 swap(c, __q.c);
717 swap(comp, __q.comp);
718}
719
720template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38721inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59722typename enable_if<
723 __is_swappable<_Container>::value
724 && __is_swappable<_Compare>::value,
725 void
726>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16727swap(priority_queue<_Tp, _Container, _Compare>& __x,
728 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33729 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16730{
731 __x.swap(__y);
732}
733
734template <class _Tp, class _Container, class _Compare, class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34735struct _LIBCPP_TYPE_VIS_ONLY uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16736 : public uses_allocator<_Container, _Alloc>
737{
738};
739
740_LIBCPP_END_NAMESPACE_STD
741
742#endif // _LIBCPP_QUEUE