If I have a struct like
struct Point4D
{
let x:Double,
y:Double,
z:Double,
w:Double
}
is there an efficient way to access the members of the struct by integer index? Meaning
let index:Int = 2
let point:Point4D = Point4D(x: 1, y: 5, z: 3, w: 8)
let component:Double = point [index] // 3
I suppose this is possible by defining the subscript() method on Point4D and using a switch statement but this doesn’t seem very efficient. In C I believe you can increment a pointer to the first struct member since they are all of type Double, but Swift doesn’t allow this…