Iterate all visible symbols, even from imported modules

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 18 14:12:38 PDT 2016


On Monday, 18 July 2016 at 13:00:16 UTC, Lodovico Giaretta wrote:
> 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.

This answer to a similar question on StackOverflow may be useful:

http://stackoverflow.com/questions/25555329/d-finding-all-functions-with-certain-attribute/25560800#25560800


More information about the Digitalmars-d-learn mailing list