[phobos] AutoImplement: Shouldn't it be a mixin template?

Shin Fujishiro rsinfu at gmail.com
Wed Sep 8 10:11:37 PDT 2010


David Simcha <dsimcha at gmail.com> wrote:
> Shouldn't we just make AutoImplement a mixin template instead?  This can 
> be done trivially by mixing the string mixin currently used to implement 
> it into a mixin template's scope.  It seems like it would solve all the 
> relevant problems.

I agree that there should be a mixin template.

Actually, at first I created AutoImplement as a mixin-able template.
But it turned out that template mixins had problems with virtual
functions, and I changed it to a class.


> class Class : Interface1, Interface2 {
>      mixin AutoImplement!(Interface1, generateEmptyFunction, isAbstractFunction);
>      mixin AutoImplement!(Interface2, generateEmptyFunction, isAbstractFunction);
> 
>      // Override the automatic implementation of fun() taking advantage of
>      // template mixin name lookup rules.
>     override void fun() {
>         writeln("Overridden.");
>      }
> }
>
> The killer use case for this would be automatic forwarding for the 
> decorator pattern.  You could just mix in an AutoImplement that forwards 
> all of your decorator interface functions to the encapsulated object, 
> and then override whichever ones you need to.

Bug 2740 blocks such a use of template mixins.  In spite of being
annotated as override, your fun() doesn't go into vtable!

Template Mixins do not work as advertised
  http://d.puremagic.com/issues/show_bug.cgi?id=2740

That said, I think we can make AutoImplement a template mixin.  With a
quick test (unit tests), there seems to be no problem to make it so
except for that particular limitation (bug 2740).


Shin


More information about the phobos mailing list