<div class="gmail_extra">On 27 November 2012 17:49, Gor Gyolchanyan <span dir="ltr"><<a href="mailto:gor.f.gyolchanyan@gmail.com" target="_blank">gor.f.gyolchanyan@gmail.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Can you implement this use case?<div>Have classes mix in something,, which will register them in a single place, which can later suppl the registered classes as a type tuple.</div>
</blockquote><div><br></div><div>I don't do it as a type tuple, why do you need that?</div><div>I do it as a runtime registry.</div><div><br></div></div><div class="gmail_quote">I have 'mixin RegisterModule;' at the top of every module. RegisterModule looks kinda like:<br>
</div><div class="gmail_quote"><br></div><div class="gmail_quote">mixin template RegisterModule()</div><div class="gmail_quote">{</div><div class="gmail_quote"> // produces a module constructor that collects all the things you're interested in and registers them with a central repository.</div>
<div class="gmail_quote"> shared static this()<br> {</div><div class="gmail_quote"> foreach(m; __traits(allMembers, mixin(moduleName!FindModules))<br></div><div class="gmail_quote"> {</div><div class="gmail_quote">
// work out if you're interested in 'm'</div><div class="gmail_quote"> static if(isInterested!(mixin(m)))</div><div class="gmail_quote"> {</div><div class="gmail_quote"> // register the thing you're interested in with some global registry</div>
<div class="gmail_quote"> RegisterThing(&mixin(m));</div><div class="gmail_quote"> }<br></div><div class="gmail_quote"> }</div><div class="gmail_quote"> }<br></div><div class="gmail_quote">}</div><div class="gmail_quote">
<br></div><div class="gmail_quote">Then I can query the registry at runtime.</div><div class="gmail_quote"><br></div><div class="gmail_quote">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.</div>
<div class="gmail_quote">I suspect this could only be done with a recursive template, since I don't think foreach over allMembers can append to a tuple...</div></div>