`return const` parameters make `inout` obsolete

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 12:03:27 PDT 2015


On Monday, 16 March 2015 at 16:22:46 UTC, Marc Sch├╝tz wrote:
> On Monday, 16 March 2015 at 14:17:58 UTC, Zach the Mystic wrote:
>> char* fun(return const char* x);
>>
>> Compiler has enough information to adjust the return type of 
>> `fun()` to that of input `x`. This assumes return parameters 
>> have been generalized to all reference types. Destroy.
>
> That's a very interesting observation. I never liked the name 
> `inout`, as it doesn't describe what it does. The only downside 
> I see is that it's more magic, because nothing on the return 
> type says its mutability is going to depend on an argument.
>
> I think Kenji also had additional plans for `inout`, related to 
> uniqueness. There was a PR. Better ask him whether it's going 
> to be compatible.

`return` would work just as well for uniqueness.

inout(T*) fun(inout(T*) x);
->
T* fun(return const T* x);

I don't think any information is being lost. My attitude is that 
unless you are losing information, the underlying logic won't be 
any harder to implement. I think that `return` parameters are a 
building block of `inout`, but more useful because they can be 
used separately from it. Perhaps in the early days of D, it just 
seemed too weird to have `return` parameters, but now with ref 
safety, they are better justified. But if they'd been there back 
then, `inout` probably wouldn't exist, since you can just build 
it in its current form from `const` and `return`.



More information about the Digitalmars-d mailing list