mixin troubles

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Oct 4 13:07:07 PDT 2006

"Derek Parnell" <derek at nomail.afraid.org> wrote in message 
news:kawtg2nmq5d6$.1dp41k208dts4.dlg at 40tude.net...

> No such luck ...
> test.d(10): template instance cannot use local 'a' as template parameter
> test.d(3): function test.Foo!(a).Foo cannot access frame of function main
> test.d(10): template instance test.Foo!(a) error instantiating
> test.d(10): mixin Foo!() is not defined

Almost, you "just" have to split it out into an alias:

template Foo(alias b)
 typeof(b) Foo() { return b; }

void main()
 int a = 2;
 float b = 3.25;

 mixin .Foo!(a) tempX;
 mixin .Foo!(b) tempY;

 alias tempX.Foo x;
 alias tempY.Foo y;

 assert(x() == 2);
 assert(y() == 3.25);

That works.  And is the ugliest thing ever. 

More information about the Digitalmars-d-learn mailing list