Discussion: Rvalue refs and a Move construtor for D

Suleyman sahmi.soulaimane at gmail.com
Fri Sep 6 20:24:24 UTC 2019

On Friday, 6 September 2019 at 17:59:11 UTC, kinke wrote:
> The problem here is the extended lifetime of the by-value 
> parameter. Example:
> T global;
> void foo(T param) { /* make T own a huge buffer */ }
> void caller()
> {
>     foo(move(global));
>     // without destructing and resetting to T.init, `param` 
> continues to live
>     // and keeps the huge buffer alive, until `global` is 
> reassigned or destructed
> }

I see no problem with that. That is valid behavior with rvalue 
ref. You're trying to get the benefit of rvalue ref you can't get 
the full benefit without the draw backs. There is no in middle 
solution, either pass by ref or call the move constructor.

More information about the Digitalmars-d mailing list