xvalue and std::move in D

Mike Parker aldacron at gmail.com
Thu Mar 6 04:10:48 PST 2014


On 3/6/2014 8:49 PM, Edwin van Leeuwen wrote:
> On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote:
>>
>> See std.algorithm.move
>>
>
> Thank you, can't believe I missed that. How do I specify that the
> function expects a temporary/xvalue (&&) parameter though?

D doesn't have anything like that. The compiler will generally move for 
you when possible. Passing an RValue to a function will be done as a 
move. When returning structs from a function, they're moved. For 
LValues, it's up to the caller to make the move with std.algorithm.move. 
There's been a good deal of discussion here in the NG about this. Hit 
google with 'dlang move semantics' and you'll get some hits. There's 
also Ali's presentation (video[1] and slides[2]) from last year's DConf.

[1] http://www.youtube.com/watch?v=mPr2UspS0fE
[2] http://dconf.org/2013/talks/cehreli.pdf


More information about the Digitalmars-d-learn mailing list