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

mw mingwu at
Mon Sep 14 17:03:03 UTC 2020

On Monday, 14 September 2020 at 09:14:42 UTC, Sebastiaan Koppe 
> 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() {
>     mixin(generate!int);
>     bla = 5;
> }

Thanks for the simple example to illustrate my points:

-- in D, there are too many choices, with no clear guideline 
which one is *THE* one to use for a particular purpose
-- in D, there is no easy way to convert between token <==> 

from the following discussions of this example, it clearly shows 
people have different choices to pass either the token <int>, or 
string "int", and use ".stringof" or ".mangleof", some leads to 
dead end, some cause scope errors.

(And Sebastiaan is a long timer on this forum than me, yet still 
puzzled to make this simple meta-programming example to work.)

More information about the Digitalmars-d mailing list