On Tuesday, 3 June 2014 at 05:40:44 UTC, Edwin van Leeuwen wrote:
On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote:
On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen
wrote:
As you may have guessed, a workaround is to copy the iteration
variable yourself:
unittest {
On 06/02/2014 10:40 PM, Edwin van Leeuwen wrote:
On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote:
On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote:
As you may have guessed, a workaround is to copy the iteration
variable yourself:
unittest {
size_t
I've run across this myself. The workaround I used was to call a
function from inside the foreach loop, and in that function you
construct the delegate (with the index variable passed as a
parameter).
Hah, sorry, I didn't read the last post. I did exactly what Ali
just suggested.
On Tuesday, 3 June 2014 at 07:00:35 UTC, Ali Çehreli wrote:
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);
}
assert( events[1]()
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:
On Mon, 02 Jun 2014 19:43:58 -0400, Rene Zwanenburg
renezwanenb...@gmail.com wrote:
On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote:
I'm probably missing something basic, but I am confused by what is
going on in the following code.
unittest {
size_t delegate()[size_t]
On Tuesday, 3 June 2014 at 13:30:13 UTC, Steven Schveighoffer
wrote:
There is a school of thought (to which I subscribe) that says
you shouldn't allocate a separate closure for each loop
iteration.
Basically, a closure will only use the stack frame of the
calling function, not any loop
On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote:
I'm probably missing something basic, but I am confused by what
is going on in the following code.
unittest {
size_t delegate()[size_t] events;
foreach( i; 1..4 ) {
events[i] = { return i; };
}
writeln(
On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote:
On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote:
As you may have guessed, a workaround is to copy the iteration
variable yourself:
unittest {
size_t delegate()[size_t] events;
foreach(_i; 1..4 ) {
10 matches
Mail list logo