rvalue references

kinke via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 9 12:40:40 PDT 2015


On Tuesday, 9 June 2015 at 17:38:00 UTC, Steven Schveighoffer 
wrote:
> But passing a large rvalue by value does not involve any moving 
> of data, and can be abstracted to a pass by ref if needed. It's 
> never less performing than an explicit pass by ref.

Thanks Steve.

The problem I see here on Win64 is that the current `auto ref` 
implementation for templates, i.e., 2^N function instantiations 
for N lvalue/rvalue combinations, seems totally useless for value 
types for which the ABI enforces pass-by-ref anyway.

In essence, `auto ref T` for templated functions on Win64 boils 
down to a simple `ref` accepting rvalue arguments iff T cannot be 
passed by value. All what's needed is constructing the rvalue on 
the caller's stack and destroying it after the call; the callee 
isn't affected at all, so no need for 2^N function versions, 1 is 
enough. Note that I haven't inspected the DMD code yet, but I 
assume it makes no exception for Win64 in that regard.

No opinions on the semantics for `in` I proposed earlier? `in T` 
would be something like a non-escapable `const auto ref T` 
accepting rvalues without codebloat and avoiding the indirection 
for small POD types T. Wouldn't that eliminate 99% of the use 
cases for `auto ref`, improve readability substantially and be 
the solution for all the C++ guys missing the rvalue-bindability 
of `const T&`?


More information about the Digitalmars-d mailing list