foreach range with index
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 14 15:02:30 PDT 2017
On 06/14/2017 12:22 PM, Steven Schveighoffer wrote:
> foreach(i, v; hashmap) => i is counter, v is value
>
> Later hashmap adds support for iterating key and value. Now i is key, v
> is value. Code means something completely different.
>
> Compare with
>
> foreach(i, v; hashmap.enumerate)
>
> Intent is clear from the code.
>
> -Steve
Then, perhaps we're arguing in favor of
* writing .enumerate even for slices (implying that automatic indexing
for them has been a historical artifact and code that wants to be
portable should always write .enumerate)
* making sure that enumerate() on arrays don't bring extra cost
Ali
More information about the Digitalmars-d
mailing list