Discussion: Rvalue refs and a Move construtor for D

kinke noone at nowhere.com
Sat Sep 7 12:42:58 UTC 2019


On Saturday, 7 September 2019 at 12:04:49 UTC, kinke wrote:
> Wrt. rvalue ref params and return 'values', maybe we could get 
> away without introducing `@rvalue ref` by changing the current 
> `auto ref` semantics for params (and return 'values') to what 
> you proposed - an l/rvalue ref, i.e., a reference in both 
> cases, just annotated with rvalue-ness, and never a value 
> anymore.
> [...]

In C++ terms:

struct S
{
     S(S&&);            // D: moveThis(ref S);
     S& operator=(S&&); // D: ref S opMoveAssign(ref S);
}

// universal reference:
template <typename T> void foo(T&&);
// D: void foo(T)(auto ref T);

// rvalue reference:
void bar(S&&);
// D: void bar()(auto ref S s) if (__traits(isRvalueRef, s));

move/forward working just like in C++, but intrinsics.


More information about the Digitalmars-d mailing list