On Wednesday, 17 June 2015 at 06:08:57 UTC, Andrei Alexandrescu
wrote:
Consider e.g. "SList!T.clear()". Right now it's O(1) and only
reassigns the root to point to no element, thus leaving all
elements to be collected. Moreover, if there are ranges
iterating the now cleared list, they'll just continue wandering
in the desert as if nothing happened.
What I think SList should do is first switch to a refcounted
implementation. Then, clear() should call destroy() for
payloads of all nodes, safely invalidate all ranges, and
deallocate memory allocated for all nodes.
I think this decision should be left to the end-user. A container
that supports only RC is just as bad as one that supports only
GC. Instead, use SList!T or SList!(Unique!T) or
SList(RefCounted!T) as appropriate.
All internal metadata, on the other hand, should be treated as
owned by the container. Calling clear() or removing individual
elements needs to destroy the associated meta data, which in turn
will correctly call the payload's (e.g. RefCounted!T or Unique!T)
destructor if it has one.