Invariant Question (yes, another one)
Steven Schveighoffer
schveiguy at yahoo.com
Thu Nov 15 08:23:48 PST 2007
"Janice Caron" wrote
> On 11/15/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>> Your first data type is an AA with invariant strings as keys and values.
>> HOWEVER, the AA itself is not invariant. Suppose after you converted to
>> an
>> AA with const strings as keys and values, you replaced one of the values
>> with a mutable string cast into a const string.
>
> Yes, you're right.
>
> invariant(char)[][] won't implicitly convert to const(char)[][]
> either, for the same reason.
> But...
> invariant(char[])[] will implicitly conver to const(char[])[]
Yes, this makes sense, because you then wouldn't be able to change any
strings in the array, because the pointers in the strings are const.
>
> But here's the odd thing...
>
> invariant(char[])[] will implicitly conver to const(char[])[]
> but
> invariant(char[])[int] won't implicitly convert to const(char[])[int]
The only thing I can think of is that an AA does not do a copy-on-write when
adding a new element as normal arrays do, so you could potentially add a
member to the original AA which is not invariant. Don't know if this is why
it's not allowed, or if it's even true :)
-Steve
More information about the Digitalmars-d
mailing list