Can we fix reverse operator overloading (opSub_r et. al.)?

ponce aliloko at gmail.com
Sun Jul 12 13:53:31 PDT 2009


> Curiously, in the DMD front-end, that's almost what happens with array 
> operations.
> 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.



More information about the Digitalmars-d mailing list