What is the Status of __mutable ?

Kagamin spam at here.lot
Thu Dec 20 15:10:58 UTC 2018


How about this?

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

struct A
{
     __mutable!(int*) rc;
     this(int) immutable
     {
         rc=new int;
     }
     int inc() immutable
     {
         return ++*rc.unwrap;
     }
}

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

I think it doesn't violate type system (formally): the mutable 
location is never seen as immutable, so immutability is not 
casted away, but it's not rebindable.


More information about the Digitalmars-d mailing list