www.digitalmars.com         C & C++   DMDScript  

D - Associative arrays with dynamic strings

reply "Robert M. Münch" <robert.muench robertmuench.de> writes:
Hi, I would like to do something like this:

char[] [char[]] assoc_array;

assoc_array["Hello"] = "Test";

But this doesn't compile:  cannot implicitly convert wchar[5] to int
The problem doesn't show up if I use: = 3 for example. Any idea?

--
Robert M. Münch
IT & Management Freelancer
Mobile: +49 (0)177 2452 802
Fax   : +49 (0)721 8408 9112
Web   : http://www.robertmuench.de
Sep 20 2002
next sibling parent Patrick Down <pat codemoon.com> writes:
"Robert M. Münch" <robert.muench robertmuench.de> wrote in news:amfhoe$2097
$1 digitaldaemon.com:

 Hi, I would like to do something like this:
 
 char[] [char[]] assoc_array;
 
 assoc_array["Hello"] = "Test";
I've run into this before. You can declare it like this: char[char[]][] assoc_array;
Sep 20 2002
prev sibling parent reply MicroWizard <MicroWizard_member pathlink.com> writes:
I see you have faced two different problems simultaneously. One was pointed out
by Patrick. (You have defined different type of indices in one order and used
them in reversed order, first is int, second is char[])

But the other problem is with the present D implementation.
String constants have the type of wchar[n], but the assoc array works
only with char[]. It implies you have to cast char[] and wchar[]
very often and vice versa. I hope these kind of problems will be solved
when the specification of D gets clearer.

I think wchar[] is good for UTF8-UTF16-UNICODE representations, but
it is inconvenient to cast string constants always.

Walter surely could give us proper explanation.

Regards,
Tamas (microwizard ax.hu)

In article <amfhoe$2097$1 digitaldaemon.com>, Robert M. Münch says...
Hi, I would like to do something like this:

char[] [char[]] assoc_array;

assoc_array["Hello"] = "Test";

But this doesn't compile:  cannot implicitly convert wchar[5] to int
The problem doesn't show up if I use: = 3 for example. Any idea?

--
Robert M. Münch
IT & Management Freelancer
Mobile: +49 (0)177 2452 802
Fax   : +49 (0)721 8408 9112
Web   : http://www.robertmuench.de
Sep 20 2002
parent "Walter" <walter digitalmars.com> writes:
I just need to fix dynamic arrays to work with wchar[]'s.

"MicroWizard" <MicroWizard_member pathlink.com> wrote in message
news:amg5j5$2omd$1 digitaldaemon.com...
 I see you have faced two different problems simultaneously. One was
pointed out
 by Patrick. (You have defined different type of indices in one order and
used
 them in reversed order, first is int, second is char[])

 But the other problem is with the present D implementation.
 String constants have the type of wchar[n], but the assoc array works
 only with char[]. It implies you have to cast char[] and wchar[]
 very often and vice versa. I hope these kind of problems will be solved
 when the specification of D gets clearer.

 I think wchar[] is good for UTF8-UTF16-UNICODE representations, but
 it is inconvenient to cast string constants always.

 Walter surely could give us proper explanation.
Sep 22 2002