mixin troubles

Derek Parnell derek at nomail.afraid.org
Mon Oct 2 21:48:05 PDT 2006


Ok, I'm the first to admit that I don't understand the syntax of mixins. It
just seems *SO* unintuitive that it never sticks in my mind, and when I
look up the documentation I find that it is misleading and/or wrong.

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);
 }


I was expecting that code to be equivalent to ...

 void main()
 {
    int a = 3;
    double b = 3.14;
    typeof(a) y() { return a; }
    typeof(b) z() { return b; }
    assert(y() == 3);
    assert(z() == 3.14);
 }

BTW, the docs say that the instantiation syntax for mixins is 


   mixin Foo!() a y;

that is that the template arguments are placed outside and following the
parenthesis, but that has just got to be wrong.

I quote ...

"
TemplateMixin:
	mixin TemplateIdentifier ;
	mixin TemplateIdentifier MixinIdentifier ;
	mixin TemplateIdentifier !() TemplateArgumentList  ;
	mixin TemplateIdentifier !() TemplateArgumentList  MixinIdentifier ;

MixinIdentifier:
	Identifier
"

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
3/10/2006 2:42:56 PM



More information about the Digitalmars-d-learn mailing list