On Tuesday, 26 February 2013 at 19:03:01 UTC, Ben Gertzfield wrote:
Hi folks,

In preparation for my upcoming talk at DConf 2013, I'm working on a compile-time dependency injection prototype for D.

I'd like part of public interface for this system to take a module at compile time, and return a list of the classes in that module. Something like:

string GetMembers(T)() {
  auto members = [__traits(allMembers, T)];
  return join(result, ", ");
}

Use an alias:

string GetMembers(alias T)() {
  auto members = [__traits(allMembers, T)];
  return join(members, ", ");
}

void main() {
  stdout.writefln("Got members: %s", GetMembers!(std.stdio));
}

Also make sure you parenthesize the call in GetMembers. For some reason these two are different:

GetMembers!std.stdio  // actually calls (GetMembers!std).stdio
GetMembers!(std.stdio)

That could be a bug though.

Reply via email to