Quiz of the day: Why does this not work?
Sean Kelly
sean at invisibleduck.org
Thu Nov 6 14:34:57 PST 2008
Jarrett Billingsley wrote:
> On Thu, Nov 6, 2008 at 4:23 PM, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>>
>> Won't make a difference. ClassInfo does not override the default opEquals,
>> which does an is compare.
>
> Even if it did, it's not really enough to do something like a name
> compare to see if the two typeinfos are the same. (Actually now that
> I think about it, I think classinfo does that.. or did at some point
> in the past.)
Oops, you're right. TypeInfo does a name comparison but ClassInfo does
an identity comparison.
> You would have to check and make sure that every piece
> of the type - every member, every method, all the bases - were the
> same in order for the types to be "equal". This is obviously a
> nontrivial operation and not something you want to have happen every
> time you do a cast.
I'd expect a name comparison to be sufficient so long as the name is the
fully qualified name of the class. At least within a single binary.
There's obviously the rare chance that different class implementations
could have the same name between an app and a DLL. So my suggestion
wouldn't have worked in every case anyway.
> Having duplicated typeinfos is always bad news. The best solution -
> the one that DDLs and SOs provide - is the only sane, correct one: use
> the same damn typeinfo for the same types.
Agreed. It would be nice to gain some traction here.
Sean
More information about the Digitalmars-d
mailing list