TypeFunction example: reason about class hierachies
Stefan Koch
uplink.coder at googlemail.com
Sat Oct 24 20:27:37 UTC 2020
Hi Folks,
Luckily no one uses type functions yet otherwise I would have to
announce a breaking change.
The type of types changed it's name again from __type to __type__.
Since it turns out that the glibc in.h header uses __type as a
parameter name already.
Let's hope no one is using __type__.
Because the only option I have after that is
'__type___make_______bloody_sure____no_one_____uses_this____as_an_identifier'
The code below should be fairly self explanatory.
Please let me know what you think
---
alias type = __type__;
type getSuper(type T)
{
return __traits(getSuper, T);
}
class B {}
class C : B{}
class D : B {}
bool eq(type A, type B)
{
return is(A == B);
}
pragma(msg, getSuper(B).eq(getSuper(C)) ); // false
pragma(msg, getSuper(C).eq(B) ); // true
pragma(msg, getSuper(D).eq(getSuper(C)) ); // true
---
P.S. getting is(Myclass SuperType == super) to work, requires
unreasonably much code.
Since I would need to extend my partial evaluation system ...
let's not go into it.
I can explain it though if desired.
Besides ... the syntax is one of the things I always look up.
__traits(getSuper) should be more intuitive.
More information about the Digitalmars-d
mailing list