www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8363] New: Provide an intutive way to clear all entries in Associative Array

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363

           Summary: Provide an intutive way to clear all entries in
                    Associative Array
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: puneet coverify.org



---
Deleting all the entries from an associative array is not intuitive. This has
been discussed at the D forum here:
http://forum.dlang.org/thread/iu3ll6$2d48$1 digitalmars.com

I suggest the following syntax should work

int[string] aa;
aa["foo"] = 1;
aa = []; // clear all array entries


At this point only this works. I think this is not very intuitive.

int[string] aa;
int[string] empty;

aa["foo"] = 1;
aa = empty;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



aa.clear() should work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363




---

 aa.clear() should work.
I had not tried it because the forum topic (only one year old) said that it does not worl. But it does seem too work now. Can we add that to the Assoc array documentation here http://dlang.org/hash-map.html ? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com
            Summary|Provide an intutive way to  |Empty array literal does
                   |clear all entries in        |not implicitly convert to
                   |Associative Array           |associative array




 aa = []; // clear all array entries
 
This should probably work.
 
 At this point only this works. I think this is not very intuitive.
 
 int[string] aa;
 int[string] empty;
 
 aa["foo"] = 1;
 aa = empty;
try aa = null; But be careful, don't forget AAs are reference types. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
 aa.clear() should work.
I believe that that's the same as setting it to null. It doesn't actually remove anything from the AA. It just makes that reference null. If you want to actually remove all of the elements from the AA, you currently have to iterate over them and call remove on each one. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 09 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8363




PDT ---
However, with clear being renamed to destroy for 2.060 (with clear scheduled
for deprecation), I don't see any problem with adding a clear function to AAs
which actually clears the AA (that's probably what most everyone using clear on
AAs wanted anyway). Presumably, that could be done as part of the AA
implementation redesign that's currently being worked on.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2012