tipo de vetor estendido personalizado: por exemplo float4 b = v.xxyz;
OpenCL, GCC e Clang têm tipo de vetor convinenteextensões.
Uma das características que eu mais gosto é a capacidade de fazer um swizzle assim:
float4 a(1,2,3,4);
float4 b = a.xxyw; //1124
Como posso fazer minhas próprias extensões de vetor para fazer isso, por exemplo, MSVC também? O melhor que eu tenho é algo que fariafloat4 b = a.xxyw()
(veja o código abaixo). Então, a minha principal questão é como seria possível fazer isso sem o()
notação.
No caso de alguém estar interessado, eu criei algum código que cria todas as permutações usando
#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;
}