Template for going from Array --> list of args

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jan 30 13:11:16 PST 2007


Bill Baxter wrote:
> Kirk McDonald wrote:
>>     ParameterTypeTuple!(typeof(&fn)) t;
> 
> Whoa, didn't realize you could make a variable out of a type tuple.  Or 
> if I did know it once, I completely forgot it.
> 
>>     foreach (i, e; t) {
>>         t[i] = array[i];
>>     }
> 
> I guess this squashes any hope of the thing getting inlined... :-(

Are you sure? 'foreach' with a tuple as aggregate is automatically 
unrolled. Sort of a "static foreach", really. So it's not actually a 
loop. In fact, the index is a compile-time constant.
I'm not sure how the compiler handles this, but I suspect the optimizer 
may not even know it used to be any kind of loop at all...


More information about the Digitalmars-d-learn mailing list