www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - `in` parameters optimization

reply Adnan <contact.adnan.02 protonmail.com> writes:
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.
Dec 24 2019
parent Meta <jared771 gmail.com> writes:
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.
Dec 25 2019