View mode: basic / threaded / horizontal-split · Log in · Help
February 25, 2013
[Issue 9585] New: Implement getPair() for Associative Arrays
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@puremagic.com
       ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@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: -------
February 25, 2013
[Issue 9585] Implement getPair() for Associative Arrays
http://d.puremagic.com/issues/show_bug.cgi?id=9585


bearophile_hugs@eml.cc changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2013-02-24 17:12:27 PST ---
Dupe of Issue 5466 ?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 25, 2013
[Issue 9585] Implement getPair() for Associative Arrays
http://d.puremagic.com/issues/show_bug.cgi?id=9585



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-24 17:15:28 PST ---
(In reply to comment #1)
> Dupe of Issue 5466 ?

That's iteration, this is lookup. But you could say the two are related.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 25, 2013
[Issue 9585] Implement getPair() for Associative Arrays
http://d.puremagic.com/issues/show_bug.cgi?id=9585



--- Comment #3 from bearophile_hugs@eml.cc 2013-02-24 18:02:39 PST ---
(In reply to comment #2)

> That's iteration, this is lookup. But you could say the two are related.

You are right, sorry.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home