mixin troubles

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Oct 3 23:55:45 PDT 2006


Derek Parnell wrote:
> On Wed, 4 Oct 2006 00:03:17 -0400, Jarrett Billingsley wrote:
> 
> 
>>"Derek Parnell" <derek at nomail.afraid.org> wrote in message 
>>news:327lkdzeqky1$.11w3vhc3ana9f.dlg at 40tude.net...
>>
>>
>>>Anyhow, what am I doing wrong here ...
>>>
>>>template Foo(alias b)
>>>{
>>>   typeof(b) Foo() { return b; }
>>>}
>>>
>>>void main()
>>>{
>>>   int a = 3;
>>>   double b = 3.14;
>>>   mixin Foo!(a) y;
>>>   mixin Foo!(b) z;
>>>   assert(y() == 3);
>>>   assert(z() == 3.14);
>>>}
>>>
>>
>>Mixins bug me too.  Here's the "correct" version of your code:
> 
> 
> Thanks for patience.
>  
> 
>> template Foo(alias b)
>> {
>>    typeof(b) Foo() { return b; }
>> }
>>
>> void main()
>> {
>>    int a = 3;
>>    double b = 3.14;
>>    mixin .Foo!(a) y;
>>    mixin .Foo!(b) z;
>>    assert(y.Foo() == 3);
>>    assert(z.Foo() == 3.14);
>> }
>>
>>Notice the global scope operators on the mixin instantiations, and the 
>>explicit access of y.Foo/z.Foo.
>>

I may be wrong, but I think you could do this:
# mixin .Foo!(a).Foo  y ;
# mixin .Foo!(b).Foo  z ;
# assert(y() == 3);
# assert(z() == 3.14);

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-learn mailing list