Discussion: Rvalue refs and a Move construtor for D
kinke
noone at nowhere.com
Fri Sep 6 19:50:30 UTC 2019
On Friday, 6 September 2019 at 19:25:57 UTC, Manu wrote:
> There's another case where you can attribute a method with
> `@rvalue` to apply to the `this` reference. This should
> naturally work in D under the `@rvalue` proposal.
>
> Ie:
>
> struct S
> {
> Thing member;
> ref Thing fun() { return member; }
> Thing fun() @rvalue { return move(member); }
> }
>
> This can be very valuable, and even more so in D where we use a
> lot of UFCS chains.
Oh wow, this might be able to convince me, as returning an rvalue
ref from a method invoked on an rvalue instance would allow
absolutely perfect forwarding of members (no copy/move and
preserving rvalue-ness):
struct S
{
Thing member;
ref Thing fun() { return member; }
@rvalue ref Thing fun() @rvalue { return member; }
// maybe we could even represent both at once via something
like:
// auto ref Thing fun()() { return member; }
}
More information about the Digitalmars-d
mailing list