Does the stack in the C++ STL expose any iterators of the underlying container or should I use that container directly?
+7
A:
Stack does not have iterators, by definition of stack. If you need stack with iterators, you'll need to implement it yourself on top of other container (std::list, std::vector, etc). Stack doc is here.
P.S. According to a comment i got from Iraimbilanja, std::stack by default uses std::deque for implementation.
Drakosha
2009-02-08 08:02:06
+1. note also that std::stack by default uses std::deque as its implementation so this might be a good choice for the default implementation of an iterstack as well. Another question is, *why* do you want an iterable stack and not, say, a straight deque
2009-02-08 08:18:09
10x, i didn't know that
Drakosha
2009-02-09 15:30:46
A:
If you need a stack with iterators, you have two choices. std::vector using push_back(), pop_back(). std::deque with either push_back()/pop_back() or push_front()/pop_front().
ceretullis
2009-02-08 18:01:10