range behaviour

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 05:34:47 PDT 2014


On Wednesday, 14 May 2014 at 14:00:18 UTC, Ola Fosheim Grøstad 
wrote:
> On Wednesday, 14 May 2014 at 13:29:35 UTC, Dicebot wrote:
>>  9 int foo1(int max)
>> 10 {
>> 11     int sum = 0;
>> 12     for (auto i = 0; i < max; ++i)
>> 13     {
>> 14         sum += i*2;
>> 15     }
>> 16     return sum;
>> 17 }
>
> This isn't really a loop. It is an expression: n*(n+1)
>
> Try something more realistic such as doing alpha-blending to a 
> buffer or DSP.

I think it is your turn to make a counter-example ;) It does not 
matter that much what loop actually does. It was effectively an 
expression here but compiler was able to reduce range version to 
quite the same expression despite all the intermediate code. Of 
course there are still many ways to fool existing optimizers but 
declaring fundamental inability to do so? No way.


More information about the Digitalmars-d mailing list