A matter of inout
Ali Çehreli
acehreli at yahoo.com
Fri Jul 27 10:28:31 PDT 2012
On 07/27/2012 10:13 AM, bearophile wrote:
> Artur Skawina:
>
>> 'inout' basically means 'local const' - if you'd allow inout
>> data to be modified then it wouldn't be possible to call the
>> function with a const or immutable argument - which is the
>> whole point of inout...
>
> dmd 2.059 was wrong then.
I think so.
I have understood that aspect of inout recently: since the function is
not a template (bear with me please! I know it is a template here :)),
there will be a single instance of it. Since that instance must work
with mutable and immutable, the parameter cannot be modified inside the
function.
Even if the function is never called with immutable, the compiler must
compile the code as if 'inout' is spelled as 'const'.
The above makes sense for a regular function. I guess the guideline here
is not to use inout on a template parameter as it doesn't make sense
because T carries that information anyway.
Ali
More information about the Digitalmars-d-learn
mailing list