Can someone clarify things for me? So I use .clear() as usual to clear my
arrays and associative arrays. But a post by Jonathan M Davis in D.learn
made me realize that same name is used to call a destructor on an object
and now I wonder if clear() was ever supposed to be called on associative
arrays and what the official way is to reset the contents of an
associative array (except for solutions containing null and foreach :) ).
clear() is well established and known to set the container length to 0
(releasing references and destroying owned objects, often keeping the
capacity) as seen in these references of container types in various
languages:
(C++ STL) http://www.cplusplus.com/reference/stl/vector/clear/
(.NET) http://msdn.microsoft.com/en-us/library/dwb5h52a.aspx
(Pascal)
http://www.freepascal.org/docs-html/rtl/classes/tlist.clear.html
(Ruby) http://www.ruby-doc.org/core/classes/Array.html#M000263
Is there a reason why the method that calls the destructor hasn't been
called 'deinit', 'destruct', 'invalidate' or 'destroy' instead?
And are these bug reports in fact invalid as per specification of clear() ?
http://www.digitalmars.com/d/archives/digitalmars/D/bugs/Issue_5816_New_clear_breaks_associative_array_29122.html
http://www.digitalmars.com/d/archives/digitalmars/D/bugs/Issue_5683_New_Calling_.clear_on_a_fresh_associative_array_causes_subsequent_segfault_28632.html
I'm confused :p
- Marco