On Thursday, 8 May 2014 at 21:38:12 UTC, Andrei Alexandrescu wrote:
Interesting. So then the range returned by format() will save everything passed to it, which means...

int fun(int[] a)
{
   auto before = format("Before: %s", a);
   foreach (ref e; a) ++e;
   auto after = format("After: %s", a);
   writeln(before, "\n--->\n", after);
}

*ouch*

Andrei

void fun(int[] a)
{
   auto before = a.map!(a => a + 1);
   foreach (ref e; a) ++e;
   auto after = a.map!(a => a + 1);
   writeln(before, "\n--->\n", after);
}

Laziness and mutable references are not the best of friends.

Reply via email to