Iterate all visible symbols, even from imported modules

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 18 06:00:16 PDT 2016


As per title, is it possible to iterate all visible symbols of 
the current module and of all imported modules and packages? My 
aim is to find everything in scope that has a specific UDA.

module foo;

import std.stdio, std.array, std.algorithm;

void bar(){}

struct S{}

void main()
{
     // prints ["object", "std", "bar", "S", "main"]
     // how do I discover that "std" is a package?
     writeln([__traits(allMembers, foo)]);


     // prints ["object", "core", "std", "KeepTerminator", 
"GCC_IO", ... ]
     // strange thing: it looks the same even if I remove all 
imports other than std.stdio
     writeln([__traits(allMembers, foo.std)]);
}

Thank you in advance.


More information about the Digitalmars-d-learn mailing list