Operator overloading -- lets collect some use cases

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Dec 30 08:31:16 PST 2008

Denis Koroskin wrote:
> On Tue, 30 Dec 2008 17:30:13 +0300, Frits van Bommel 
> <fvbommel at remwovexcapss.nl> wrote:
>> Bill Baxter wrote:
>>> Merging might be useful there too --- A ~= b ~ c ~ d  is probably more
>>> efficiently implemented as 3 ~= ops.
>> Actually, it's probably most efficiently implemented as 1 "~=" with 
>> multiple parameters. (DMD already does this for arrays)
> Perhaps, not not general enough:
> A += a * b - c / d; // how to do this one?

That's a very different case, IMHO. Look at Don's posts for an answer to 
that one.

I think '~' and '~=' are more likely to allocate if used for their 
conventional meaning (adding items to some form of collection). When 
performing this operation in-place several times on the same collection 
it's quite possibly more efficient to do one big allocation instead of 
several small (temporary) ones by pre-calculating the required space.

Your example is likely most efficiently implemented as something like
   A += a * b;     // Something like FMULADD?
   A -= c / d;     // Do FDIVADD-like instructions exist?
for most implementations.
(I think Don's suggested semantics should result in this, assuming 
sufficient optimization)

More information about the Digitalmars-d mailing list