An associative array of string[string] can't be indexed with .get using a const(char)[], unlike normal/raw indexing:
void main()
{
string[string] foo = ["k": "v"];
const(char)[] key = "k";
string value;
// if this works...
assert(foo[key] == "v");
// and this works...
string* pValue = key in foo;
value = pValue ? *pValue : null;
assert(value == "v");
// ...then this should work
//assert(foo.get(key, null) == "v");
}
Comment #1 by jrdemail2000-dlang — 2016-03-10T05:46:21Z
Some discussion in this thread: https://forum.dlang.org/post/[email protected]
The summary is that there can be performance implications if it is necessary to copy a char[] to a string just to test for presence in the associative array. This can happen when streaming text from an input source, as it's natural to read as char[] (eg. File.byLine).
Comment #2 by petar.p.kirov — 2016-03-10T21:11:24Z
While I agree that const should be as good as immutable in this case, sometimes it is not so clear. For example, if the key type is immutable(char[])[], should those be accepted:
1) immutable(char)[][] (a.k.a. string[])
2) const(char)[][]
3) const(char[])[]
Comment #3 by petar.p.kirov — 2016-03-10T21:12:19Z