Can't recreate a range?

Paul Backus snarwin at gmail.com
Thu Apr 30 13:23:25 UTC 2020


On Thursday, 30 April 2020 at 13:04:47 UTC, Casey wrote:
> Here's a minimal code example that duplicates the issue:
>
> import std.array, std.range, std.stdio, std.traits, std.string;
>
> auto readStream(Range)(auto ref Range r) if 
> (isInputRange!(Unqual!Range))
> {
> 	struct StreamRange(Range)
> 	{
> 		alias R = Unqual!Range;
> 		R _input;
>
> 		auto buff = appender!string;

Using a default value like this means that it will be shared 
among all instances of the struct. Instead, you should set `buff 
= appender!string` in the constructor, so that each struct will 
have its own appender.


More information about the Digitalmars-d-learn mailing list