[Issue 8224] std.typetuple: foreach loop returns always first element
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 9 12:16:38 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=8224
Simen Kjaeraas <simen.kjaras at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |simen.kjaras at gmail.com
--- Comment #7 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
The problem is reducible to this:
unittest {
import std.stdio, std.typetuple;
const fun1 = () => 0;
const fun2 = () => 1;
foreach (i, f; AliasSeq!(fun1, fun2)) {
alias f2 = Alias!f;
assert(i == f(), "foreach alias works great");
assert(i == f2(), "template is incorrectly cached");
}
}
As we can see, the issue occurs when f is passed to a template. It seems DMD
caches the template instantiation and doesn't update it for each iteration.
--
More information about the Digitalmars-d-bugs
mailing list