Make all functions from std.typecons "Proxy" inout

Kenji Hara k.hara.pg at gmail.com
Tue May 8 21:49:37 PDT 2012


On Tuesday, 8 May 2012 at 22:58:07 UTC, Namespace wrote:
> In my development of the Ref / NotNull structure, I came across 
> a
> problem: All the methods of "Proxy" aren't "inout". Has this a
> reason or will change? In my opinion they should all be "inout".
> I mentioned previous self fixes in my corresponding "Ref /
> NotNull" thread already.

It is necessary. See following conceptual code:

struct S
{
     void f() {}
     void g() {}
}
struct Proxy(T)
{
     T o;
     void f()() inout { return o.f(); }
     void g(this T)() { return o.g(); }
}
void main()
{
     Proxy!S p;
     //p.f();  // inside Proxy.f, typeof(o) == inout
     p.g();
}

'Proxy' object should forward its 'this' type to original object.
For the purpose, TemplateThisParameter ('this T') works as 
expected.

Kenji Hara


More information about the Digitalmars-d-learn mailing list