Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

stack


Container Adapter

Summary

A container adapter that behaves like a stack (last in, first out).

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <stack>
template <class T, class Container = deque<T> >
class stack ;

Description

The stack container adapter causes a container to behave like a "last in, first out" (LIFO) stack. The last item that was put ("pushed") onto the stack is the first item removed ("popped" off). The stack can adapt to any container that includes the operations back(), push_back(), and pop_back(). In particular, deque, list, and vector can be used.

Interface

template <class T, class Container = deque<T> >
class stack {
public:
// typedefs
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef Container container_type;
// Construct
explicit stack (const Container& = Container());
// Accessors
bool empty () const;
size_type size () const;
value_type& top ();
const value_type& top () const;
void push (const value_type&);
void pop ();
};

// Non-member Operators
template <class T, class Container>
bool operator== (const stack<T, Container>&, 
const stack<T, Container>&);
template <class T, class Container>
bool operator!= (const stack<T, Container>&, 
const stack<T, Container>&);
template <class T, class Container>
bool operator< (const stack<T, Container>&, 
const stack<T, Container>&);
template <class T, class Container>
bool operator> (const stack<T, Container>&, 
const stack<T, Container>&);
template <class T, class Container>
bool operator<= (const stack<T, Container>&, 
const stack<T, Container>&);
template <class T, class Container>
bool operator>= (const stack<T, Container>&, 
const stack<T, Container>&);

Constructors

explicit
stack(const Container& = Container());

Member Functions

bool 
empty() const;
void 
pop();
void 
push(const value_type& x);
size_type 
size() const;
value_type& 
top();
const value_type& 
top() const;

Non-member Operators

template <class T, class Container>
bool operator==(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator!=(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator<(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator>(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator<=(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator>=(const stack<T, Container>& x,
const stack<T, Container>& y);

Example

Program Output

Warnings

If your compiler does not support template parameter defaults, you are required to supply a template parameter for Container. For example:

You would not be able to write,

stack<int> var;

Instead, you would have to write,

stack<int, deque<int> > var;

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

allocator, Containers, deque, list, vector



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998