www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interface inheritance simplification

It would be nice if this is possible:

interface A // : gets inserted by the mixin
     mixin sometemplate!B;   // Is able to make A extend B


interface A : mixin sometemplate!B
    // methods get inserted by the template

instead of

interface A : B
     mixin sometemplate!B;

which locks A to B.

One, I imagine can easily accomplish the same task with mixins 
and static if's but it requires writing code in two places.


interface A : mixin somtemplateA!B
     mixin sometemplateB!B;

The point is to simplify boilerplate code... e.g., write 
interfaces and templates that automatically write default methods 
for you.

I think ideally something like the 2nd example would work best:

interface A : mixin sometemplate!B { }

so that we know A herits B but the template is able to insert 
methods into the body of the interface WITHOUT having to manually 
call another mixin to do so.

One can sort of achieve this with a mixin but it's not a good 
way. e.g.,

interface A : mixin("B { void method(); ")


I *think* will work but the correct syntax is hidden...
Jul 13 2013