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

"Jérôme M. Berger" jeberger at free.fr
Sat Jul 11 01:06:36 PDT 2009


Lars T. Kyllingstad wrote:
> Don wrote:
>> Andrei Alexandrescu wrote:
>>> Walter Bright wrote:
>>>> Andrei Alexandrescu wrote:
>>>>> This also reminds me that the entire operator overloading feature 
>>>>> must be thrown away and redesigned.
>>>>
>>>> :-(
>>>
>>> It's run its course like an old BMW. We need to do new things, and 
>>> bolting them on what we have won't work.
>>>
>>> Andrei
>>
>> Indeed, I even think that the concept of operator overloading is wrong.
>> In C++, operator overloading was just for syntax sugar. That's wrong: 
>> pretty much everything that you want overloaded operators for, is 
>> performance-critical. And that implies you need to deal on the level 
>> of complete expressions, not individual operations.
> 
> 
> That is true. There is, for instance, a good reason why the basic BLAS 
> matrix multiplication routine calculates
> 
>   a A B + b C        (a,b: scalars; A,B,C: matrices)
> 
> instead of just AB.
> 
> Would/could one could gain something, performance-wise, by having such 
> "expression overloading" as a built-in feature of the language itself, 
> rather than as a library?
> 
> BLADE has already shown that it is possible to do stuff like this in a 
> library, but I think it goes without saying that if it was built into 
> the language the syntax could be made considerably nicer. Compare:
> 
>   auto m = MatrixOp!("a*A*B + b*C")(aVal, bVal, aMtrx, bMtrx, cMtrx);
> 
>   auto m = a*A*B + b*C;
> 
> If D could do this, I think it would become the next FORTRAN. :)
> 
> -Lars

	Actually, this has already been done in C++: 
http://flens.sourceforge.net/ It should be possible to port it to D...

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090711/8a3d3c1c/attachment.pgp>


More information about the Digitalmars-d mailing list