http://d.puremagic.com/issues/show_bug.cgi?id=8247



--- Comment #6 from jens.k.muel...@gmx.de 2012-06-15 01:22:31 PDT ---
(In reply to comment #5)
> > Why should a RNG type have reference semantics? I think it's fine to pass 
> > them
> by reference where needed.
> 
> Because it makes no sense for it to have value semantics. Take this for 
> example
> 
> auto func(R)(R r)
> {
>  r.popFront();
>  auto var1 = r.front;
>  ///...
> }
> 
> func(generator);
> generator.popFront();
> auto var2 = generator.front;
> 
> Both var1 and var2 will have the exact same value. This is an easy mistake to
> make, and since random number generators are supposed to be returning random
> numbers, having them return the _same_ number after popFront has been called 
> is
> definitely problematic.
> 
> By making them reference types, the only time that you get the same number
> multiple times in a row is when you do it on purpose (e.g. by storing the 
> value
> of front or by calling save on the range).
> 
> There's a discussion on this in issue# 7067.

I see. Thanks.
Since passing around RNGs should be by default by reference RNGs should be
reference types. Otherwise everybody writing own functions accepting RNGs has
to use ref which is error-prone.
Using ref when passing RNGs in std.random won't solve this general design
issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to