blob: 80546fd81ad1cf0f5130e5eba8137ad14d3fc854 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_QUEUE
12#define _LIBCPP_QUEUE
13
14/*
15 queue synopsis
16
17namespace std
18{
19
20template <class T, class Container = deque<T>>
21class queue
22{
23public:
24 typedef Container container_type;
25 typedef typename container_type::value_type value_type;
26 typedef typename container_type::reference reference;
27 typedef typename container_type::const_reference const_reference;
28 typedef typename container_type::size_type size_type;
29
30protected:
31 container_type c;
32
33public:
Howard Hinnant6a094412011-06-04 21:32:33 +000034 queue() = default;
35 ~queue() = default;
36
37 queue(const queue& q) = default;
38 queue(queue&& q) = default;
39
40 queue& operator=(const queue& q) = default;
41 queue& operator=(queue&& q) = default;
42
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 explicit queue(const container_type& c);
Howard Hinnant6a094412011-06-04 21:32:33 +000044 explicit queue(container_type&& c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 template <class Alloc>
46 explicit queue(const Alloc& a);
47 template <class Alloc>
48 queue(const container_type& c, const Alloc& a);
49 template <class Alloc>
50 queue(container_type&& c, const Alloc& a);
51 template <class Alloc>
Howard Hinnant6a094412011-06-04 21:32:33 +000052 queue(const queue& q, const Alloc& a);
53 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 queue(queue&& q, const Alloc& a);
55
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056 bool empty() const;
57 size_type size() const;
58
59 reference front();
60 const_reference front() const;
61 reference back();
62 const_reference back() const;
63
64 void push(const value_type& v);
65 void push(value_type&& v);
Marshall Clow4e42dc92017-01-24 23:09:12 +000066 template <class... Args> reference emplace(Args&&... args); // reference in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 void pop();
68
Eric Fiselier8f1e73d2016-04-21 23:38:59 +000069 void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070};
71
72template <class T, class Container>
73 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
74
75template <class T, class Container>
76 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
77
78template <class T, class Container>
79 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
80
81template <class T, class Container>
82 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
83
84template <class T, class Container>
85 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
86
87template <class T, class Container>
88 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
89
90template <class T, class Container>
Howard Hinnant6a094412011-06-04 21:32:33 +000091 void swap(queue<T, Container>& x, queue<T, Container>& y)
92 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000093
94template <class T, class Container = vector<T>,
95 class Compare = less<typename Container::value_type>>
96class priority_queue
97{
98public:
99 typedef Container container_type;
100 typedef typename container_type::value_type value_type;
101 typedef typename container_type::reference reference;
102 typedef typename container_type::const_reference const_reference;
103 typedef typename container_type::size_type size_type;
104
105protected:
106 container_type c;
107 Compare comp;
108
109public:
Howard Hinnant6a094412011-06-04 21:32:33 +0000110 priority_queue() = default;
111 ~priority_queue() = default;
112
113 priority_queue(const priority_queue& q) = default;
114 priority_queue(priority_queue&& q) = default;
115
116 priority_queue& operator=(const priority_queue& q) = default;
117 priority_queue& operator=(priority_queue&& q) = default;
118
119 explicit priority_queue(const Compare& comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 priority_queue(const Compare& comp, const container_type& c);
121 explicit priority_queue(const Compare& comp, container_type&& c);
122 template <class InputIterator>
123 priority_queue(InputIterator first, InputIterator last,
124 const Compare& comp = Compare());
125 template <class InputIterator>
126 priority_queue(InputIterator first, InputIterator last,
127 const Compare& comp, const container_type& c);
128 template <class InputIterator>
129 priority_queue(InputIterator first, InputIterator last,
130 const Compare& comp, container_type&& c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000131 template <class Alloc>
132 explicit priority_queue(const Alloc& a);
133 template <class Alloc>
134 priority_queue(const Compare& comp, const Alloc& a);
135 template <class Alloc>
136 priority_queue(const Compare& comp, const container_type& c,
137 const Alloc& a);
138 template <class Alloc>
139 priority_queue(const Compare& comp, container_type&& c,
140 const Alloc& a);
141 template <class Alloc>
Howard Hinnant6a094412011-06-04 21:32:33 +0000142 priority_queue(const priority_queue& q, const Alloc& a);
143 template <class Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144 priority_queue(priority_queue&& q, const Alloc& a);
145
146 bool empty() const;
147 size_type size() const;
148 const_reference top() const;
149
150 void push(const value_type& v);
151 void push(value_type&& v);
152 template <class... Args> void emplace(Args&&... args);
153 void pop();
154
Howard Hinnant6a094412011-06-04 21:32:33 +0000155 void swap(priority_queue& q)
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000156 noexcept(is_nothrow_swappable_v<Container> &&
157 is_nothrow_swappable_v<Comp>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000158};
159
160template <class T, class Container, class Compare>
161 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnant6a094412011-06-04 21:32:33 +0000162 priority_queue<T, Container, Compare>& y)
163 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164
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:10 +0000175#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000177#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000178
179_LIBCPP_BEGIN_NAMESPACE_STD
180
Eric Fiselierc3589a82017-01-04 23:56:00 +0000181template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182
183template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000184_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185bool
186operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
187
188template <class _Tp, class _Container>
Howard Hinnant33be35e2012-09-14 00:39:16 +0000189_LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190bool
191operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
192
Marshall Clowa46f5ce2015-02-18 17:51:56 +0000193template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000194class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195{
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:11 +0000202 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000203
204protected:
205 container_type c;
206
207public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000209 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
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000216 _LIBCPP_INLINE_VISIBILITY
217 queue& operator=(const queue& __q) {c = __q.c; return *this;}
218
219#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000220 _LIBCPP_INLINE_VISIBILITY
221 queue(queue&& __q)
222 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000223 : c(_VSTD::move(__q.c)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000224
225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000226 queue& operator=(queue&& __q)
227 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000228 {c = _VSTD::move(__q.c); return *this;}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000229#endif // _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000230
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000233#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000235 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000236#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000237 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239 explicit queue(const _Alloc& __a,
240 typename enable_if<uses_allocator<container_type,
241 _Alloc>::value>::type* = 0)
242 : c(__a) {}
243 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245 queue(const queue& __q, const _Alloc& __a,
246 typename enable_if<uses_allocator<container_type,
247 _Alloc>::value>::type* = 0)
248 : c(__q.c, __a) {}
249 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251 queue(const container_type& __c, const _Alloc& __a,
252 typename enable_if<uses_allocator<container_type,
253 _Alloc>::value>::type* = 0)
254 : c(__c, __a) {}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000255#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 queue(container_type&& __c, const _Alloc& __a,
259 typename enable_if<uses_allocator<container_type,
260 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000261 : c(_VSTD::move(__c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 template <class _Alloc>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264 queue(queue&& __q, const _Alloc& __a,
265 typename enable_if<uses_allocator<container_type,
266 _Alloc>::value>::type* = 0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000267 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000269#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
Marshall Clow88626bf2017-11-15 05:51:26 +0000271 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274 size_type size() const {return c.size();}
275
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277 reference front() {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279 const_reference front() const {return c.front();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000281 reference back() {return c.back();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000283 const_reference back() const {return c.back();}
284
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000287#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0949eed2011-06-30 21:18:19 +0000289 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290 template <class... _Args>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000291 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4e42dc92017-01-24 23:09:12 +0000292#if _LIBCPP_STD_VER > 14
Marshall Clowcc704882018-01-24 22:42:25 +0000293 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier3816ef92016-07-21 03:20:17 +0000294 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clow4e42dc92017-01-24 23:09:12 +0000295#else
296 void emplace(_Args&&... __args)
297 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
298#endif
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000299#endif // _LIBCPP_CXX03_LANG
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301 void pop() {c.pop_front();}
302
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000304 void swap(queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000305 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000307 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308 swap(c, __q.c);
309 }
310
311 template <class _T1, class _C1>
312 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314 bool
315 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant324bb032010-08-22 00:02:43 +0000316
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317 template <class _T1, class _C1>
318 friend
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320 bool
321 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
322};
323
324template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000325inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326bool
327operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
328{
329 return __x.c == __y.c;
330}
331
332template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000333inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334bool
335operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
336{
337 return __x.c < __y.c;
338}
339
340template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342bool
343operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
344{
345 return !(__x == __y);
346}
347
348template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000349inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350bool
351operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
352{
353 return __y < __x;
354}
355
356template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000357inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358bool
359operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
360{
361 return !(__x < __y);
362}
363
364template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000365inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366bool
367operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
368{
369 return !(__y < __x);
370}
371
372template <class _Tp, class _Container>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000373inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000374typename enable_if<
375 __is_swappable<_Container>::value,
376 void
377>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000379 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380{
381 __x.swap(__y);
382}
383
384template <class _Tp, class _Container, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000385struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 : public uses_allocator<_Container, _Alloc>
387{
388};
389
390template <class _Tp, class _Container = vector<_Tp>,
391 class _Compare = less<typename _Container::value_type> >
Eric Fiselierc3589a82017-01-04 23:56:00 +0000392class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393{
394public:
395 typedef _Container container_type;
396 typedef _Compare value_compare;
397 typedef typename container_type::value_type value_type;
398 typedef typename container_type::reference reference;
399 typedef typename container_type::const_reference const_reference;
400 typedef typename container_type::size_type size_type;
Marshall Clowed77ffb2016-03-14 17:58:11 +0000401 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402
403protected:
404 container_type c;
405 value_compare comp;
406
407public:
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000409 priority_queue()
410 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
411 is_nothrow_default_constructible<value_compare>::value)
412 : c(), comp() {}
413
414 _LIBCPP_INLINE_VISIBILITY
415 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
416
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000417 _LIBCPP_INLINE_VISIBILITY
418 priority_queue& operator=(const priority_queue& __q)
419 {c = __q.c; comp = __q.comp; return *this;}
420
421#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000422 _LIBCPP_INLINE_VISIBILITY
423 priority_queue(priority_queue&& __q)
424 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
425 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000426 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnant6a094412011-06-04 21:32:33 +0000427
428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000429 priority_queue& operator=(priority_queue&& __q)
430 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
431 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000432 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000433#endif // _LIBCPP_CXX03_LANG
Howard Hinnant6a094412011-06-04 21:32:33 +0000434
435 _LIBCPP_INLINE_VISIBILITY
436 explicit priority_queue(const value_compare& __comp)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 : c(), comp(__comp) {}
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000440#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 explicit priority_queue(const value_compare& __comp, container_type&& __c);
443#endif
444 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 priority_queue(_InputIter __f, _InputIter __l,
447 const value_compare& __comp = value_compare());
448 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 priority_queue(_InputIter __f, _InputIter __l,
451 const value_compare& __comp, const container_type& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000452#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 priority_queue(_InputIter __f, _InputIter __l,
456 const value_compare& __comp, container_type&& __c);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000457#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000458 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460 explicit priority_queue(const _Alloc& __a,
461 typename enable_if<uses_allocator<container_type,
462 _Alloc>::value>::type* = 0);
463 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465 priority_queue(const value_compare& __comp, const _Alloc& __a,
466 typename enable_if<uses_allocator<container_type,
467 _Alloc>::value>::type* = 0);
468 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 priority_queue(const value_compare& __comp, const container_type& __c,
471 const _Alloc& __a,
472 typename enable_if<uses_allocator<container_type,
473 _Alloc>::value>::type* = 0);
474 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476 priority_queue(const priority_queue& __q, const _Alloc& __a,
477 typename enable_if<uses_allocator<container_type,
478 _Alloc>::value>::type* = 0);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000479#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000480 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482 priority_queue(const value_compare& __comp, container_type&& __c,
483 const _Alloc& __a,
484 typename enable_if<uses_allocator<container_type,
485 _Alloc>::value>::type* = 0);
486 template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 priority_queue(priority_queue&& __q, const _Alloc& __a,
489 typename enable_if<uses_allocator<container_type,
490 _Alloc>::value>::type* = 0);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000491#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492
Marshall Clow88626bf2017-11-15 05:51:26 +0000493 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494 bool empty() const {return c.empty();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496 size_type size() const {return c.size();}
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498 const_reference top() const {return c.front();}
499
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 void push(const value_type& __v);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000502#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 void push(value_type&& __v);
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000505 template <class... _Args>
506 _LIBCPP_INLINE_VISIBILITY
507 void emplace(_Args&&... __args);
508#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510 void pop();
511
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6a094412011-06-04 21:32:33 +0000513 void swap(priority_queue& __q)
514 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
515 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516};
517
518template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000519inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
521 const container_type& __c)
522 : c(__c),
523 comp(__comp)
524{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000525 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526}
527
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000528#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529
530template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000531inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
533 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000534 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000535 comp(__comp)
536{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000537 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538}
539
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000540#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541
542template <class _Tp, class _Container, class _Compare>
543template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000544inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
546 const value_compare& __comp)
547 : c(__f, __l),
548 comp(__comp)
549{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000550 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551}
552
553template <class _Tp, class _Container, class _Compare>
554template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000555inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
557 const value_compare& __comp,
558 const container_type& __c)
559 : c(__c),
560 comp(__comp)
561{
562 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000563 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564}
565
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000566#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567
568template <class _Tp, class _Container, class _Compare>
569template <class _InputIter>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000570inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
572 const value_compare& __comp,
573 container_type&& __c)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000574 : c(_VSTD::move(__c)),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575 comp(__comp)
576{
577 c.insert(c.end(), __f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000578 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579}
580
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000581#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582
583template <class _Tp, class _Container, class _Compare>
584template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000585inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
587 typename enable_if<uses_allocator<container_type,
588 _Alloc>::value>::type*)
589 : c(__a)
590{
591}
592
593template <class _Tp, class _Container, class _Compare>
594template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000595inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
597 const _Alloc& __a,
598 typename enable_if<uses_allocator<container_type,
599 _Alloc>::value>::type*)
600 : c(__a),
601 comp(__comp)
602{
603}
604
605template <class _Tp, class _Container, class _Compare>
606template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000607inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
609 const container_type& __c,
610 const _Alloc& __a,
611 typename enable_if<uses_allocator<container_type,
612 _Alloc>::value>::type*)
613 : c(__c, __a),
614 comp(__comp)
615{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000616 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617}
618
619template <class _Tp, class _Container, class _Compare>
620template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000621inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
623 const _Alloc& __a,
624 typename enable_if<uses_allocator<container_type,
625 _Alloc>::value>::type*)
626 : c(__q.c, __a),
627 comp(__q.comp)
628{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000629 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630}
631
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000632#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633
634template <class _Tp, class _Container, class _Compare>
635template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000636inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
638 container_type&& __c,
639 const _Alloc& __a,
640 typename enable_if<uses_allocator<container_type,
641 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000642 : c(_VSTD::move(__c), __a),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 comp(__comp)
644{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000645 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000646}
647
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648template <class _Tp, class _Container, class _Compare>
649template <class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000650inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
652 const _Alloc& __a,
653 typename enable_if<uses_allocator<container_type,
654 _Alloc>::value>::type*)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000655 : c(_VSTD::move(__q.c), __a),
656 comp(_VSTD::move(__q.comp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000658 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659}
660
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000661#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662
663template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000664inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665void
666priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
667{
668 c.push_back(__v);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000669 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670}
671
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000672#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673
674template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000675inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676void
677priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
678{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000679 c.push_back(_VSTD::move(__v));
680 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681}
682
683template <class _Tp, class _Container, class _Compare>
684template <class... _Args>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000685inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686void
687priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
688{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000689 c.emplace_back(_VSTD::forward<_Args>(__args)...);
690 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691}
692
Eric Fiseliera8d1b912017-04-18 21:23:18 +0000693#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694
695template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000696inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697void
698priority_queue<_Tp, _Container, _Compare>::pop()
699{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000700 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701 c.pop_back();
702}
703
704template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55 +0000705inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706void
707priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnant6a094412011-06-04 21:32:33 +0000708 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
709 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000711 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 swap(c, __q.c);
713 swap(comp, __q.comp);
714}
715
716template <class _Tp, class _Container, class _Compare>
Howard Hinnantb9af2ea2010-09-22 18:02:38 +0000717inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8f1e73d2016-04-21 23:38:59 +0000718typename enable_if<
719 __is_swappable<_Container>::value
720 && __is_swappable<_Compare>::value,
721 void
722>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723swap(priority_queue<_Tp, _Container, _Compare>& __x,
724 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnant6a094412011-06-04 21:32:33 +0000725 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726{
727 __x.swap(__y);
728}
729
730template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000731struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732 : public uses_allocator<_Container, _Alloc>
733{
734};
735
736_LIBCPP_END_NAMESPACE_STD
737
738#endif // _LIBCPP_QUEUE