reflection based on my experience so far on compile-time meta-programming in D as a novice user: the problems

Sebastiaan Koppe mail at
Mon Sep 14 09:14:42 UTC 2020

On Monday, 14 September 2020 at 08:01:47 UTC, FeepingCreature 
> There is an easy way to convert between a token and a string: 
> "token". Seriously, stringof should be renamed to 
> stringof__debugOnlyReallyYouDontNeedThisForMetaprogrammingTrustMe. It's like catnip to C people. I don't know if the docs have a big fat warning saying "DO NOT USE THIS FOR METAPROGRAMMING EXCEPT FOR DEBUGGING AND ERROR MESSAGES, TRUST ME" but they probably should. Just use the name of the token metavariable!

I have been trying, but there is one I can't get...


import std;

string generate(T)() {
     return "%s bla;".format(T.stringof);

void main() {
     bla = 5;

More information about the Digitalmars-d mailing list