More tricky range semantics
Joseph Rushton Wakeling via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 16 09:13:32 PST 2015
On Friday, 16 January 2015 at 17:09:47 UTC, Tobias Pankrath wrote:
> While the first example is indeed problematic, this one
> actually is not. If this does not print the same 10 numbers
> every time, your save method is wrong.
> Regardless of being a reference type or not it has to clone the
> RNG state or it doesn't do its job.
I think you've misunderstood what I was getting at, probably
because I didn't explain myself well.
Obviously it's correct that the second function example should
print out the same thing 10 times. However, what is wrong is
that at the end of that function, the source range -- if a
reference type -- should itself have been popFront'ed a
sufficient number of times, but it hasn't been.
That's a design fault in the function implementation, which
doesn't take into account the desirable behaviour (for the
caller) if the range given to the function is a reference type.
More information about the Digitalmars-d
mailing list