[swift-evolution] [RFC] New collections model: collections advance indices
Károly Lőrentey
karoly at lorentey.hu
Tue Mar 8 10:16:00 CST 2016
On 2016-03-08 15:09:35 +0000, Károly Lőrentey via swift-evolution said:
> My problem is that this example assumes that mutating `c` at a certain
> index won't invalidate earlier indices. And even if that is true for
> `c`, whenever `c.indices` holds a strong reference, an idiom like
>
> for i in c.indices {
> c.mutate(i)
> }
>
> will certainly lead to COW copying that isn't happening today with
>
> var i = c.startIndex
> while i != c.endIndex {
> c.mutate(i)
> i = i.successor()
> }
>
> How would I emulate the exact semantics of today's code with `c.indices`?
Sorry, I guess that second code should read
var i = c.startIndex
let end = c.endIndex
while i != end {
c.mutate(i)
i = i.successor()
}
I think it would be interesting to see the `c.indices` versions of both
variants, though.
--
Károly
More information about the swift-evolution
mailing list