Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
July 09, 2012 [Issue 8363] New: Provide an intutive way to clear all entries in Associative Array | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from Puneet Goel <puneet@coverify.org> 2012-07-09 06:22:08 PDT --- 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: ------- |
July 09, 2012 [Issue 8363] Provide an intutive way to clear all entries in Associative Array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Puneet Goel | http://d.puremagic.com/issues/show_bug.cgi?id=8363 timon.gehr@gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |timon.gehr@gmx.ch --- Comment #1 from timon.gehr@gmx.ch 2012-07-09 06:49:35 PDT --- aa.clear() should work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 09, 2012 [Issue 8363] Provide an intutive way to clear all entries in Associative Array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Puneet Goel | http://d.puremagic.com/issues/show_bug.cgi?id=8363 --- Comment #2 from Puneet Goel <puneet@coverify.org> 2012-07-09 07:11:51 PDT --- (In reply to comment #1) > 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: ------- |
July 09, 2012 [Issue 8363] Empty array literal does not implicitly convert to associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Puneet Goel | 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 --- Comment #3 from yebblies <yebblies@gmail.com> 2012-07-10 01:54:12 EST --- (In reply to comment #0) > 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: ------- |
July 09, 2012 [Issue 8363] Empty array literal does not implicitly convert to associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Puneet Goel | http://d.puremagic.com/issues/show_bug.cgi?id=8363 Jonathan M Davis <jmdavisProg@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg@gmx.com --- Comment #4 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-09 10:45:46 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: ------- |
July 09, 2012 [Issue 8363] Empty array literal does not implicitly convert to associative array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Puneet Goel | http://d.puremagic.com/issues/show_bug.cgi?id=8363 --- Comment #5 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-09 11:02:47 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: ------- |
Copyright © 1999-2021 by the D Language Foundation