immutable struct/class is mutable!
John Colvin
john.loughran.colvin at gmail.com
Mon Jul 15 09:17:01 PDT 2013
On Monday, 15 July 2013 at 15:59:44 UTC, JS wrote:
> On Monday, 15 July 2013 at 15:08:58 UTC, Dicebot wrote:
>> On Monday, 15 July 2013 at 14:50:04 UTC, JS wrote:
>>> Why does isMutable and isAssignable return true for a
>>> struct/class that are immutable?
>>>
>>> immutable struct A { }
>>>
>>> isMutable!A returns true.
>>
>> looks like
>>
>> immutable struct A
>> {
>> int a;
>> }
>>
>> acts as a
>>
>> struct A
>> {
>> immutable:
>> int a;
>> }
>>
>> Now, I don't see this use case (qualified aggregate
>> definition) anywhere in spec and this may be intended
>> behavior. But I do agree this looks misleading.
>
> Yes, I need immutable to do what it does but also need a way to
> emulate an enum.
>
> This is because I need to constrain my templates properly. If
> struct A isn't immutable then it is no different than any other
> struct which is bad because I want only enum like structs.
>
> maybe immutable immutable(struct) A would be a good way to
> specify this.
>
> An immutable struct should be similar to an enum... a purely
> compile time construct not meant to be instantiated in any way.
Why is it you're trying to emulate an enum? Perhaps there's a way
to achieve what you want by more normal means.
More information about the Digitalmars-d-learn
mailing list