One thing you can do is create an auxiliary template that generates a structure type with a union, which is the "core" of your type:
template <typename T>
struct Vector3_core {
union {
T data[3];
struct { T x, y, z; };
};
T length() { ... }
};
float :
template <>
struct Vector3_core<float> {
union {
float data[3];
struct { float x, y, z; };
__m128 xmm;
};
float Length() { ... }
};
:
template<class T> class Vector3 : public Vector3_core<T>
{
// Need to pull anonymous-struct members into this class' scope
using Vector3_core<T>::x;
using Vector3_core<T>::y;
using Vector3_core<T>::z;
// All your functions...
};
, . , , Length .
CRTP, .
Coliru, , ++ 11, .
http://coliru.stacked-crooked.com/a/ef10d0c574a5a040