Introspecting a Module with Traits, allMembers

Maxime Chevalier-Boisvert via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 9 13:04:46 PDT 2014


Hello,

I'm looking to introspect a module, list all the members, iterate 
over them and filter them by kind inside of a static constructor. 
This is in the hope of shortening some hand-written code that is 
quite repetitive (adding many struct instances to an associative 
array in a static constructor).

The code I'm trying to improve upon can be seen here:
https://github.com/maximecb/Higgs/blob/master/source/ir/iir.d#L56

I've done some googling, and it seems I should be able to use the 
allMembers trait 
(http://wiki.dlang.org/Finding_all_Functions_in_a_Module), but 
unfortunately, the module name seems to be unrecognized, no 
matter which way I spell it:

auto members = [__traits(allMembers, "ir.ir")];
pragma(msg, members);

Produces:
ir/iir.d(85): Error: argument has no members

Other people seem to have run into this problem. Am I doing it 
wrong or is this a bug in DMD?


More information about the Digitalmars-d-learn mailing list