On 10/12/13 21:42, luminousone wrote: > On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote: >> template isBaseOf(BASE, C) { >> enum isBaseOf = { >> static if (is(C S == super)) >> foreach (A; S) >> static if (is(A==BASE)) >> return true; >> return is(C==BASE); >> }(); >> } > > I like that! Avoids importing std.traits, And will correctly handle > interfaces as well.
It's also buggy. A more useful version would be: template isBaseOf(BASE, C) { enum isBaseOf = { static if (is(C S == super)) foreach (A; S) static if (isBaseOf!(BASE, A)) return true; return is(C==BASE); }(); } Sorry, didn't test this properly; going to blame the dlang is-expression docs. It's not like D has multiple inheritance, so using "base classes" (plural) is very misleading... artur