The future of UDAs.

Manu turkeyman at gmail.com
Tue Nov 27 08:19:50 PST 2012


On 27 November 2012 17:49, Gor Gyolchanyan <gor.f.gyolchanyan at 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...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121127/f32be5a2/attachment.html>


More information about the Digitalmars-d mailing list