Introspecting a Module with Traits, allMembers
Maxime Chevalier-Boisvert via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 9 13:14:02 PDT 2014
On Wednesday, 9 July 2014 at 20:07:57 UTC, NCrashed wrote:
> On Wednesday, 9 July 2014 at 20:04:47 UTC, Maxime
> Chevalier-Boisvert wrote:
>> auto members = [__traits(allMembers, "ir.ir")];
>> pragma(msg, members);
>
> Have you tried without quotes?
> pragma(msg, __traits(allMembers, ir.ir));
Did need to write it without the quotes, and to add "enum" to
force compile-time evaluation. It's actually ir.ops that I wanted
to list the members of. Got the following snippet to work:
static this()
{
enum members = [__traits(allMembers, ir.ops)];
pragma(msg, members);
}
Prints:
["object", "ir", "jit", "OpArg", "OpInfo", "Opcode", "GET_ARG",
"SET_STR", "MAKE_VALUE", "GET_WORD", "GET_TYPE", "IS_I32", ...]
More information about the Digitalmars-d-learn
mailing list