Struct that destroys its original handle on copy-by-value
Kagamin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 3 01:54:30 PDT 2015
On Saturday, 1 August 2015 at 11:47:29 UTC, Joseph Rushton
Wakeling wrote:
> Yea, but that's not what I'm trying to achieve. I know how I
> can pass something to `take` so as to e.g. obtain reference
> semantics or whatever; what I'm trying to achieve is a range
> that _doesn't rely on the user knowing the right way to handle
> it_.
Wrapping a reference to a stack-allocated struct is also unsafe,
so no way for the user to not know about it.
On Saturday, 1 August 2015 at 12:10:43 UTC, Joseph Rushton
Wakeling wrote:
> On the other hand, what you want to disallow is this:
>
> auto sample = iota(100).randomSample(10, gen);
>
> sample.take(5).writeln;
> sample.take(5).writeln; // statistical correlations result,
> // probably unwanted
Try
auto sample = iota(100).randomSample(10, &gen);
More information about the Digitalmars-d-learn
mailing list