[swift-evolution] [Pitch] Change the endIndex value for closed Ranges and Collections
andrey at tarantsov.com
Wed Mar 23 15:40:43 CDT 2016
endIndex is exclusive by definition. You can iterate over any collection by going from startIndex until you reach endIndex.
If we change endIndex on ranges, *all* generic iteration code will be broken when dealing with ranges, even the for statement.
I understand that there are two concerns here:
1) The desire to keep the semantics of 1...10 intact, so that you can access that 10 somehow (perhaps something like lastValidIndex?), the description returns the expected value, etc. To achieve this, a different class (ClosedRange) would probably make more sense, because there's no need to make this decision at runtime.
2) The desire to change endIndex specifically. This is a no-go.
More information about the swift-evolution