References

andrea9940 no at mail.plz
Fri Sep 20 02:36:17 PDT 2013


Running this code I would expect to get "ref" three times, but ...

-------
import std.stdio;
struct A {
	int[128] data;
	ref A opAdd(const ref A a) {
		A cp = this;
		cp.data[] += a.data[];
		return cp;
	}
}

void fun(A a) { writeln("copy"); }
void fun(const ref A a) { writeln("ref"); }

void main() {
	A a, b;
	fun(a + b); //prints "copy"
	fun(A());   //prints "copy"
	fun(a);     //prints "copy"
}
-------

After some tests I concluded that is not possible to pass the 
result of a+b as a reference (which is what interests me most) 
and this creates an evident performance problem.
Is there any solution that I missed ?


More information about the Digitalmars-d-learn mailing list