Let me start this question by stating that I don't know if what I am aiming to do is possible, and if it is, I don't know how to find the information.
The OpenGL shading language permits a syntax called swizzeling.
If one has a vector
v {x, y, z}
one can construct a new vector by doing
v.xxx, v.xxy, v.xxz, v.xyx, ... etc
There are a total of 3 * 3 * 3 = 27 possible options.
I would like to implement this kind of feature in my own vector library.
Here is one example of such a function:
vec3<T> xxx() const
{
vec3<T> v(x, x, x);
return v;
}
I could then write another 26 functions to account for all possible options, but this seems like something I should be able to do using a macro. For example, something like
vec3<T> (#A)(#B)(#C)() const
{
vec3<T> v(#A, #B, #C);
return v;
}
where #A, #B and #C are 3 single characters which the compiler expands with possible options being x, y and z.
Is such a thing possible with gcc/g++ ?