|
|
|
|
|
by simonask
381 days ago
|
|
Surely you must be kidding? Inserting/removing in a container while iterating through it is one of the all time greatest and most iconic bugs. People do it because they want to do it. In reality, very few real-life containers can support this pattern, which is why this is a headline case for Rust, because it statically prevents this bug. But yes, for removal the correct thing is always to use `std::erase_if` (C++) or `retain()` (Rust). For insertions, the only real solution is to build up a separate collection while iterating and then merging it into the original container when done. Yucky, but won't crash. |
|