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

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Mar 30 04:08:50 UTC 2018


On Thursday, March 29, 2018 23:28:54 Nick Sabalausky  via Digitalmars-d 
wrote:
> On 03/23/2018 09:06 PM, Jonathan M Davis wrote:
> > My biggest concern in all of this is that I don't want to see ref start
> > accepting rvalues as has been occasionally discussed. It needs to be
> > clear when a function is accept an argument by ref because it's going
> > to mutate the object and when it's accepting by ref because it wants to
> > avoid a copy.
> That ship sailed ages ago: It's already unclear. If we want to fix that,
> we can fix it, but blocking rvalue ref does nothing for that cause.

Really? And how often does ref get used just to avoid copying? You can
almost always look at a function, see that it accepts ref, and know that
it's supposed to mutate the argument. Functions that want to avoid copying
lvalues usually use auto ref, not ref, whereas if ref accepted rvalues, a
number of folks would start using it all over the place to avoid copying.
Right now, folks rarely use ref that way, because it becomes too annoying to
call the function with an rvalue. So, while it might not be the case 100% of
the time right now that ref is used with the purpose of mutating the
argument, it almost always is. As such, you can pretty reliably look at a
function signature and expect that if one of its parameters is ref, it's
going to be mutating that argument. The function that accepts an argument by
ref with no intention of mutating it is very much the exception, and I
really don't want to see that change.

- Jonathan M Davis



More information about the Digitalmars-d mailing list