Improved iterator validation in erase().