Compile time function execution...

Bill Baxter dnewsgroup at billbaxter.com
Fri Feb 16 14:55:26 PST 2007


Walter Bright wrote:
> Bill Baxter wrote:
>> I'd like to write this:
>>
>> char[] NReps(char[] x, int n)
>> {
>>     char[] ret = "";
>>     for(int i=0; i<n; i++) { ret ~= x; }
>>     return ret;
>> }
>>
>> But that doesn't work.
> 
> It does when I try it:
> ---------------------
> import std.stdio;
> 
> char[] NReps(char[] x, int n)
> {
>     char[] ret = "";
>     for(int i=0; i<n; i++) { ret ~= x; }
>     return ret;
> }
> 
> void main()
> {
>    static x = NReps("3", 6);
>    writefln(x);
> }
> -----------------------
> prints:
> 
> 333333


Doh!  You're right.  I must have had some other bad code commented in 
accidentally at the time.

--bb



More information about the Digitalmars-d mailing list