Bug 15038 – Associative Array .get property const vs immutable

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-11T12:55:49Z
Last change time
2024-12-13T18:44:40Z
Assigned to
No Owner
Creator
Luís Marques
Moved to GitHub: dmd#17723 →

Comments

Comment #0 by luis — 2015-09-11T12:55:49Z
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
Comment #4 by robert.schadek — 2024-12-13T18:44:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17723 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB