match class specialization
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Wed Apr 25 11:33:45 PDT 2007
BCS wrote:
> template TestA(U : A!(T))
> {
> const bool TestA = true;
> }
>
> template TestA(U)
> {
> static if(is(U.superof))
> const bool TestA = TestA!(U.superof);
> else
> const bool TestA = false;
> }
>
> This compiles but doesn't work.
There's no mention in the spec (at least, that I or Google can find) of
a "superof" property. Google did find two previous threads where it's
mentioned mentioning in the newsgroup archives, but the only post
claiming it should already work seems to be posted by you...
By the way, above code probably only compiles because .superof is only
mentioned in an is() expression (which therefore evaluates to false) and
a syntactically-correct declaration in the false branch of a static if.
> I seem to recall that there is no way to
> get the base class of a type at compile time (that is what .superof is
> supposed to be doing) If that can be replaced with something that
> acutely works, the above would work, I think.
As I posted just before you (you probably missed it while posting), this
seems to work:
---
static if (is(U Bases == super) && is(Bases[0] == class))
// Bases[0] is th base class
}
---
More information about the Digitalmars-d-learn
mailing list