get type name from current class at compile time?
Jack
jckj33 at gmail.com
Sun Apr 25 02:11:16 UTC 2021
On Sunday, 25 April 2021 at 02:02:47 UTC, Ali Çehreli wrote:
> 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
good one Ali, thanks. Where is this template parameter documented
at?
More information about the Digitalmars-d-learn
mailing list