~= call copy ctor?

Ali Çehreli acehreli at yahoo.com
Sat Jul 21 15:20:45 PDT 2012


First, my earlier writeln("exit main"); wasn't achieving much without 
putting everything before it in a scope (like it is below).

On 07/21/2012 03:12 PM, Namespace wrote:
 > Cool. Any idea how to fix it?
 > Check whether this._ptr! is null && *this._ptr! is null does not help.
 > Although I'm just experimenting, but it would be nice to have a solution.

For Test to own a scoped_ptr member that holds on to a local class 
reference, it must be destroyed when leaving the same scope as the class 
reference (not potentially much later when the GC kicks in.)

One of guaranteeing it is using std.typecons.scoped:

import std.typecons;

void main() {
     {
         Foo f3 = new Foo();

         auto t = scoped!Test(f3);
     }

     writeln("exit main");
}

Now it is destroyed at the end of its scope (the scope is NOT needed for 
correctness, just for demonstration):

this
this
DTOR TEST
exit main    <--

Ali



More information about the Digitalmars-d-learn mailing list