What is the Status of __mutable ?

Kagamin spam at here.lot
Thu Dec 20 15:33:09 UTC 2018


On Thursday, 20 December 2018 at 15:19:39 UTC, Steven 
Schveighoffer wrote:
> The biggest issue is that immutable is implicitly shared.

struct __mutable(T)
{
     private size_t _ref;
     this(shared T val){ _ref=cast(size_t)val; }
     shared(T) unwrap() const
     {
         return cast(shared T)_ref;
     }
}

struct A
{
     __mutable!(int*) rc;
     this(int) immutable
     {
         rc=new shared int;
     }
     int inc() immutable
     {
         import core.atomic;
         return atomicOp!"+="(*rc.unwrap,1);
     }
}

int main()
{
     immutable A b=0;
     assert(b.inc==1);
     assert(b.inc==2);
     return 0;
}


More information about the Digitalmars-d mailing list