Why is there no range iteration with index by the language?

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Wed Jun 10 13:14:47 UTC 2020


On Tuesday, 9 June 2020 at 23:53:16 UTC, Q. Schroll wrote:
> Is there any particular reason why std.range : enumerate is a 
> thing

Someone already mentioned dictionary.

Consider that most ranges don't actually have an index. In this 
case you aren't actually asking to add indexes, but a count of 
iteration.

For those ranges which do have indexing, what if the range is 
iterating from a location in the middle. Now you have an 
iteration count but not the true index. `enumerate` allows for 
specifying a starting number but this still isn't sufficient 
since a filter could easily jump to any index.

Now none of this may come as a surprise to you, but having an 
iteration counter and an array index using the same api does open 
the door for confusion.


More information about the Digitalmars-d-learn mailing list