Invariant Question (yes, another one)

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 15 06:44:12 PST 2007


"Janice Caron" wrote
>I got this error...
>
> Error: cannot implicitly convert expression (aa) of type
> invariant(char)[][invariant(char)[]] to const(char)[][const(char)[]]
>
> Why not?
>
> Since invariant(char)[] can implicitly convert to const(char)[], I
> just don't see a problem with this.

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.   I think what you might 
want is:

const(const(char)[][const(char)[]])

This guarantees that the data will not be changed no matter what.

But I'm not sure this will work either.  It should, but I don't know if the 
compiler is smart enough to figure this out?

-Steve 





More information about the Digitalmars-d mailing list