Stack vs other STL

Why would I want to use a stack when the containers themselves are more versatile? In fact, it seems to me that if I use a stack I am losing some of the functionality of the container I use it with. Maybe someone can suggest a situation where it would be more advantageous to use a stack? I've read everything I could find about them, and played with coding a couple, but still don't know why I would want to use one?
The only benefit is that it is more self-documenting to declare a variable of type stack<int> as opposed
to, for example, list<int>, and then proceeding to use the list as a stack (ie, only ever push_front/pop_front).

Otherwise you are right.

Typically one chooses the appropriate STL container based upon the runtime efficiencies of the various
operations. For example, list is constant time for general insert/remove, but linear for search.
vector is linear for insert/remove but log(n) for search. etc.

Occasionally vector<> is chosen over other containers because it is guaranteed contiguous -- it is
the best approximation of an array. Occasionally deque<> or vector<> is chosen because they
support random access iterators.
thank you for your input. So basically, I should use a stack when I want other programmers to realize that that is how I intend to use my container: only from the back.
All else equal, I think it is a matter of personal preference.
Topic archived. No new replies allowed.