BetterC and TypeInfo Question
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 22 07:50:45 PDT 2017
On Thursday, 22 June 2017 at 14:30:31 UTC, jmh530 wrote:
> I was looking through the C++ standard library headers and
> noticed <typeinfo> that has a typeid also. One difference with
> D is that it is opt-in as there is some cost using it.
C++ also leaves most the properties for typeinfo to be
implementation defined, meaning things like .name can just return
an empty string. I believe the only thing the standard requires
is consistent opEquals.
Additionally, C++ will only generate it for classes with at least
one virtual member (the main use of it is dynamic casts, or
substitutes thereof, and using those is often bad object oriented
design anyway!)
> I suppose I'm wondering what other differences there are. Could
> TypeInfo be made optional in D, like it is in C++?
Much of it can, yes, and it can also be defined to offer less (or
more! I'm actually a fan of runtime reflection) than it does now.
There's an effort to convert typeinfo to be library templates
instead of a compiler-provided blob like it is now.
But, even in C++, RTTI is necessary for dynamic casting... so how
is D going to address that? I think it is necessary, but can
prolly be quite minimal. I will think about it more later.
More information about the Digitalmars-d-learn
mailing list