rvalue based copy

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 30 10:24:54 PDT 2015


On Monday, 30 March 2015 at 17:20:30 UTC, matovitch wrote:
> Yes but you know what they say does it really do a copy of the 
> struct or is the compiler smart enougth most of the time to 
> avoid copy. (I think it's called return value optimization).

Copying isn't necessarily a problem, for small structs it is more 
efficient to copy than passing by ref. But the return value 
optimization *is* typically done, yes.

> Why is this only restricted to templates ?

It makes two versions of the function, like overloading on the 
two types of arguments automatically.


More information about the Digitalmars-d-learn mailing list