www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Associative arrays not ?:'d

reply Robert Clipsham <robert octarineparrot.com> writes:
I was under the impression that associative arrays now used ?: to find 
the best type for the array? Or was this change only made in D2? The 
following:
----
void main()
{
     auto foo = [ 2 : "a", 3 : "ab" ];
}
----
Gives the error:
----
test.d(3): Error: cannot implicitly convert expression ("ab") of type 
char[2LU] to char[1LU]
test.d(3): Error: cannot implicitly convert expression 
([2:"a",3:__error]) of type char[1LU][int] to char[1LU][int]
----
When using D1. This means that some of my code that should be constant 
needs to be initialised at runtime (the only way around this seems to be 
to change "a" to "a"[], and apparently strings can't be []'d at compile 
time). Is there any way around this in D1, or is this a bug?

-- 
Robert
http://octarineparrot.com/
Dec 11 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Robert Clipsham:

 I was under the impression that associative arrays now used ?: to find 
 the best type for the array? Or was this change only made in D2?

I think the change was for D2. (In my opinion D1 language is supposed to not go on for lot of more time). Bye, bearophile
Dec 11 2010