I guess I don't really understand the mixin concept after all. Here is the
code example (after cutting it down from a very large source file) that is
giving me grief...
module test;
class Foo
{
template SetStool(T) { void Setter(T A) { BarStool = A;} }
real BarStool;
mixin SetStool!(real); // #1
mixin SetStool!(float); // #2
// void Setter(real A){ BarStool = A; } // #3
// void Setter(float A){ BarStool = A; } // #4
this (float A) { this.Setter( A ); }
this (real A) { this.Setter( A ); }
}
The messages I get are ...
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
Now, if I comment out the lines marked #1 and #2, and uncomment #3 and #4,
it compiles fine.
I thought that the two mixin lines (#1, #2) were exactly equivalent to #3
and #4. In other words, by using the mixin, it was as if I'd actually typed
in the text of the template with the appropriate substitutions.
To make matter more confusing, if I just comment out either *one* of the
mixins, it also compiles okay, making it seem as if I'd typed in the Setter
function in full instead of the mixin.
Can somebody explain to me where my understanding is off track?
--
Derek
Melbourne, Australia
18/02/2005 2:30:28 PM

I guess I don't really understand the mixin concept after all. Here is
the
code example (after cutting it down from a very large source file) that
is
giving me grief...
module test;
class Foo
{
template SetStool(T) { void Setter(T A) { BarStool = A;} }
real BarStool;
mixin SetStool!(real); // #1
mixin SetStool!(float); // #2
// void Setter(real A){ BarStool = A; } // #3
// void Setter(float A){ BarStool = A; } // #4
this (float A) { this.Setter( A ); }
this (real A) { this.Setter( A ); }
}
The messages I get are ...
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
Now, if I comment out the lines marked #1 and #2, and uncomment #3 and
#4,
it compiles fine.
I thought that the two mixin lines (#1, #2) were exactly equivalent to #3
and #4. In other words, by using the mixin, it was as if I'd actually
typed
in the text of the template with the appropriate substitutions.
To make matter more confusing, if I just comment out either *one* of the
mixins, it also compiles okay, making it seem as if I'd typed in the
Setter
function in full instead of the mixin.
Can somebody explain to me where my understanding is off track?

I guess I don't really understand the mixin concept after all. Here is
the
code example (after cutting it down from a very large source file) that
is
giving me grief...
module test;
class Foo
{
template SetStool(T) { void Setter(T A) { BarStool = A;} }
real BarStool;
mixin SetStool!(real); // #1
mixin SetStool!(float); // #2
// void Setter(real A){ BarStool = A; } // #3
// void Setter(float A){ BarStool = A; } // #4
this (float A) { this.Setter( A ); }
this (real A) { this.Setter( A ); }
}
The messages I get are ...
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
Now, if I comment out the lines marked #1 and #2, and uncomment #3 and
#4,
it compiles fine.
I thought that the two mixin lines (#1, #2) were exactly equivalent to #3
and #4. In other words, by using the mixin, it was as if I'd actually
typed
in the text of the template with the appropriate substitutions.
To make matter more confusing, if I just comment out either *one* of the
mixins, it also compiles okay, making it seem as if I'd typed in the
Setter
function in full instead of the mixin.
Can somebody explain to me where my understanding is off track?

Thanks for the hint. Now I read the docs with this fresh perspective, I
suspect its the rule ...
"If two different mixins are put in the same scope, and each define a
declaration with the same name, there is an ambiguity error when the
declaration is referenced"
coming in to play. Up until now, I read this as "two different mixin
_templates_" but it seems that it literally means two "mixin" statements
regardless of the template name they are mixing in.
Well, I was hoping to reduce the amount of typing I had to do but as the
mixin solution involves more typing than copy-paste solution, I guess I
leave mixins for another day.
--
Derek
Melbourne, Australia
18/02/2005 3:37:01 PM

I guess I don't really understand the mixin concept after all. Here is
the
code example (after cutting it down from a very large source file) that
is
giving me grief...
module test;
class Foo
{
template SetStool(T) { void Setter(T A) { BarStool = A;} }
real BarStool;
mixin SetStool!(real); // #1
mixin SetStool!(float); // #2
// void Setter(real A){ BarStool = A; } // #3
// void Setter(float A){ BarStool = A; } // #4
this (float A) { this.Setter( A ); }
this (real A) { this.Setter( A ); }
}
The messages I get are ...
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
test.d(6): function test.Foo.SetStool!(real).Setter conflicts with
test.Foo.SetStool!(float).Setter at test.d(6)
Now, if I comment out the lines marked #1 and #2, and uncomment #3 and
#4,
it compiles fine.
I thought that the two mixin lines (#1, #2) were exactly equivalent to #3
and #4. In other words, by using the mixin, it was as if I'd actually
typed
in the text of the template with the appropriate substitutions.
To make matter more confusing, if I just comment out either *one* of the
mixins, it also compiles okay, making it seem as if I'd typed in the
Setter
function in full instead of the mixin.
Can somebody explain to me where my understanding is off track?

BTW, it would be nice if we could do ...
alias mixin SetStool!(real).Setter Setter;
instead of having to invent a symbol name just for this purpose.

This worked for me:
alias SetStool!(float).Setter Setter;
alias SetStool!(real).Setter Setter;

Thanks. I was so fixated on 'mixin' that I forgot using it a template ;-)

I was actually surprised the mixin-less version worked. I don't think Setter
becomes a member function without using a mixin so I'm not exactly sure what
state Setter is in. Some experiments with subclassing should flush out any
bugs if there are compiler bugs in there.