2 ms·
Move your for-loop in to an algorithm that takes Container by const& and your resize() / iterator invalidation problem becomes a compile error. If you actually
by nly 11y ago
Move your for-loop in to an algorithm that takes Container by const& and your resize() / iterator invalidation problem becomes a compile error. If you actually need to resize your array while you iterate, then a language like Rust is going to catch your pointer invalidation, but it's not going to make the impossible possible and suddenly make your algorithm do something sensible.
I never claimed C++ statically enforced memory safety. Clearly that can't happen while its a superset of C. I just claim that it's steadily reaching the point where the most concise and elegant code with the best API is the safest.
And I'd argue that's the problem with C. The language is too weak to write safe code concisely, so you end up with too much cognitive load, get lazy, and then end up with sprawling unauditable messes like we see in glibc lately.