[swift-evolution] Removing enumerated?

Ole Begemann ole at oleb.net
Fri Feb 17 10:32:19 CST 2017

> On 17 Feb 2017, at 16:53, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
> Btw, in context of discussion of indices,
> should this be fixed soon:
> func function<C: Collection>(c: C) {
>  for index in c.indices {
>    print(c[index])
>  }
> }
> ERROR: cannot subscript a value of type 'C' with an index of type 'C.Indices.Iterator.Element'
> ?
> (have access for Swift 3.0.2 Release only for now, so probably this already fixed in dev version)

This will work once SE-0142 "Permit where clauses to constrain associated types" (https://github.com/apple/swift-evolution/blob/master/proposals/0142-associated-types-constraints.md) is implemented and the standard library takes advantage of this.

For the time being, you need to add an explicit constraint to the function:

    func function<C: Collection>(c: C)
        where C.Indices.Iterator.Element == C.Index {
        for index in c.indices {

More information about the swift-evolution mailing list