Discussion: Rvalue refs and a Move construtor for D

kinke kinke at gmx.net
Wed Sep 4 14:56:03 UTC 2019


On Wednesday, 4 September 2019 at 14:45:34 UTC, Suleyman wrote:
> I think you scored a valid point here. This is where having 
> rvalue ref comes in handy. In C++ assigning an rvalue ref to an 
> lvalue does move not copy.
>
> C++ example:
> ```
> void fun(T&& arg)
> {
>     T var = arg; // move not copy
> }
> ```

Nope, this calls the copy ctor (https://godbolt.org/z/Ds1vmQ) 
without an explicit `T var = std::move(arg)`. This is part of 
what makes C++ rvalue refs difficult to grasp.


More information about the Digitalmars-d mailing list