When are associative arrays meant to throw a RangeError?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Feb 18 12:54:52 PST 2012

Returning the default initializer of the value type when the key
doesn't exist is a bad idea. Consider an integer, it's .init value is
0. If I want to check if a value of a key is zero I could easily end
up with a silent bug:

int[string] aa;
aa["foobar"] = 5;
if (aa["fobar"] == 0) { }  // will always be true
else { }

More information about the Digitalmars-d mailing list