Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 10, 2002 Assoc array bug? | ||||
---|---|---|---|---|
| ||||
What I want is an associative array of char[] to char[] The following program generates this compiler error: test.d(9): cannot implicitly convert wchar[3] to int Line 9 is map["str"] = "str"; int main(char[][] args) { char[][char[]] map; map["str"] = "str"; return 0; } This little work around fixes the problem. alias char[] string; int main(char[][] args) { string[char[]] map; map["str"] = "str"; return 0; } |
May 10, 2002 Re: Assoc array bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | Thanks! "Patrick Down" <pat@codemoon.com> wrote in message news:Xns9209D80E1BC4Bpatcodemooncom@63.105.9.61... > What I want is an associative array of char[] to char[] > > The following program generates this compiler error: > test.d(9): cannot implicitly convert wchar[3] to int > Line 9 is map["str"] = "str"; > > int main(char[][] args) > { > char[][char[]] map; > > map["str"] = "str"; > > return 0; > } > > This little work around fixes the problem. > > alias char[] string; > > int main(char[][] args) > { > string[char[]] map; > > map["str"] = "str"; > > return 0; > } |
May 10, 2002 Re: Assoc array bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Patrick Down | Maybe I'm wrong but you should change braces order: char[char[]][] map; Then I think map["..."] will refer to char[] element. "Patrick Down" <pat@codemoon.com> wrote in message news:Xns9209D80E1BC4Bpatcodemooncom@63.105.9.61... > What I want is an associative array of char[] to char[] > > The following program generates this compiler error: > test.d(9): cannot implicitly convert wchar[3] to int > Line 9 is map["str"] = "str"; > > int main(char[][] args) > > char[][char[]] map; > > map["str"] = "str"; > > return 0; > } > > This little work around fixes the problem. > > alias char[] string; > > int main(char[][] args) > > string[char[]] map; > > map["str"] = "str"; > > return 0; > } |
May 10, 2002 Re: Assoc array bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nic Tiger | "Nic Tiger" <nictiger@pt.comcor.ru> wrote in news:abfjm4$1m56$1 @digitaldaemon.com:
> Maybe I'm wrong but you should change braces order:
> char[char[]][] map;
Well I could be wrong but I think you read it right to left So what you have is...
[] a dynamic array
[char[]][] a dynamic array of assoc array with char[] as the key
char[char[]][] a dynamic array of assoc array with char[] as the key that maps to a single char
Or another way to look ar it is...
alias char[char[]] charmap; char[] -> char
charmap[] map;
|
May 26, 2002 Re: Assoc array bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | How to read arrays. :-) elem_type[] A; One way to "read" this is: A is a dynamic array of type elem_type elem_type[5] A; A is a dynamic array of length 5 of type elem_type elem_type[5][6] A; A is an array of length 5 of type (array of length 6 of type elem_type). elem_type[key_type] A; A is an associtive array that maps a key of type key_type to a value type of elem_type. elem_type[key_elem_type[]][] A; A is an associative array that maps a key of type (dynamic array of type key_elem_type) to a value type of (dynamic array of type elem_type) elem_type[][key_elem_type[]] A; A is a dynamic array of type (associative array that maps a key of type (dynamic array of type key_elem_type) to a value type of elem_type) elem_type [key_elem_type[]][5][6] A; A is an associative array that maps a key of type (dynamic array of type key_elem_type) to a value type of (an array of length 5 of type (array of length 6 of type elem_type))) So can parentheses be used to associate types together? (char[])[char[]] A; // Same as char[char[]][] map; This reads a little better to me because it retains the pattern value_type[key_type] A; |
Copyright © 1999-2021 by the D Language Foundation