`inout` subscript parameters

Why are inout subscript parameters prohibited?

I just tried making a Collection subscript that post-increments the index, and was met with this error:

extension Collection {
  // error: 'inout' must not be used on subscript parameters
  subscript (postIncrement i: inout Index) -> Element {
    defer { formIndex(after: &i) }
    return self[i]
  }
}

What’s the rationale here?

4 Likes

It just introduces some implementation complexity that we haven't had the time to handle right.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy