Compile time function execution...
Walter Bright
newshound at digitalmars.com
Fri Feb 16 01:42:20 PST 2007
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
More information about the Digitalmars-d
mailing list