mixin troubles
Derek Parnell
derek at nomail.afraid.org
Wed Oct 4 00:02:15 PDT 2006
On Wed, 04 Oct 2006 01:55:45 -0500, Chris Nicholson-Sauls wrote:
> 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);
>
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
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
4/10/2006 5:01:36 PM
More information about the Digitalmars-d-learn
mailing list