blob: cbd07140a72648445dc8f368a30d12e160c75e4b [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&);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500118 explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); // before C++20
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100119 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,
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500125 const Compare& comp, const Container& c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 template <class InputIterator>
127 priority_queue(InputIterator first, InputIterator last,
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500128 const Compare& comp, Container&& 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>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500134 priority_queue(const Compare& comp, const Container& c,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 const Alloc& a);
136 template <class Alloc>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500137 priority_queue(const Compare& comp, Container&& c,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138 const Alloc& a);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500139 template <class InputIterator>
140 priority_queue(InputIterator first, InputIterator last,
141 const Alloc& a);
142 template <class InputIterator>
143 priority_queue(InputIterator first, InputIterator last,
144 const Compare& comp, const Alloc& a);
145 template <class InputIterator>
146 priority_queue(InputIterator first, InputIterator last,
147 const Compare& comp, const Container& c, const Alloc& a);
148 template <class InputIterator>
149 priority_queue(InputIterator first, InputIterator last,
150 const Compare& comp, Container&& c, const Alloc& a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151 template <class Alloc>
Howard Hinnantbf438282011-06-04 21:32:33 +0000152 priority_queue(const priority_queue& q, const Alloc& a);
153 template <class Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154 priority_queue(priority_queue&& q, const Alloc& a);
155
156 bool empty() const;
157 size_type size() const;
158 const_reference top() const;
159
160 void push(const value_type& v);
161 void push(value_type&& v);
162 template <class... Args> void emplace(Args&&... args);
163 void pop();
164
Howard Hinnantbf438282011-06-04 21:32:33 +0000165 void swap(priority_queue& q)
Eric Fiselier6bfed252016-04-21 23:38:59 +0000166 noexcept(is_nothrow_swappable_v<Container> &&
167 is_nothrow_swappable_v<Comp>)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168};
169
Marshall Clow592d9952018-05-22 01:57:53 +0000170template <class Compare, class Container>
171priority_queue(Compare, Container)
172 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000173
174template<class InputIterator,
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500175 class Compare = less<iter-value-type<InputIterator>>,
176 class Container = vector<iter-value-type<InputIterator>>>
Marshall Clow592d9952018-05-22 01:57:53 +0000177priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500178 -> priority_queue<iter-value-type<InputIterator>, Container, Compare>; // C++17
Louis Dionne173f29e2019-05-29 16:01:36 +0000179
Marshall Clow592d9952018-05-22 01:57:53 +0000180template<class Compare, class Container, class Allocator>
181priority_queue(Compare, Container, Allocator)
182 -> priority_queue<typename Container::value_type, Container, Compare>; // C++17
183
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500184template<class InputIterator, class Allocator>
185priority_queue(InputIterator, InputIterator, Allocator)
186 -> priority_queue<iter-value-type<InputIterator>,
187 vector<iter-value-type<InputIterator>, Allocator>,
188 less<iter-value-type<InputIterator>>>;
189
190template<class InputIterator, class Compare, class Allocator>
191priority_queue(InputIterator, InputIterator, Compare, Allocator)
192 -> priority_queue<iter-value-type<InputIterator>,
193 vector<iter-value-type<InputIterator>, Allocator>, Compare>;
194
195template<class InputIterator, class Compare, class Container, class Allocator>
196priority_queue(InputIterator, InputIterator, Compare, Container, Allocator)
197 -> priority_queue<typename Container::value_type, Container, Compare>;
198
Howard Hinnantc51e1022010-05-11 19:42:16 +0000199template <class T, class Container, class Compare>
200 void swap(priority_queue<T, Container, Compare>& x,
Howard Hinnantbf438282011-06-04 21:32:33 +0000201 priority_queue<T, Container, Compare>& y)
202 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203
204} // std
205
206*/
207
208#include <__config>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400209#include <__memory/uses_allocator.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000210#include <__utility/forward.h>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400211#include <algorithm>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400212#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213#include <deque>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214#include <functional>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400215#include <vector>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000217#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000219#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220
221_LIBCPP_BEGIN_NAMESPACE_STD
222
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000223template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224
225template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000226_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227bool
228operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
229
230template <class _Tp, class _Container>
Howard Hinnanta54386e2012-09-14 00:39:16 +0000231_LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232bool
233operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
234
Marshall Clow9e1b8452015-02-18 17:51:56 +0000235template <class _Tp, class _Container /*= deque<_Tp>*/>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000236class _LIBCPP_TEMPLATE_VIS queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237{
238public:
239 typedef _Container container_type;
240 typedef typename container_type::value_type value_type;
241 typedef typename container_type::reference reference;
242 typedef typename container_type::const_reference const_reference;
243 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000244 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
246protected:
247 container_type c;
248
249public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000251 queue()
252 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
253 : c() {}
254
255 _LIBCPP_INLINE_VISIBILITY
256 queue(const queue& __q) : c(__q.c) {}
257
Eric Fiselier26081dd2017-04-18 21:23:18 +0000258 _LIBCPP_INLINE_VISIBILITY
259 queue& operator=(const queue& __q) {c = __q.c; return *this;}
260
261#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000262 _LIBCPP_INLINE_VISIBILITY
263 queue(queue&& __q)
264 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000265 : c(_VSTD::move(__q.c)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000266
267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000268 queue& operator=(queue&& __q)
269 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000270 {c = _VSTD::move(__q.c); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400271#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000272
Howard Hinnantf5f99992010-09-22 18:02:38 +0000273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274 explicit queue(const container_type& __c) : c(__c) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000275#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000277 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400278#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 explicit queue(const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400282 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 : c(__a) {}
284 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 queue(const queue& __q, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400287 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 : c(__q.c, __a) {}
289 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291 queue(const container_type& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400292 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293 : c(__c, __a) {}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000294#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000297 queue(container_type&& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400298 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000299 : c(_VSTD::move(__c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 template <class _Alloc>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 queue(queue&& __q, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400303 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000304 : c(_VSTD::move(__q.c), __a) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400306#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307
Marshall Clow425f5752017-11-15 05:51:26 +0000308 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311 size_type size() const {return c.size();}
312
Howard Hinnantf5f99992010-09-22 18:02:38 +0000313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 reference front() {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316 const_reference front() const {return c.front();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318 reference back() {return c.back();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320 const_reference back() const {return c.back();}
321
Howard Hinnantf5f99992010-09-22 18:02:38 +0000322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000323 void push(const value_type& __v) {c.push_back(__v);}
Eric Fiselier26081dd2017-04-18 21:23:18 +0000324#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000326 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 template <class... _Args>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000328 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea52cc42017-01-24 23:09:12 +0000329#if _LIBCPP_STD_VER > 14
Marshall Clow88746852018-01-24 22:42:25 +0000330 decltype(auto) emplace(_Args&&... __args)
Eric Fiselier34ba5b92016-07-21 03:20:17 +0000331 { return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
Marshall Clowea52cc42017-01-24 23:09:12 +0000332#else
333 void emplace(_Args&&... __args)
334 { c.emplace_back(_VSTD::forward<_Args>(__args)...);}
335#endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400336#endif // _LIBCPP_CXX03_LANG
Howard Hinnantf5f99992010-09-22 18:02:38 +0000337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 void pop() {c.pop_front();}
339
Howard Hinnantf5f99992010-09-22 18:02:38 +0000340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000341 void swap(queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000342 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000344 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345 swap(c, __q.c);
346 }
347
348 template <class _T1, class _C1>
349 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351 bool
352 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000353
Howard Hinnantc51e1022010-05-11 19:42:16 +0000354 template <class _T1, class _C1>
355 friend
Howard Hinnantf5f99992010-09-22 18:02:38 +0000356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357 bool
358 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
359};
360
Louis Dionned59f8a52021-08-17 11:59:07 -0400361#if _LIBCPP_STD_VER >= 17
Marshall Clow592d9952018-05-22 01:57:53 +0000362template<class _Container,
Louis Dionne25547162021-08-17 12:26:09 -0400363 class = enable_if_t<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000364>
365queue(_Container)
366 -> queue<typename _Container::value_type, _Container>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000367
Marshall Clow592d9952018-05-22 01:57:53 +0000368template<class _Container,
369 class _Alloc,
Louis Dionne25547162021-08-17 12:26:09 -0400370 class = enable_if_t<!__is_allocator<_Container>::value>,
371 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000372>
373queue(_Container, _Alloc)
374 -> queue<typename _Container::value_type, _Container>;
375#endif
376
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379bool
380operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
381{
382 return __x.c == __y.c;
383}
384
385template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000387bool
388operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
389{
390 return __x.c < __y.c;
391}
392
393template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395bool
396operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
397{
398 return !(__x == __y);
399}
400
401template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000402inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403bool
404operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
405{
406 return __y < __x;
407}
408
409template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000410inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411bool
412operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
413{
414 return !(__x < __y);
415}
416
417template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419bool
420operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
421{
422 return !(__y < __x);
423}
424
425template <class _Tp, class _Container>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000426inline _LIBCPP_INLINE_VISIBILITY
Louis Dionne9ce598d2021-09-08 09:14:43 -0400427__enable_if_t<__is_swappable<_Container>::value, void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000429 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430{
431 __x.swap(__y);
432}
433
434template <class _Tp, class _Container, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000435struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436 : public uses_allocator<_Container, _Alloc>
437{
438};
439
440template <class _Tp, class _Container = vector<_Tp>,
441 class _Compare = less<typename _Container::value_type> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000442class _LIBCPP_TEMPLATE_VIS priority_queue
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443{
444public:
445 typedef _Container container_type;
446 typedef _Compare value_compare;
447 typedef typename container_type::value_type value_type;
448 typedef typename container_type::reference reference;
449 typedef typename container_type::const_reference const_reference;
450 typedef typename container_type::size_type size_type;
Marshall Clowb8825f02016-03-14 17:58:11 +0000451 static_assert((is_same<_Tp, value_type>::value), "" );
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452
453protected:
454 container_type c;
455 value_compare comp;
456
457public:
Howard Hinnantf5f99992010-09-22 18:02:38 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000459 priority_queue()
460 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
461 is_nothrow_default_constructible<value_compare>::value)
462 : c(), comp() {}
463
464 _LIBCPP_INLINE_VISIBILITY
465 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
466
Eric Fiselier26081dd2017-04-18 21:23:18 +0000467 _LIBCPP_INLINE_VISIBILITY
468 priority_queue& operator=(const priority_queue& __q)
469 {c = __q.c; comp = __q.comp; return *this;}
470
471#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000472 _LIBCPP_INLINE_VISIBILITY
473 priority_queue(priority_queue&& __q)
474 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
475 is_nothrow_move_constructible<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000476 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
Howard Hinnantbf438282011-06-04 21:32:33 +0000477
478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000479 priority_queue& operator=(priority_queue&& __q)
480 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
481 is_nothrow_move_assignable<value_compare>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000482 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400483#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbf438282011-06-04 21:32:33 +0000484
485 _LIBCPP_INLINE_VISIBILITY
486 explicit priority_queue(const value_compare& __comp)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487 : c(), comp(__comp) {}
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 priority_queue(const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000490#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000491 _LIBCPP_INLINE_VISIBILITY
Marek Kurdejcd0bd6a2021-01-19 08:21:09 +0100492 priority_queue(const value_compare& __comp, container_type&& __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493#endif
Louis Dionne9ce598d2021-09-08 09:14:43 -0400494 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 priority_queue(_InputIter __f, _InputIter __l,
497 const value_compare& __comp = value_compare());
Louis Dionne9ce598d2021-09-08 09:14:43 -0400498 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 priority_queue(_InputIter __f, _InputIter __l,
501 const value_compare& __comp, const container_type& __c);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000502#ifndef _LIBCPP_CXX03_LANG
Louis Dionne9ce598d2021-09-08 09:14:43 -0400503 template <class _InputIter, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 priority_queue(_InputIter __f, _InputIter __l,
506 const value_compare& __comp, container_type&& __c);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400507#endif // _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 explicit priority_queue(const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400511 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 priority_queue(const value_compare& __comp, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400515 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 priority_queue(const value_compare& __comp, const container_type& __c,
519 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400520 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523 priority_queue(const priority_queue& __q, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400524 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000525#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 priority_queue(const value_compare& __comp, container_type&& __c,
529 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400530 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 priority_queue(priority_queue&& __q, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400534 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400535#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536
Louis Dionne9ce598d2021-09-08 09:14:43 -0400537 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500538 _LIBCPP_INLINE_VISIBILITY
539 priority_queue(_InputIter __f, _InputIter __l, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400540 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500541
Louis Dionne9ce598d2021-09-08 09:14:43 -0400542 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500543 _LIBCPP_INLINE_VISIBILITY
544 priority_queue(_InputIter __f, _InputIter __l,
545 const value_compare& __comp, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400546 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500547
Louis Dionne9ce598d2021-09-08 09:14:43 -0400548 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500549 _LIBCPP_INLINE_VISIBILITY
550 priority_queue(_InputIter __f, _InputIter __l,
551 const value_compare& __comp, const container_type& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400552 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500553
554#ifndef _LIBCPP_CXX03_LANG
Louis Dionne9ce598d2021-09-08 09:14:43 -0400555 template <class _InputIter, class _Alloc, class = __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value> >
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500556 _LIBCPP_INLINE_VISIBILITY
557 priority_queue(_InputIter __f, _InputIter __l,
558 const value_compare& __comp, container_type&& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400559 __enable_if_t<uses_allocator<container_type, _Alloc>::value>* = 0);
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500560#endif // _LIBCPP_CXX03_LANG
561
Marshall Clow425f5752017-11-15 05:51:26 +0000562 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 bool empty() const {return c.empty();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 size_type size() const {return c.size();}
Howard Hinnantf5f99992010-09-22 18:02:38 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 const_reference top() const {return c.front();}
568
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 void push(const value_type& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000571#ifndef _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573 void push(value_type&& __v);
Eric Fiselier26081dd2017-04-18 21:23:18 +0000574 template <class... _Args>
575 _LIBCPP_INLINE_VISIBILITY
576 void emplace(_Args&&... __args);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400577#endif // _LIBCPP_CXX03_LANG
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 void pop();
580
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbf438282011-06-04 21:32:33 +0000582 void swap(priority_queue& __q)
583 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
584 __is_nothrow_swappable<value_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585};
586
Louis Dionned59f8a52021-08-17 11:59:07 -0400587#if _LIBCPP_STD_VER >= 17
Marshall Clow592d9952018-05-22 01:57:53 +0000588template <class _Compare,
589 class _Container,
Louis Dionne25547162021-08-17 12:26:09 -0400590 class = enable_if_t<!__is_allocator<_Compare>::value>,
591 class = enable_if_t<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000592>
593priority_queue(_Compare, _Container)
594 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000595
596template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500597 class _Compare = less<__iter_value_type<_InputIterator>>,
598 class _Container = vector<__iter_value_type<_InputIterator>>,
Louis Dionne25547162021-08-17 12:26:09 -0400599 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
600 class = enable_if_t<!__is_allocator<_Compare>::value>,
601 class = enable_if_t<!__is_allocator<_Container>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000602>
603priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500604 -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>;
Louis Dionne173f29e2019-05-29 16:01:36 +0000605
606template<class _Compare,
Marshall Clow592d9952018-05-22 01:57:53 +0000607 class _Container,
608 class _Alloc,
Louis Dionne25547162021-08-17 12:26:09 -0400609 class = enable_if_t<!__is_allocator<_Compare>::value>,
610 class = enable_if_t<!__is_allocator<_Container>::value>,
611 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
Marshall Clow592d9952018-05-22 01:57:53 +0000612>
613priority_queue(_Compare, _Container, _Alloc)
614 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500615
616template<class _InputIterator, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -0400617 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
618 class = enable_if_t<__is_allocator<_Allocator>::value>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500619>
620priority_queue(_InputIterator, _InputIterator, _Allocator)
621 -> priority_queue<__iter_value_type<_InputIterator>,
622 vector<__iter_value_type<_InputIterator>, _Allocator>,
623 less<__iter_value_type<_InputIterator>>>;
624
625template<class _InputIterator, class _Compare, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -0400626 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
627 class = enable_if_t<!__is_allocator<_Compare>::value>,
628 class = enable_if_t<__is_allocator<_Allocator>::value>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500629>
630priority_queue(_InputIterator, _InputIterator, _Compare, _Allocator)
631 -> priority_queue<__iter_value_type<_InputIterator>,
632 vector<__iter_value_type<_InputIterator>, _Allocator>, _Compare>;
633
634template<class _InputIterator, class _Compare, class _Container, class _Alloc,
Louis Dionne25547162021-08-17 12:26:09 -0400635 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
636 class = enable_if_t<!__is_allocator<_Compare>::value>,
637 class = enable_if_t<!__is_allocator<_Container>::value>,
638 class = enable_if_t<uses_allocator<_Container, _Alloc>::value>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500639>
640priority_queue(_InputIterator, _InputIterator, _Compare, _Container, _Alloc)
641 -> priority_queue<typename _Container::value_type, _Container, _Compare>;
Marshall Clow592d9952018-05-22 01:57:53 +0000642#endif
643
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000645inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
647 const container_type& __c)
648 : c(__c),
649 comp(__comp)
650{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000651 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652}
653
Eric Fiselier26081dd2017-04-18 21:23:18 +0000654#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
656template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000657inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
659 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000660 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 comp(__comp)
662{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000663 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664}
665
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400666#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667
668template <class _Tp, class _Container, class _Compare>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500669template <class _InputIter, class>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000670inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
672 const value_compare& __comp)
673 : c(__f, __l),
674 comp(__comp)
675{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000676 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677}
678
679template <class _Tp, class _Container, class _Compare>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500680template <class _InputIter, class>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000681inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
683 const value_compare& __comp,
684 const container_type& __c)
685 : c(__c),
686 comp(__comp)
687{
688 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000689 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690}
691
Eric Fiselier26081dd2017-04-18 21:23:18 +0000692#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693
694template <class _Tp, class _Container, class _Compare>
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500695template <class _InputIter, class>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000696inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
698 const value_compare& __comp,
699 container_type&& __c)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000700 : c(_VSTD::move(__c)),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 comp(__comp)
702{
703 c.insert(c.end(), __f, __l);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000704 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705}
706
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400707#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708
709template <class _Tp, class _Container, class _Compare>
710template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000711inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400713 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714 : c(__a)
715{
716}
717
718template <class _Tp, class _Container, class _Compare>
719template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000720inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
722 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400723 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 : c(__a),
725 comp(__comp)
726{
727}
728
729template <class _Tp, class _Container, class _Compare>
730template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000731inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
733 const container_type& __c,
734 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400735 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736 : c(__c, __a),
737 comp(__comp)
738{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000739 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740}
741
742template <class _Tp, class _Container, class _Compare>
743template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000744inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
746 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400747 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748 : c(__q.c, __a),
749 comp(__q.comp)
750{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751}
752
Eric Fiselier26081dd2017-04-18 21:23:18 +0000753#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754
755template <class _Tp, class _Container, class _Compare>
756template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000757inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
759 container_type&& __c,
760 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400761 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000762 : c(_VSTD::move(__c), __a),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 comp(__comp)
764{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000765 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766}
767
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768template <class _Tp, class _Container, class _Compare>
769template <class _Alloc>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000770inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
772 const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400773 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000774 : c(_VSTD::move(__q.c), __a),
775 comp(_VSTD::move(__q.comp))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776{
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500777}
778
779#endif // _LIBCPP_CXX03_LANG
780
781template <class _Tp, class _Container, class _Compare>
782template <class _InputIter, class _Alloc, class>
783inline
784priority_queue<_Tp, _Container, _Compare>::priority_queue(
785 _InputIter __f, _InputIter __l, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400786 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500787 : c(__f, __l, __a),
788 comp()
789{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000790 _VSTD::make_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791}
792
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500793template <class _Tp, class _Container, class _Compare>
794template <class _InputIter, class _Alloc, class>
795inline
796priority_queue<_Tp, _Container, _Compare>::priority_queue(
797 _InputIter __f, _InputIter __l,
798 const value_compare& __comp, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400799 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500800 : c(__f, __l, __a),
801 comp(__comp)
802{
803 _VSTD::make_heap(c.begin(), c.end(), comp);
804}
805
806template <class _Tp, class _Container, class _Compare>
807template <class _InputIter, class _Alloc, class>
808inline
809priority_queue<_Tp, _Container, _Compare>::priority_queue(
810 _InputIter __f, _InputIter __l,
811 const value_compare& __comp, const container_type& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400812 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500813 : c(__c, __a),
814 comp(__comp)
815{
816 c.insert(c.end(), __f, __l);
817 _VSTD::make_heap(c.begin(), c.end(), comp);
818}
819
820#ifndef _LIBCPP_CXX03_LANG
821template <class _Tp, class _Container, class _Compare>
822template <class _InputIter, class _Alloc, class>
823inline
824priority_queue<_Tp, _Container, _Compare>::priority_queue(
825 _InputIter __f, _InputIter __l, const value_compare& __comp,
826 container_type&& __c, const _Alloc& __a,
Louis Dionne9ce598d2021-09-08 09:14:43 -0400827 __enable_if_t<uses_allocator<container_type, _Alloc>::value>*)
Arthur O'Dwyer4e06bc82021-03-02 00:23:21 -0500828 : c(_VSTD::move(__c), __a),
829 comp(__comp)
830{
831 c.insert(c.end(), __f, __l);
832 _VSTD::make_heap(c.begin(), c.end(), comp);
833}
834#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835
836template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000837inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838void
839priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
840{
841 c.push_back(__v);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000842 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843}
844
Eric Fiselier26081dd2017-04-18 21:23:18 +0000845#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846
847template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000848inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849void
850priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
851{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000852 c.push_back(_VSTD::move(__v));
853 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854}
855
856template <class _Tp, class _Container, class _Compare>
857template <class... _Args>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000858inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859void
860priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
861{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000862 c.emplace_back(_VSTD::forward<_Args>(__args)...);
863 _VSTD::push_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864}
865
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400866#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867
868template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000869inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870void
871priority_queue<_Tp, _Container, _Compare>::pop()
872{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000873 _VSTD::pop_heap(c.begin(), c.end(), comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 c.pop_back();
875}
876
877template <class _Tp, class _Container, class _Compare>
Evgeniy Stepanov3b68ae52016-04-22 01:04:55 +0000878inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879void
880priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
Howard Hinnantbf438282011-06-04 21:32:33 +0000881 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
882 __is_nothrow_swappable<value_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000884 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885 swap(c, __q.c);
886 swap(comp, __q.comp);
887}
888
889template <class _Tp, class _Container, class _Compare>
Howard Hinnantf5f99992010-09-22 18:02:38 +0000890inline _LIBCPP_INLINE_VISIBILITY
Louis Dionne9ce598d2021-09-08 09:14:43 -0400891__enable_if_t<
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500892 __is_swappable<_Container>::value && __is_swappable<_Compare>::value,
Eric Fiselier6bfed252016-04-21 23:38:59 +0000893 void
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500894>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895swap(priority_queue<_Tp, _Container, _Compare>& __x,
896 priority_queue<_Tp, _Container, _Compare>& __y)
Howard Hinnantbf438282011-06-04 21:32:33 +0000897 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898{
899 __x.swap(__y);
900}
901
902template <class _Tp, class _Container, class _Compare, class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000903struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 : public uses_allocator<_Container, _Alloc>
905{
906};
907
908_LIBCPP_END_NAMESPACE_STD
909
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400910#endif // _LIBCPP_QUEUE