DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

stack(C++std)


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

Synopsis

   namespace std {
   template<class T, class Cont>
       class stack;

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

Description

Include the STL standard header <stack> to define the template class stack and two supporting templates.

operator!=

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

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

operator==

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

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

operator<

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

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

operator<=

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

The template function returns !(rhs < lhs).

operator>

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

The template function returns rhs < lhs.

operator>=

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

The template function returns !(lhs < rhs).

stack


c , container_type , empty , pop , push , size , size_type , stack , top , value_type

   template<class T,
       class Cont = deque<T> >
       class stack {
   public:
       typedef Cont container_type;
       typedef typename Cont::value_type value_type;
       typedef typename Cont::size_type size_type;
       stack();
       explicit stack(const container_type& cont);
       bool empty() const;
       size_type size() const;
       value_type& top();
       const value_type& top() 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, list, and vector (all 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& back();
       const value_type& back() const;
       void push_back(const value_type& x);
       void pop_back();
   	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.

stack::container_type

   typedef Cont container_type;

The type is a synonym for the template parameter Cont.

stack::empty

   bool empty() const;

The member function returns true for an empty controlled sequence.

stack::pop

   void pop();

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

stack::push

   void push(const T& x);

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

stack::size

   size_type size() const;

The member function returns the length of the controlled sequence.

stack::size_type

   typedef typename Cont::size_type size_type;

The type is a synonym for Cont::size_type.

stack::stack

   stack();
   explicit stack(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.

stack::top

   value_type& top();
   const value_type& top() const;

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

stack::value_type

   typedef typename Cont::value_type value_type;

The type is a synonym for Cont::value_type.

References

deque(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.