Suggestion to implement __traits(getImports, Scope)

Yuriy via Digitalmars-d digitalmars-d at puremagic.com
Thu May 8 12:17:27 PDT 2014


Adam, that doesn't seem to work for me:
import std.typetuple;
import std.string;
import std.stdio;

template isImport(string i)
{
     static if (__traits(compiles, mixin(i).stringof) && 
mixin(i).stringof.startsWith("module "))
         enum isImport = true;
     else
         enum isImport = false;
}

alias GetModuleImports(string moduleName) = Filter!(isImport, 
__traits(allMembers, mixin(moduleName)));

unittest
{
     foreach(i; GetModuleImports!__MODULE__)
     {
         writeln("import ", i.stringof);
     }
}

This will output just:
import "object"

What did i miss here?


More information about the Digitalmars-d mailing list