How can I provide a class that has constructors as part of a union?
I’ve read that any class that has a trivial constructor can be part of a union. Especially with c++0x, I thought unions are supposed to be unrestricted. Why is this float4 class not suitable? How can I do this?
struct float4
{
union
{
struct { float z, y, x, w; };
float v[4];
__m128 xmm;
};
inline float4() { }
inline float4(float x, float y, float z, float w) :
xmm(_mm_setr_ps(z, y, x, w)) { }
};
struct float44
{
union
{
float v[16];
__m128 xmm[4];
struct { __m128 xmm1, xmm2, xmm3, xmm4; };
struct { float4 row1, row2, row3, row4; };
};
};
VC2010 doesn’t implement that part of the C++0x spec yet.