Proposal: Operator overloading without temporaries
Regan Heath
regan at netwin.co.nz
Mon Mar 27 13:17:31 PST 2006
On Mon, 27 Mar 2006 10:29:13 +0200, Don Clugston <dac at nospam.com.au> wrote:
> Comments?
I was wondering the exact same thing recently:
http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/35382
Do you think we gain anything by using the lhs variable where possible.
i.e.
Instead of:
T1 = B.opMul(C);
T1.opAddAssign(D);
T1.opMulAssign(E);
T1.opSubAssign_r(A);
X = T1;
We have:
X = B;
X.opMulAssign(C);
X.opAddAssign(D);
X.opMulAssign(E);
X.opSubAssign_r(A);
It seems to me that this results in 1 less temporary and therefore 1 less
assignment.
Of course, it doesn't help/work in cases where there is no existing lhs,
i.e.
foo(A - ((B*C) + D)* E);
Regan
More information about the Digitalmars-d
mailing list