On 8/21/21 2:48 PM, jfondren wrote:
On Saturday, 21 August 2021 at 21:13:58 UTC, Jeremy T. Gibson wrote:
On Saturday, 21 August 2021 at 18:27:34 UTC, Ali Çehreli wrote:
return __traits(identifier, typeof(this));
That works perfectly! Thanks. =)
This is exactly the solution you linked to in your first post, and found
wanting.
```d
class Whoami {
string name() {
return __traits(identifier, typeof(this));
}
}
class AnotherOne : Whoami { }
unittest {
assert((new Whoami).name == "Whoami");
assert((new AnotherOne).name == "Whoami");
}
```
I did not read the linked thread but a "this template parameter" seems
to work in this case:
class Whoami {
string name(this This)() const {
return __traits(identifier, This);
}
}
class AnotherOne : Whoami { }
unittest {
assert((new Whoami).name == "Whoami");
assert((new AnotherOne).name == "AnotherOne");
}
void main() {
}
Ali