DIP 1014

Shachar Shemesh shachar at weka.io
Wed Oct 3 14:07:58 UTC 2018


On 03/10/18 16:56, Stanislav Blinov wrote:
> struct S {
>      this(S rhs);

OMG, that's so simple!!! Why didn't I think of it?

Oh wait, I did.

And this simply and utterly doesn't work.

If you read the DIP, you will notice that the *address* in which the old 
instance resides is quite important for performing the actual move. This 
is not available with the interface you're suggesting, mainly because by 
the time you have rhs, it has already moved.

In other words, for the interface above to work, the type must already 
be movable, which kinda contradict what we're trying to achieve here.

> in C++ would have an equivalent signature of
> 
> ReturnType foo(Type&& x); // NOT ReturnType foo(Type x);

No, it is not. You see, in C++, x is an "rvalue *reference*". x has not 
moved by this point in the run, it has simply had its address passed to 
foo. Please see 
https://stackoverflow.com/questions/28483250/rvalue-reference-is-treated-as-an-lvalue

Shachar


More information about the Digitalmars-d mailing list