this is not an lvalue

kinke via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 15 07:57:26 PST 2016


On Thursday, 15 December 2016 at 15:29:13 UTC, Adam D. Ruppe 
wrote:
> General rule of thumb: if you are refing for performance, 
> actually check it before and after first, ref isn't always 
> faster.

But D doesn't make this easy, as it disallows rvalues to be 
passed by ref. It's a very common pitfall for C++ guys. `auto 
ref` for templates is an insufficient workaround/hack for that.

On a side note, wrt. `ref isn't always faster` (due to the 
indirection): it's almost always faster on Windows 64, as all 
value types > 64 bit (excluding vectors for the vectorcall 
convention, but let's keep things simple) need to be passed by 
reference (ABI requirement). What this means and what keeps on 
being ignored is that passing a D value type > 64 bits by value 
(to allow rvalue args, although the parameter is a read-only one) 
yields the worst of both worlds - a bitcopy of the original 
argument passed by reference.


More information about the Digitalmars-d-learn mailing list