IFTI - first impressions

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Mar 9 01:01:22 PST 2006


Sean Kelly wrote:
> Oskar Linde wrote:
>> Hello,
>>
>> With the new IFTI support, I just had to do some quick tests. It turns 
>> out it works perfectly given its limitations. I had to rewrite some 
>> templates to be more IFTI-friendly. One example:
>>
>> Before:
>>
>> template filter(T:T[]) {
>>     T[] filter(T[] arr, bool function func(T)) {
>>         ...
>>     }
>> }
>>
>> After:
>>
>> template filter(ArrTy, FuncTy) {
>>     ArrTy filter(ArrTy arr, FunTy fun) {
>>         ...
>>     }
>> }
> 
> This should only be a temporary measure.  Once IFTI matures a bit, your 
> original function should work as expected.  In fact, the first form is 
> necessary in some cases to make sure the proper overload is called.

A quick way to make many cases of template specializations to work is to 
write a template wrapper function:

template func(A,B) {
	void func(A a, B b) {
		func_imp!(A,B)(a,b);
	}
}

But it doesn't cover all cases of course...

/Oskar



More information about the Digitalmars-d mailing list