advanced function binding

Moritz Warning moritzwarning at web.de
Fri Mar 30 20:55:02 PDT 2007


After some additional input by Kirk (thanks!), this come up for solution:

class Wrapper(B, alias Func, FuncPtr = typeof(&Func)
{
	alias ReturnType!(FuncPtr) R;
	alias ParameterTypeTuple!(FuncPtr) Params;
	char[][] args;
	
	void bind(char[][] u) {
		args = u;
	}
	
	private static FuncPtr get_funcptr() { return &Func; }

	R call(B b) {
		R delegate(Params) dg;
		dg.funcptr = get_funcptr();
		dg.ptr = cast(void*)b;
		Params t;
		foreach (i, arg; t) {
			t[i] = convert!(typeof(arg))(this.args[i]);
		}
		return dg(t);
	}
}

Thread.join()  // ;-)


More information about the Digitalmars-d-learn mailing list