[swift-evolution] [Pitch] Change the endIndex value for closed Ranges and Collections

Dave Abrahams dabrahams at apple.com
Thu Mar 24 16:24:32 CDT 2016

on Wed Mar 23 2016, Howard Lovatt <swift-evolution at swift.org> wrote:

> +1 I think it is a good idea to make a collection run from firstIndex to
> lastIndex inclusively (note name change to match firstElement and
> lastElement). For an empty collection both firstIndex and lastIndex would
> be invalid values that would cause both c[c.firstIndex] and c.[c,lastIndex]
> to fail.

That direction is pretty much a nonstarter with me.  There are *many*
algorithms that are correct for empty collections without any
special-case testing, as long as you use half-open ranges.  There's no
reason to make every algorithm that uses indices test for emptiness
before proceeding.

See also
for philosophical background on why most ranges should be half-open.


More information about the swift-evolution mailing list