Struct that destroys its original handle on copy-by-value
Joseph Rushton Wakeling via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 26 05:16:09 PDT 2015
On 26/07/15 13:45, Martijn Pot via Digitalmars-d-learn wrote:
> Sounds like unique_ptr (so UniqueRange might be a nice name). Maybe you can get
> some ideas from that.
There is already a Unique in std.typecons. However, I'm not sure that it's
doing what I require.
Example:
Unique!Random rng = new Random(unpredictableSeed);
rng.take(10).writeln;
... will fail with an error:
Error: struct std.typecons.Unique!(MersenneTwisterEngine!(uint, 32LU,
624LU, 397LU, 31LU, 2567483615u, 11LU, 7LU, 2636928640u, 15LU, 4022730752u,
18LU)).Unique is not copyable because it is annotated with @disable
My aim by contrast is to _allow_ that kind of use, but render the original
handle empty when it's done.
More information about the Digitalmars-d-learn
mailing list