SmartRef: The Smart Pointer In D

biozic via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Jan 15 09:24:25 PST 2017


On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote:
> and : In 
> https://github.com/dlang/phobos/blob/master/std/typecons.d#L147
>     ~this()
>     {
>         debug(Unique) writeln("Unique destructor of ", (_p is 
> null)? null: _p);
>         if (_p !is null) destroy(_p);
>         _p = null;
> }
>  if the 'T' is a struct, it will not exec the Destory function. 
> Is it a bug?

What do you mean? This works for me:
---
import std.stdio, std.typecons;

struct Foo {
     ~this() {
         writeln("I'm destroyed");
     }
}

void main() {
     Unique!Foo foo = new Foo;
} // Prints "I'm destroyed"
---



More information about the Digitalmars-d-announce mailing list