Proposal: Operator overloading without temporaries

Bruno Medeiros daiphoenixNO at SPAMlycos.com
Sun Apr 2 04:49:40 PDT 2006


Don Clugston wrote:
> Background: Operator overloading, in the form it exists in C++ and 
> currently in D, inherently results in sub-optimal code, because it 
> always results in unnecessary temporary objects being created.
> 
> For example,
> X = A - ((B*C) + D)* E;
> 
> becomes:
> T1 = B * C;
> T2 = T1 + D;
> T3 = T2 * E;
> T4 = A - T3;
> X = T4;
> Four objects were created, whereas only one was strictly required.

Ok, I'm new to this, so it took me a while to understand the problem. 
Let's see if I got it right: this is actually only a problem when the 
operator methods explicitly instantiate a *class object*, to be used as 
the return of the method, right?



-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list