Consider the following code:
unordered_set<T> S = ...; for (const auto& x : S) if (...) S.insert(...);This is broken correct? If we insert something into
S
then the iterators may be invalidated (due to a rehash), which will break the range-for because under the hood it is usingS.begin
...S.end
.
Is there some pattern to deal with this?
Add a Comment
Comments are closed.