Thread overview | |||||
---|---|---|---|---|---|
|
April 30, 2020 in vs inout | ||||
---|---|---|---|---|
| ||||
The recent change log for v2.092.0 Beta says that with the new implementation for the `in` storage class:
> `in` should be the storage class of choice for purely input function parameters.
I had been using inout for some time now for "purely input function parameters". Is there a case to be made in favor of const? why would be scope const preferred over scope inout?
Cheers!
Arredondo.
|
April 30, 2020 Re: in vs inout | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arredondo | 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.
`const` is for when you are just looking without returning any of it.
scope inout may be more appropriate if you are going to return it at all...
|
April 30, 2020 Re: in vs inout | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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
|
Copyright © 1999-2021 by the D Language Foundation