On 08/23/2012 11:47 PM, Jacob Carlborg wrote:

How about this:

import std.stdio;

class Foo
{
     auto forward (alias fn, Args...) (Args args)
     {
         return fn(args);
     }

     void bar (int a = 3)
     {
         writeln("bar ", a);
     }
}

auto call (alias fn, T, Args...) (T t, Args args)
{
     t.forward!(fn)(args);
}

void main ()
{
     auto foo = new Foo;
     call!(Foo.bar)(foo);
     call!(Foo.bar)(foo, 4);
}

Prints:

bar 3
bar 4

Could this work for you?


Nope :)

class Zoo: Foo
{
    override void bar(int a = 3) {
        writeln("Zoobar: ", a);
    }
}


auto zoo = new Zoo;
call!(Foo.bar)(zoo,4); // prints Zoobar: 4

And anyways, my two solutions composed together quite nicely.

Reply via email to