December 11, 2010 Associative arrays not ?:'d | ||||
---|---|---|---|---|
| ||||
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/
|
December 11, 2010 Re: Associative arrays not ?:'d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Clipsham | 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
|
Copyright © 1999-2021 by the D Language Foundation