Navigate from ClassInfo to TypeInfo

Daniel Keep daniel.keep.lists at gmail.com
Tue Apr 14 23:33:35 PDT 2009



Frank Benoit wrote:
> Daniel Keep schrieb:
>> davidl wrote:
>>> 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley
>>> <jarrett.billingsley at gmail.com> 写道:
>>>
>>>> 2009/4/14 davidl <davidl at nospam.org>:
>>>>> Send this object to vararg func, and retrieve the TypeInfo there and
>>>>> return?
>>>> No.  The typeinfo passed to vararg functions is also determined at
>>>> compile-time.
>>> so it's a bug?
>>>
>>> I think vararg funcs always want the real typeinfo of the object
>> No, they get the typeinfo of what they're passed.
>>
>>> class A {}
>>> class B : A {}
>>>
>>> void foo(...) {}
>>>
>>> void bar(A a) { foo(a); }
>>>
>>> void main()
>>> {
>>>     scope b = new B;
>>>     bar(b);
>>> }
>> bar cannot possibly know what the "real" TypeInfo of a is.  But that
>> doesn't matter because it's passing an A with A's TypeInfo.  And if foo
>> is maybe interested in Bs, then it can just try to up-cast.
>>
>>   -- Daniel
> 
> Or it can request the classinfo of the passed object. Hey, and now the
> typeinfo please :)

Ok.  What do you propose to do with this TypeInfo?

The ONLY thing a given TypeInfo_Class gives you is the ClassInfo, which
you already have.  The TypeInfo object itself gives you getHash, equals
and compare, all of which are in Object and thus redundant, tsize which
is the size of a pointer, swap which I can't see a use for, next which
is useless, init which is also redundant and flags which is already in
ClassInfo.

Again, why do you even want that specific TypeInfo when it is less
useful than the ClassInfo?

  -- Daniel



More information about the Digitalmars-d mailing list