member function as template parameter workaround needed

timotheecour thelastmammoth at gmail.com
Thu Sep 13 17:15:08 PDT 2012


> Why not pass it as a runtime argument?
> void run(Fun, T...)(Fun fun, T args)

Yes I actually ended up doing that however the behavior seems 
very buggy / unpredictable.

It has issues when the class is defined in a different modules, 
but not always!

Here's a very weird example:

file main.d:
----
import fun;

void run3(Fun,T...)(Fun fun,T args){
	fun(args);
}

class A1{
	void fun1(double x){
	}
	double fun2(double x){
		return x;
	}
	auto fun3(double x){
		return x;
	}
	auto fun4(double x){
	}
}

void main(){
	test1;
	test2;
}
void test1(){
	auto a=new A1;
	run3(&a.fun1,1);
	run3(&a.fun2,1);
	run3(&a.fun3,1);
	run3(&a.fun4,1);
}

void test2(){
	auto a=new A2;
	run3(&a.fun1,1);
	run3(&a.fun2,1);
	run3(&a.fun3,1);//CT error
	run3(&a.fun4,1);//CT error
}


-----

file fun.d:
----
module fun;

class A2{
	void fun1(double x){
	}
	double fun2(double x){
		return x;
	}
	auto fun3(double x){
		return x;
	}
	auto fun4(double x){
	}
}
----

There are other weird behaviors even without the auto statement, 
when dealing with templates defined outside.

Please help or suggest alternatives! (esp in the case we don't 
want to edit said fun.d file.


More information about the Digitalmars-d-learn mailing list