On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote:
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

yea "is" can be a lil confusing, especially that "is( C S == super)" expression.

I take it that "is( C S == super)" is only the bases directly listed for inheritance by the class and not the bases bases as well? which is the reason for the change you made their?

That expression is weird lol.

Reply via email to