Discussion: Rvalue refs and a Move construtor for D
Les De Ridder
les at lesderid.net
Sun Sep 1 08:59:08 UTC 2019
On Saturday, 31 August 2019 at 20:15:22 UTC, Suleyman wrote:
> I made a POC for the implementation without rvalue ref.
> Here it is: https://github.com/dlang/dmd/pull/10383.
>
> It compiles. And works just like the rvalue ref implementation
> would.
I realise you need to differentiate between copy constructors and
move
constructors somehow, but I'm not sure calling move constructors
`__move_ctor` is the right solution. The average user of D should
neverhave to use a `__` symbol, but it's not unlikely they might
want to
write a struct with move semantics. Maybe a solution with a UDA
is
possible?
> I also added a `cast(rvalue)` which does the same as the
> `(T&&)` in C++ but returns an rvalue. And an intrinsic
> `__move()` and a `__traits(getRvalue)` which are simply
> syntactic flavors of `cast(rvalue)`.
I'm not sure why there are three different ways to 'cast to an
rvalue'?
Is there a technical reason?
I also noticed you're casting lvalues to 'rvalues' and then
binding them
to a `ref` param. Is that not an rvalue reference? Why can't we
have
generalised rvalue references instead?
More information about the Digitalmars-d
mailing list