digitalmars.D.learn - TDPL dictionary example - error
- Caligo (24/24) Dec 23 2010 Greetings,
Greetings, I just joined here, so sorry if this has been posted before. I'm reading TDPL and the example on page 8 doesn't compile. I'm using the latest GDC with GCC 4.4.5. I've checked the errata, but nothing for this error. import std.stdio; import std.string; void main(){ size_t[char[]] dictionary; foreach(line; stdin.byLine()){ foreach(word; splitter(strip(line))){ if(word in dictionary) continue; auto newID = dictionary.length; dictionary[word] = newID; writeln(newID, '\t', word); } } //writeln(dictionary.length); } This is the error: dictionary.d:12: Error: associative arrays can only be assigned values with immutable keys, not char[] If i use immutable keys, it works, but it defeats the purpose. So what's wrong with the code?
Dec 23 2010