[ create a new paste ] login | about

Link: http://codepad.org/SXIP2jBL    [ raw code | output | fork ]

D, pasted on Nov 18:
import std.traits;

class A
{
	void foo(int x) { writefln("A.foo %s", x); }
}

class B : A
{
	override void foo(int x) { writefln("B.foo %s", x); }
}

struct PTM(T, char[] name)
{
	mixin("alias " ~ T.stringof ~ "." ~ name ~ " Method;");

	ReturnType!(Method) opCall(T _this, ParameterTypeTuple!(Method) args)
	{
		return mixin("_this." ~ name ~ "(args)");
	}
}

void main()
{
	auto a = new A();
	auto b = new B();

	PTM!(A, "foo") ptm;
	ptm(a, 3);
	ptm(b, 4);
}


Output:
1
2
A.foo 3
B.foo 4


Create a new paste based on this one


Comments: