TDPL dictionary example - ERROR with dmd and gdc

Caligo iteronvexor at gmail.com
Fri Dec 24 09:35:10 PST 2010


I've been following the examples in the book and on page 8 we have this:

import std.stdio;
import std.string;

void main(){

     size_t[string] 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);
            }
    }
}

With the latest GDC, which I think uses the latest 2.051, I get this error:
dictionary.d:12: Error: associative arrays can only be assigned values with
immutable keys, not char[]

Someone told me on digitalmars-d.learn that it works with DMD, but I just
downloaded the latest DMD that was just released and I still get the same
error.

Is there a workaround to this? and why the error?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101224/1382990a/attachment.html>


More information about the Digitalmars-d mailing list