Note that QValueStack does not store pointers to the members of the stack; it holds a copy of every member. That is why these kinds of classes are called "value based"; QPtrStack, QPtrList, QDict, etc., are "pointer based".
.PP
A stack is a last in, first out (LIFO) structure. Items are added to the top of the stack with push() and retrieved from the top with pop(). The top() function provides access to the topmost item without removing it.
.PP
Example:
.PP
.nf
.br
QValueStack<int> stack;
.br
stack.push( 1 );
.br
stack.push( 2 );
.br
stack.push( 3 );
.br
while ( ! stack.isEmpty() )
.br
cout << "Item: " << stack.pop() << endl;
.br
.br
// Output:
.br
// Item: 3
.br
// Item: 2
.br
// Item: 1
.br
.fi
.PP
QValueStack is a specialized QValueList provided for convenience. All of QValueList's functionality also applies to QPtrStack, for example the facility to iterate over all elements using QValueStack<T>::Iterator. See QValueListIterator for further details.
.PP
Some classes cannot be used within a QValueStack, for example everything derived from QObject and thus all classes that implement widgets. Only values can be used in a QValueStack. To qualify as a value, the class must provide
.TP
a copy constructor;
.TP
an assignment operator;
.TP
a default constructor, i.e. a constructor that does not take any arguments.
.PP
Note that C++ defaults to field-by-field assignment operators and copy constructors if no explicit version is supplied. In many cases this is sufficient.
Destroys the stack. References to the values in the stack and all iterators of this stack become invalidated. Because QValueStack is highly tuned for performance, you won't see warnings if you use invalid iterators because it is impossible for an iterator to check whether or not it is valid.
.SH "T QValueStack::pop ()"
Removes the top item from the stack and returns it.
.PP
See also top() and push().
.SH "void QValueStack::push ( const T & d )"
Adds element, \fId\fR, to the top of the stack. Last in, first out.
.PP
This function is equivalent to append().
.PP
See also pop() and top().
.SH "T & QValueStack::top ()"
Returns a reference to the top item of the stack or the item referenced by end() if no such item exists. Note that you must not change the value the end() iterator points to.
.PP
This function is equivalent to last().
.PP
See also pop(), push(), and QValueList::fromLast().
.SH "const T & QValueStack::top () const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a reference to the top item of the stack or the item referenced by end() if no such item exists.
.PP
This function is equivalent to last().
.PP
See also pop(), push(), and QValueList::fromLast().