# HG changeset patch # User thomask # Date 1173611843 0 # Node ID 5cc974ee1e2f69191597960440aa8f367bb2a37c # Parent b9844b283021e575a9eeacefbdc8eb413ab4d922 Re: Compile time function execution... Lionello Lunesu 2007-02-16 http://www.digitalmars.com/webnews/newsgroups.php?group=digitalmars.D&article_id=48917 diff -r b9844b283021 -r 5cc974ee1e2f run/i/interpret_01_A.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/i/interpret_01_A.d Sun Mar 11 11:17:23 2007 +0000 @@ -0,0 +1,32 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ Lionello Lunesu +// @date@ 2007-02-16 +// @uri@ http://www.digitalmars.com/webnews/newsgroups.php?group=digitalmars.D&article_id=48917 +// @desc@ Re: Compile time function execution... + +module dstress.run.i.interpret_01_A; + +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; +} + +int main(){ + char[] a = eval!(trimfirst(" test"))[0]; + if(a != "test"){ + assert(0); + } + return 0; +} diff -r b9844b283021 -r 5cc974ee1e2f run/i/interpret_01_B.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run/i/interpret_01_B.d Sun Mar 11 11:17:23 2007 +0000 @@ -0,0 +1,33 @@ +// $HeadURL$ +// $Date$ +// $Author$ + +// @author@ Lionello Lunesu +// @date@ 2007-02-16 +// @uri@ http://www.digitalmars.com/webnews/newsgroups.php?group=digitalmars.D&article_id=48917 +// @desc@ Re: Compile time function execution... + +module dstress.run.i.interpret_01_B; + +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; +} + +int main(){ + char[] a = eval!(trimfirst(" test"))[0]; + if(a != "test"){ + assert(0); + } + return 0; +}