Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?

Adam D. Ruppe destructionator at gmail.com
Thu Sep 27 13:16:58 UTC 2018


On Thursday, 27 September 2018 at 05:18:14 UTC, Chad Joan wrote:
> How does this work?
>
> The language reference states that typeid(Type) returns "an 
> instance of class TypeInfo corresponding to Type".
> (https://dlang.org/spec/expression.html#typeid_expressions)
>
> But then the TypeInfo class doesn't seem to have a .create() 
> method, or at least not one in the documentation:
> https://dlang.org/phobos/object.html#.TypeInfo


I forgot about the create method, lol, that is what you want.

But typeid(obj) - pass it an existing object of the type btw - 
when obj is a class will return TypeInfo_Class - a subclass of 
TypeInfo.

It is *that* which has the create method.
https://dlang.org/phobos/object.html#.TypeInfo_Class.create

(or less horrible docs
http://dpldocs.info/experimental-docs/object.TypeInfo_Class.html
)


More information about the Digitalmars-d-learn mailing list