mem_fun
オッケーメムファンですね!
http://d.hatena.ne.jp/rinset/20060530/1148987859
import std.stdio; template mem_fun(T) { T (*mem_fun(T (*f)()))(Object o) { return cast(T (*)(Object o))f; } } class C { int val_; this(int val) { val_ = val; } int func() { return val_; } } int main() { auto mf = mem_fun(&C.func); C c1 = new C(1); C c2 = new C(2); writefln(mf(c1)); writefln(mf(c2)); return 0; }
1引数メソッドを2引数にするのは……
import std.stdio; class mem_fun_t(T, U) { T (*fp)(U, Object); this(T (*f)(U, Object)) { fp = f; } T opCall(Object o, U u) { return fp(u, o); } } template mem_fun(T, U) { mem_fun_t!(T, U) mem_fun(T (*f)(U)) { return new mem_fun_t!(T, U)(cast(T (*)(U, Object))f); } } class C { int val_; this(int val) { val_ = val; } int func(int x) { return val_+x; } } int main() { auto mf = mem_fun(&C.func); C c1 = new C(1); C c2 = new C(2); writefln(mf(c1, 3)); writefln(mf(c2, 4)); return 0; }
あ、以下参考に。