[swift-evolution] Strings in Swift 4

Dave Abrahams dabrahams at apple.com
Tue Jan 31 13:26:13 CST 2017

on Mon Jan 30 2017, Jaden Geller <jaden.geller-AT-gmail.com> wrote:

>> On Jan 30, 2017, at 11:35 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>> Why should that be out-of-bounds?  Whether it is out-of-bounds would
>> depend on what items is.  If it's an array, that should be equivalent to
>>   let x = items[items.startIndex..<items.endIndex]
> It seems to me that `items[0…]` would be equivalent to
> `items[0…Int.max]` if we’re going to treat `0…` as an “infinite"
> range, no? Otherwise, we’re either giving subscript of InfiniteRange
> types special behavior or we’re making subscript ignore past-the-end
> indices; `”hello”.characters[0…10]` would need to return the same as
> “hello”.characters[0…4]` to be consistent.

What is it they say about “a foolish consistency?” ;-)

More seriously, I think you may be viewing these ranges the wrong way


is not a range with an upper bound of infinity (which is, after all, not
a number!); it's a range with *no* upper bound.  When you use the range
for slicing, the collection substitutes its own upper bound.



More information about the swift-evolution mailing list