Instantiate templated class at runtime
Simen Kjærås
simen.kjaras at gmail.com
Mon May 27 07:51:32 UTC 2019
On Sunday, 26 May 2019 at 17:51:37 UTC, Aphex wrote:
> 1. Is it possible to have a runtime class and struct creator
> function that can deal with templates. It doesn't seem like it
> should be that big a deal. One only needs to actually know the
> size of class and that will depend on the template parameter
> sizes, which if they are known then everything is known?
The root problem is described in
https://issues.dlang.org/show_bug.cgi?id=2484. In short, the D
runtime keeps track of all class types and lets you search
through them and instantiate them if you wish. Sadly, this
doesn't cover templated classes, in part because an instantiation
of a templated class is not necessarily in the module that
defined it, and because there may be multiple identical
instantiations across multiple modules.
Now, templated classes still have .classinfo members, and these
can be used with _d_newclass to create new instances of the
class. I filed an issue with Orange for this:
https://github.com/jacob-carlborg/orange/issues/57
> 2. Is the output or Orange for templated classes correct?
> "Issue1.Y!string.Y" or should it be "Issue1.Y!string"? Else
> this is a bug that I'll need to track down and fix.
The name Issue1.Y!string.Y is correct - 'class Y(T) {}' is short
for 'template Y(T) { class Y {} }'.
--
Simen
More information about the Digitalmars-d-learn
mailing list