IFTI - first impressions

Oskar Linde oskar.lindeREM at OVEgmail.com
Wed Mar 8 04:45:03 PST 2006


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) {
		...
	}
}

With a simple map and filter template, the following code works:

const int[] data = [1,2,3,76,2,1,3,45,2];
writefln("data = ", data);

auto squared = map(data, function int(int x) { return x*x; });
writefln("squared = ", squared);

auto sqrooted = map(data, function double(int x) { return 
sqrt(cast(float)x); });
writefln("sqrooted = ", sqrooted);

auto even = filter(data, function bool(int x) { return (x&1) == 0; });
writefln("even = ", even);

auto odd = filter(data, function bool(int x) { return (x&1) == 1; });
writefln("odd = ", odd);

And prints:

data = [1,2,3,76,2,1,3,45,2]
squared = [1,4,9,5776,4,1,9,2025,4]
sqrooted = [1,1.41421,1.73205,8.7178,1.41421,1,1.73205,6.7082,1.41421]
even = [2,76,2,2]
odd = [1,3,1,3,45]

In conclusion, I'm very pleased.
I've attached the full 50-line source code if anyone is interested.

/Oskar
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ifti.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20060308/58631ccb/attachment.ksh>


More information about the Digitalmars-d mailing list