xxxxxxxxxx
import std;
struct Point4 {
union {
float[4] cs = [1,2,3,4];
struct { float x,y,z,w; }
}
float opIndex( size_t i)
in( i <= 3) // unsigned never become <0
{
return cs[ i];
}
void opIndexAssign( float v, size_t i)
in( i <= 3)
{
cs[ i] = v;
}
}
// check for no UB
static assert( Point4.sizeof == 16 );
void main() {
Point4 p;
p[2].writeln;
assert( p[2] == p.z );
p[5] = 0;
}