Comment Comment by pptr If you declare using an invalidated iterator as UB, the compiler can optimize as if the container was effectively immutable during the loop. parent pptr 1 year ago