Ali Çehreli:
Here is a workaround:
unittest {
size_t delegate()[size_t] events;
auto makeClosure(size_t i) {
return { return i; };
}
foreach( i; 1..4 ) {
events[i] = makeClosure(i);
}
You can also use two lambdas to do that, without the
"makeClosure":
http://rosettacode.org/wiki/Closures/Value_capture#Less_Functional_Version
Also don't forget do make the foreach argument immutable (I think
this is a lost war for me. Even smart programmers like you stick
to the defaults, even when they are a design mistake of the
language. So immutability by default is very important).
Bye,
bearophile