auto ref is on the docket

via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 28 04:06:00 PDT 2015


On Sunday, 28 June 2015 at 07:36:41 UTC, Jonathan M Davis wrote:
> It makes no sense to pass rvalues by ref. The ref has to refer 
> to a memory location so that a pointer can be passed underneath 
> the hood, and rvalues don't qualify for that.

I strongly disagree with that. This is an implementation detail. 
`ref` describes a specific semantic, namely that no copying 
(observable by a postblit being called) takes place, and that it 
refers to the same "thing" as the original (observable by 
mutations being visible on the original object, if relevant). How 
a value is stored is completely up to the compiler. It can be in 
a register, a memory location, or even - if the compiler knows 
the value in advance - as an immediate of a machine instruction. 
The same is true for passing values: the compiler is free to 
implement it as it wants, as long as it keeps the required 
semantics.


More information about the Digitalmars-d mailing list