[swift-evolution] Add ability to validate collection indices

Anton Zhilin 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
utterly rediculous.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161216/22518b1c/attachment.html>

More information about the swift-evolution mailing list