advanced function binding

Jason House jason.james.house at gmail.com
Mon Apr 16 19:11:13 PDT 2007


Out of curiosity, not have call accept a delegate instead of a class? 
That would make wrapper independent of the specific class (B)...

Moritz Warning wrote:
> 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