On Monday, 10 December 2012 at 11:39:24 UTC, Thiez wrote:
On Saturday, 8 December 2012 at 21:47:32 UTC, Dan wrote:
My approach is to have a general dup function. I call it gdup,
for global dup so the name does not conflict with the existing
dup. It dup's fields recursively. Feel free to have a look and
any suggestions appreciated. Would greatly appreciate if
seasoned D developers like (Ali, bearophile, ...) would
review - as I use these mixins to simplify development with
structs.
What would happen to the recursive dup if the structure
contains a cycle (e.g. A has a reference to B, which has a
reference to C, which has a reference to the original A)?
By reference I assume you mean pointer.
That would be an infinite loop. If you have a compile time cycle
you would likely need your own custom dups anyway, as you are
doing low level and heap allocating already. But for the simpler
cases without cycles, if dup encounters a pointer it creates a
new instance on the heap (if compilation is possible) and dup's
into it.