Compile time function execution...

Daniel919 Daniel919 at web.de
Fri Feb 16 10:21:43 PST 2007


Hi, GREAT new feature !

1) There is a bug with parentheses:
---------------------------------------------
import std.stdio;

template eval(A...) { alias A eval; }

char[] trimfirst(char[] s)
{
	int x = 0;
	foreach (char each; s) {
		if (each != ' ')
			return s[x .. $];
		x++;
	}
	return s;
}

void main()
{
	writefln(eval!(trimfirst("  test")));
	writefln(trimfirst("  test"));
}
---------------------------------------------
 >  test
 >test

So you see, the compile-time version doesn't work.


Now change line 9-10 to:
		if (each != ' ') {
			return s[x .. $];
		}

And voila ! Output is correct:
 >test
 >test


2) Would it be possible to make this working ?
writefln(eval!(std.string.stripl("  test")));

And all the other string functions from phobos, too ?


Daniel



More information about the Digitalmars-d mailing list