Invariant Question (yes, another one)
Regan Heath
regan at netmail.co.nz
Thu Nov 15 07:51:12 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[])[]
>
> 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 difference is the int in the square brackets.
void main()
{
char[] fred = "fred".dup;
invariant(char)[][int] iaa;
const(char)[][int] caa;
iaa[1] = "world";
caa = iaa; //pretend this is allowed
caa[2] = fred;
}
Using the same reasoning :)
Regan
More information about the Digitalmars-d
mailing list