template this parameters

Trass3r un at known.com
Tue Jan 25 07:44:23 PST 2011


Why do they exist and why does typeof(this) strip constness?

import std.stdio;
struct S
{
    const void foo(this T)(int i)
    {
	writeln(typeid(T));
    }

    const void bar()
    {
    	writeln(typeid(typeof(this)));
    }
}

void main()
{
    const(S) s;
    (&s).foo(1);
    S s2;
    s2.foo(2);
    immutable(S) s3;
    s3.foo(3);

    s.bar();
    s2.bar();
    s3.bar();
}

yields:
const(templatethis.S)
templatethis.S
immutable(templatethis.S)
templatethis.S
templatethis.S
templatethis.S


More information about the Digitalmars-d-learn mailing list