No index for cycle ranges

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 2 15:31:13 PDT 2011


On Thu, 02 Jun 2011 18:01:21 -0400, Andrej Mitrovic  
<andrej.mitrovich at gmail.com> wrote:

> On 6/2/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>> On Thu, 02 Jun 2011 17:38:38 -0400, Andrej Mitrovic
>> <andrej.mitrovich at gmail.com> wrote:
>>
>>> Well actually all I wanted was a counter variable. I can put the thing
>>> in a for loop or while loop, but I thought that a counter variable is
>>> something that the compiler can always add without too much thinking.
>>
>> Also, BTW, you can still do this with a foreach loop:
>>
>> size_t idx = ~0;  //hacky, I know.
>> foreach(x; range)
>> {
>>     ++idx;
>>     ...
>> }
>>
>> -Steve
>>
>
> Heh, I thought I'd never see a use-case for an overflow. Btw., did ya
> know you can cram more expressions before the range?
>
> size_t idx;
> foreach(x; idx = ~0, [1, 2, 3])
> {
>     writeln(++idx);
> }

That is so... so evil...

I mean the plethora of commas, *shudder*.

:)

-Steve


More information about the Digitalmars-d-learn mailing list