Should 'in' Imply 'ref' as Well for Value Types?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat May 5 15:39:19 UTC 2018


On Saturday, May 05, 2018 15:22:04 Bolpat via Digitalmars-d wrote:
> On Friday, 4 May 2018 at 09:34:14 UTC, Jonathan M Davis wrote:
> > [...]
> > It's actually not infrequent now that in C++, you want to pass
> > stuf by value rather than const& precisely because move
> > semantics can be used to avoid copies. So, it's not at all
> > necessarily the case that passing by ref is the efficient thing
> > to do. It's heavily dependent on the code in question.
>
> I once proposed that `in` can mean `const scope ref` that also
> binds rvalues.
> https://github.com/dlang/DIPs/pull/111#issuecomment-381911140
> We could make `in` be something similar to `inline`. The compiler
> can implement it as stated above (assign the expression to
> temporary, reference it), or use copy if copy is cheaper than
> referencing.

Having ref of any kind accept rvalues is a highly controversial issue, and
it may or may not ever be in the language. If it's added, then at that
point, whether it makes sense to make in imply ref could be re-examined, and
maybe at that point, doing so would make great sense. But as long as ref
does not accept rvalues, it really doesn't make sense. It would break too
much code and would be far too annoying to use in many, many cases where it
is currently commonly used.

- Jonathan M Davis



More information about the Digitalmars-d mailing list