[Pitch] Make offset index available for String

The problem with this is that String indexes don't have a reference to the string they're indexes for, and therefore don't know how far forward to move each time they're advanced. This used to be the case, but was changed in [RFC] New collections model: collections advance indices, so you can look at the reasoning there.

As for using OffsetIndex as a solution to the problem, doing a for i in index1..<index2 would have O(n^2) time complexity, which would (I think) surprise many people. If you do want an index that works in a for i in index1..<index2, it would be better to make an index that wraps the base string and a String.Index and uses that to implement Strideable, since it wouldn't have the performance issues, but I think the use cases of something like that are too small to implement in the standard library.

Finally, what are the enum index problems you're talking about? I don't know of any ways I would want to use a String.Index with an enum...

1 Like