Cascading, variable mixins

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Oct 1 05:20:32 PDT 2007


"Slavisa Radic" <konfusious at gmx.de> wrote in message 
news:fdqo5g$2prv$1 at digitalmars.com...
>
> To illustrate this a little bit:
> ---------------------------
> import std.stdio;
>
> class A(alias T)
> {
>    mixin T;
> }
> -------------------------
>
> module b;
> import std.stdio;
>
> template B(alias T)
> {
>    public void foo()
>    {
>        writefln("This is template-code from Template B");
>    }
>
>    mixin T;
> }
> -------------------------------------------------------------------
>
> module b2;
>
> template B2()
> {
>    public void bar()
>    {
>
>        writefln("And This is Code from a different Template, namely 
> Template B2");
>    }
> }
> --------------------------------
> private import a;
> private import b;
> private import b2;
>
> int main(char[][] args)
> {
>    A! ( B! (B2) ) a = new A! ( B! (B2) ) ();
>    a.foo();
>    a.bar();
>    return 0;
> }
> --------------------------------------------

Try something like..

class A(alias T, Args...)
{
    mixin T!(Args);
}

...

auto a = new A!(B, B2)();
a.foo();
a.bar();

WOrks for me :) 




More information about the Digitalmars-d-learn mailing list