Re: get type name from current class at compile time?

2021-04-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 25 April 2021 at 12:54:43 UTC, Jack wrote: I find out this later. I give up trying to get this in automatic way at compile time That's because the type might not be known at compile time at all, it might come from like a plugin loaded at run time and only ever accessed through the

Re: get type name from current class at compile time?

2021-04-25 Thread Jack via Digitalmars-d-learn
On Sunday, 25 April 2021 at 08:36:51 UTC, Adam D. Ruppe wrote: On Sunday, 25 April 2021 at 03:45:13 UTC, Jack wrote: that's better, thanks Imporant to remember that any compile time thing will be the static type. If someone does: Base a = new Derived(); a.something(); it will still show

Re: get type name from current class at compile time?

2021-04-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 25 April 2021 at 03:45:13 UTC, Jack wrote: that's better, thanks Imporant to remember that any compile time thing will be the static type. If someone does: Base a = new Derived(); a.something(); it will still show up as Base in the this template. The knowledge that it is

Re: get type name from current class at compile time?

2021-04-24 Thread Jack via Digitalmars-d-learn
On Sunday, 25 April 2021 at 02:45:38 UTC, Paul Backus wrote: On Sunday, 25 April 2021 at 02:26:00 UTC, Jack wrote: doesn't this work when called from member in a derived class? ```d class A { void doSomething(this T)() { writefln("name = [%s]",

Re: get type name from current class at compile time?

2021-04-24 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 25 April 2021 at 02:26:00 UTC, Jack wrote: doesn't this work when called from member in a derived class? ```d class A { void doSomething(this T)() { writefln("name = [%s]", __traits(identifier, T)); } } class K : A { void baa()

Re: get type name from current class at compile time?

2021-04-24 Thread Jack via Digitalmars-d-learn
On Sunday, 25 April 2021 at 02:26:00 UTC, Jack wrote: 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 {

Re: get type name from current class at compile time?

2021-04-24 Thread Jack via Digitalmars-d-learn
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]",

Re: get type name from current class at compile time?

2021-04-24 Thread Jack via Digitalmars-d-learn
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]",

Re: get type name from current class at compile time?

2021-04-24 Thread Ali Çehreli via Digitalmars-d-learn
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()