tipo de vector ampliado personalizado: por ejemplo, float4 b = v.xxyz;

OpenCL, GCC y Clang tienen un vector de tipo convinenteextensiones.

Una de las características que más me gustan es la posibilidad de hacer un swizzle como este:

float4 a(1,2,3,4);
float4 b = a.xxyw;  //1124

¿Cómo puedo hacer mis propias extensiones vectoriales para hacer esto con, por ejemplo, MSVC también? Lo mejor que he encontrado es algo que haríafloat4 b = a.xxyw() (ver el código de abajo). Así que mi pregunta principal es cómo sería posible hacer esto sin el() notación.

En caso de que alguien esté interesado, se me ocurrió un código que crea todas las permutaciones usando define

#define DEF_SWIZ4(a,b,c,d)  Vec4 a##b##c##d() const { return Vec4(a, b, c, d); }
#define DEF_SWIZ3(a,b,c)    DEF_SWIZ4(a,b,c,x) DEF_SWIZ4(a,b,c,y) DEF_SWIZ4(a,b,c,z) DEF_SWIZ4(a,b,c,w)
#define DEF_SWIZ2(a,b)      DEF_SWIZ3(a,b,x) DEF_SWIZ3(a,b,y) DEF_SWIZ3(a,b,z) DEF_SWIZ3(a,b,w)
#define DEF_SWIZ1(a)        DEF_SWIZ2(a,x) DEF_SWIZ2(a,y) DEF_SWIZ2(a,z) DEF_SWIZ2(a,w)
#define DEF_SWIZ()          DEF_SWIZ1(x) DEF_SWIZ1(y) DEF_SWIZ1(z) DEF_SWIZ1(w)

class Vec4
{
public:
    double x, y, z, w;
    Vec4() : x(0), y(0), z(0), w(0) {}
    Vec4(double x, double y, double z, double w) : x(x), y(y), z(z), w(w) {}
    DEF_SWIZ()
};

#include <iostream>

int main()
{
    Vec4 v(1, 2, 3, 4);
    Vec4 s = v.yyxw();
    std::cout << s.x << " " << s.y << " " << s.z << " " << s.w << std::endl;
}