[Issue 5655] New: Lambda inside static foreach saves wrong value of counter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 26 09:27:54 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5655
Summary: Lambda inside static foreach saves wrong value of
counter
Product: D
Version: D2
Platform: Other
OS/Version: Mac OS X
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrei at metalanguage.com
--- Comment #0 from Andrei Alexandrescu <andrei at metalanguage.com> 2011-02-26 09:25:07 PST ---
This program should print 1 but instead prints 0. Apparently all lambdas inside
a static foreach loop capture 0.
import std.stdio, std.typetuple;
void main()
{
TypeTuple!(int, float) TT;
void function() funs[2];
foreach (i, T; TT)
{
funs[i] = function { writeln(i); };
}
funs[1]();
}
--
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