C++ Boost
queue

A boost::queue is a container adaptor that provides both std::queue and Buffer functionality.

Where Defined

boost/queue.hpp

Template Parameters

Parameter Description Default
T The type of object stored in the queue.
Sequence The type of the underlying container used to implement the queue. std::deque<T>

Models

Type Requirements

Public Base Classes

None.

Members

Member Where Defined Description
value_type Buffer The type of object stored in the queue. This is the same as T and Sequence::value_type.
size_type Buffer An unsigned integral type. This is the same as Sequence::size_type.
queue() Default Constructible The default constructor. Creates an empty queue.
queue(const Sequence& c) boost::queue The constructor. Creates a queue initialized to contain the elements in c, in back-insertion order.
bool empty() const Buffer Returns true if the queue contains no elements, and false otherwise. empty() is equivalent to size() == 0.
size_type size() const Buffer Returns the number of elements contained in the queue.
value_type& top() Buffer Returns a mutable reference to the least recently inserted element in the queue. Precondition: empty() is false.
value_type& front() std::queue Serves the same function as value_type& top().
const value_type& top() const Buffer Returns a const reference to the least recently inserted element in the queue. Precondition: empty() is false.
const value_type& front() const boost::queue, not std::queue Serves the same function as const value_type& top() const.
void push(const value_type& x) Buffer Inserts x into the queue. Postcondition: size() will be incremented by 1.
void pop() Buffer Removes the least recently inserted element from the queue. Postcondition: size() will be decremented by 1.
bool operator==(const queue&, const queue&) boost::queue Compares two queues for equality. Two queues are equal if they contain the same number of elements and if they are equal element-by-element. This is a global function, not a member function.
bool operator<(const queue&, const queue&) boost::queue Lexicographical ordering of two queues. This is a global function, not a member function.

Complexity

Example

#include <boost/queue>
#include <cassert>

int main()
{
  boost::queue<int> Q;

  Q.push(8);
  Q.push(7);
  Q.push(6);
  Q.push(2);
  
  assert(Q.size() == 4);
  assert(Q.top() == 8);
  Q.pop();

  assert(Q.top() == 7);
  Q.pop();

  assert(Q.top() == 6);
  Q.pop();
  
  assert(Q.top() == 2);
  Q.pop();

  assert(Q.empty());

  return 0;
}

Copyright © 2004 Jeremy Siek, Univ. of Notre Dame (jsiek@lsc.nd.edu)

Use, modification, and distribution are subject to the Boost Software License, Version 1.0 at http://www.boost.org/LICENSE_1_0.txt