Declaring rvalue function arguments

Matt Elkins via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 31 09:21:54 PST 2016


I know I can mark an argument ref to require lvalues, so I'm 
wondering whether there is an equivalent for rvalues; that is, is 
there a way to specify that an argument to a function MUST be an 
rvalue?

For example, in C++ I can do this:
[code]
void foo(int && x) {...}

foo(5); // Works fine
int y = 5;
foo(y); // Compile error; y is not an rvalue
[/code]

This functionality turns out to be really useful when dealing 
with transferring ownership of resources.


More information about the Digitalmars-d-learn mailing list