[Issue 9628] New: Lambda in foreach loop Vs. lambda in static foreach loop

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 1 16:48:19 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9628

           Summary: Lambda in foreach loop Vs. lambda in static foreach
                    loop
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-03-01 16:48:17 PST ---
This program shows two similar versions of the same loop:



import std.stdio, std.algorithm, std.typetuple, std.range;

void main() {
    auto items = [[10, 20], [30]];

    foreach (_; 0 .. 2) {
        foreach (sub; items) {
            iota(sub.length)
            .map!((i){ writeln(sub); return 0; })
            .array();
        }
    }

    writeln();

    foreach (_; TypeTuple!(0, 1)) {
        foreach (sub; items) {
            iota(sub.length)
            .map!((i){ writeln(sub); return 0; })
            .array();
        }
    }
}


Its output (dmd 2.063alpha):

[10, 20]
[10, 20]
[30]
[10, 20]
[10, 20]
[30]

[10, 20]
[10, 20]
[30]
[30]
[30]
[30]


Probably the two loops should give the same output.

(Also, this program can't be compiled with -inline).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list