Movable resource handles

Era Scarecrow via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 27 19:47:56 PST 2016


On Thursday, 28 January 2016 at 03:38:32 UTC, Era Scarecrow wrote:
>  hmmm... You'd best be allocating the reference directly on the 
> array, you should be able to add to it.

  Forgot to mention. Since UniqueRef is likely just to ensure 
nothing else can copy away with the data, you don't HAVE to make 
it unique until the last step. So you could do all your 
calculations, then wrap it as a last step when returning it, say 
outside of the function. Then the assignment happens when the 
function returns and not where you generated it.

[code]
UR func(...) {
   int val;

   // calculates while it's in a safe/pure environment

   return UR(val);
}
[/code]


More information about the Digitalmars-d mailing list