Enhancing foreach

Ali Çehreli acehreli at yahoo.com
Wed Jan 9 09:45:42 PST 2013


On 01/09/2013 09:07 AM, ixid wrote:
 >> Just like the terser iota,

iota got it wrong. I would expect new users to be confused by iota(5). 
Is that "ends at 5" or "begins with 5"? The latter is more consistent 
with how the function parameters at the and can have default values. So 
it is likely to be perceived as the following. Ignoring that iota is a 
template:

   /* ... */ iota(size_t begin, size_t end = size_t.max);

 >> it's more elegant and easier for newer
 >> users.

I think having multiple ways of doing the same thing is confusing.

 > It would be even nicer to be able to write for(i;5) and have it behave
 > as foreach.

Maybe nicer but not helpful. What is the meaning of the following?

   for (i; ++j) {
       /* ... */
   }

Did I forget something or is it "from zero to the incremented value of j"?

Ali



More information about the Digitalmars-d-learn mailing list