`in` parameters optimization

Meta jared771 at gmail.com
Wed Dec 25 16:14:30 UTC 2019

On Wednesday, 25 December 2019 at 01:24:52 UTC, Adnan wrote:
> Does the compiler automatically pass values by reference if 
> possible with `in` parameters in higher level of optimization 
> flags? I would normally use `in ref` but sometimes it's not 
> compatible with different types.

No. "in" is short for "const scope" 
(https://dlang.org/spec/function.html#param-storage). The only 
mechanism D has for expressing "pass this argument by ref if 
possible, and by value otherwise" is "auto ref" 
(https://dlang.org/spec/function.html#auto-ref-functions), which 
requires your function to be templated.

More information about the Digitalmars-d-learn mailing list