Does DMD unroll loops?
Jascha Wetzel
"[firstname]" at mainia.de
Tue Mar 13 02:54:41 PDT 2007
ah, that's nice (and works)
Daniel Keep wrote:
>
> Jascha Wetzel wrote:
>> is there a way to make DMD unroll loops?
>> i can use mixins instead, but it's ugly...
>>
>> struct Vec(T,int dim)
>> {
>> alias Vec!(T,dim) vec_t;
>>
>> T[dim] data;
>>
>> void opAddAssign(vec_t v)
>> {
>> foreach ( int i, inout d; data )
>> d += v.data[i];
>> // alternatively:
>> // for ( int i = 0; i < dim; ++i )
>> // data[i] += v.data[i];
>> }
>> }
>
>> template Tuple(T...)
>> {
>> alias T Tuple;
>> }
>>
>> template Range(int n)
>> {
>> static if( n < 1 )
>> alias Tuple!() Range;
>> else
>> alias Tuple!(Range!(n-1), n) Range;
>> }
>>
>> struct Vec(T,int dim)
>> {
>> alias Vec!(T,dim) vec_t;
>>
>> T[dim] data;
>>
>> void opAddAssign(vec_t v)
>> {
>> // foreach ( int i, inout d; data )
>> // d += v.data[i];
>> // alternatively:
>> // for ( int i = 0; i < dim; ++i )
>> // data[i] += v.data[i];
>> foreach( i ; Range!(dim) )
>> data[i] += v.data[i];
>> }
>> }
>
> Note: not tested, but you should be able to do something like the
> above... :P
>
> -- Daniel
>
More information about the Digitalmars-d
mailing list