tags:

views:

551

answers:

3

Does the stack in the C++ STL expose any iterators of the underlying container or should I use that container directly?

A: 

In SGI, MSDN and GNU documentations, stack doesn't provide an iterator.

Hosam Aly
+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
+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
10x, i didn't know that
Drakosha
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