casting int[] to bool[]

Saaa empty at needmail.com
Thu Jan 29 15:22:16 PST 2009


Thanks, that makes sense!
>
> Tuples are like arrays that have a fixed length, where each element can
> be of absolutely any type at all.
>
> What this means is that it potentially takes different code to access
> each element of a tuple.  So when you see
>
>> foreach( i ; Range!(4) ) foo(i);
>
> What is actually being generated is this:
>
>> foo(0);
>> foo(1);
>> foo(2);
>> foo(3);
>
> It's not really doing the foreach at compile time, but it is unrolling
> it.  You might think "but why doesn't this happen for arrays?"  Because
> you can't do THIS with arrays:
>
>> foreach( i,x ; Tuple!(0, "b", 3.0) ) writefln("Element %s == %s",i,x);
>
> Which expands to:
>
>> writefln("Element %s == %s",0,0);
>> writefln("Element %s == %s",1,"b");
>> writefln("Element %s == %s",2,3.0);
>
> -- Daniel 




More information about the Digitalmars-d-learn mailing list