Object.factory

Dan Struthers dsstruthers at nospamplease.yahoo.com
Thu Sep 27 10:34:12 PDT 2007


Sean Kelly Wrote:

> DanO wrote:
> > Sean Kelly Wrote:
> > 
> > 
> >> You will need to generate the code for any template you want to generate 
> >> via Object.factory by aliasing or instantiating it at compile-time. 
> >> Otherwise, the code won't even exist in your app.  This should do the trick:
> >>
> >> alias MyDict!(int) GenerateMyDict_int;
> > 
> > Just so everyone knows, all of the templates I am trying to dynamically create are declared and instantiated in the same module where they are defined, and all of the ones I am trying to instantiate are used somewhere in the module, usually as members of other classes.  I have tried every conceivable permutation of things to get it to work, but it just looks like those classes are not in the ModuleInfo.  Probably a compiler issue.
> 
> Sounds like it.  It would be nice if the compiler at least registered 
> templates declared in the same module they are defined.
> 
> 
> Sean

I have found some more interesting tidbits:

<code>
MyDict(T)
{
   T[char[]] dict;
}

alias MyDict!(int) MyDictInt;

auto o1 = MyDict!(int).classinfo.create();  // fails to compile with "undefined identifier MyDict.classinfo"

// but

auto o2 = MyDictInt.classinfo.create();  // works fine
</code>

So, it does look like there are some compiler or parser problems with getting at the template's ClassInfo directly, as well as it not getting inserted into the ModuleInfo.localclasses.  I wonder if they may be related...

Walter, do you have any insight here?  Should I add a bug for this?

=DanO



More information about the Digitalmars-d mailing list