The following goes into an infinite loop...
With what I'm trying to accomplish, I need to be able to pop the first stack in the list like I'm trying to do above. Problem is, it seems to me, a const iterator is being used, so no popping is actually taking place (during the loop, the stack size remains 3).Code:#include <iostream> #include <stack> #include <list> struct Foo{}; int main() { std::list<std::stack<Foo>> foo_list; std::stack<Foo> first_foos; first_foos.push(Foo()); first_foos.push(Foo()); first_foos.push(Foo()); foo_list.push_back(first_foos); /* Add some more stacks of foos... */ for(int i = 0; i < 10; i++) { std::stack<Foo> foo_stack; for(int j = 0; j < 10; j++) { foo_stack.push(Foo()); } foo_list.push_back(foo_stack); } while(!first_foos.empty()) { std::cout << "Stack size: " << first_foos.size() << "\n"; std::cout << "Popping...\n"; std::list<std::stack<Foo>>::iterator first_foos_iter = foo_list.begin(); first_foos_iter->pop(); } return 0; }
I'm heavily invested in the code thus far, and I really need to iterate over the list, and to use the iterator to pop the first stack when needed.
Is there a way to do this? Am I just overlooking something obvious?