blob: a2048c1e22cc1eac8661b3091b98ef9e9ffb99d9 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- queue ------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_QUEUE
11#define _LIBCPP_QUEUE
12
13/*
14 queue synopsis
15
16namespace std
17{
18
19template <class T, class Container = deque<T>>
20class queue
21{
22public:
23 typedef Container container_type;
24 typedef typename container_type::value_type value_type;
25 typedef typename container_type::reference reference;
26 typedef typename container_type::const_reference const_reference;
27 typedef typename container_type::size_type size_type;
28
29protected:
30 container_type c;
31
32public:
Howard Hinnantbf438282011-06-04 21:32:33 +000033 queue() = default;
34 ~queue() = default;
35
36 queue(const queue& q) = default;
37 queue(queue&& q) = default;
38
39 queue& operator=(const queue& q) = default;
40 queue& operator=(queue&& q) = default;
41
Howard Hinnantc51e1022010-05-11 19:42:16 +000042 explicit queue(const container_type& c);
Howard Hinnantbf438282011-06-04 21:32:33 +000043 explicit queue(container_type&& c)
Howard Hinnantc51e1022010-05-11 19:42:16 +000044 template <class Alloc>
45 explicit queue(const Alloc& a);
46 template <class Alloc>
47 queue(const container_type& c, const Alloc& a);
48 template <class Alloc>
49 queue(container_type&& c, const Alloc& a);
50 template <class Alloc>
Howard Hinnantbf438282011-06-04 21:32:33 +000051 queue(const queue& q, const Alloc& a);
52 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +000053 queue(queue&& q, const Alloc& a);
54
Howard Hinnantc51e1022010-05-11 19:42:16 +000055 bool empty() const;
56 size_type size() const;
57
58 reference front();
59 const_reference front() const;
60 reference back();
61 const_reference back() const;
62
63 void push(const value_type& v);
64 void push(value_type&& v);
Marshall Clowea52cc42017-01-24 23:09:12 +000065 template <class... Args> reference emplace(Args&&... args); // reference in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000066 void pop();
67
Eric Fiselier6bfed252016-04-21 23:38:59 +000068 void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
Howard Hinnantc51e1022010-05-11 19:42:16 +000069};
70
Marshall Clow592d9952018-05-22 01:57:53 +000071template<class Container>
72 queue(Container) -> queue<typename Container::value_type, Container>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +000073
74template<class Container, class Allocator>
Marshall Clow592d9952018-05-22 01:57:53 +000075 queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
76
Howard Hinnantc51e1022010-05-11 19:42:16 +000077template <class T, class Container>
78 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
79
80template <class T, class Container>
81 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
82
83template <class T, class Container>
84 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
85
86template <class T, class Container>
87 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
88
89template <class T, class Container>
90 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
91
92template <class T, class Container>
93 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
94
95template <class T, class Container>
Howard Hinnantbf438282011-06-04 21:32:33 +000096 void swap(queue<T, Container>& x, queue<T, Container>& y)
97 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +000098
99template <class T, class Container = vector<T>,
100 class Compare = less<typename Container::value_type>>
101class priority_queue
102{
103public:
104 typedef Container container_type;
105 typedef typename container_type::value_type value_type;
106 typedef typename container_type::reference reference;
107 typedef typename container_type::const_reference const_reference;
108 typedef typename container_type::size_type size_type;
109
110protected:
111 container_type c;
112 Compare comp;
113
114public:
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100115 priority_queue() : priority_queue(Compare()) {} // C++20
116 explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}
117 priority_queue(const Compare& x, const Container&);
118 explicit priority_queue(const Compare& x = Compare(), Container&&= Container()); // before C++20
119 priority_queue(const Compare& x, Container&&); // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 template <class InputIterator>
121 priority_queue(InputIterator first, InputIterator last,
122 const Compare& comp = Compare());
123 template <class InputIterator>
124 priority_queue(InputIterator first, InputIterator last,
125 const Compare& comp, const container_type& c);
126 template <class InputIterator>
127 priority_queue(InputIterator first, InputIterator last,
128 const Compare& comp, container_type&& c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129 template <class Alloc>
130 explicit priority_queue(const Alloc& a);
131 template <class Alloc>
132 priority_queue(const Compare& comp, const Alloc& a);
133 template <class Alloc>
134 priority_queue(const Compare& comp, const container_type& c,
135 const Alloc& a);
136 template <class Alloc>
137 priority_queue(const Compare& comp, container_type&& c,
138 const Alloc& a);
139 template <class Alloc>
Howard Hinnantbf438282011-06-04 21:32:33 +0000140 priority_queue(const priority_queue& q, const Alloc& a);
141 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142 priority_queue(priority_queue&& q, const Alloc& a);
143
144 bool empty() const;
145 size_type size() const;
146 const_reference top() const;
147
148 void push(const value_type& v);
149 void push(value_type&& v);
150 template <class... Args> void emplace(Args&&... args);
151 void pop();
152
Howard Hinnantbf438282011-06-04 21:32:33 +0000153 void swap(priority_queue& q)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000154 noexcept(is_nothrow_swappable_v<Container> &&
155 is_nothrow_swappable_v<Comp>)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156};
157
Marshall Clow592d9952018-05-22 01:57:53 +0000158template <class Compare, class Container>
159priority_queue(Compare, Container)
160 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000161
162template<class InputIterator,
Marshall Clow592d9952018-05-22 01:57:53 +0000163 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
164 class Container = vector<typename iterator_traits<InputIterator>::value_type>>
165priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
166 -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000167
Marshall Clow592d9952018-05-22 01:57:53 +0000168template<class Compare, class Container, class Allocator>
169priority_queue(Compare, Container, Allocator)
170 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172template <class T, class Container, class Compare>
173 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnantbf438282011-06-04 21:32:33 +0000174 priority_queue<T, Container, Compare>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176
177} // std
178
179*/
180
181#include <__config>
182#include <deque>
183#include <vector>
184#include <functional>
185#include <algorithm>
186
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000187#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000189#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190
191_LIBCPP_BEGIN_NAMESPACE_STD
192
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000193template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194
195template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000196_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197bool
198operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
199
200template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000201_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202bool
203operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
204
Marshall Clow9e1b8452015-02-18 17:51:56 +0000205template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000206class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207{
208public:
209 typedef _Container container_type;
210 typedef typename container_type::value_type value_type;
211 typedef typename container_type::reference reference;
212 typedef typename container_type::const_reference const_reference;
213 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000214 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215
216protected:
217 container_type c;
218
219public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000221 queue()
222 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
223 : c() {}
224
225 _LIBCPP_INLINE_VISIBILITY
226 queue(const queue& __q) : c(__q.c) {}
227
Eric Fiselier26081dd2017-04-18 21:23:18 +0000228 _LIBCPP_INLINE_VISIBILITY
229 queue& operator=(const queue& __q) {c = __q.c; return *this;}
230
231#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000232 _LIBCPP_INLINE_VISIBILITY
233 queue(queue&& __q)
234 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000235 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000236
237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000238 queue& operator=(queue&& __q)
239 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000240 {c = _VSTD::move(__q.c); return *this;}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000241#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000242
Howard Hinnantf5f99992010-09-22 18:02:38 +0000243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000245#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000247 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000248#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 explicit queue(const _Alloc& __a,
252 typename enable_if<uses_allocator<container_type,
253 _Alloc>::value>::type* = 0)
254 : c(__a) {}
255 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 queue(const queue& __q, const _Alloc& __a,
258 typename enable_if<uses_allocator<container_type,
259 _Alloc>::value>::type* = 0)
260 : c(__q.c, __a) {}
261 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 queue(const container_type& __c, const _Alloc& __a,
264 typename enable_if<uses_allocator<container_type,
265 _Alloc>::value>::type* = 0)
266 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000267#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 queue(container_type&& __c, const _Alloc& __a,
271 typename enable_if<uses_allocator<container_type,
272 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000273 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 queue(queue&& __q, const _Alloc& __a,
277 typename enable_if<uses_allocator<container_type,
278 _Alloc>::value>::type* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000279 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280
Eric Fiselier26081dd2017-04-18 21:23:18 +0000281#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282
Marshall Clow425f5752017-11-15 05:51:26 +0000283 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 size_type size() const {return c.size();}
287
Howard Hinnantf5f99992010-09-22 18:02:38 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 const_reference back() const {return c.back();}
296
Howard Hinnantf5f99992010-09-22 18:02:38 +0000297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000299#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000301 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000303 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000304#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000305 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000306 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000307#else
308 void emplace(_Args&&... __args)
309 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
310#endif
Eric Fiselier26081dd2017-04-18 21:23:18 +0000311#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 void pop() {c.pop_front();}
314
Howard Hinnantf5f99992010-09-22 18:02:38 +0000315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000317 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000319 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 swap(c, __q.c);
321 }
322
323 template <class _T1, class _C1>
324 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 bool
327 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000328
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 template <class _T1, class _C1>
330 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 bool
333 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
334};
335
Marshall Clow592d9952018-05-22 01:57:53 +0000336#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
337template<class _Container,
338 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
339>
340queue(_Container)
341 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000342
Marshall Clow592d9952018-05-22 01:57:53 +0000343template<class _Container,
344 class _Alloc,
345 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
346 class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
347>
348queue(_Container, _Alloc)
349 -> queue<typename _Container::value_type, _Container>;
350#endif
351
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354bool
355operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
356{
357 return __x.c == __y.c;
358}
359
360template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362bool
363operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
364{
365 return __x.c < __y.c;
366}
367
368template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000369inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370bool
371operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
372{
373 return !(__x == __y);
374}
375
376template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378bool
379operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
380{
381 return __y < __x;
382}
383
384template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000385inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386bool
387operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
388{
389 return !(__x < __y);
390}
391
392template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394bool
395operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
396{
397 return !(__y < __x);
398}
399
400template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000401inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +0000402typename enable_if<
403 __is_swappable<_Container>::value,
404 void
405>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000407 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408{
409 __x.swap(__y);
410}
411
412template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000413struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414 : public uses_allocator<_Container, _Alloc>
415{
416};
417
418template <class _Tp, class _Container = vector<_Tp>,
419 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000420class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421{
422public:
423 typedef _Container container_type;
424 typedef _Compare value_compare;
425 typedef typename container_type::value_type value_type;
426 typedef typename container_type::reference reference;
427 typedef typename container_type::const_reference const_reference;
428 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000429 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
431protected:
432 container_type c;
433 value_compare comp;
434
435public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000437 priority_queue()
438 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
439 is_nothrow_default_constructible<value_compare>::value)
440 : c(), comp() {}
441
442 _LIBCPP_INLINE_VISIBILITY
443 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
444
Eric Fiselier26081dd2017-04-18 21:23:18 +0000445 _LIBCPP_INLINE_VISIBILITY
446 priority_queue& operator=(const priority_queue& __q)
447 {c = __q.c; comp = __q.comp; return *this;}
448
449#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000450 _LIBCPP_INLINE_VISIBILITY
451 priority_queue(priority_queue&& __q)
452 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
453 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000454 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000455
456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000457 priority_queue& operator=(priority_queue&& __q)
458 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
459 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000460 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000461#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000462
463 _LIBCPP_INLINE_VISIBILITY
464 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000468#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000469 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100470 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471#endif
472 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 priority_queue(_InputIter __f, _InputIter __l,
475 const value_compare& __comp = value_compare());
476 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 priority_queue(_InputIter __f, _InputIter __l,
479 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000480#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481 template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483 priority_queue(_InputIter __f, _InputIter __l,
484 const value_compare& __comp, container_type&& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000485#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488 explicit priority_queue(const _Alloc& __a,
489 typename enable_if<uses_allocator<container_type,
490 _Alloc>::value>::type* = 0);
491 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 priority_queue(const value_compare& __comp, const _Alloc& __a,
494 typename enable_if<uses_allocator<container_type,
495 _Alloc>::value>::type* = 0);
496 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 priority_queue(const value_compare& __comp, const container_type& __c,
499 const _Alloc& __a,
500 typename enable_if<uses_allocator<container_type,
501 _Alloc>::value>::type* = 0);
502 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 priority_queue(const priority_queue& __q, const _Alloc& __a,
505 typename enable_if<uses_allocator<container_type,
506 _Alloc>::value>::type* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000507#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 priority_queue(const value_compare& __comp, container_type&& __c,
511 const _Alloc& __a,
512 typename enable_if<uses_allocator<container_type,
513 _Alloc>::value>::type* = 0);
514 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 priority_queue(priority_queue&& __q, const _Alloc& __a,
517 typename enable_if<uses_allocator<container_type,
518 _Alloc>::value>::type* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000519#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520
Marshall Clow425f5752017-11-15 05:51:26 +0000521 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 const_reference top() const {return c.front();}
527
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000530#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000533 template <class... _Args>
534 _LIBCPP_INLINE_VISIBILITY
535 void emplace(_Args&&... __args);
536#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 void pop();
539
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000541 void swap(priority_queue& __q)
542 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
543 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544};
545
Marshall Clow592d9952018-05-22 01:57:53 +0000546#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
547template <class _Compare,
548 class _Container,
549 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
550 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
551>
552priority_queue(_Compare, _Container)
553 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000554
555template<class _InputIterator,
Marshall Clow592d9952018-05-22 01:57:53 +0000556 class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
557 class _Container = vector<typename iterator_traits<_InputIterator>::value_type>,
Eric Fiseliercd5a6772019-11-18 01:46:58 -0500558 class = typename enable_if< __is_cpp17_input_iterator<_InputIterator>::value, nullptr_t>::type,
Marshall Clow592d9952018-05-22 01:57:53 +0000559 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
560 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
561>
562priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
563 -> priority_queue<typename iterator_traits<_InputIterator>::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000564
565template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000566 class _Container,
567 class _Alloc,
568 class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
569 class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
570 class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
571>
572priority_queue(_Compare, _Container, _Alloc)
573 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
574#endif
575
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000577inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
579 const container_type& __c)
580 : c(__c),
581 comp(__comp)
582{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000583 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584}
585
Eric Fiselier26081dd2017-04-18 21:23:18 +0000586#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587
588template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000589inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
591 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000592 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 comp(__comp)
594{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000595 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596}
597
Eric Fiselier26081dd2017-04-18 21:23:18 +0000598#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
600template <class _Tp, class _Container, class _Compare>
601template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000602inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
604 const value_compare& __comp)
605 : c(__f, __l),
606 comp(__comp)
607{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000608 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609}
610
611template <class _Tp, class _Container, class _Compare>
612template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000613inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
615 const value_compare& __comp,
616 const container_type& __c)
617 : c(__c),
618 comp(__comp)
619{
620 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000621 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622}
623
Eric Fiselier26081dd2017-04-18 21:23:18 +0000624#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625
626template <class _Tp, class _Container, class _Compare>
627template <class _InputIter>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000628inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
630 const value_compare& __comp,
631 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000632 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 comp(__comp)
634{
635 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000636 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637}
638
Eric Fiselier26081dd2017-04-18 21:23:18 +0000639#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
641template <class _Tp, class _Container, class _Compare>
642template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000643inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
645 typename enable_if<uses_allocator<container_type,
646 _Alloc>::value>::type*)
647 : c(__a)
648{
649}
650
651template <class _Tp, class _Container, class _Compare>
652template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000653inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
655 const _Alloc& __a,
656 typename enable_if<uses_allocator<container_type,
657 _Alloc>::value>::type*)
658 : c(__a),
659 comp(__comp)
660{
661}
662
663template <class _Tp, class _Container, class _Compare>
664template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000665inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
667 const container_type& __c,
668 const _Alloc& __a,
669 typename enable_if<uses_allocator<container_type,
670 _Alloc>::value>::type*)
671 : c(__c, __a),
672 comp(__comp)
673{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000674 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675}
676
677template <class _Tp, class _Container, class _Compare>
678template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000679inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
681 const _Alloc& __a,
682 typename enable_if<uses_allocator<container_type,
683 _Alloc>::value>::type*)
684 : c(__q.c, __a),
685 comp(__q.comp)
686{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000687 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688}
689
Eric Fiselier26081dd2017-04-18 21:23:18 +0000690#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691
692template <class _Tp, class _Container, class _Compare>
693template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000694inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
696 container_type&& __c,
697 const _Alloc& __a,
698 typename enable_if<uses_allocator<container_type,
699 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000700 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 comp(__comp)
702{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000703 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704}
705
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706template <class _Tp, class _Container, class _Compare>
707template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000708inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
710 const _Alloc& __a,
711 typename enable_if<uses_allocator<container_type,
712 _Alloc>::value>::type*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000713 : c(_VSTD::move(__q.c), __a),
714 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000716 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717}
718
Eric Fiselier26081dd2017-04-18 21:23:18 +0000719#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720
721template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000722inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723void
724priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
725{
726 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000727 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728}
729
Eric Fiselier26081dd2017-04-18 21:23:18 +0000730#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731
732template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000733inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734void
735priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
736{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000737 c.push_back(_VSTD::move(__v));
738 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739}
740
741template <class _Tp, class _Container, class _Compare>
742template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000743inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744void
745priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
746{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000747 c.emplace_back(_VSTD::forward<_Args>(__args)...);
748 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749}
750
Eric Fiselier26081dd2017-04-18 21:23:18 +0000751#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752
753template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000754inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755void
756priority_queue<_Tp, _Container, _Compare>::pop()
757{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000758 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 c.pop_back();
760}
761
762template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000763inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764void
765priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000766 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
767 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000769 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 swap(c, __q.c);
771 swap(comp, __q.comp);
772}
773
774template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000775inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +0000776typename enable_if<
777 __is_swappable<_Container>::value
778 && __is_swappable<_Compare>::value,
779 void
780>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781swap(priority_queue<_Tp, _Container, _Compare>& __x,
782 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000783 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784{
785 __x.swap(__y);
786}
787
788template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000789struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 : public uses_allocator<_Container, _Alloc>
791{
792};
793
794_LIBCPP_END_NAMESPACE_STD
795
796#endif // _LIBCPP_QUEUE