struct template constructors

Boris-Barboris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 22 12:57:21 PDT 2017


On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote:
> No time to think about the rest of the design but just to get 
> the code compiled, replace 'ref' with 'auto ref' like so:

Ok, looks like this indeed passes rhs by reference, thank you.

destcalls - number of times UniquePtr destructor was called
deallocs - number of times internal pointer was freed.

unittest
{
     deallocs = destcalls = 0;

     class A {}
     class B: A {}

     {
         UniquePtr!B b = UniquePtr!B.make();
         assert(b.owner);
         {
             UniquePtr!A a = b;
             assert(!b.owner);
             assert(a.owner);
             assert(destcalls == 0);
             assert(deallocs == 0);
         }
         assert(destcalls == 1);
         assert(deallocs == 1);
     }
     assert(destcalls == 2);
     assert(deallocs == 1);
}




More information about the Digitalmars-d-learn mailing list