Discussion: Rvalue refs and a Move construtor for D

Manu turkeyman at gmail.com
Wed Sep 4 18:43:08 UTC 2019

On Wed, Sep 4, 2019 at 7:50 AM Suleyman via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Wednesday, 4 September 2019 at 00:58:44 UTC, Manu wrote:
> > Move semantics aren't a feature of the move constructor, they
> > are USED
> > BY the move constructor.
> > You can move an argument to any function. Consider a
> > unique_ptr, which
> > can only move. It would be impossible to pass a unique_ptr to
> > any
> > other function than the move constructor itself.
> If you can get the move constructor and move assignment in
> addition to an intrinsic function for moving lvalues to rvalues
> then you can do move semantics without rvalue ref.
> unique_ptr in C++ doesn't move itself magically. You have to
> eplicitly move it by calling `move()`. Example:
> https://cpp.godbolt.org/z/8jVONg.
> You can do that with the machinery provided in the POC without
> rvalue ref.

You misunderstood what I'm saying.
I'm saying that it can't only be a `@move` constructor that can accept
rval references, any argument should be able to be one. Functions may
have multiple arguments, and some of them may be unique_ptr-like
If you accept by-value, and you use a move-constructor to construct
the argument, then we're back at making a copy at every level of the
callstack, and that's specifically what we need to avoid.

More information about the Digitalmars-d mailing list