Bug with writeln?
Simen Kjærås
simen.kjaras at gmail.com
Thu Sep 6 09:06:21 UTC 2018
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.
--
Simen
More information about the Digitalmars-d-learn
mailing list