[swift-evolution] Add ability to validate collection indices
antonyzhilin at gmail.com
Fri Dec 16 08:51:38 CST 2016
It will be impossible without huge additional overhead.
I assume that "invalidated" means "no more points to that element".
Consider that an element is inserted in the middle of an Array.
Assuming enough capacity, all iterators after that one will be invalidated.
But all new iterators pointing to the same spots will be valid.
How do you differentiate between the "old" ones and the "new" ones?
I see only one general approach to this:
1. Make iterator type a class
2. Add to the collection, an array of all iterators, which have been
created (and are being used)
3. Add a "valid" flag to iterator
4. On most operations on the collection, it will walk through its
iterators, marking some as "invalid".
It's a safe way to eliminate some "out of bounds" errors, but it's just
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution