Why isn't global operator overloading allowed in D?

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 15 08:57:28 PDT 2015


On Thursday, 15 October 2015 at 15:45:00 UTC, Shriramana Sharma 
wrote:
> John Colvin wrote:
>
>> On Wednesday, 14 October 2015 at 15:02:02 UTC, Shriramana 
>> Sharma
>> wrote:
>> What binary arithmetic operators do you need that real[] 
>> doesn't
>> already support?
>
> OMG silly me! I can already do a[] /= b[]... D is great! :-D 
> Thanks a lot!

Also:

a[] = b[] + c[] * d[] - 42;

and so on... All that's required is that there is pre-allocated 
memory for the result to go in i.e. there has to be enough space 
in a[].

You should be aware that with DMD these array operations should 
be much faster than a straightforward loop, as they are done in 
handwritten asm using vector instructions. Be wary of using them 
on very small arrays, there is some overhead.

With LDC/GDC you probably wont see much difference either way, if 
I remember correctly they rely on the optimiser instead.


More information about the Digitalmars-d-learn mailing list