What is the Status of __mutable ?
Steven Schveighoffer
schveiguy at gmail.com
Thu Dec 20 15:19:39 UTC 2018
On 12/20/18 10:10 AM, Kagamin wrote:
> 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.
The biggest issue is that immutable is implicitly shared.
-Steve
More information about the Digitalmars-d
mailing list