For a std::deque, what is invalidated by a single push_front call?
Correct answer
D. All existing iterators, though references to existing elements stay valid
21 views
D. All existing iterators, though references to existing elements stay valid
21 views
std::deque stores elements in fixed-size blocks mapped by a central array, and inserting at either end may reallocate that map, invalidating every iterator while leaving references to existing elements intact. Insertion in the middle invalidates both iterators and references. This is why deque suits a queue well but is a poor choice when long-lived iterators must survive insertions.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.