DIP 1016--ref T accepts r-values--Community Review Round 1

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jul 21 00:33:35 UTC 2018


On Saturday, July 21, 2018 00:10:09 Nicholas Wilson via Digitalmars-d wrote:
> So this problem is restricted output range @properties that
> somehow don't return by ref, aren't intended to be used after
> having data written to them _and_ aren't singleton like?

It's a problem for any function that accepts by ref with the intention of
mutating the argument rather than to avoid copying, and something other than
an lvalue is passed. Output ranges are just a particularly common use case.
And property functions are just an easy way to think that you're passing an
lvalue when you're not. For that matter, it's an easy mistake to make with
lots of functions in D, because parens are unnecessary when there are no
function arguments or when the only function argument is passed via UFCS.
And of course, if someone doesn't read the docs carefully enough (which
happens far too often), there are plenty of problems that someone could run
into where they pass an rvalue to a function designed to operate on an
lvalue. Right now, ref catches any and all mistakes where someone tries to
pass an rvalue by ref, but if ref accepts rvalues, it won't catch any of
them.

- Jonathan M Davis



More information about the Digitalmars-d mailing list