Compile-time reflection and templates
Jean-Louis Leroy
jl at leroy.nyc
Wed Sep 27 19:47:32 UTC 2017
I can identify the templates in a module:
module modtemp;
import std.stdio;
import std.traits;
void foo(T)(T x) {}
void main()
{
foreach (m; __traits(allMembers, modtemp)) {
if (__traits(isTemplate, mixin(m))) {
mixin("alias F = " ~ m ~ ";");
writeln(m);
}
}
}
// output:
// foo
I'd like to go further: find the template arguments and the
function arguments and return types. Looking at __traits and
std.traits, it doesn't seem feasible, but maybe I overlooked
something?
More information about the Digitalmars-d
mailing list