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