2 //===--------------------------- queue ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
20 template <class T, class Container = deque<T>>
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;
37 queue(const queue& q) = default;
38 queue(queue&& q) = default;
40 queue& operator=(const queue& q) = default;
41 queue& operator=(queue&& q) = default;
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);
57 size_type size() const;
60 const_reference front() const;
62 const_reference back() const;
64 void push(const value_type& v);
65 void push(value_type&& v);
66 template <class... Args> void emplace(Args&&... args);
69 void swap(queue& q) noexcept(noexcept(swap(c, q.c)));
72 template <class T, class Container>
73 bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
75 template <class T, class Container>
76 bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
78 template <class T, class Container>
79 bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
81 template <class T, class Container>
82 bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
84 template <class T, class Container>
85 bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
87 template <class T, class Container>
88 bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
90 template <class T, class Container>
91 void swap(queue<T, Container>& x, queue<T, Container>& y)
92 noexcept(noexcept(x.swap(y)));
94 template <class T, class Container = vector<T>,
95 class Compare = less<typename Container::value_type>>
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;
110 priority_queue() = default;
111 ~priority_queue() = default;
113 priority_queue(const priority_queue& q) = default;
114 priority_queue(priority_queue&& q) = default;
116 priority_queue& operator=(const priority_queue& q) = default;
117 priority_queue& operator=(priority_queue&& q) = default;
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,
138 template <class Alloc>
139 priority_queue(const Compare& comp, container_type&& c,
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);
147 size_type size() const;
148 const_reference top() const;
150 void push(const value_type& v);
151 void push(value_type&& v);
152 template <class... Args> void emplace(Args&&... args);
155 void swap(priority_queue& q)
156 noexcept(noexcept(swap(c, q.c)) && noexcept(swap(comp.q.comp)));
159 template <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)));
171 #include <functional>
174 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
175 #pragma GCC system_header
178 _LIBCPP_BEGIN_NAMESPACE_STD
180 template <class _Tp, class _Container> class queue;
182 template <class _Tp, class _Container>
184 operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
186 template <class _Tp, class _Container>
188 operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
190 template <class _Tp, class _Container = deque<_Tp> >
191 class _LIBCPP_VISIBLE queue
194 typedef _Container container_type;
195 typedef typename container_type::value_type value_type;
196 typedef typename container_type::reference reference;
197 typedef typename container_type::const_reference const_reference;
198 typedef typename container_type::size_type size_type;
204 _LIBCPP_INLINE_VISIBILITY
206 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
209 _LIBCPP_INLINE_VISIBILITY
210 queue(const queue& __q) : c(__q.c) {}
212 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
213 _LIBCPP_INLINE_VISIBILITY
215 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
216 : c(_VSTD::move(__q.c)) {}
217 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
219 _LIBCPP_INLINE_VISIBILITY
220 queue& operator=(const queue& __q) {c = __q.c; return *this;}
222 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
223 _LIBCPP_INLINE_VISIBILITY
224 queue& operator=(queue&& __q)
225 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
226 {c = _VSTD::move(__q.c); return *this;}
227 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
229 _LIBCPP_INLINE_VISIBILITY
230 explicit queue(const container_type& __c) : c(__c) {}
231 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
232 _LIBCPP_INLINE_VISIBILITY
233 explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
234 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
235 template <class _Alloc>
236 _LIBCPP_INLINE_VISIBILITY
237 explicit queue(const _Alloc& __a,
238 typename enable_if<uses_allocator<container_type,
239 _Alloc>::value>::type* = 0)
241 template <class _Alloc>
242 _LIBCPP_INLINE_VISIBILITY
243 queue(const queue& __q, const _Alloc& __a,
244 typename enable_if<uses_allocator<container_type,
245 _Alloc>::value>::type* = 0)
247 template <class _Alloc>
248 _LIBCPP_INLINE_VISIBILITY
249 queue(const container_type& __c, const _Alloc& __a,
250 typename enable_if<uses_allocator<container_type,
251 _Alloc>::value>::type* = 0)
253 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
254 template <class _Alloc>
255 _LIBCPP_INLINE_VISIBILITY
256 queue(container_type&& __c, const _Alloc& __a,
257 typename enable_if<uses_allocator<container_type,
258 _Alloc>::value>::type* = 0)
259 : c(_VSTD::move(__c), __a) {}
260 template <class _Alloc>
261 _LIBCPP_INLINE_VISIBILITY
262 queue(queue&& __q, const _Alloc& __a,
263 typename enable_if<uses_allocator<container_type,
264 _Alloc>::value>::type* = 0)
265 : c(_VSTD::move(__q.c), __a) {}
267 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
269 _LIBCPP_INLINE_VISIBILITY
270 bool empty() const {return c.empty();}
271 _LIBCPP_INLINE_VISIBILITY
272 size_type size() const {return c.size();}
274 _LIBCPP_INLINE_VISIBILITY
275 reference front() {return c.front();}
276 _LIBCPP_INLINE_VISIBILITY
277 const_reference front() const {return c.front();}
278 _LIBCPP_INLINE_VISIBILITY
279 reference back() {return c.back();}
280 _LIBCPP_INLINE_VISIBILITY
281 const_reference back() const {return c.back();}
283 _LIBCPP_INLINE_VISIBILITY
284 void push(const value_type& __v) {c.push_back(__v);}
285 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
286 _LIBCPP_INLINE_VISIBILITY
287 void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
288 #ifndef _LIBCPP_HAS_NO_VARIADICS
289 template <class... _Args>
290 _LIBCPP_INLINE_VISIBILITY
291 void emplace(_Args&&... __args)
292 {c.emplace_back(_VSTD::forward<_Args>(__args)...);}
293 #endif // _LIBCPP_HAS_NO_VARIADICS
294 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
295 _LIBCPP_INLINE_VISIBILITY
296 void pop() {c.pop_front();}
298 _LIBCPP_INLINE_VISIBILITY
299 void swap(queue& __q)
300 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
306 template <class _T1, class _C1>
308 _LIBCPP_INLINE_VISIBILITY
310 operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
312 template <class _T1, class _C1>
314 _LIBCPP_INLINE_VISIBILITY
316 operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
319 template <class _Tp, class _Container>
320 inline _LIBCPP_INLINE_VISIBILITY
322 operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
324 return __x.c == __y.c;
327 template <class _Tp, class _Container>
328 inline _LIBCPP_INLINE_VISIBILITY
330 operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
332 return __x.c < __y.c;
335 template <class _Tp, class _Container>
336 inline _LIBCPP_INLINE_VISIBILITY
338 operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
340 return !(__x == __y);
343 template <class _Tp, class _Container>
344 inline _LIBCPP_INLINE_VISIBILITY
346 operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
351 template <class _Tp, class _Container>
352 inline _LIBCPP_INLINE_VISIBILITY
354 operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
359 template <class _Tp, class _Container>
360 inline _LIBCPP_INLINE_VISIBILITY
362 operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
367 template <class _Tp, class _Container>
368 inline _LIBCPP_INLINE_VISIBILITY
370 swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
371 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
376 template <class _Tp, class _Container, class _Alloc>
377 struct _LIBCPP_VISIBLE uses_allocator<queue<_Tp, _Container>, _Alloc>
378 : public uses_allocator<_Container, _Alloc>
382 template <class _Tp, class _Container = vector<_Tp>,
383 class _Compare = less<typename _Container::value_type> >
384 class _LIBCPP_VISIBLE priority_queue
387 typedef _Container container_type;
388 typedef _Compare value_compare;
389 typedef typename container_type::value_type value_type;
390 typedef typename container_type::reference reference;
391 typedef typename container_type::const_reference const_reference;
392 typedef typename container_type::size_type size_type;
399 _LIBCPP_INLINE_VISIBILITY
401 _NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
402 is_nothrow_default_constructible<value_compare>::value)
405 _LIBCPP_INLINE_VISIBILITY
406 priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
408 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
409 _LIBCPP_INLINE_VISIBILITY
410 priority_queue(priority_queue&& __q)
411 _NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
412 is_nothrow_move_constructible<value_compare>::value)
413 : c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
414 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
416 _LIBCPP_INLINE_VISIBILITY
417 priority_queue& operator=(const priority_queue& __q)
418 {c = __q.c; comp = __q.comp; return *this;}
420 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
421 _LIBCPP_INLINE_VISIBILITY
422 priority_queue& operator=(priority_queue&& __q)
423 _NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
424 is_nothrow_move_assignable<value_compare>::value)
425 {c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
426 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
428 _LIBCPP_INLINE_VISIBILITY
429 explicit priority_queue(const value_compare& __comp)
430 : c(), comp(__comp) {}
431 priority_queue(const value_compare& __comp, const container_type& __c);
432 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
433 explicit priority_queue(const value_compare& __comp, container_type&& __c);
435 template <class _InputIter>
436 priority_queue(_InputIter __f, _InputIter __l,
437 const value_compare& __comp = value_compare());
438 template <class _InputIter>
439 priority_queue(_InputIter __f, _InputIter __l,
440 const value_compare& __comp, const container_type& __c);
441 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
442 template <class _InputIter>
443 priority_queue(_InputIter __f, _InputIter __l,
444 const value_compare& __comp, container_type&& __c);
445 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
446 template <class _Alloc>
447 explicit priority_queue(const _Alloc& __a,
448 typename enable_if<uses_allocator<container_type,
449 _Alloc>::value>::type* = 0);
450 template <class _Alloc>
451 priority_queue(const value_compare& __comp, const _Alloc& __a,
452 typename enable_if<uses_allocator<container_type,
453 _Alloc>::value>::type* = 0);
454 template <class _Alloc>
455 priority_queue(const value_compare& __comp, const container_type& __c,
457 typename enable_if<uses_allocator<container_type,
458 _Alloc>::value>::type* = 0);
459 template <class _Alloc>
460 priority_queue(const priority_queue& __q, const _Alloc& __a,
461 typename enable_if<uses_allocator<container_type,
462 _Alloc>::value>::type* = 0);
463 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
464 template <class _Alloc>
465 priority_queue(const value_compare& __comp, container_type&& __c,
467 typename enable_if<uses_allocator<container_type,
468 _Alloc>::value>::type* = 0);
469 template <class _Alloc>
470 priority_queue(priority_queue&& __q, const _Alloc& __a,
471 typename enable_if<uses_allocator<container_type,
472 _Alloc>::value>::type* = 0);
473 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
475 _LIBCPP_INLINE_VISIBILITY
476 bool empty() const {return c.empty();}
477 _LIBCPP_INLINE_VISIBILITY
478 size_type size() const {return c.size();}
479 _LIBCPP_INLINE_VISIBILITY
480 const_reference top() const {return c.front();}
482 void push(const value_type& __v);
483 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
484 void push(value_type&& __v);
485 #ifndef _LIBCPP_HAS_NO_VARIADICS
486 template <class... _Args> void emplace(_Args&&... __args);
488 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
491 void swap(priority_queue& __q)
492 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
493 __is_nothrow_swappable<value_compare>::value);
496 template <class _Tp, class _Container, class _Compare>
497 inline _LIBCPP_INLINE_VISIBILITY
498 priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
499 const container_type& __c)
503 _VSTD::make_heap(c.begin(), c.end(), comp);
506 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
508 template <class _Tp, class _Container, class _Compare>
509 inline _LIBCPP_INLINE_VISIBILITY
510 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
511 container_type&& __c)
512 : c(_VSTD::move(__c)),
515 _VSTD::make_heap(c.begin(), c.end(), comp);
518 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
520 template <class _Tp, class _Container, class _Compare>
521 template <class _InputIter>
522 inline _LIBCPP_INLINE_VISIBILITY
523 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
524 const value_compare& __comp)
528 _VSTD::make_heap(c.begin(), c.end(), comp);
531 template <class _Tp, class _Container, class _Compare>
532 template <class _InputIter>
533 inline _LIBCPP_INLINE_VISIBILITY
534 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
535 const value_compare& __comp,
536 const container_type& __c)
540 c.insert(c.end(), __f, __l);
541 _VSTD::make_heap(c.begin(), c.end(), comp);
544 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
546 template <class _Tp, class _Container, class _Compare>
547 template <class _InputIter>
548 inline _LIBCPP_INLINE_VISIBILITY
549 priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
550 const value_compare& __comp,
551 container_type&& __c)
552 : c(_VSTD::move(__c)),
555 c.insert(c.end(), __f, __l);
556 _VSTD::make_heap(c.begin(), c.end(), comp);
559 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
561 template <class _Tp, class _Container, class _Compare>
562 template <class _Alloc>
563 inline _LIBCPP_INLINE_VISIBILITY
564 priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
565 typename enable_if<uses_allocator<container_type,
566 _Alloc>::value>::type*)
571 template <class _Tp, class _Container, class _Compare>
572 template <class _Alloc>
573 inline _LIBCPP_INLINE_VISIBILITY
574 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
576 typename enable_if<uses_allocator<container_type,
577 _Alloc>::value>::type*)
583 template <class _Tp, class _Container, class _Compare>
584 template <class _Alloc>
585 inline _LIBCPP_INLINE_VISIBILITY
586 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
587 const container_type& __c,
589 typename enable_if<uses_allocator<container_type,
590 _Alloc>::value>::type*)
594 _VSTD::make_heap(c.begin(), c.end(), comp);
597 template <class _Tp, class _Container, class _Compare>
598 template <class _Alloc>
599 inline _LIBCPP_INLINE_VISIBILITY
600 priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
602 typename enable_if<uses_allocator<container_type,
603 _Alloc>::value>::type*)
607 _VSTD::make_heap(c.begin(), c.end(), comp);
610 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
612 template <class _Tp, class _Container, class _Compare>
613 template <class _Alloc>
614 inline _LIBCPP_INLINE_VISIBILITY
615 priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
616 container_type&& __c,
618 typename enable_if<uses_allocator<container_type,
619 _Alloc>::value>::type*)
620 : c(_VSTD::move(__c), __a),
623 _VSTD::make_heap(c.begin(), c.end(), comp);
626 template <class _Tp, class _Container, class _Compare>
627 template <class _Alloc>
628 inline _LIBCPP_INLINE_VISIBILITY
629 priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
631 typename enable_if<uses_allocator<container_type,
632 _Alloc>::value>::type*)
633 : c(_VSTD::move(__q.c), __a),
634 comp(_VSTD::move(__q.comp))
636 _VSTD::make_heap(c.begin(), c.end(), comp);
639 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
641 template <class _Tp, class _Container, class _Compare>
642 inline _LIBCPP_INLINE_VISIBILITY
644 priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
647 _VSTD::push_heap(c.begin(), c.end(), comp);
650 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
652 template <class _Tp, class _Container, class _Compare>
653 inline _LIBCPP_INLINE_VISIBILITY
655 priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
657 c.push_back(_VSTD::move(__v));
658 _VSTD::push_heap(c.begin(), c.end(), comp);
661 #ifndef _LIBCPP_HAS_NO_VARIADICS
663 template <class _Tp, class _Container, class _Compare>
664 template <class... _Args>
665 inline _LIBCPP_INLINE_VISIBILITY
667 priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
669 c.emplace_back(_VSTD::forward<_Args>(__args)...);
670 _VSTD::push_heap(c.begin(), c.end(), comp);
673 #endif // _LIBCPP_HAS_NO_VARIADICS
674 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
676 template <class _Tp, class _Container, class _Compare>
677 inline _LIBCPP_INLINE_VISIBILITY
679 priority_queue<_Tp, _Container, _Compare>::pop()
681 _VSTD::pop_heap(c.begin(), c.end(), comp);
685 template <class _Tp, class _Container, class _Compare>
686 inline _LIBCPP_INLINE_VISIBILITY
688 priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
689 _NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
690 __is_nothrow_swappable<value_compare>::value)
694 swap(comp, __q.comp);
697 template <class _Tp, class _Container, class _Compare>
698 inline _LIBCPP_INLINE_VISIBILITY
700 swap(priority_queue<_Tp, _Container, _Compare>& __x,
701 priority_queue<_Tp, _Container, _Compare>& __y)
702 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
707 template <class _Tp, class _Container, class _Compare, class _Alloc>
708 struct _LIBCPP_VISIBLE uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
709 : public uses_allocator<_Container, _Alloc>
713 _LIBCPP_END_NAMESPACE_STD
715 #endif // _LIBCPP_QUEUE