https://issues.dlang.org/show_bug.cgi?id=2954
--- Comment #12 from Andrei Alexandrescu <[email protected]> --- (In reply to hsteoh from comment #11) > Which of the following cases should/shouldn't be valid? > > Case 1: > > int[string] aa; > char[] key; > aa[key] = 1; This shouldn't compile, although we ought to make it work in the future (e.g. by defining and using a protocol). The problem with this is efficiency: int[string] aa; char[] key = ...; aa[key.idup] = 1; // Alternatively aa[to!string(key)] = 1; This is correct but less efficient than it could - it compulsively allocates a new string even when not needed (i.e. the key is already there). > Case 2: > > int[string] aa; > char[] key; > if (aa[key] == 1) { ... } > auto p = key in aa; > > > It seems to me that we should allow case 2, but prohibit case 1. Yah, lookup should always work with any type that allows comparison. --
