Template for going from Array --> list of args

Don Clugston dac at nospam.com.au
Wed Jan 31 03:10:17 PST 2007


Frits van Bommel wrote:
> 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...

I'm almost certain you're right. If inside the loop, you insert asm 
statements, they are placed after each other, with no indication that 
the loop ever existed. (Makes it possible to write a compile-time 
compiler that writes directly to asm code...).


More information about the Digitalmars-d-learn mailing list