My question is basically if I have a 4D vector like
_declspec(align(16)) class Vec4
{
float x;
float y;
float z;
float w;
}
and I want to use operators like
Vec4 a(Vector4.One),b(Vector4.One),c(Vector4.Zero);
c = a + b; //Creates a 4th Vector4 here that is wasted
It would seem it should be possible to get rid of that wasted 4th vector in some way but can't figure out a way that does it without allocating memory for a pointer AND 4 floats for each vector which I'd like to avoid. Seems like this could be easily avoided through compiler in theory if syntax such as
Vec4 c = a + b;
was used. Since c is going to call the default constructor but instead wouldn't need to because it knows a + b returns a value that it should be. So instead could just move the temporary created by a + b to c in that situation without risk.
Been doing some 3D math optimizations that have been pretty profitable on a program of mine since a lot of libraries don't take advantage of application specific truncations that I can do. The coding is kinda laborious and was just wondering if their was a way to make the code look better without sacrificing a large amount of performance because of excess allocation / wastage. Seems like a pretty big oversight imo.
I also dream of a day that compilers will be able to tell the difference based on return type between void and non-void versions of the function involving things like '+=' or '='. But that is too much.