I am trying to convert a math library written with VS so it will compile though GCC. The trouble is, I have a lot of overloaded operators that look like this:
template
<typename T>
inline quaternion<T>
operator+(quaternion<T>
&a, quaternion<T>
&b)
{return quaternion<T>
(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);}
and so on.
The problem is: These operators were designed under the assumption that other compilers would support the automatic intermediates created for expressions like the following:
...
quaternion<T>
q = log(exp(q0)*t);
...
Without them, the above would need to turn into:
...
quaternion<T>
tmp = exp(q0);
tmp *= t;
quaternion<T>
q = log(tmp);
...
And this is just a simple example. Some of the expressions within the systems that use this library would expand to several hundreds of lines -- something quite unpleasant considering that the overhead involved in debugging assembly-style numerics code for, say, a single function that stretches over 600 lines is astronomical in the least.
It seems unreasonable to me that the whole mechanism of overloading operators was introduced into the language only to provide a different naming convention for ordinary functions, while offering no real syntactical advantage when it comes to mathematical expressions.
But, of course, I hope I am wrong in assuming this.
Which brings me to ask: Does GCC have the ability to create automatic intermediates? If not, what compilers aside from the MS brands are capable of this?
Or have I gone about this in the wrong way altogether and there is a better technique for creating the same effect?