Bug 9585 – [AA] Implement getPair() for Associative Arrays

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-24T16:44:21Z
Last change time
2022-07-04T17:35:25Z
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2013-02-24T16:44:21Z
This was requested recently in IRC. A getPair() function would return a key+val combination from an existing key (ideally as a struct), e.g.: void main() { string buffer = "abc def"; string abc = buffer[0 .. 3]; bool[string] hash; hash[abc] = true; auto pair = hash.getPair("abc"); // enhancement assert(pair.key is abc); // L9 assert(pair.val == true); // not the same as: alias Tuple!(string, "key", bool, "val") Tup; Tup tup; tup.key = "abc"; tup.val = hash["abc"]; assert(tup.key is abc); // this would fail assert(tup.val == true); } Note the importance of line 9, it is an 'is' check, not an equality check.
Comment #1 by bearophile_hugs — 2013-02-24T17:12:27Z
Dupe of Issue 5466 ?
Comment #2 by andrej.mitrovich — 2013-02-24T17:15:28Z
(In reply to comment #1) > Dupe of Issue 5466 ? That's iteration, this is lookup. But you could say the two are related.
Comment #3 by bearophile_hugs — 2013-02-24T18:02:39Z
(In reply to comment #2) > That's iteration, this is lookup. But you could say the two are related. You are right, sorry.
Comment #4 by andrej.mitrovich — 2022-07-04T17:35:25Z
Lack of interest, I think it's not really that important since the key is right there anyway.