Call site 'ref'

Peter Alexander peter.alexander.au at gmail.com
Sun Jan 15 14:41:14 PST 2012


On 15/01/12 10:10 PM, Timon Gehr wrote:
> Another thing that would have to be discussed: what happens to const ref
> parameters? It is very reasonable that someone will decide to change
> calling conventions from by value to by const ref or the other way round
> after profiling. It is very convenient that such a change is
> syntactically transparent to the caller and this should stay.

Actually, that would be very dangerous. const ref does not have the 
privilege of being able to bind to rvalues in D like it does in C++.

void foo(const ref int x) {...}

foo(1); // this is legal in C++, but illegal in D

In case, const ref would not require the ref at call site because 
there's no danger of it being modified.



More information about the Digitalmars-d mailing list