Bug with writeln?

Simen Kjærås simen.kjaras at gmail.com
Thu Sep 6 09:19:51 UTC 2018


On Thursday, 6 September 2018 at 09:06:21 UTC, Simen Kjærås wrote:
> On Thursday, 6 September 2018 at 08:40:08 UTC, Saurabh Das 
> wrote:
>> Is this a bug with writeln?
>
> Yup. What happens is writeln destructively iterates over b[i]. 
> Since b[i] is a forward range, this shouldn't be done 
> destructively. Instead, a copy should be made using b[i].save, 
> somewhere deep in Phobos' bowels.
>
> For now, here's a workaround:
>
> writeln(b.dup);
> writeln(b); // Look ma, it works twice!
>
> .dup creates a copy of the array, and the destructive iteration 
> happens on the copy instead.

Issue: https://issues.dlang.org/show_bug.cgi?id=19229
PR: https://github.com/dlang/phobos/pull/6695


More information about the Digitalmars-d-learn mailing list