Consider the following program:
#include <list>
#include <cstdio>
int main() {
std::list<int> l;
std::list<int>::iterator it = l.begin();
l.push_back(0);
l.insert(it, 1);
for(const int &i: l) {
printf("%d", i);
}
}
This prints 01
. Very surprising. If I change the list to a deque, it prints the expected .10
Is this a bug?
EDIT: The deque behavior is irrelevant, iterators to deques are invalidated by push_back.