Declaring rvalue function arguments

maik klein via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 31 09:23:45 PST 2016


On Sunday, 31 January 2016 at 17:21:54 UTC, Matt Elkins wrote:
> 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.

I am also very interested in this. I just asked this question 
today on SO 
https://stackoverflow.com/questions/35115702/how-do-i-express-ownership-semantics-in-d




More information about the Digitalmars-d-learn mailing list