Access derived type in baseclass static function template

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 2 08:38:12 PDT 2017


On 8/2/17 11:06 AM, Timoses wrote:
> On Wednesday, 2 August 2017 at 13:51:01 UTC, Steven Schveighoffer wrote:
>> However, your original code has potential as an enhancement request, 
>> as the type is known at compile-time and could certainly be resolved 
>> to pass in as the `this` template parameter.
> 
> I guess the `this` is really misleading it being a static method.
> I suppose 
> https://issues.dlang.org/buglist.cgi?bug_severity=enhancement&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&product=D&query_format=report-table&y_axis_field=bug_severity 
> would be the place for an enhancement request?
> Possibly related:
> https://issues.dlang.org/show_bug.cgi?id=14191

Yes, that's exactly it.

Note that typeof(this) has special meaning for static methods:

class C
{
    static typeof(this) foo() { return new typeof(this); }
}

So there is precedence for the meaning of `this` in a static context.

-Steve


More information about the Digitalmars-d-learn mailing list