Why do "const inout" and "const inout shared" exist?
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 2 01:55:18 PDT 2017
On 7/2/2017 1:12 AM, Sönke Ludwig wrote:
> The idea is to be able to write: string result = foo(true, "bar");
If it is declared as:
inout(char)[] foo(bool condition, inout(char)[] chars);
your specific case will work as expected. Perhaps you meant:
char[] s;
string result = foo(true, s);
which will never work, even if const inout is a type, because the returns in the
function body do NOT determine the return type's inout meaning. Only the type of
the argument supplied to the inout parameter does that.
> However, in this case it can be also argued that supporting this specific case
> adds it's own complexity. The concept of const(inout(T)) definitely sounds like
> one of the harder ones to explain. So I'd probably still opt for simplifying the
> conversion hierarchy.
Neither I nor anyone here seems to understand its purpose. The existence of it
is likely a significant contributor to peoples' confusion about inout.
It's my fault as I should have noticed this getting slipped into the compiler.
More information about the Digitalmars-d
mailing list