[Issue 15335] getSymbolsByUDA fails if type has private members

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Nov 23 05:56:48 PST 2015


https://issues.dlang.org/show_bug.cgi?id=15335

--- Comment #5 from ryan at rcorre.net ---
Here's another idea, this time with more mixins! Don't have time to test
thoroughly right now but I _think_ its working with private members and giving
back symbols rather than names:

template getMembersByUDA(T, alias attribute) {
  import std.string : format;
  import std.meta : Filter;

  template toSymbols(names...) {
    static if (names.length == 1)
      mixin("alias toSymbols = AliasSeq!(T.%s);".format(names[0]));
    else
      mixin("alias toSymbols = AliasSeq!(toSymbols!(names[1..$]),
%s);".format(names[0]));
  }

  enum hasSpecificUDA(string name) = mixin("hasUDA!(T."~name~", attribute)");

  alias membersWithAttribute = Filter!(hasSpecificUDA, __traits(allMembers,
T));

  alias getMembersByUDA = toSymbols!(membersWithAttribute);
}

mixins are like violence ... if they don't work you're not using enough of
them.
I'll test more later and put up a separate PR if it looks more promising.

--


More information about the Digitalmars-d-bugs mailing list