This passes everything except 2 tests, which I listed in another answer
import std.algorithm : startsWith, canFind; template isTemplate(alias B) { enum isTemplate = !__traits(compiles, {auto x=B;}) // excludes values && !__traits(compiles, {B x;}) // excludes types && __traits(compiles, {alias B x;}) // excludes instance members && !B.stringof.startsWith("module ", "package ") // excludes modules && !B.stringof.canFind("!("); // excludes instantiated templates }
Two tests that failed:
struct Inner2(string U="!(") {} static assert(isTemplate(Inner2));
If you are sure that the template will not contain a default argument containing "...!(..." , I think it is safe to use.
kennytm
source share