call member function alias

Ellery Newcomer ellery-newcomer at utulsa.edu
Fri Aug 24 13:01:46 PDT 2012


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.


More information about the Digitalmars-d-learn mailing list