Inout table

nkm1 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 13 12:04:53 PDT 2017


On Wednesday, 13 September 2017 at 17:39:29 UTC, Steven 
Schveighoffer wrote:
> Correct. So given a function:
>
> inout(int*) foo(inout(int*)p1, inout(int*)p2)
>
> The table shows what inout is resolved as when calling the 
> function.
>
> If you consider the column the mutability of p1, and the row 
> the mutability of p2, then the value in the table represents 
> the mutability of the return value.
>
> So for instance:
>
> int *m;
> const int *c;
> immutable int *i;
> inout int *w;
>
> auto v1 = foo(m, m); // typeof(v1) is int*
> auto v2 = foo(m, c); // typeof(v2) is const(int*)
> auto v3 = foo(i, m); // typeof(v3) is const(int*)
> auto v4 = foo(w, w); // typeof(v4) is inout(int*)
> auto v5 = foo(w, i); // typeof(v5) is inout(const(int *))
>
> etc.

Thank you. Now it is clear to me. The source of my confusion was 
that, say, given a function:
inout(int*) foo(inout(int*) p)
as per table, combining (mutable) argument int* m with parameter 
inout(int*) p would produce parameter type const(int*). But now I 
see that the table deduces the common type of all parameters, not 
the common type of a parameter and its argument (the 
documentation is kind of hard to parse: "If such a match occurs, 
the inout is considered the common qualifier of the matched 
qualifiers...").


More information about the Digitalmars-d-learn mailing list