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

Sebastiaan Koppe mail at skoppe.eu
Mon Sep 14 16:56:21 UTC 2020


On Monday, 14 September 2020 at 15:38:07 UTC, FeepingCreature 
wrote:
> You mean:
>
> mixin(generate!"T").
>
> "token" :)

You are mixin-in the T right inside the template, where T is 
defined. That is not always the case though.

----

struct S {
   mixin(generate!int);
}

string generate(T)() {
   // [...] bunch of introspect code
   return "T blah;"; // no works
}

---

but by introducing an intermediate layer it works:

---

struct S {
   mixin generate!int;
}

mixin template generate(T) {
   mixin(generateImpl!T);
}

string generateImpl(T)() {
   // [...] bunch of introspect code
   return "T blah;";
}

---

So yeah, it can work without stringof. But is it any better? I 
don't think so.


More information about the Digitalmars-d mailing list