rvalues -> ref (yup... again!)

Rubn where at is.this
Tue Mar 27 20:36:00 UTC 2018


On Tuesday, 27 March 2018 at 15:50:37 UTC, Atila Neves wrote:
>> It's fine for references to
>> just be references in D. We're not struggling to make 
>> references
>> move-able in D, that's not a thing, we already have move 
>> semantics.
>> Any extension of this conversation about references into C++
>> rvalue-references (T&&) and or move-semantics are red-herrings.
>> There's no such problem in D that needs to be resolved, and the
>> existing solution is excellent.
>
> If I'm reading you correctly (which I might not), you seem to 
> be saying that there's a way forward in which:
>
> 1) D's move semantics aren't affected
> 2) No rvalue references are introduced
> 3) Temporaries can bind to ref const(T)
>
> I'd love to know what that would look like.
>
> Atila


Well currently if you only have this implemented:

void foo(const ref Type);

Type temp = Type(10);
foo(temp);

Where the hell are you going to do your move semantics? You can't 
do it anyways currently, it's completely meaningless cause you 
can't.

void foo(Type);
void foo(const ref Type);

foo(Type(10));

Now we have move semantics with an additional definition.


With the proposed change, nothing about that would change. A 
temporary is only passed to a const ref as a "last resort". If it 
can do a move instead, it will do the move. The only change that 
is desired is to make the first sample code above have nicer 
syntax. That's it, like in the first example you don't care about 
it being a temporary or not.





More information about the Digitalmars-d mailing list