Inheritance of mixin

Andrew Benton via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 28 17:32:54 PDT 2016


On Thursday, 28 April 2016 at 12:28:23 UTC, tsbockman wrote:
> On Thursday, 28 April 2016 at 10:21:34 UTC, Andrew Benton wrote:
>> So to the point: Is there an easier way to do this that I'm 
>> missing?  Is there a language-design reason that mixed in 
>> templates can't inherit?  It seems like an intuitive use of 
>> mixin.
>
> Mixins are (mostly) just a convenient way to generate code, 
> given some parameters. They aren't supposed to work any 
> differently than the same code would if you instantiated the 
> mixin by hand and inserted its contents at each usage site.

I understand that is the point of mixin, as it exists today.  It 
also seems like it isn't capable of what I want.

> (I'll skip your example code here, since it has some problems 
> and won't compile without significant changes.)

I'm not sure what issues you're having that are significant.  I 
forgot to close a string, but the rest compiles and executes for 
me.

> Doing this manually requires that some code be added to 
> Inheritor. Using a mixin doesn't - and shouldn't - change this.

What I'm trying to get at is that I want to add behavior to a 
hierarchy.  I know that I can get that done in a _really_ light 
example with a templated function, or in a heavier example by 
repeating my code.  The problem with the former is that it 
doesn't actually cover my use case.  The problem with the later 
is that any architect that sees that amount of repetition will 
likely start pulling their hair out.  What are the reasons that 
mixin shouldn't be able to be used to change the behavior of a 
whole hierarchy?



More information about the Digitalmars-d mailing list