get type name from current class at compile time?

Ali Çehreli acehreli at yahoo.com
Sun Apr 25 02:02:47 UTC 2021


On 4/24/21 6:50 PM, Jack wrote:
> I'd like to output `K` and get this identifier at compile time.

This is solved by the "this template parameter":

import std.stdio;

class A {
   void showMyName(this T)() {
     writefln("name = [%s]", __traits(identifier, T));
   }
}

class K : A { }

void main() {
   new K().showMyName();
}

Ali


More information about the Digitalmars-d-learn mailing list