www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Can we fix reverse operator overloading (opSub_r et. al.)?

 Curiously, in the DMD front-end, that's almost what happens with array 
 x[] = a*y[] + c*z[];
 gets translated into:
 __somemangledarrayfuncname(x, y, z, a, c);
 and creates:
 __somemangledarrayfuncname(T[] p1, T[] p2, T[] p3, T c1, T c2)
    for(int p=0; p < p1.length; ++p) {
      p1[p] = c1*p2[p] + c2*p3[p];

Wow, I didn't know that. I think such a behaviour is not advertised enough. It's valuable since making a single loop for such things optimizes cache usage and speed up things a lot. In C++ you would have to use a templated library like Eigen to do something, and then your code would become unreadable.
Jul 12 2009