casting int[] to bool[]

Saaa empty at needmail.com
Thu Jan 29 12:56:30 PST 2009


This will take some time to understand.
Things I have never used before : D
Tuple, variadic function, template, mixin
.stringof(can't find this one), static if

I'll read up until I understand this.

One question I can ask.
Why is that foreach loop run at compile time?
The compiler checks for a template parameter?

> // declare these at global scope
> template Tuple(T...) { alias T Tuple; }
>
> // Generates a tuple of numbers in the range [0, n)
> template Range(int n)
> {
>    static if(n == 0)
>        alias Tuple!() Range;
>    else
>        alias Tuple!(Range!(n - 1), n - 1) Range;
> }
>
> // then this is your loop in main
> foreach(i, line; data)
> {
>    // this foreach loop is run at compile time
>    foreach(j; Range!(60))
>        mixin("dataIn[i][" ~ j.stringof ~
>            "] = line[14 + 2 * " ~ j.stringof ~ "] == '1';");
> } 




More information about the Digitalmars-d-learn mailing list