# <queue>
<queue>
# ``
* * *
Include the [STL](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#STL)
standard header **``**
to define the template classes `priority_queue` and
`queue`, and several supporting templates.
namespace std {
template
class queue;
template
class priority_queue;
// TEMPLATE FUNCTIONS
template
bool operator==(const queue& left,
const queue&);
template
bool operator!=(const queue& left,
const queue&);
template
bool operator<(const queue& left,
const queue&);
template
bool operator>(const queue& left,
const queue&);
template
bool operator<=(const queue& left,
const queue&);
template
bool operator>=(const queue& left,
const queue&);
} // namespace stdCopy to clipboard
## `operator!=`
template
bool operator!=(const queue & left,
const queue & right);Copy to clipboard
The template function returns `!(left == right)`.
## `operator==`
template
bool operator==(const queue & left,
const queue & right);Copy to clipboard
The template function overloads `operator==` to compare
two objects of template class
[`queue`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_queue.html#queue). The function returns
`left.c == right.c`.
## `operator<`
template
bool operator<(const queue & left,
const queue & right);Copy to clipboard
The template function overloads `operator<` to compare
two objects of template class
[`queue`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_queue.html#queue). The function returns
`left.c < right.c`.
## `operator<=`
template
bool operator<=(const queue & left,
const queue & right);Copy to clipboard
The template function returns `!(right < left)`.
## `operator>`
template
bool operator>(const queue & left,
const queue & right);Copy to clipboard
The template function returns `right < left`.
## `operator>=`
template
bool operator>=(const queue & left,
const queue & right);Copy to clipboard
The template function returns `!(left < right)`.
## `priority_queue`
template,
class Pr = less >
class priority_queue {
public:
typedef Container container_type;
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
priority_queue();
explicit priority_queue(const Pr& pred);
priority_queue(const Pr& pred,
const container_type& cont);
priority_queue(const priority_queue& right);
template
priority_queue(InIt first, InIt last);
template
priority_queue(InIt first, InIt last,
const Pr& pred);
template
priority_queue(InIt first, InIt last,
const Pr& pred, const container_type& cont);
bool empty() const;
size_type size() const;
const_reference top() const;
void push(const value_type& val);
void pop();
protected:
Container c;
Pr comp;
};Copy to clipboard
The template class describes an object that controls a
varying-length sequence of elements.
The object allocates and frees storage for the sequence it controls
through a protected object named
**`c`**,
of class `Container`.
The type `Ty` of elements in the controlled sequence must match
`value_type`.
The sequence is ordered using a protected object named
**`comp`**.
After each insertion or removal of the top element (at position zero),
for the iterators `P0` and `Pi`
designating elements at positions `0`
and `I`, `comp(*P0, *Pi)` is false.
(For the default template parameter
`less`
the top element of the sequence compares largest, or highest priority.)
An object of class `Container` must supply
random-access iterators and
several public members defined the same as for
`deque` and
`vector`
(both of which are suitable candidates for class `Container`).
The required members are:
typedef Ty value_type;
typedef T0 size_type;
typedef T1 iterator;
typedef T2 reference;
typedef T3 const_reference;
Container();
template
Container(InIt first, InIt last);
template
void insert(iterator where, InIt first, InIt last);
iterator begin();
iterator end();
bool empty() const;
size_type size() const;
const_reference front() const;
void push_back(const value_type& val);
void pop_back();Copy to clipboard
Here, `T0`, `T1`, `T2`, and `T3`
are unspecified types that meet the stated requirements.
### `priority_queue::const_reference`
typedef typename Container::const_reference const_reference;Copy to clipboard
The type is a synonym for `Container::const_reference`.
### `priority_queue::container_type`
typedef typename Container::container_type container_type;Copy to clipboard
The type is a synonym for the template parameter `Container`.
### `priority_queue::empty`
bool empty() const;Copy to clipboard
The member function returns true for an empty controlled sequence.
### `priority_queue::pop`
void pop();Copy to clipboard
The member function removes the first element of the
controlled sequence, which must be non-empty, then reorders it.
### `priority_queue::priority_queue`
priority_queue();
explicit priority_queue(const Pr& pred);
priority_queue(const Pr& pred,
const container_type& cont);
priority_queue(const priority_queue& right);
template
priority_queue(InIt first, InIt last);
template
priority_queue(InIt first, InIt last,
const Pr& pred);
template
priority_queue(InIt first, InIt last,
const Pr& pred, const container_type& cont);Copy to clipboard
All constructors with an argument `cont`
initialize the stored object with
`c(cont)`.
The remaining constructors initialize the stored object with
`c`, to specify an
empty initial controlled sequence.
The last three constructors then call
`c.insert(c.end(), first, last)`.
All constructors also store a function object in
`comp`.
The function object `comp` is the argument `pred`, if present.
For the copy constructor, it is `right.comp`.
Otherwise, it is `Pr()`.
A non-empty initial controlled sequence is then ordered by calling
`make_heap(c.begin(),
c.end(), comp)`.
### `priority_queue::push`
void push(const Ty& val);Copy to clipboard
The member function inserts an element with value `val`
at the end of the controlled sequence, then reorders it.
### `priority_queue::reference`
typedef typename Container::reference reference;Copy to clipboard
The type is a synonym for `Container::reference`.
### `priority_queue::size`
size_type size() const;Copy to clipboard
The member function returns the length of the controlled sequence.
### `priority_queue::size_type`
typedef typename Container::size_type size_type;Copy to clipboard
The type is a synonym for `Container::size_type`.
### `priority_queue::top`
const_reference top() const;Copy to clipboard
The member function returns a reference to the first (highest priority)
element of the controlled sequence, which must be non-empty.
### `priority_queue::value_type`
typedef typename Container::value_type value_type;Copy to clipboard
The type is a synonym for `Container::value_type`.
## `queue`
template >
class queue {
public:
typedef Container container_type;
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
queue();
explicit queue(const container_type& cont);
bool empty() const;
size_type size() const;
reference back();
const_reference back() const;
reference front();
const_reference front() const;
void push(const value_type& val);
void pop();
protected:
Container c;
};Copy to clipboard
The template class describes an object that controls a
varying-length sequence of elements.
The object allocates and frees storage for the sequence it controls
through a protected object named
**`c`**,
of class `Container`.
The type `Ty` of elements in the controlled sequence must match
`value_type`.
An object of class `Container` must supply
several public members defined the same as for
`deque` and
`list`
(both of which are suitable candidates for class `Container`).
The required members are:
typedef Ty value_type;
typedef T0 size_type;
typedef T1 reference;
typedef T2 const_reference;
Container();
bool empty() const;
size_type size() const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
void push_back(const value_type& val);
void pop_front();
bool operator==(const Container& cont) const;
bool operator!=(const Container& cont) const;
bool operator<(const Container& cont) const;
bool operator>(const Container& cont) const;
bool operator<=(const Container& cont) const;
bool operator>=(const Container& cont) const;Copy to clipboard
Here, `T0`, `T1`, and `T2` are unspecified
types that meet the stated requirements.
### `queue::back`
reference back();
const_reference back() const;Copy to clipboard
The member function returns a reference to the last element of the
controlled sequence, which must be non-empty.
### `queue::const_reference`
typedef typename Container::const_reference const_reference;Copy to clipboard
The type is a synonym for `Container::const_reference`.
### `queue::container_type`
typedef Container container_type;Copy to clipboard
The type is a synonym for the template parameter `Container`.
### `queue::empty`
bool empty() const;Copy to clipboard
The member function returns true for an empty controlled sequence.
### `queue::front`
reference front();
const_reference front() const;Copy to clipboard
The member function returns a reference to the first element of the
controlled sequence, which must be non-empty.
### `queue::pop`
void pop();Copy to clipboard
The member function removes the first element of the
controlled sequence, which must be non-empty.
### `queue::push`
void push(const Ty& val);Copy to clipboard
The member function inserts an element with value `val`
at the end of the controlled sequence.
### `queue::queue`
queue();
explicit queue(const container_type& cont);Copy to clipboard
The first constructor initializes the stored object with
`c()`, to specify an
empty initial controlled sequence.
The second constructor initializes the stored object with
`c(cont)`, to specify an
initial controlled sequence that is a copy of the sequence controlled
by `cont`.
### `queue::reference`
typedef typename Container::reference reference;Copy to clipboard
The type is a synonym for `Container::reference`.
### `queue::size`
size_type size() const;Copy to clipboard
The member function returns the length of the controlled sequence.
### `queue::size_type`
typedef typename Container::size_type size_type;Copy to clipboard
The type is a synonym for `Container::size_type`.
### `queue::value_type`
typedef typename Container::value_type value_type;Copy to clipboard
The type is a synonym for `Container::value_type`.
* * *
See also the
**[Table of Contents](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#Table%20of%20Contents)** and the
**[Index](https://docs.qualcomm.com/doc/80-N3040-23/topic/_cpp_index.html)**.
*[Copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_pjp.html) © 1992-2006by P.J. Plauger. Portions derived from work[copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_hp.html) © 1994by Hewlett-Packard Company. All rights reserved.*
Last Published: Oct 06, 2026
Previous Topic
Next Topic