Should out/ref parameters require the caller to specify out/ref like in C#?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon May 29 03:02:37 PDT 2017


On Monday, May 29, 2017 09:17:31 Ola Fosheim Grøstad via Digitalmars-d 
wrote:
> On Monday, 29 May 2017 at 08:41:05 UTC, Jonathan M Davis wrote:
> > With C++, if you have const T&, it will accept both lvalues and
> > rvalues. A number of folks (particularly those writing games)
> > want an equivalent to that in D where they can then pass both
> > lvalues and rvalues without incurring a copy.
>
> Mmm. But it sounds more like a compiler hint on const value types
> could work? Except when the making of a copy creates
> side-effects... so you would have to guard against that.
>
> The whole thing with temporaries in C++ in part lead to && move
> semantics. So this is a slippery slope, perhaps.

I don't know what's going to be proposed, so I can't really say much about
it. I just know what the problem is that they want to solve. However, I can
say that whatever they do, having const as a requirement would not fly,
because D's const is so restrictive. I think that in a previous discussion,
it was suggested that we do something like have an attribute like @rvalue
that would go on a ref parameter which would then make it so that the ref
parameter would accept rvalues. So, we may get something like that, or it
could be that something completely different will be proposed. My main
concern is that we not simply make it so that ref accepts rvalues, because
then it makes it harder to know when ref is used because a value is going to
be returned via the ref parameter and when it's used simply to avoid
copying. But I don't know what it will take to alleviate Andrei's concerns
about rvalue references, and I expect that that's ultimately the hurdle that
any DIP would have to get over. However, DIPs 25 and 1000 should solve the
related @safety concerns which were always what Walter was worried about.

- Jonathan M Davis




More information about the Digitalmars-d mailing list