1 1.1 joerg // -*- C++ -*- 2 1.1 joerg //===--------------------------- queue ------------------------------------===// 3 1.1 joerg // 4 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 6 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg 10 1.1 joerg #ifndef _LIBCPP_QUEUE 11 1.1 joerg #define _LIBCPP_QUEUE 12 1.1 joerg 13 1.1 joerg /* 14 1.1 joerg queue synopsis 15 1.1 joerg 16 1.1 joerg namespace std 17 1.1 joerg { 18 1.1 joerg 19 1.1 joerg template <class T, class Container = deque<T>> 20 1.1 joerg class queue 21 1.1 joerg { 22 1.1 joerg public: 23 1.1 joerg typedef Container container_type; 24 1.1 joerg typedef typename container_type::value_type value_type; 25 1.1 joerg typedef typename container_type::reference reference; 26 1.1 joerg typedef typename container_type::const_reference const_reference; 27 1.1 joerg typedef typename container_type::size_type size_type; 28 1.1 joerg 29 1.1 joerg protected: 30 1.1 joerg container_type c; 31 1.1 joerg 32 1.1 joerg public: 33 1.1 joerg queue() = default; 34 1.1 joerg ~queue() = default; 35 1.1 joerg 36 1.1 joerg queue(const queue& q) = default; 37 1.1 joerg queue(queue&& q) = default; 38 1.1 joerg 39 1.1 joerg queue& operator=(const queue& q) = default; 40 1.1 joerg queue& operator=(queue&& q) = default; 41 1.1 joerg 42 1.1 joerg explicit queue(const container_type& c); 43 1.1 joerg explicit queue(container_type&& c) 44 1.1 joerg template <class Alloc> 45 1.1 joerg explicit queue(const Alloc& a); 46 1.1 joerg template <class Alloc> 47 1.1 joerg queue(const container_type& c, const Alloc& a); 48 1.1 joerg template <class Alloc> 49 1.1 joerg queue(container_type&& c, const Alloc& a); 50 1.1 joerg template <class Alloc> 51 1.1 joerg queue(const queue& q, const Alloc& a); 52 1.1 joerg template <class Alloc> 53 1.1 joerg queue(queue&& q, const Alloc& a); 54 1.1 joerg 55 1.1 joerg bool empty() const; 56 1.1 joerg size_type size() const; 57 1.1 joerg 58 1.1 joerg reference front(); 59 1.1 joerg const_reference front() const; 60 1.1 joerg reference back(); 61 1.1 joerg const_reference back() const; 62 1.1 joerg 63 1.1 joerg void push(const value_type& v); 64 1.1 joerg void push(value_type&& v); 65 1.1 joerg template <class... Args> reference emplace(Args&&... args); // reference in C++17 66 1.1 joerg void pop(); 67 1.1 joerg 68 1.1 joerg void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>) 69 1.1 joerg }; 70 1.1 joerg 71 1.1 joerg template<class Container> 72 1.1 joerg queue(Container) -> queue<typename Container::value_type, Container>; // C++17 73 1.1 joerg 74 1.1 joerg template<class Container, class Allocator> 75 1.1 joerg queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17 76 1.1 joerg 77 1.1 joerg template <class T, class Container> 78 1.1 joerg bool operator==(const queue<T, Container>& x,const queue<T, Container>& y); 79 1.1 joerg 80 1.1 joerg template <class T, class Container> 81 1.1 joerg bool operator< (const queue<T, Container>& x,const queue<T, Container>& y); 82 1.1 joerg 83 1.1 joerg template <class T, class Container> 84 1.1 joerg bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y); 85 1.1 joerg 86 1.1 joerg template <class T, class Container> 87 1.1 joerg bool operator> (const queue<T, Container>& x,const queue<T, Container>& y); 88 1.1 joerg 89 1.1 joerg template <class T, class Container> 90 1.1 joerg bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y); 91 1.1 joerg 92 1.1 joerg template <class T, class Container> 93 1.1 joerg bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y); 94 1.1 joerg 95 1.1 joerg template <class T, class Container> 96 1.1 joerg void swap(queue<T, Container>& x, queue<T, Container>& y) 97 1.1 joerg noexcept(noexcept(x.swap(y))); 98 1.1 joerg 99 1.1 joerg template <class T, class Container = vector<T>, 100 1.1 joerg class Compare = less<typename Container::value_type>> 101 1.1 joerg class priority_queue 102 1.1 joerg { 103 1.1 joerg public: 104 1.1 joerg typedef Container container_type; 105 1.1 joerg typedef typename container_type::value_type value_type; 106 1.1 joerg typedef typename container_type::reference reference; 107 1.1 joerg typedef typename container_type::const_reference const_reference; 108 1.1 joerg typedef typename container_type::size_type size_type; 109 1.1 joerg 110 1.1 joerg protected: 111 1.1 joerg container_type c; 112 1.1 joerg Compare comp; 113 1.1 joerg 114 1.1 joerg public: 115 1.1 joerg priority_queue() : priority_queue(Compare()) {} // C++20 116 1.1 joerg explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {} 117 1.1 joerg priority_queue(const Compare& x, const Container&); 118 1.1 joerg explicit priority_queue(const Compare& x = Compare(), Container&&= Container()); // before C++20 119 1.1 joerg priority_queue(const Compare& x, Container&&); // C++20 120 1.1 joerg template <class InputIterator> 121 1.1 joerg priority_queue(InputIterator first, InputIterator last, 122 1.1 joerg const Compare& comp = Compare()); 123 1.1 joerg template <class InputIterator> 124 1.1 joerg priority_queue(InputIterator first, InputIterator last, 125 1.1 joerg const Compare& comp, const container_type& c); 126 1.1 joerg template <class InputIterator> 127 1.1 joerg priority_queue(InputIterator first, InputIterator last, 128 1.1 joerg const Compare& comp, container_type&& c); 129 1.1 joerg template <class Alloc> 130 1.1 joerg explicit priority_queue(const Alloc& a); 131 1.1 joerg template <class Alloc> 132 1.1 joerg priority_queue(const Compare& comp, const Alloc& a); 133 1.1 joerg template <class Alloc> 134 1.1 joerg priority_queue(const Compare& comp, const container_type& c, 135 1.1 joerg const Alloc& a); 136 1.1 joerg template <class Alloc> 137 1.1 joerg priority_queue(const Compare& comp, container_type&& c, 138 1.1 joerg const Alloc& a); 139 1.1 joerg template <class Alloc> 140 1.1 joerg priority_queue(const priority_queue& q, const Alloc& a); 141 1.1 joerg template <class Alloc> 142 1.1 joerg priority_queue(priority_queue&& q, const Alloc& a); 143 1.1 joerg 144 1.1 joerg bool empty() const; 145 1.1 joerg size_type size() const; 146 1.1 joerg const_reference top() const; 147 1.1 joerg 148 1.1 joerg void push(const value_type& v); 149 1.1 joerg void push(value_type&& v); 150 1.1 joerg template <class... Args> void emplace(Args&&... args); 151 1.1 joerg void pop(); 152 1.1 joerg 153 1.1 joerg void swap(priority_queue& q) 154 1.1 joerg noexcept(is_nothrow_swappable_v<Container> && 155 1.1 joerg is_nothrow_swappable_v<Comp>) 156 1.1 joerg }; 157 1.1 joerg 158 1.1 joerg template <class Compare, class Container> 159 1.1 joerg priority_queue(Compare, Container) 160 1.1 joerg -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 161 1.1 joerg 162 1.1 joerg template<class InputIterator, 163 1.1 joerg class Compare = less<typename iterator_traits<InputIterator>::value_type>, 164 1.1 joerg class Container = vector<typename iterator_traits<InputIterator>::value_type>> 165 1.1 joerg priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container()) 166 1.1 joerg -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17 167 1.1 joerg 168 1.1 joerg template<class Compare, class Container, class Allocator> 169 1.1 joerg priority_queue(Compare, Container, Allocator) 170 1.1 joerg -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 171 1.1 joerg 172 1.1 joerg template <class T, class Container, class Compare> 173 1.1 joerg void swap(priority_queue<T, Container, Compare>& x, 174 1.1 joerg priority_queue<T, Container, Compare>& y) 175 1.1 joerg noexcept(noexcept(x.swap(y))); 176 1.1 joerg 177 1.1 joerg } // std 178 1.1 joerg 179 1.1 joerg */ 180 1.1 joerg 181 1.1 joerg #include <__config> 182 1.1 joerg #include <compare> 183 1.1 joerg #include <deque> 184 1.1 joerg #include <vector> 185 1.1 joerg #include <functional> 186 1.1 joerg #include <algorithm> 187 1.1 joerg 188 1.1 joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 189 1.1 joerg #pragma GCC system_header 190 1.1 joerg #endif 191 1.1 joerg 192 1.1 joerg _LIBCPP_BEGIN_NAMESPACE_STD 193 1.1 joerg 194 1.1 joerg template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue; 195 1.1 joerg 196 1.1 joerg template <class _Tp, class _Container> 197 1.1 joerg _LIBCPP_INLINE_VISIBILITY 198 1.1 joerg bool 199 1.1 joerg operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); 200 1.1 joerg 201 1.1 joerg template <class _Tp, class _Container> 202 1.1 joerg _LIBCPP_INLINE_VISIBILITY 203 1.1 joerg bool 204 1.1 joerg operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y); 205 1.1 joerg 206 1.1 joerg template <class _Tp, class _Container /*= deque<_Tp>*/> 207 1.1 joerg class _LIBCPP_TEMPLATE_VIS queue 208 1.1 joerg { 209 1.1 joerg public: 210 1.1 joerg typedef _Container container_type; 211 1.1 joerg typedef typename container_type::value_type value_type; 212 1.1 joerg typedef typename container_type::reference reference; 213 1.1 joerg typedef typename container_type::const_reference const_reference; 214 1.1 joerg typedef typename container_type::size_type size_type; 215 1.1 joerg static_assert((is_same<_Tp, value_type>::value), "" ); 216 1.1 joerg 217 1.1 joerg protected: 218 1.1 joerg container_type c; 219 1.1 joerg 220 1.1 joerg public: 221 1.1 joerg _LIBCPP_INLINE_VISIBILITY 222 1.1 joerg queue() 223 1.1 joerg _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value) 224 1.1 joerg : c() {} 225 1.1 joerg 226 1.1 joerg _LIBCPP_INLINE_VISIBILITY 227 1.1 joerg queue(const queue& __q) : c(__q.c) {} 228 1.1 joerg 229 1.1 joerg _LIBCPP_INLINE_VISIBILITY 230 1.1 joerg queue& operator=(const queue& __q) {c = __q.c; return *this;} 231 1.1 joerg 232 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 233 1.1 joerg _LIBCPP_INLINE_VISIBILITY 234 1.1 joerg queue(queue&& __q) 235 1.1 joerg _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value) 236 1.1 joerg : c(_VSTD::move(__q.c)) {} 237 1.1 joerg 238 1.1 joerg _LIBCPP_INLINE_VISIBILITY 239 1.1 joerg queue& operator=(queue&& __q) 240 1.1 joerg _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value) 241 1.1 joerg {c = _VSTD::move(__q.c); return *this;} 242 1.1 joerg #endif // _LIBCPP_CXX03_LANG 243 1.1 joerg 244 1.1 joerg _LIBCPP_INLINE_VISIBILITY 245 1.1 joerg explicit queue(const container_type& __c) : c(__c) {} 246 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 247 1.1 joerg _LIBCPP_INLINE_VISIBILITY 248 1.1 joerg explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {} 249 1.1 joerg #endif // _LIBCPP_CXX03_LANG 250 1.1 joerg template <class _Alloc> 251 1.1 joerg _LIBCPP_INLINE_VISIBILITY 252 1.1 joerg explicit queue(const _Alloc& __a, 253 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0) 254 1.1 joerg : c(__a) {} 255 1.1 joerg template <class _Alloc> 256 1.1 joerg _LIBCPP_INLINE_VISIBILITY 257 1.1 joerg queue(const queue& __q, const _Alloc& __a, 258 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0) 259 1.1 joerg : c(__q.c, __a) {} 260 1.1 joerg template <class _Alloc> 261 1.1 joerg _LIBCPP_INLINE_VISIBILITY 262 1.1 joerg queue(const container_type& __c, const _Alloc& __a, 263 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0) 264 1.1 joerg : c(__c, __a) {} 265 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 266 1.1 joerg template <class _Alloc> 267 1.1 joerg _LIBCPP_INLINE_VISIBILITY 268 1.1 joerg queue(container_type&& __c, const _Alloc& __a, 269 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0) 270 1.1 joerg : c(_VSTD::move(__c), __a) {} 271 1.1 joerg template <class _Alloc> 272 1.1 joerg _LIBCPP_INLINE_VISIBILITY 273 1.1 joerg queue(queue&& __q, const _Alloc& __a, 274 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0) 275 1.1 joerg : c(_VSTD::move(__q.c), __a) {} 276 1.1 joerg 277 1.1 joerg #endif // _LIBCPP_CXX03_LANG 278 1.1 joerg 279 1.1 joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 280 1.1 joerg bool empty() const {return c.empty();} 281 1.1 joerg _LIBCPP_INLINE_VISIBILITY 282 1.1 joerg size_type size() const {return c.size();} 283 1.1 joerg 284 1.1 joerg _LIBCPP_INLINE_VISIBILITY 285 1.1 joerg reference front() {return c.front();} 286 1.1 joerg _LIBCPP_INLINE_VISIBILITY 287 1.1 joerg const_reference front() const {return c.front();} 288 1.1 joerg _LIBCPP_INLINE_VISIBILITY 289 1.1 joerg reference back() {return c.back();} 290 1.1 joerg _LIBCPP_INLINE_VISIBILITY 291 1.1 joerg const_reference back() const {return c.back();} 292 1.1 joerg 293 1.1 joerg _LIBCPP_INLINE_VISIBILITY 294 1.1 joerg void push(const value_type& __v) {c.push_back(__v);} 295 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 296 1.1 joerg _LIBCPP_INLINE_VISIBILITY 297 1.1 joerg void push(value_type&& __v) {c.push_back(_VSTD::move(__v));} 298 1.1 joerg template <class... _Args> 299 1.1 joerg _LIBCPP_INLINE_VISIBILITY 300 1.1 joerg #if _LIBCPP_STD_VER > 14 301 1.1 joerg decltype(auto) emplace(_Args&&... __args) 302 1.1 joerg { return c.emplace_back(_VSTD::forward<_Args>(__args)...);} 303 1.1 joerg #else 304 1.1 joerg void emplace(_Args&&... __args) 305 1.1 joerg { c.emplace_back(_VSTD::forward<_Args>(__args)...);} 306 1.1 joerg #endif 307 1.1 joerg #endif // _LIBCPP_CXX03_LANG 308 1.1 joerg _LIBCPP_INLINE_VISIBILITY 309 1.1 joerg void pop() {c.pop_front();} 310 1.1 joerg 311 1.1 joerg _LIBCPP_INLINE_VISIBILITY 312 1.1 joerg void swap(queue& __q) 313 1.1 joerg _NOEXCEPT_(__is_nothrow_swappable<container_type>::value) 314 1.1 joerg { 315 1.1 joerg using _VSTD::swap; 316 1.1 joerg swap(c, __q.c); 317 1.1 joerg } 318 1.1 joerg 319 1.1 joerg template <class _T1, class _C1> 320 1.1 joerg friend 321 1.1 joerg _LIBCPP_INLINE_VISIBILITY 322 1.1 joerg bool 323 1.1 joerg operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); 324 1.1 joerg 325 1.1 joerg template <class _T1, class _C1> 326 1.1 joerg friend 327 1.1 joerg _LIBCPP_INLINE_VISIBILITY 328 1.1 joerg bool 329 1.1 joerg operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y); 330 1.1 joerg }; 331 1.1 joerg 332 1.1 joerg #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 333 1.1 joerg template<class _Container, 334 1.1 joerg class = _EnableIf<!__is_allocator<_Container>::value> 335 1.1 joerg > 336 1.1 joerg queue(_Container) 337 1.1 joerg -> queue<typename _Container::value_type, _Container>; 338 1.1 joerg 339 1.1 joerg template<class _Container, 340 1.1 joerg class _Alloc, 341 1.1 joerg class = _EnableIf<!__is_allocator<_Container>::value>, 342 1.1 joerg class = _EnableIf<__is_allocator<_Alloc>::value> 343 1.1 joerg > 344 1.1 joerg queue(_Container, _Alloc) 345 1.1 joerg -> queue<typename _Container::value_type, _Container>; 346 1.1 joerg #endif 347 1.1 joerg 348 1.1 joerg template <class _Tp, class _Container> 349 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 350 1.1 joerg bool 351 1.1 joerg operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 352 1.1 joerg { 353 1.1 joerg return __x.c == __y.c; 354 1.1 joerg } 355 1.1 joerg 356 1.1 joerg template <class _Tp, class _Container> 357 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 358 1.1 joerg bool 359 1.1 joerg operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 360 1.1 joerg { 361 1.1 joerg return __x.c < __y.c; 362 1.1 joerg } 363 1.1 joerg 364 1.1 joerg template <class _Tp, class _Container> 365 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 366 1.1 joerg bool 367 1.1 joerg operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 368 1.1 joerg { 369 1.1 joerg return !(__x == __y); 370 1.1 joerg } 371 1.1 joerg 372 1.1 joerg template <class _Tp, class _Container> 373 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 374 1.1 joerg bool 375 1.1 joerg operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 376 1.1 joerg { 377 1.1 joerg return __y < __x; 378 1.1 joerg } 379 1.1 joerg 380 1.1 joerg template <class _Tp, class _Container> 381 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 382 1.1 joerg bool 383 1.1 joerg operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 384 1.1 joerg { 385 1.1 joerg return !(__x < __y); 386 1.1 joerg } 387 1.1 joerg 388 1.1 joerg template <class _Tp, class _Container> 389 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 390 1.1 joerg bool 391 1.1 joerg operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y) 392 1.1 joerg { 393 1.1 joerg return !(__y < __x); 394 1.1 joerg } 395 1.1 joerg 396 1.1 joerg template <class _Tp, class _Container> 397 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 398 1.1 joerg _EnableIf<__is_swappable<_Container>::value, void> 399 1.1 joerg swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y) 400 1.1 joerg _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 401 1.1 joerg { 402 1.1 joerg __x.swap(__y); 403 1.1 joerg } 404 1.1 joerg 405 1.1 joerg template <class _Tp, class _Container, class _Alloc> 406 1.1 joerg struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc> 407 1.1 joerg : public uses_allocator<_Container, _Alloc> 408 1.1 joerg { 409 1.1 joerg }; 410 1.1 joerg 411 1.1 joerg template <class _Tp, class _Container = vector<_Tp>, 412 1.1 joerg class _Compare = less<typename _Container::value_type> > 413 1.1 joerg class _LIBCPP_TEMPLATE_VIS priority_queue 414 1.1 joerg { 415 1.1 joerg public: 416 1.1 joerg typedef _Container container_type; 417 1.1 joerg typedef _Compare value_compare; 418 1.1 joerg typedef typename container_type::value_type value_type; 419 1.1 joerg typedef typename container_type::reference reference; 420 1.1 joerg typedef typename container_type::const_reference const_reference; 421 1.1 joerg typedef typename container_type::size_type size_type; 422 1.1 joerg static_assert((is_same<_Tp, value_type>::value), "" ); 423 1.1 joerg 424 1.1 joerg protected: 425 1.1 joerg container_type c; 426 1.1 joerg value_compare comp; 427 1.1 joerg 428 1.1 joerg public: 429 1.1 joerg _LIBCPP_INLINE_VISIBILITY 430 1.1 joerg priority_queue() 431 1.1 joerg _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value && 432 1.1 joerg is_nothrow_default_constructible<value_compare>::value) 433 1.1 joerg : c(), comp() {} 434 1.1 joerg 435 1.1 joerg _LIBCPP_INLINE_VISIBILITY 436 1.1 joerg priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {} 437 1.1 joerg 438 1.1 joerg _LIBCPP_INLINE_VISIBILITY 439 1.1 joerg priority_queue& operator=(const priority_queue& __q) 440 1.1 joerg {c = __q.c; comp = __q.comp; return *this;} 441 1.1 joerg 442 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 443 1.1 joerg _LIBCPP_INLINE_VISIBILITY 444 1.1 joerg priority_queue(priority_queue&& __q) 445 1.1 joerg _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value && 446 1.1 joerg is_nothrow_move_constructible<value_compare>::value) 447 1.1 joerg : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {} 448 1.1 joerg 449 1.1 joerg _LIBCPP_INLINE_VISIBILITY 450 1.1 joerg priority_queue& operator=(priority_queue&& __q) 451 1.1 joerg _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value && 452 1.1 joerg is_nothrow_move_assignable<value_compare>::value) 453 1.1 joerg {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;} 454 1.1 joerg #endif // _LIBCPP_CXX03_LANG 455 1.1 joerg 456 1.1 joerg _LIBCPP_INLINE_VISIBILITY 457 1.1 joerg explicit priority_queue(const value_compare& __comp) 458 1.1 joerg : c(), comp(__comp) {} 459 1.1 joerg _LIBCPP_INLINE_VISIBILITY 460 1.1 joerg priority_queue(const value_compare& __comp, const container_type& __c); 461 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 462 1.1 joerg _LIBCPP_INLINE_VISIBILITY 463 1.1 joerg priority_queue(const value_compare& __comp, container_type&& __c); 464 1.1 joerg #endif 465 1.1 joerg template <class _InputIter> 466 1.1 joerg _LIBCPP_INLINE_VISIBILITY 467 1.1 joerg priority_queue(_InputIter __f, _InputIter __l, 468 1.1 joerg const value_compare& __comp = value_compare()); 469 1.1 joerg template <class _InputIter> 470 1.1 joerg _LIBCPP_INLINE_VISIBILITY 471 1.1 joerg priority_queue(_InputIter __f, _InputIter __l, 472 1.1 joerg const value_compare& __comp, const container_type& __c); 473 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 474 1.1 joerg template <class _InputIter> 475 1.1 joerg _LIBCPP_INLINE_VISIBILITY 476 1.1 joerg priority_queue(_InputIter __f, _InputIter __l, 477 1.1 joerg const value_compare& __comp, container_type&& __c); 478 1.1 joerg #endif // _LIBCPP_CXX03_LANG 479 1.1 joerg template <class _Alloc> 480 1.1 joerg _LIBCPP_INLINE_VISIBILITY 481 1.1 joerg explicit priority_queue(const _Alloc& __a, 482 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 483 1.1 joerg template <class _Alloc> 484 1.1 joerg _LIBCPP_INLINE_VISIBILITY 485 1.1 joerg priority_queue(const value_compare& __comp, const _Alloc& __a, 486 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 487 1.1 joerg template <class _Alloc> 488 1.1 joerg _LIBCPP_INLINE_VISIBILITY 489 1.1 joerg priority_queue(const value_compare& __comp, const container_type& __c, 490 1.1 joerg const _Alloc& __a, 491 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 492 1.1 joerg template <class _Alloc> 493 1.1 joerg _LIBCPP_INLINE_VISIBILITY 494 1.1 joerg priority_queue(const priority_queue& __q, const _Alloc& __a, 495 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 496 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 497 1.1 joerg template <class _Alloc> 498 1.1 joerg _LIBCPP_INLINE_VISIBILITY 499 1.1 joerg priority_queue(const value_compare& __comp, container_type&& __c, 500 1.1 joerg const _Alloc& __a, 501 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 502 1.1 joerg template <class _Alloc> 503 1.1 joerg _LIBCPP_INLINE_VISIBILITY 504 1.1 joerg priority_queue(priority_queue&& __q, const _Alloc& __a, 505 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>* = 0); 506 1.1 joerg #endif // _LIBCPP_CXX03_LANG 507 1.1 joerg 508 1.1 joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 509 1.1 joerg bool empty() const {return c.empty();} 510 1.1 joerg _LIBCPP_INLINE_VISIBILITY 511 1.1 joerg size_type size() const {return c.size();} 512 1.1 joerg _LIBCPP_INLINE_VISIBILITY 513 1.1 joerg const_reference top() const {return c.front();} 514 1.1 joerg 515 1.1 joerg _LIBCPP_INLINE_VISIBILITY 516 1.1 joerg void push(const value_type& __v); 517 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 518 1.1 joerg _LIBCPP_INLINE_VISIBILITY 519 1.1 joerg void push(value_type&& __v); 520 1.1 joerg template <class... _Args> 521 1.1 joerg _LIBCPP_INLINE_VISIBILITY 522 1.1 joerg void emplace(_Args&&... __args); 523 1.1 joerg #endif // _LIBCPP_CXX03_LANG 524 1.1 joerg _LIBCPP_INLINE_VISIBILITY 525 1.1 joerg void pop(); 526 1.1 joerg 527 1.1 joerg _LIBCPP_INLINE_VISIBILITY 528 1.1 joerg void swap(priority_queue& __q) 529 1.1 joerg _NOEXCEPT_(__is_nothrow_swappable<container_type>::value && 530 1.1 joerg __is_nothrow_swappable<value_compare>::value); 531 1.1 joerg }; 532 1.1 joerg 533 1.1 joerg #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 534 1.1 joerg template <class _Compare, 535 1.1 joerg class _Container, 536 1.1 joerg class = _EnableIf<!__is_allocator<_Compare>::value>, 537 1.1 joerg class = _EnableIf<!__is_allocator<_Container>::value> 538 1.1 joerg > 539 1.1 joerg priority_queue(_Compare, _Container) 540 1.1 joerg -> priority_queue<typename _Container::value_type, _Container, _Compare>; 541 1.1 joerg 542 1.1 joerg template<class _InputIterator, 543 1.1 joerg class _Compare = less<__iter_value_type<_InputIterator>>, 544 1.1 joerg class _Container = vector<__iter_value_type<_InputIterator>>, 545 1.1 joerg class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>, 546 1.1 joerg class = _EnableIf<!__is_allocator<_Compare>::value>, 547 1.1 joerg class = _EnableIf<!__is_allocator<_Container>::value> 548 1.1 joerg > 549 1.1 joerg priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container()) 550 1.1 joerg -> priority_queue<__iter_value_type<_InputIterator>, _Container, _Compare>; 551 1.1 joerg 552 1.1 joerg template<class _Compare, 553 1.1 joerg class _Container, 554 1.1 joerg class _Alloc, 555 1.1 joerg class = _EnableIf<!__is_allocator<_Compare>::value>, 556 1.1 joerg class = _EnableIf<!__is_allocator<_Container>::value>, 557 1.1 joerg class = _EnableIf<__is_allocator<_Alloc>::value> 558 1.1 joerg > 559 1.1 joerg priority_queue(_Compare, _Container, _Alloc) 560 1.1 joerg -> priority_queue<typename _Container::value_type, _Container, _Compare>; 561 1.1 joerg #endif 562 1.1 joerg 563 1.1 joerg template <class _Tp, class _Container, class _Compare> 564 1.1 joerg inline 565 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp, 566 1.1 joerg const container_type& __c) 567 1.1 joerg : c(__c), 568 1.1 joerg comp(__comp) 569 1.1 joerg { 570 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 571 1.1 joerg } 572 1.1 joerg 573 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 574 1.1 joerg 575 1.1 joerg template <class _Tp, class _Container, class _Compare> 576 1.1 joerg inline 577 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, 578 1.1 joerg container_type&& __c) 579 1.1 joerg : c(_VSTD::move(__c)), 580 1.1 joerg comp(__comp) 581 1.1 joerg { 582 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 583 1.1 joerg } 584 1.1 joerg 585 1.1 joerg #endif // _LIBCPP_CXX03_LANG 586 1.1 joerg 587 1.1 joerg template <class _Tp, class _Container, class _Compare> 588 1.1 joerg template <class _InputIter> 589 1.1 joerg inline 590 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, 591 1.1 joerg const value_compare& __comp) 592 1.1 joerg : c(__f, __l), 593 1.1 joerg comp(__comp) 594 1.1 joerg { 595 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 596 1.1 joerg } 597 1.1 joerg 598 1.1 joerg template <class _Tp, class _Container, class _Compare> 599 1.1 joerg template <class _InputIter> 600 1.1 joerg inline 601 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, 602 1.1 joerg const value_compare& __comp, 603 1.1 joerg const container_type& __c) 604 1.1 joerg : c(__c), 605 1.1 joerg comp(__comp) 606 1.1 joerg { 607 1.1 joerg c.insert(c.end(), __f, __l); 608 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 609 1.1 joerg } 610 1.1 joerg 611 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 612 1.1 joerg 613 1.1 joerg template <class _Tp, class _Container, class _Compare> 614 1.1 joerg template <class _InputIter> 615 1.1 joerg inline 616 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l, 617 1.1 joerg const value_compare& __comp, 618 1.1 joerg container_type&& __c) 619 1.1 joerg : c(_VSTD::move(__c)), 620 1.1 joerg comp(__comp) 621 1.1 joerg { 622 1.1 joerg c.insert(c.end(), __f, __l); 623 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 624 1.1 joerg } 625 1.1 joerg 626 1.1 joerg #endif // _LIBCPP_CXX03_LANG 627 1.1 joerg 628 1.1 joerg template <class _Tp, class _Container, class _Compare> 629 1.1 joerg template <class _Alloc> 630 1.1 joerg inline 631 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a, 632 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 633 1.1 joerg : c(__a) 634 1.1 joerg { 635 1.1 joerg } 636 1.1 joerg 637 1.1 joerg template <class _Tp, class _Container, class _Compare> 638 1.1 joerg template <class _Alloc> 639 1.1 joerg inline 640 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, 641 1.1 joerg const _Alloc& __a, 642 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 643 1.1 joerg : c(__a), 644 1.1 joerg comp(__comp) 645 1.1 joerg { 646 1.1 joerg } 647 1.1 joerg 648 1.1 joerg template <class _Tp, class _Container, class _Compare> 649 1.1 joerg template <class _Alloc> 650 1.1 joerg inline 651 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, 652 1.1 joerg const container_type& __c, 653 1.1 joerg const _Alloc& __a, 654 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 655 1.1 joerg : c(__c, __a), 656 1.1 joerg comp(__comp) 657 1.1 joerg { 658 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 659 1.1 joerg } 660 1.1 joerg 661 1.1 joerg template <class _Tp, class _Container, class _Compare> 662 1.1 joerg template <class _Alloc> 663 1.1 joerg inline 664 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q, 665 1.1 joerg const _Alloc& __a, 666 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 667 1.1 joerg : c(__q.c, __a), 668 1.1 joerg comp(__q.comp) 669 1.1 joerg { 670 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 671 1.1 joerg } 672 1.1 joerg 673 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 674 1.1 joerg 675 1.1 joerg template <class _Tp, class _Container, class _Compare> 676 1.1 joerg template <class _Alloc> 677 1.1 joerg inline 678 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp, 679 1.1 joerg container_type&& __c, 680 1.1 joerg const _Alloc& __a, 681 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 682 1.1 joerg : c(_VSTD::move(__c), __a), 683 1.1 joerg comp(__comp) 684 1.1 joerg { 685 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 686 1.1 joerg } 687 1.1 joerg 688 1.1 joerg template <class _Tp, class _Container, class _Compare> 689 1.1 joerg template <class _Alloc> 690 1.1 joerg inline 691 1.1 joerg priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q, 692 1.1 joerg const _Alloc& __a, 693 1.1 joerg _EnableIf<uses_allocator<container_type, _Alloc>::value>*) 694 1.1 joerg : c(_VSTD::move(__q.c), __a), 695 1.1 joerg comp(_VSTD::move(__q.comp)) 696 1.1 joerg { 697 1.1 joerg _VSTD::make_heap(c.begin(), c.end(), comp); 698 1.1 joerg } 699 1.1 joerg 700 1.1 joerg #endif // _LIBCPP_CXX03_LANG 701 1.1 joerg 702 1.1 joerg template <class _Tp, class _Container, class _Compare> 703 1.1 joerg inline 704 1.1 joerg void 705 1.1 joerg priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v) 706 1.1 joerg { 707 1.1 joerg c.push_back(__v); 708 1.1 joerg _VSTD::push_heap(c.begin(), c.end(), comp); 709 1.1 joerg } 710 1.1 joerg 711 1.1 joerg #ifndef _LIBCPP_CXX03_LANG 712 1.1 joerg 713 1.1 joerg template <class _Tp, class _Container, class _Compare> 714 1.1 joerg inline 715 1.1 joerg void 716 1.1 joerg priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v) 717 1.1 joerg { 718 1.1 joerg c.push_back(_VSTD::move(__v)); 719 1.1 joerg _VSTD::push_heap(c.begin(), c.end(), comp); 720 1.1 joerg } 721 1.1 joerg 722 1.1 joerg template <class _Tp, class _Container, class _Compare> 723 1.1 joerg template <class... _Args> 724 1.1 joerg inline 725 1.1 joerg void 726 1.1 joerg priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args) 727 1.1 joerg { 728 1.1 joerg c.emplace_back(_VSTD::forward<_Args>(__args)...); 729 1.1 joerg _VSTD::push_heap(c.begin(), c.end(), comp); 730 1.1 joerg } 731 1.1 joerg 732 1.1 joerg #endif // _LIBCPP_CXX03_LANG 733 1.1 joerg 734 1.1 joerg template <class _Tp, class _Container, class _Compare> 735 1.1 joerg inline 736 1.1 joerg void 737 1.1 joerg priority_queue<_Tp, _Container, _Compare>::pop() 738 1.1 joerg { 739 1.1 joerg _VSTD::pop_heap(c.begin(), c.end(), comp); 740 1.1 joerg c.pop_back(); 741 1.1 joerg } 742 1.1 joerg 743 1.1 joerg template <class _Tp, class _Container, class _Compare> 744 1.1 joerg inline 745 1.1 joerg void 746 1.1 joerg priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q) 747 1.1 joerg _NOEXCEPT_(__is_nothrow_swappable<container_type>::value && 748 1.1 joerg __is_nothrow_swappable<value_compare>::value) 749 1.1 joerg { 750 1.1 joerg using _VSTD::swap; 751 1.1 joerg swap(c, __q.c); 752 1.1 joerg swap(comp, __q.comp); 753 1.1 joerg } 754 1.1 joerg 755 1.1 joerg template <class _Tp, class _Container, class _Compare> 756 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 757 1.1 joerg _EnableIf< 758 1.1 joerg __is_swappable<_Container>::value && __is_swappable<_Compare>::value, 759 1.1 joerg void 760 1.1 joerg > 761 1.1 joerg swap(priority_queue<_Tp, _Container, _Compare>& __x, 762 1.1 joerg priority_queue<_Tp, _Container, _Compare>& __y) 763 1.1 joerg _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 764 1.1 joerg { 765 1.1 joerg __x.swap(__y); 766 1.1 joerg } 767 1.1 joerg 768 1.1 joerg template <class _Tp, class _Container, class _Compare, class _Alloc> 769 1.1 joerg struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc> 770 1.1 joerg : public uses_allocator<_Container, _Alloc> 771 1.1 joerg { 772 1.1 joerg }; 773 1.1 joerg 774 1.1 joerg _LIBCPP_END_NAMESPACE_STD 775 1.1 joerg 776 1.1 joerg #endif // _LIBCPP_QUEUE 777