foreach (x; a .. b) and foreach_reverse (x; a .. b) should be disallowed for floats

Steven Schveighoffer schveiguy at yahoo.com
Mon May 18 11:09:06 PDT 2009


On Mon, 18 May 2009 13:30:19 -0400, Bill Baxter <wbaxter at gmail.com> wrote:

> On Mon, May 18, 2009 at 9:21 AM, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>> On Mon, 18 May 2009 12:02:30 -0400, Andrei Alexandrescu
>>> I'm a bit leery about this - what if user code has a bug and I  
>>> transform
>>> that into a feature?
>>
>> hm... I guess that's one way to look at it.  I don't anticipate many  
>> typing
>> this by mistake.
>
> Can't you use variables in those ".." expressions?   If so it's not so
> obvious when you see x..y that y is less than x.

And what happens today if y is less than x?  Just no loop iterations, or  
does it wrap?

Honestly, I thought it was a compile time feature only.

Can you use delegates/properties also?

In that case, returning a range that's reversed is the only  
alternative...  It's still better than foreach_reverse(x; 1..4) IMO.

-Steve



More information about the Digitalmars-d mailing list