in vs inout

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 30 15:02:15 UTC 2020


On 4/30/20 10:52 AM, Adam D. Ruppe wrote:
> On Thursday, 30 April 2020 at 14:00:40 UTC, Arredondo wrote:
>> I had been using inout for some time now for "purely input function 
>> parameters".
> 
> `inout` is more specifically for things you take in, look at, then pass 
> back out. So it forms part of your return value.

We have discovered actually that inout has some nice properties even if 
you aren't returning it.

For example:

void rearrange(inout(int)*[] arr);

This can actually accept const(int)*[], int*[], and immutable(int)*[] 
with one function. The function can edit the array without editing any 
of the values pointed at.

But in terms of 'in' vs. 'inout', I'd say 'in' unless you have a 
specific reason to use inout (the above included).

-Steve


More information about the Digitalmars-d-learn mailing list