Why is indexed foreach restricted to build in array ?

Jakob Ovrum via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 11 03:53:44 PDT 2015


On Saturday, 11 April 2015 at 10:50:17 UTC, matovitch wrote:
> Hello,
>
> The question is in the title. It should be possible for a 
> finite random access ranges to perform an indexed foreach no ? 
> I mean like :
>
> foreach(size_t i = 0, auto ref x; R)
> {
>     /*...*/
> }
>
> Why are other foreach statements overloadable but this one ?
>
> Thanks in advance.

As of 2.067, you can use std.range.enumerate[1]. See the PR that 
added it[2] and the enhancement request that proposed it[3] for 
more information about why it's a library function.

[1] http://dlang.org/phobos/std_range#enumerate
[2] https://github.com/D-Programming-Language/phobos/pull/1866
[3] https://issues.dlang.org/show_bug.cgi?id=5550


More information about the Digitalmars-d-learn mailing list