Ouput-UFCS proposal: void fun(A a,ref B b) <=> B fun(A a);

timotheecour thelastmammoth at gmail.com
Sat Feb 2 17:22:27 PST 2013


> As of the proposal in itself, out parameter is known to be 
> confusing. They are here simply for C compat, and because D is 
> unable to return multiple values. Fixing that problem is 
> probably way then introducing something that promote out 
> parameter usage.

D can return tuples, and certainly its support could be improved 
(see [Issue 6365] AutoTupleDeclaration ), but this is besides the 
question.

Oftentimes we NEED both versions, as I discussed in the previous 
post. The void fun(A a, ref B b) can reuse already allocated 
data, avoiding expensive allocations. This pattern is quite 
common.

----
void fun(int n, ref B b){
b.length=n;
//do something with b
}

B fun(int n){
B b;
fun(n,b);
return b;
}
----


More information about the Digitalmars-d mailing list