Is there a way to use Object.factory with templated classes? Or some way to construct templated classes given RTTI of an instance?
Chad Joan
chadjoan at gmail.com
Thu Sep 27 18:46:34 UTC 2018
On Thursday, 27 September 2018 at 13:16:58 UTC, Adam D. Ruppe
wrote:
> 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
> )
Yep, that solves the mystery! Thanks!
More information about the Digitalmars-d-learn
mailing list