I was writing a nominal tuple type using variadic generics, so I could slap some conditional conformances on it, but apparently you can't implement a dynamicMember subscript on top of a tuple variable:
@dynamicMemberLookup
struct Tuple<each Element> {
typealias Elements = (repeat each Element)
var elements: Elements
init(_ element: repeat each Element) {
elements = (repeat each element)
}
subscript<T>(dynamicMember keypath: WritableKeyPath<Elements, T>) -> T {
_read {
yield elements[keypath: keypath]
}
_modify {
yield &elements[keypath: keypath]
}
}
}
Gives me an - error: cannot access element using subscript for tuple type '(repeat each Element)'; use '.' notation instead
Which I think puts this idea to bed for now.
I really expected this to just work. I'm not sure why you can't apply keypaths to tuples.