D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6616 - foreach argument type inference
Summary: foreach argument type inference
Status: RESOLVED DUPLICATE of issue 4090
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-07 00:57 UTC by bearophile_hugs
Modified: 2011-09-07 02:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-09-07 00:57:03 UTC
In this program the Foo struct is large, so I use ref to avoid its copies. I also use const because I want to make sure (and document) the two loops will not change the matrix contents:


struct Foo { int[1000] a; }
void bar(ref Foo x) {}
void main() {
    auto m = new Foo[][](3, 3);
    foreach (const(Foo[]) row; m)
        foreach (ref const(Foo) x; row)
            bar(x);
}


But I'd like type inference there, and be able to write something like:

struct Foo { int[1000] a; }
void bar(ref Foo x) {}
void main() {
    auto m = new Foo[][](3, 3);
    foreach (const row; m)
        foreach (ref const x; row)
            bar(x);
}


With DMD 2.055beta3 this gives:

test.d(5): no identifier for declarator const(row)
test.d(6): no identifier for declarator const(x)
Comment 1 yebblies 2011-09-07 01:14:50 UTC
You're kidding me right?  This is the THIRD time you've reported this exact bug.

*** This issue has been marked as a duplicate of issue 4090 ***
Comment 2 bearophile_hugs 2011-09-07 02:07:39 UTC
I am sorry.
Comment 3 yebblies 2011-09-07 02:15:27 UTC
(In reply to comment #2)
> I am sorry.

Just don't forget to do a quick search first next time!
I know you have over 200 enhancement requests open, but it might be worth going through and checking they all still make sense.