Ranges of char and wchar

Peter Alexander via Digitalmars-d digitalmars-d at puremagic.com
Sat May 10 05:07:13 PDT 2014


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.



More information about the Digitalmars-d mailing list