DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

queue(C++std)


operator!= , operator> , operator>= , operator< , operator<= , operator== , priority_queue , queue - defines a template class that implements a queue container (standard template library)

Synopsis

   namespace std {
   template<class T, class Cont>
       class queue;
   template<class T, class Cont, class Pred>
       class priority_queue;

           // TEMPLATE FUNCTIONS
   template<class T, class Cont>
       bool operator==(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
   template<class T, class Cont>
       bool operator!=(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
   template<class T, class Cont>
       bool operator<(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
   template<class T, class Cont>
       bool operator>(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
   template<class T, class Cont>
       bool operator<=(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
   template<class T, class Cont>
       bool operator>=(const queue<T, Cont>& lhs,
           const queue<T, Cont>&);
       };

Description

Include the STL standard header <queue> to define the template classes priority_queue and queue, and several supporting templates.

operator!=

   template<class T, class Cont>
       bool operator!=(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function returns !(lhs == rhs).

operator==

   template<class T, class Cont>
       bool operator==(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function overloads operator== to compare two objects of template class queue. The function returns lhs.c == rhs.c.

operator<

   template<class T, class Cont>
       bool operator<(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function overloads operator< to compare two objects of template class queue. The function returns lhs.c < rhs.c.

operator<=

   template<class T, class Cont>
       bool operator<=(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function returns !(rhs < lhs).

operator>

   template<class T, class Cont>
       bool operator>(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function returns rhs < lhs.

operator>=

   template<class T, class Cont>
       bool operator>=(const queue <T, Cont>& lhs,
           const queue <T, Cont>& rhs);

The template function returns !(lhs < rhs).

priority_queue


c , comp , container_type , empty , pop , priority_queue , push , size , size_type , top , value_type

   template<class T,
       class Cont = vector<T>,
       class Pred = less<typename Cont::value_type> >
       class priority_queue {
   public:
       typedef Cont container_type;
       typedef typename Cont::value_type value_type;
       typedef typename Cont::size_type size_type;
       priority_queue();
       explicit priority_queue(const Pred& pr);
       priority_queue(const Pred& pr,
           const container_type& cont);
       priority_queue(const priority_queue& x);
       template<class InIt>
           priority_queue(InIt first, InIt last);
       template<class InIt>
           priority_queue(InIt first, InIt last,
               const Pred& pr);
       template<class InIt>
           priority_queue(InIt first, InIt last,
               const Pred& pr, const container_type& cont);
       bool empty() const;
       size_type size() const;
       const value_type& top() const;
       void push(const value_type& x);
       void pop();
   protected:
       Cont c;
       Pred comp;
       };

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 Cont. The type T 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<typename Cont::value_type> the top element of the sequence compares largest, or highest priority.)

An object of class Cont 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 Cont). The required members are:

       typedef T value_type;
       typedef T0 size_type;
       typedef T1 iterator;
       Cont();
       template<class InIt>
           Cont(InIt first, InIt last);
       template<class InIt>
           void insert(iterator it, InIt first, InIt last);
       iterator begin();
       iterator end();
       bool empty() const;
       size_type size() const;
       const value_type& front() const;
       void push_back(const value_type& x);
       void pop_back();

Here, T0 and T1 are unspecified types that meet the stated requirements.

priority_queue::container_type

   typedef typename Cont::container_type container_type;

The type is a synonym for the template parameter Cont.

priority_queue::empty

   bool empty() const;

The member function returns true for an empty controlled sequence.

priority_queue::pop

   void pop();

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 Pred& pr);
   priority_queue(const Pred& pr,
       const container_type& cont);
   priority_queue(const priority_queue& x);
   template<class InIt>
       priority_queue(InIt first, InIt last);
   template<class InIt>
       priority_queue(InIt first, InIt last,
           const Pred& pr);
   template<class InIt>
       priority_queue(InIt first, InIt last,
           const Pred& pr, const container_type& cont);

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 pr is the argument pr, if present. For the copy constructor, it is x.comp. Otherwise, it is Pred().

A non-empty initial controlled sequence is then ordered by calling make_heap(c.begin(), c.end(), comp).

priority_queue::push

   void push(const T& x);

The member function inserts an element with value x at the end of the controlled sequence, then reorders it.

priority_queue::size

   size_type size() const;

The member function returns the length of the controlled sequence.

priority_queue::size_type

   typedef typename Cont::size_type size_type;

The type is a synonym for Cont::size_type.

priority_queue::top

   const value_type& top() const;

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 Cont::value_type value_type;

The type is a synonym for Cont::value_type.

queue


back , c , container_type , empty , front , front , pop , push , queue , size , size_type , value_type

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

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 Cont. The type T of elements in the controlled sequence must match value_type.

An object of class Cont must supply several public members defined the same as for deque and list (both of which are suitable candidates for class Cont). The required members are:

       typedef T value_type;
       typedef T0 size_type;
       Cont();
       bool empty() const;
       size_type size() const;
       value_type& front();
       const value_type& front() const;
       value_type& back();
       const value_type& back() const;
       void push_back(const value_type& x);
       void pop_front();
       bool operator==(const Cont& X) const;
       bool operator!=(const Cont& X) const;
       bool operator<(const Cont& X) const;
       bool operator>(const Cont& X) const;
       bool operator<=(const Cont& X) const;
       bool operator>=(const Cont& X) const;

Here, T0 is an unspecified type that meets the stated requirements.

queue::back

   value_type& back();
   const value_type& back() const;

The member function returns a reference to the last element of the controlled sequence, which must be non-empty.

queue::container_type

   typedef Cont container_type;

The type is a synonym for the template parameter Cont.

queue::empty

   bool empty() const;

The member function returns true for an empty controlled sequence.

queue::front

   value_type& front();
   const value_type& front() const;

The member function returns a reference to the first element of the controlled sequence, which must be non-empty.

queue::pop

   void pop();

The member function removes the last element of the controlled sequence, which must be non-empty.

queue::push

   void push(const T& x);

The member function inserts an element with value x at the end of the controlled sequence.

queue::queue

   queue();
   explicit queue(const container_type& cont);

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::size

   size_type size() const;

The member function returns the length of the controlled sequence.

queue::size_type

   typedef typename Cont::size_type size_type;

The type is a synonym for Cont::size_type.

queue::value_type

   typedef typename Cont::value_type value_type;

The type is a synonym for Cont::value_type.

References

algorithm() , deque(C++std) , functional(C++std) , list(C++std) , vector(C++std)
18 February 2000
© 2000 The Santa Cruz Operation, Inc. All rights reserved.

Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.