Tricky semantics of ranges & potentially numerous Phobos bugs
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Oct 17 10:20:07 PDT 2012
On 10/16/12 3:41 PM, H. S. Teoh wrote:
> I think with D's compile-time introspection capabilities, it _should_ be
> possible to implement a generic deepCopy template that works for any
> type.
>
> Of course, then one has to address tricky issues such as complex data
> structures that have interlinking parts; a blind recursive deep-copy may
> not have the desired effect (e.g., if we're deep-copying a graph and
> there are multiple paths (via references) to the same node, then we
> shouldn't end up with multiple copies of that node). Some care will also
> need to be taken to deal with cyclic structures, etc.. And some
> optimizations can probably be done to avoid copying immutable objects,
> since that would be a waste of time& memory.
>
> Probably some kind of graph traversal algorithm can be used to address
> these issues, I think, perhaps with the help of an AA or two to recreate
> the original linking structure in the copy.
Yes, deepDup should be implementable as a library and use a temporary
dictionary of already-duplicated items to avoid infinite recursion.
We should add that to Phobos - could you please add a task to trello.
Andrei
More information about the Digitalmars-d
mailing list