[Issue 9585] New: Implement getPair() for Associative Arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 24 16:44:23 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9585
Summary: Implement getPair() for Associative Arrays
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: druntime
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-02-24 16:44:21 PST ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list