`return const` parameters make `inout` obsolete
Zach the Mystic via Digitalmars-d
digitalmars-d at puremagic.com
Tue Mar 17 08:55:58 PDT 2015
On Tuesday, 17 March 2015 at 12:02:15 UTC, Nick Treleaven wrote:
> On 16/03/2015 14:17, 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.
>
> inout can be used for local variables too.
Yeah that might be a use for it.
inout(T*) fun(inout(T*) t) {
inout(T*) x = t;
return x;
}
-->
T* gun(return const T* t) {
const(T*) x = t;
return x;
}
To be fully viable, `return` would have to be secretly recorded
as part of the `x's type, so that the compiler could forgive
returning it to a non-const. But the compiler should probably
track that `x` is copied from `t` anyway, so that it can verify
`return t` when it returns `x`, and the same information would be
used to forgive `x's constness.
But yeah, there might still be a use for `inout`.
More information about the Digitalmars-d
mailing list