Struct that destroys its original handle on copy-by-value

Joseph Rushton Wakeling via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 1 04:47:09 PDT 2015


On 31/07/15 13:40, Kagamin via Digitalmars-d-learn wrote:
> On Sunday, 26 July 2015 at 12:16:30 UTC, Joseph Rushton Wakeling wrote:
>> Example:
>>
>>     Unique!Random rng = new Random(unpredictableSeed);
>>     rng.take(10).writeln;
>> My aim by contrast is to _allow_ that kind of use, but render the original
>> handle empty when it's done.
>
> `take` stores the range, you can try to use some sort of a weak reference.

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_.

I'll expand on this more responding to Ali, so as to clarify the context of what 
I'm aiming for and why.



More information about the Digitalmars-d-learn mailing list