-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It is easy to break IR::IndexedVector using its iterators #5083
Comments
Is that actually incorrect, though? If you exchange two objects in the same Vector via iterators, they're both still in the vector (so the internal map does not need to be changed). So The incorrect thing that might be of concern is if iterators are used to move/copy/swap objects between two different vectors. |
That would hold if
... https://en.cppreference.com/w/cpp/algorithm/remove So a latter element is moved "over" the "to-be-removed" element, which therefore ceases to exist. But in However, this is just an example, the point is that |
So the
IR::IndexedVector
does not do a good job of keeping its invariants, namely that it is properly indexed. This is (in part) because it exposed modifiable iterators. Therefore, it is possible to modify the objects by iterators (e.g. exchange them), without modifying the map. Example could be usingstd::remove_if
on an indexed vector.I think the best solution would be to not expose modifiable iterators at all. Of course, that could be a breaking change, but presumably it would only break code which is already buggy. Alternatively, we could offer a "heavyweight" modifiable iterator that actually causes the map to be updated on assignments, but I am not very keen on that.
The text was updated successfully, but these errors were encountered: