-preview=in might break code

Daniel N no at public.email
Fri Oct 2 21:57:06 UTC 2020


On Friday, 2 October 2020 at 21:13:29 UTC, Mathias LANG wrote:
>
> To me, the `in` approach is better. From the point of view of 
> `foo`'s implementer, you get a stable `ref` or non-`ref` (not 
> both!). You can also rely on it being `ref` if you know more 
> about the type (e.g. if it has a destructor).
> From the point of view of the caller, calling the function with 
> the same values will always behave the same, no matter if you 
> pass rvalues or lvalues.

I totally agree.

Also see the formally accepted DIP1021!
https://github.com/dlang/DIPs/blob/148001a963f5d6e090bb6beef5caf9854372d0bc/DIPs/accepted/DIP1021.md

"Therefore, if more than one reference to the same data is passed 
to a function, they must all be const."



More information about the Digitalmars-d mailing list