ptr wrapper with dip1000

vit vit at vit.vit
Tue Dec 19 13:22:58 UTC 2017


How to manualy declare constructor for struct Ptr which work like 
Ptr.create?

struct Ptr{
     int* ptr;

     static Ptr create(scope return int* ptr)@safe{
         Ptr x;
         x.ptr = ptr;
         return x;
     }

     /++ This doesn't work:
     this(scope return int* ptr)scope @safe{
         this.ptr = ptr;
     }
     +/
}

void main()@safe{
     int i;
     auto x = Ptr(&i);
     auto y = Ptr.create(&i);
}


More information about the Digitalmars-d-learn mailing list