Parameter forwarding

Kostiantyn Tokar tokarkonstantyn at
Sat Oct 16 19:39:14 UTC 2021

On Friday, 15 October 2021 at 17:22:52 UTC, Tejas wrote:
> On Friday, 15 October 2021 at 06:52:41 UTC, Kostiantyn Tokar 
> wrote:
>> On Thursday, 14 October 2021 at 17:53:57 UTC, Tejas wrote:
>>> Maybe DIP 1040 will automatically solve that?
>>>>last use of objects that is a copy gets elided into a move
>>> That is what it states, so maybe this one time, the problem 
>>> will go away just by waiting?
>> It would be great, but still, if I understand correctly, it is 
>> not perfect solution for lvalue arguments. Consider, e.g., 
>> `Tuple` construction from an lvalue. With this DIP and current 
>> state of constructor it will be 1 copy (from argument to 
>> constructor's parameter) and 1 blit (from parameter to the 
>> field). With `auto ref` and forwarding it would be 1 copy from 
>> parameter to the field and no blits. Forwarding saves one blit 
>> per indirection, i.e., for `tuple` it would be 2 blits vs. 0.
> Yeah blitting as a concept will go away from D(will only stay 
> for backwards-compatibility)
> Copy constructors already made blits obselete, move 
> constructors will remove the need for post-blits and finish the 
> job and the second case that you talked about will become the 
> default

Now I get it. If this DIP will be accepted, I just have to 
provide move constructor/assignment for my types and forwarding 
would work. It sounds really great. If so, there is no need to 
rewrite half of Phobos to support forwarding. And it even covers 
last use of a field of an aggregate! Hope it will be accepted.

Paul, Tejas, thank you for answers.

More information about the Digitalmars-d-learn mailing list