Name

queue class template — Queue container adapter

Synopsis

template <class T, class Container = deque<T> >
class queue {
public:
  typedef typename Container::value_type value_type;
  typedef typename Container::size_type size_type;
  typedef Container container_type;
   
  explicit queue(const Container& = Container(  ));
  bool empty(  ) const { return c.empty(  ); }
  size_type size(  ) const { return c.size(  ); }
  value_type& front(  ) { return c.front(  ); }
  const value_type& front(  ) const { return c.front(  ); }
  value_type& back(  ) { return c.back(  ); }
  const value_type& back(  ) const { return c.back(  ); }
  void push(const value_type& x) { c.push_back(x); }
  void pop(  ) { c.pop_front(  ); }
protected:
  Container c;
};

The queue class template is an adapter for any sequence container that supports the front( ), back( ), push_back( ), and pop_front( ) members. See the list and deque class templates for the standard containers that are suitable. (The default is deque.)

Because queue is not itself a standard container, it cannot be used with the standard algorithms. (In particular, note the lack of begin and end member functions.) Thus, the queue adapter is useful only for simple needs.

Most of the members of queue are straightforward mappings from a simple queue protocol to the underlying container protocol. The members are:

explicit queue (const Container& cont = Container( ))

Takes an existing container cont and copies its contents into the queue. With no argument, the constructor creates a new, empty container ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.