Thread overview
[Issue 3444] foreach(i, elem; range) should work
Feb 15, 2018
RazvanN
Feb 15, 2018
Simen Kjaeraas
May 16, 2018
Dmitry Olshansky
Sep 08, 2022
RazvanN
February 18, 2016
https://issues.dlang.org/show_bug.cgi?id=3444

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--
February 15, 2018
https://issues.dlang.org/show_bug.cgi?id=3444

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
This has been implemented. Closing as fixed.

--
February 15, 2018
https://issues.dlang.org/show_bug.cgi?id=3444

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |simen.kjaras@gmail.com
         Resolution|FIXED                       |---

--- Comment #5 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
Really? Cause this fails to compile for me:

unittest {
    import std.range, std.stdio;
    foreach (i, e; 100.iota)
        writeln(i, ": ", e);
}

Error: cannot infer argument types, expected 1 argument, not 2

Adding types for i and e, or using ranges other than iota, don't seem to change the result. This is on DMD 2.078.2 on Windows.

There's a workaround in std.range.enumerate. If that's the implementation you refer to, please include that information. If there's an implementation of this in an upcoming DMD release, please include that information.

--
May 16, 2018
https://issues.dlang.org/show_bug.cgi?id=3444

Dmitry Olshansky <dmitry.olsh@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh@gmail.com

--- Comment #6 from Dmitry Olshansky <dmitry.olsh@gmail.com> ---
(In reply to Simen Kjaeraas from comment #5)
> Really? Cause this fails to compile for me:
> 
> unittest {
>     import std.range, std.stdio;
>     foreach (i, e; 100.iota)
>         writeln(i, ": ", e);
> }
> 
> Error: cannot infer argument types, expected 1 argument, not 2
> 
> Adding types for i and e, or using ranges other than iota, don't seem to change the result. This is on DMD 2.078.2 on Windows.
> 
> There's a workaround in std.range.enumerate. If that's the implementation you refer to, please include that information. If there's an implementation of this in an upcoming DMD release, please include that information.

This works today. And arguably there many other use cases that could work in
the same way, so I do doubt the niche case of 0..n indexing will be worth
the enhancement to the compiler especially as it uses the same exact syntax as
tuple unpacking.


void main() {
    import std.range, std.stdio;
    foreach (i, e; 100.iota.enumerate)
        writeln(i, ": ", e);
}

--
September 08, 2022
https://issues.dlang.org/show_bug.cgi?id=3444

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Simen Kjaeraas from comment #5)
> Really? Cause this fails to compile for me:
> 
> unittest {
>     import std.range, std.stdio;
>     foreach (i, e; 100.iota)
>         writeln(i, ": ", e);
> }
> 
> Error: cannot infer argument types, expected 1 argument, not 2
> 
> Adding types for i and e, or using ranges other than iota, don't seem to change the result. This is on DMD 2.078.2 on Windows.
> 
> There's a workaround in std.range.enumerate. If that's the implementation you refer to, please include that information. If there's an implementation of this in an upcoming DMD release, please include that information.

I was referring to the enumarate workaround. Sorry for not being explicit.

As Dmitri has pointed out, the additional complexities added to support this aren't worth it since we have a decent workaround.

--