A standard container giving FIFO behavior.
- Template Parameters
-
_Tp | Type of element. |
_Sequence | Type of underlying sequence, defaults to deque<_Tp>. |
Meets many of the requirements of a container, but does not define anything to do with iterators. Very few of the other standard container interfaces are defined.
This is not a true container, but an adaptor. It holds another container, and provides a wrapper interface to that container. The wrapper is what enforces strict first-in-first-out queue behavior.
The second template parameter defines the type of the underlying sequence/container. It defaults to std::deque, but it can be any type that supports front
, back
, push_back
, and pop_front
, such as std::list or an appropriate user-defined type.
Members not found in normal containers are container_type
, which is a typedef for the second Sequence parameter, and push
and pop
, which are standard queue/FIFO operations.
'c' is the underlying container. Maintainers wondering why this isn't uglified as per style guidelines should note that this name is specified in the standard, [23.2.3.1]. (Why? Presumably for the same reason that it's protected instead of private: to allow derivation. But none of the other containers allow for derivation. Odd.)
Default constructor creates no elements.
Returns true if the queue is empty.
Returns the number of elements in the queue.
Returns a read/write reference to the data at the first element of the queue.
Returns a read-only (constant) reference to the data at the first element of the queue.
Returns a read/write reference to the data at the last element of the queue.
Returns a read-only (constant) reference to the data at the last element of the queue.
Add data to the end of the queue.
- Parameters
-
This is a typical queue operation. The function creates an element at the end of the queue and assigns the given data to it. The time complexity of the operation depends on the underlying sequence.
Removes first element.
This is a typical queue operation. It shrinks the queue by one. The time complexity of the operation depends on the underlying sequence.
Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called.
Queue equality comparison.
- Parameters
-
__x | A queue. |
__y | A queue of the same type as __x. |
- Returns
- True iff the size and elements of the queues are equal.
This is an equivalence relation. Complexity and semantics depend on the underlying sequence type, but the expected rules are: this relation is linear in the size of the sequences, and queues are considered equivalent if their sequences compare equal.
Queue ordering relation.
- Parameters
-
__x | A queue. |
__y | A queue of the same type as x. |
- Returns
- True iff __x is lexicographically less than __y.
This is an total ordering relation. Complexity and semantics depend on the underlying sequence type, but the expected rules are: this relation is linear in the size of the sequences, the elements must be comparable with <
, and std::lexicographical_compare() is usually used to make the determination.
Based on operator==
Based on operator<
Based on operator<
Based on operator<
A standard container automatically sorting its contents.
- Template Parameters
-
_Tp | Type of element. |
_Sequence | Type of underlying sequence, defaults to vector<_Tp>. |
_Compare | Comparison function object type, defaults to less<_Sequence::value_type>. |
This is not a true container, but an adaptor. It holds another container, and provides a wrapper interface to that container. The wrapper is what enforces priority-based sorting and queue behavior. Very few of the standard container/sequence interface requirements are met (e.g., iterators).
The second template parameter defines the type of the underlying sequence/container. It defaults to std::vector, but it can be any type that supports front()
, push_back
, pop_back
, and random-access iterators, such as std::deque or an appropriate user-defined type.
The third template parameter supplies the means of making priority comparisons. It defaults to less<value_type>
but can be anything defining a strict weak ordering.
Members not found in normal containers are container_type
, which is a typedef for the second Sequence parameter, and push
, pop
, and top
, which are standard queue operations.
- Note
- No equality/comparison operators are provided for priority_queue.
-
Sorting of the elements takes place as they are added to, and removed from, the priority_queue using the priority_queue's member functions. If you access the elements by other means, and change their data such that the sorting order would be different, the priority_queue will not re-sort the elements for you. (How could it know to do so?)
Default constructor creates no elements.
Builds a queue from a range.
- Parameters
-
__first | An input iterator. |
__last | An input iterator. |
__x | A comparison functor describing a strict weak ordering. |
__s | An initial sequence with which to start. |
Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.
For more information on function objects, see the documentation on functor base classes.
Returns true if the queue is empty.
Returns the number of elements in the queue.
Returns a read-only (constant) reference to the data at the first element of the queue.
Add data to the queue.
- Parameters
-
This is a typical queue operation. The time complexity of the operation depends on the underlying sequence.
Removes first element.
This is a typical queue operation. It shrinks the queue by one. The time complexity of the operation depends on the underlying sequence.
Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called.
64 _GLIBCXX_BEGIN_NAMESPACE_VERSION
92 template<
typename _Tp,
typename _Sequence = deque<_Tp> >
96 typedef typename _Sequence::value_type _Sequence_value_type;
102 template<typename _Tp1, typename _Seq1>
104 operator==(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&);
106 template<typename _Tp1, typename _Seq1>
108 operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&);
111 typedef typename _Sequence::value_type value_type;
112 typedef typename _Sequence::reference reference;
113 typedef typename _Sequence::const_reference const_reference;
114 typedef typename _Sequence::size_type size_type;
115 typedef _Sequence container_type;
132 #if __cplusplus < 201103L
134 queue(
const _Sequence& __c = _Sequence())
138 queue(
const _Sequence& __c)
142 queue(_Sequence&& __c = _Sequence())
143 : c(std::move(__c)) { }
151 {
return c.empty(); }
212 push(
const value_type& __x)
213 { c.push_back(__x); }
215 #if __cplusplus >= 201103L
217 push(value_type&& __x)
218 { c.push_back(std::move(__x)); }
220 template<
typename... _Args>
222 emplace(_Args&&... __args)
223 { c.emplace_back(std::forward<_Args>(__args)...); }
244 #if __cplusplus >= 201103L
247 noexcept(noexcept(
swap(c, __q.c)))
266 template<
typename _Tp,
typename _Seq>
268 operator==(
const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
269 {
return __x.c == __y.c; }
284 template<
typename _Tp,
typename _Seq>
286 operator<(const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
287 {
return __x.c < __y.c; }
290 template<
typename _Tp,
typename _Seq>
292 operator!=(
const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
293 {
return !(__x == __y); }
296 template<
typename _Tp,
typename _Seq>
298 operator>(
const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
299 {
return __y < __x; }
302 template<
typename _Tp,
typename _Seq>
304 operator<=(const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
305 {
return !(__y < __x); }
308 template<
typename _Tp,
typename _Seq>
310 operator>=(
const queue<_Tp, _Seq>& __x,
const queue<_Tp, _Seq>& __y)
311 {
return !(__x < __y); }
313 #if __cplusplus >= 201103L
314 template<
typename _Tp,
typename _Seq>
316 swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
317 noexcept(noexcept(__x.swap(__y)))
320 template<
typename _Tp,
typename _Seq,
typename _Alloc>
321 struct uses_allocator<queue<_Tp, _Seq>, _Alloc>
322 :
public uses_allocator<_Seq, _Alloc>::type { };
365 template<
typename _Tp,
typename _Sequence = vector<_Tp>,
366 typename _Compare = less<
typename _Sequence::value_type> >
370 typedef typename _Sequence::value_type _Sequence_value_type;
376 _BinaryFunctionConcept)
379 typedef typename _Sequence::value_type value_type;
380 typedef typename _Sequence::reference reference;
381 typedef typename _Sequence::const_reference const_reference;
382 typedef typename _Sequence::size_type size_type;
383 typedef _Sequence container_type;
394 #if __cplusplus < 201103L
396 priority_queue(
const _Compare& __x = _Compare(),
397 const _Sequence& __s = _Sequence())
399 { std::make_heap(c.begin(), c.end(), comp); }
402 priority_queue(
const _Compare& __x,
403 const _Sequence& __s)
405 { std::make_heap(c.begin(), c.end(), comp); }
408 priority_queue(
const _Compare& __x = _Compare(),
409 _Sequence&& __s = _Sequence())
410 : c(std::move(__s)), comp(__x)
411 { std::make_heap(c.begin(), c.end(), comp); }
429 #if __cplusplus < 201103L
430 template<
typename _InputIterator>
431 priority_queue(_InputIterator __first, _InputIterator __last,
432 const _Compare& __x = _Compare(),
433 const _Sequence& __s = _Sequence())
437 c.insert(c.end(), __first, __last);
438 std::make_heap(c.begin(), c.end(), comp);
441 template<
typename _InputIterator>
442 priority_queue(_InputIterator __first, _InputIterator __last,
444 const _Sequence& __s)
448 c.insert(c.end(), __first, __last);
449 std::make_heap(c.begin(), c.end(), comp);
452 template<
typename _InputIterator>
453 priority_queue(_InputIterator __first, _InputIterator __last,
454 const _Compare& __x = _Compare(),
455 _Sequence&& __s = _Sequence())
456 : c(std::move(__s)), comp(__x)
459 c.insert(c.end(), __first, __last);
460 std::make_heap(c.begin(), c.end(), comp);
469 {
return c.empty(); }
496 push(
const value_type& __x)
499 std::push_heap(c.begin(), c.end(), comp);
502 #if __cplusplus >= 201103L
504 push(value_type&& __x)
506 c.push_back(std::move(__x));
507 std::push_heap(c.begin(), c.end(), comp);
510 template<
typename... _Args>
512 emplace(_Args&&... __args)
514 c.emplace_back(std::forward<_Args>(__args)...);
515 std::push_heap(c.begin(), c.end(), comp);
534 std::pop_heap(c.begin(), c.end(), comp);
538 #if __cplusplus >= 201103L
540 swap(priority_queue& __pq)
541 noexcept(noexcept(
swap(c, __pq.c)) && noexcept(
swap(comp, __pq.comp)))
545 swap(comp, __pq.comp);
552 #if __cplusplus >= 201103L
553 template<
typename _Tp,
typename _Sequence,
typename _Compare>
555 swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
556 priority_queue<_Tp, _Sequence, _Compare>& __y)
557 noexcept(noexcept(__x.swap(__y)))
560 template<
typename _Tp,
typename _Sequence,
typename _Compare,
562 struct uses_allocator<priority_queue<_Tp, _Sequence, _Compare>, _Alloc>
563 :
public uses_allocator<_Sequence, _Alloc>::type { };
566 _GLIBCXX_END_NAMESPACE_VERSION
bool operator>=(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:644
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define __glibcxx_class_requires(_a, _b)
Definition: concept_check.h:48
#define __glibcxx_requires_nonempty()
Definition: debug.h:77
bool operator>(const _Safe_iterator< _IteratorL, _Sequence > &__lhs, const _Safe_iterator< _IteratorR, _Sequence > &__rhs)
Definition: safe_iterator.h:612
#define __glibcxx_class_requires2(_a, _b, _c)
Definition: concept_check.h:49
bool operator!=(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define __glibcxx_requires_valid_range(_First, _Last)
Definition: debug.h:65
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160
#define __glibcxx_class_requires4(_a, _b, _c, _d, _e)
Definition: concept_check.h:51