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 _LIBCPP_TYPE_VIS queue;
182
template <class _Tp, class _Container>
183
_LIBCPP_INLINE_VISIBILITY
185
operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
187
template <class _Tp, class _Container>
188
_LIBCPP_INLINE_VISIBILITY
190
operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
192
template <class _Tp, class _Container = deque<_Tp> >
193
class _LIBCPP_TYPE_VIS queue
196
typedef _Container container_type;
197
typedef typename container_type::value_type value_type;
198
typedef typename container_type::reference reference;
199
typedef typename container_type::const_reference const_reference;
200
typedef typename container_type::size_type size_type;
206
_LIBCPP_INLINE_VISIBILITY
208
_NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
211
_LIBCPP_INLINE_VISIBILITY
212
queue(const queue& __q) : c(__q.c) {}
214
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
215
_LIBCPP_INLINE_VISIBILITY
217
_NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
218
: c(_VSTD::move(__q.c)) {}
219
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
221
_LIBCPP_INLINE_VISIBILITY
222
queue& operator=(const queue& __q) {c = __q.c; return *this;}
224
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
225
_LIBCPP_INLINE_VISIBILITY
226
queue& operator=(queue&& __q)
227
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
228
{c = _VSTD::move(__q.c); return *this;}
229
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
231
_LIBCPP_INLINE_VISIBILITY
232
explicit queue(const container_type& __c) : c(__c) {}
233
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
234
_LIBCPP_INLINE_VISIBILITY
235
explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
236
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
237
template <class _Alloc>
238
_LIBCPP_INLINE_VISIBILITY
239
explicit queue(const _Alloc& __a,
240
typename enable_if<uses_allocator<container_type,
241
_Alloc>::value>::type* = 0)
243
template <class _Alloc>
244
_LIBCPP_INLINE_VISIBILITY
245
queue(const queue& __q, const _Alloc& __a,
246
typename enable_if<uses_allocator<container_type,
247
_Alloc>::value>::type* = 0)
249
template <class _Alloc>
250
_LIBCPP_INLINE_VISIBILITY
251
queue(const container_type& __c, const _Alloc& __a,
252
typename enable_if<uses_allocator<container_type,
253
_Alloc>::value>::type* = 0)
255
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
256
template <class _Alloc>
257
_LIBCPP_INLINE_VISIBILITY
258
queue(container_type&& __c, const _Alloc& __a,
259
typename enable_if<uses_allocator<container_type,
260
_Alloc>::value>::type* = 0)
261
: c(_VSTD::move(__c), __a) {}
262
template <class _Alloc>
263
_LIBCPP_INLINE_VISIBILITY
264
queue(queue&& __q, const _Alloc& __a,
265
typename enable_if<uses_allocator<container_type,
266
_Alloc>::value>::type* = 0)
267
: c(_VSTD::move(__q.c), __a) {}
269
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
271
_LIBCPP_INLINE_VISIBILITY
272
bool empty() const {return c.empty();}
273
_LIBCPP_INLINE_VISIBILITY
274
size_type size() const {return c.size();}
276
_LIBCPP_INLINE_VISIBILITY
277
reference front() {return c.front();}
278
_LIBCPP_INLINE_VISIBILITY
279
const_reference front() const {return c.front();}
280
_LIBCPP_INLINE_VISIBILITY
281
reference back() {return c.back();}
282
_LIBCPP_INLINE_VISIBILITY
283
const_reference back() const {return c.back();}
285
_LIBCPP_INLINE_VISIBILITY
286
void push(const value_type& __v) {c.push_back(__v);}
287
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
288
_LIBCPP_INLINE_VISIBILITY
289
void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
290
#ifndef _LIBCPP_HAS_NO_VARIADICS
291
template <class... _Args>
292
_LIBCPP_INLINE_VISIBILITY
293
void emplace(_Args&&... __args)
294
{c.emplace_back(_VSTD::forward<_Args>(__args)...);}
295
#endif // _LIBCPP_HAS_NO_VARIADICS
296
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
297
_LIBCPP_INLINE_VISIBILITY
298
void pop() {c.pop_front();}
300
_LIBCPP_INLINE_VISIBILITY
301
void swap(queue& __q)
302
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
308
template <class _T1, class _C1>
310
_LIBCPP_INLINE_VISIBILITY
312
operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
314
template <class _T1, class _C1>
316
_LIBCPP_INLINE_VISIBILITY
318
operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
321
template <class _Tp, class _Container>
322
inline _LIBCPP_INLINE_VISIBILITY
324
operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
326
return __x.c == __y.c;
329
template <class _Tp, class _Container>
330
inline _LIBCPP_INLINE_VISIBILITY
332
operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
334
return __x.c < __y.c;
337
template <class _Tp, class _Container>
338
inline _LIBCPP_INLINE_VISIBILITY
340
operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
342
return !(__x == __y);
345
template <class _Tp, class _Container>
346
inline _LIBCPP_INLINE_VISIBILITY
348
operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
353
template <class _Tp, class _Container>
354
inline _LIBCPP_INLINE_VISIBILITY
356
operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
361
template <class _Tp, class _Container>
362
inline _LIBCPP_INLINE_VISIBILITY
364
operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
369
template <class _Tp, class _Container>
370
inline _LIBCPP_INLINE_VISIBILITY
372
swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
373
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
378
template <class _Tp, class _Container, class _Alloc>
379
struct _LIBCPP_TYPE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
380
: public uses_allocator<_Container, _Alloc>
384
template <class _Tp, class _Container = vector<_Tp>,
385
class _Compare = less<typename _Container::value_type> >
386
class _LIBCPP_TYPE_VIS priority_queue
389
typedef _Container container_type;
390
typedef _Compare value_compare;
391
typedef typename container_type::value_type value_type;
392
typedef typename container_type::reference reference;
393
typedef typename container_type::const_reference const_reference;
394
typedef typename container_type::size_type size_type;
401
_LIBCPP_INLINE_VISIBILITY
403
_NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
404
is_nothrow_default_constructible<value_compare>::value)
407
_LIBCPP_INLINE_VISIBILITY
408
priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
410
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
411
_LIBCPP_INLINE_VISIBILITY
412
priority_queue(priority_queue&& __q)
413
_NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
414
is_nothrow_move_constructible<value_compare>::value)
415
: c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
416
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
418
_LIBCPP_INLINE_VISIBILITY
419
priority_queue& operator=(const priority_queue& __q)
420
{c = __q.c; comp = __q.comp; return *this;}
422
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
423
_LIBCPP_INLINE_VISIBILITY
424
priority_queue& operator=(priority_queue&& __q)
425
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
426
is_nothrow_move_assignable<value_compare>::value)
427
{c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
428
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
430
_LIBCPP_INLINE_VISIBILITY
431
explicit priority_queue(const value_compare& __comp)
432
: c(), comp(__comp) {}
433
priority_queue(const value_compare& __comp, const container_type& __c);
434
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
435
explicit priority_queue(const value_compare& __comp, container_type&& __c);
437
template <class _InputIter>
438
priority_queue(_InputIter __f, _InputIter __l,
439
const value_compare& __comp = value_compare());
440
template <class _InputIter>
441
priority_queue(_InputIter __f, _InputIter __l,
442
const value_compare& __comp, const container_type& __c);
443
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
444
template <class _InputIter>
445
priority_queue(_InputIter __f, _InputIter __l,
446
const value_compare& __comp, container_type&& __c);
447
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
448
template <class _Alloc>
449
explicit priority_queue(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 _Alloc& __a,
454
typename enable_if<uses_allocator<container_type,
455
_Alloc>::value>::type* = 0);
456
template <class _Alloc>
457
priority_queue(const value_compare& __comp, const container_type& __c,
459
typename enable_if<uses_allocator<container_type,
460
_Alloc>::value>::type* = 0);
461
template <class _Alloc>
462
priority_queue(const priority_queue& __q, const _Alloc& __a,
463
typename enable_if<uses_allocator<container_type,
464
_Alloc>::value>::type* = 0);
465
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
466
template <class _Alloc>
467
priority_queue(const value_compare& __comp, container_type&& __c,
469
typename enable_if<uses_allocator<container_type,
470
_Alloc>::value>::type* = 0);
471
template <class _Alloc>
472
priority_queue(priority_queue&& __q, const _Alloc& __a,
473
typename enable_if<uses_allocator<container_type,
474
_Alloc>::value>::type* = 0);
475
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
477
_LIBCPP_INLINE_VISIBILITY
478
bool empty() const {return c.empty();}
479
_LIBCPP_INLINE_VISIBILITY
480
size_type size() const {return c.size();}
481
_LIBCPP_INLINE_VISIBILITY
482
const_reference top() const {return c.front();}
484
void push(const value_type& __v);
485
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
486
void push(value_type&& __v);
487
#ifndef _LIBCPP_HAS_NO_VARIADICS
488
template <class... _Args> void emplace(_Args&&... __args);
490
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
493
void swap(priority_queue& __q)
494
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
495
__is_nothrow_swappable<value_compare>::value);
498
template <class _Tp, class _Container, class _Compare>
499
inline _LIBCPP_INLINE_VISIBILITY
500
priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
501
const container_type& __c)
505
_VSTD::make_heap(c.begin(), c.end(), comp);
508
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
510
template <class _Tp, class _Container, class _Compare>
511
inline _LIBCPP_INLINE_VISIBILITY
512
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
513
container_type&& __c)
514
: c(_VSTD::move(__c)),
517
_VSTD::make_heap(c.begin(), c.end(), comp);
520
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
522
template <class _Tp, class _Container, class _Compare>
523
template <class _InputIter>
524
inline _LIBCPP_INLINE_VISIBILITY
525
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
526
const value_compare& __comp)
530
_VSTD::make_heap(c.begin(), c.end(), comp);
533
template <class _Tp, class _Container, class _Compare>
534
template <class _InputIter>
535
inline _LIBCPP_INLINE_VISIBILITY
536
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
537
const value_compare& __comp,
538
const container_type& __c)
542
c.insert(c.end(), __f, __l);
543
_VSTD::make_heap(c.begin(), c.end(), comp);
546
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
548
template <class _Tp, class _Container, class _Compare>
549
template <class _InputIter>
550
inline _LIBCPP_INLINE_VISIBILITY
551
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
552
const value_compare& __comp,
553
container_type&& __c)
554
: c(_VSTD::move(__c)),
557
c.insert(c.end(), __f, __l);
558
_VSTD::make_heap(c.begin(), c.end(), comp);
561
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
563
template <class _Tp, class _Container, class _Compare>
564
template <class _Alloc>
565
inline _LIBCPP_INLINE_VISIBILITY
566
priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
567
typename enable_if<uses_allocator<container_type,
568
_Alloc>::value>::type*)
573
template <class _Tp, class _Container, class _Compare>
574
template <class _Alloc>
575
inline _LIBCPP_INLINE_VISIBILITY
576
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
578
typename enable_if<uses_allocator<container_type,
579
_Alloc>::value>::type*)
585
template <class _Tp, class _Container, class _Compare>
586
template <class _Alloc>
587
inline _LIBCPP_INLINE_VISIBILITY
588
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
589
const container_type& __c,
591
typename enable_if<uses_allocator<container_type,
592
_Alloc>::value>::type*)
596
_VSTD::make_heap(c.begin(), c.end(), comp);
599
template <class _Tp, class _Container, class _Compare>
600
template <class _Alloc>
601
inline _LIBCPP_INLINE_VISIBILITY
602
priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
604
typename enable_if<uses_allocator<container_type,
605
_Alloc>::value>::type*)
609
_VSTD::make_heap(c.begin(), c.end(), comp);
612
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
614
template <class _Tp, class _Container, class _Compare>
615
template <class _Alloc>
616
inline _LIBCPP_INLINE_VISIBILITY
617
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
618
container_type&& __c,
620
typename enable_if<uses_allocator<container_type,
621
_Alloc>::value>::type*)
622
: c(_VSTD::move(__c), __a),
625
_VSTD::make_heap(c.begin(), c.end(), comp);
628
template <class _Tp, class _Container, class _Compare>
629
template <class _Alloc>
630
inline _LIBCPP_INLINE_VISIBILITY
631
priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
633
typename enable_if<uses_allocator<container_type,
634
_Alloc>::value>::type*)
635
: c(_VSTD::move(__q.c), __a),
636
comp(_VSTD::move(__q.comp))
638
_VSTD::make_heap(c.begin(), c.end(), comp);
641
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
643
template <class _Tp, class _Container, class _Compare>
644
inline _LIBCPP_INLINE_VISIBILITY
646
priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
649
_VSTD::push_heap(c.begin(), c.end(), comp);
652
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
654
template <class _Tp, class _Container, class _Compare>
655
inline _LIBCPP_INLINE_VISIBILITY
657
priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
659
c.push_back(_VSTD::move(__v));
660
_VSTD::push_heap(c.begin(), c.end(), comp);
663
#ifndef _LIBCPP_HAS_NO_VARIADICS
665
template <class _Tp, class _Container, class _Compare>
666
template <class... _Args>
667
inline _LIBCPP_INLINE_VISIBILITY
669
priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
671
c.emplace_back(_VSTD::forward<_Args>(__args)...);
672
_VSTD::push_heap(c.begin(), c.end(), comp);
675
#endif // _LIBCPP_HAS_NO_VARIADICS
676
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
678
template <class _Tp, class _Container, class _Compare>
679
inline _LIBCPP_INLINE_VISIBILITY
681
priority_queue<_Tp, _Container, _Compare>::pop()
683
_VSTD::pop_heap(c.begin(), c.end(), comp);
687
template <class _Tp, class _Container, class _Compare>
688
inline _LIBCPP_INLINE_VISIBILITY
690
priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
691
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
692
__is_nothrow_swappable<value_compare>::value)
696
swap(comp, __q.comp);
699
template <class _Tp, class _Container, class _Compare>
700
inline _LIBCPP_INLINE_VISIBILITY
702
swap(priority_queue<_Tp, _Container, _Compare>& __x,
703
priority_queue<_Tp, _Container, _Compare>& __y)
704
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
709
template <class _Tp, class _Container, class _Compare, class _Alloc>
710
struct _LIBCPP_TYPE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
711
: public uses_allocator<_Container, _Alloc>
715
_LIBCPP_END_NAMESPACE_STD
717
#endif // _LIBCPP_QUEUE