Rvalue references

Tony tonytdominguez at aol.com
Fri Jan 12 01:59:49 UTC 2018


On Monday, 8 January 2018 at 23:31:27 UTC, Jonathan M Davis wrote:

>
> auto foo(T)(auto ref T t)
> {
>     return t;
> }
>
> foo(42);
>
> will result in foo being instantiated as
>
> int foo(int t)
> {
>     return t;
> }
>
> whereas
>
> int i;
> foo(i);
>
> will result in foo being instantiated as
>
> int foo(ref int t)
> {
>     return t;
> }
>
> So, by using auto ref, a function can accept both lvalues and 
> rvalues. And in D, rvalues get moved, not copied.

What does it mean to "move" a variable/value instead of copying 
it?

Was "auto ref" created for anything besides structs?



More information about the Digitalmars-d-learn mailing list