On 27 November 2012 17:49, Gor Gyolchanyan <gor.f.gyolchanyan@gmail.com> wrote:
Can you implement this use case?Have classes mix in something,, which will register them in a single place, which can later suppl the registered classes as a type tuple.
I don't do it as a type tuple, why do you need that?
I do it as a runtime registry.
I have 'mixin RegisterModule;' at the top of every module. RegisterModule looks kinda like:
mixin template RegisterModule()
{
// produces a module constructor that collects all the things you're interested in and registers them with a central repository.
shared static this()
{
foreach(m; __traits(allMembers, mixin(moduleName!FindModules))
{
// work out if you're interested in 'm'
static if(isInterested!(mixin(m)))
{
// register the thing you're interested in with some global registry
RegisterThing(&mixin(m));
}
}
}
}
Then I can query the registry at runtime.
If you insist it be a type tuple, you'd need to import everything into the one location where you intend to do this work, and recursively scan allMembers of all the imported modules. You could probably produce a tuple that way, but the catch being that the location that generates the tuple needs to import everything that could ever appear in the tuple.
I suspect this could only be done with a recursive template, since I don't think foreach over allMembers can append to a tuple...