struct Unique(T)

Chris Cain clcain at uncg.edu
Wed Nov 6 17:09:44 PST 2013


On Thursday, 7 November 2013 at 00:07:25 UTC, ChrisG wrote:
> My question is: what's the status of D's struct Unique? It 
> looks like struct RefCounted is current, but I can't tell with 
> Unique. There's several comments in the source that say: 
> doesn't work yet. It seems like some of it could be made to 
> work as intended. For example, the commented out code to 
> disallow construction via an lvalue:

I'm pretty sure things like Unique have been neglected for 
awhile. Probably for a decent reason, but a lot of language 
features have been landing that could help polish it up a bit 
more.

> Next, I'd like to be able to use a custom deleter. For example, 
> a naive implementation I could write would be something like:
>
> ... snip ...
>
> So, I could do things like:
>
> Unique2!(int, "free") i1 = cast(int*)malloc(int.sizeof); // 
> lame example
>
> A real implementation would allow more interesting deleters in 
> the form of delegates, but I'm already stretching my D skillz.

I think Unique will probably be getting something along those 
lines reasonably shortly, but std.allocator will have to be fully 
completed first.

http://forum.dlang.org/thread/l4btsk$5u8$1@digitalmars.com

Once that's done we'll see some memory management schemes like 
what you're suggesting be implemented. But it's probably not a 
good idea to add that stuff before we figure out a good way to 
use it with the new std.allocator effectively.


More information about the Digitalmars-d-learn mailing list