Cascading, variable mixins
BCS
ao at pathlink.com
Mon Oct 1 21:01:32 PDT 2007
Reply to Slavisa,
>> 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;
> }
> --------------------------------------------
I haven't tried it but this may work
template B(alias T)
{
template inner()
{
public void foo()
{
writefln("This is template-code from Template B");
}
mixin T;
}
}
class A(alias T)
{
mixin T.inner;
}
auto a = new A! ( B!(B2) ) ();
More information about the Digitalmars-d-learn
mailing list