Examining Members of a module at Compile Time
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 29 16:30:19 PDT 2014
On Thursday, 29 May 2014 at 23:18:32 UTC, Dicebot wrote:
> class Test {}
>
> class TestChild: Test {}
>
> class TestChildChild: TestChild {}
>
> alias Alias(alias Symbol) = Symbol; // this does the trick
>
> void main()
> {
> foreach (item; __traits(allMembers, mixin(__MODULE__)))
> {
> alias sym = Alias!(__traits(getMember, mixin(__MODULE__),
> item));
> static if (is(sym == class))
> {
> pragma(msg, item);
> }
> }
> }
>
> // http://dpaste.dzfl.pl/e3ce615ca188
Thanks, that works. It's not a perfect solution, though. It will
fail to fail if you pass it something beside a symbol, instead
failing silently. But it works okay for my use case.
More information about the Digitalmars-d-learn
mailing list