Discussion: Rvalue refs and a Move construtor for D
Suleyman
sahmi.soulaimane at gmail.com
Wed Sep 4 16:37:30 UTC 2019
On Wednesday, 4 September 2019 at 14:56:03 UTC, kinke wrote:
> 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.
Sorry I was mistaken. You're right. But still move information is
preserved with rvalue ref and it's utilizable for achieving what
Exil referred to. Ex: https://godbolt.org/z/dlesXb.
More information about the Digitalmars-d
mailing list