On Sunday, 9 December 2012 at 16:26:12 UTC, Jacob Carlborg wrote:
On 2012-12-09 15:45, Dan wrote:
Phobos can and should have a general dup function, capable of duping (i.e. recursive deep copy) structs without requiring any effort from
struct developers.

[snip]

I think much of this functionality could be shared with serialization. A few questions and comments.


I am talking about a much smaller scope (just a few of functions - 200 lines of code tops) - but there are similarities.

* Are array slices properly handled

Both array slices and associative arrays are properly handled. Let me know if you find otherwise.

* I think there need to be a way to explicitly say that a given field and a whole struct shouldn't be duped

I definitely see need for that in serialization. Not sure about a generalized dup function, though. I have a similar function for deeply comparing instances and I think this should always hold:

assert(typesDeepEqual(t, t.gdup))

If you skipped fields it would not.

* All the public strings used for mixins should be templates


The mixins in the code are for higher-up functionality, some of it on top of the dup. There is no need for mixin for a general dup. The mixin(PostBlit) is there if you want to provide a dup for your struct so assignments in generic code gets the deep copy semantics with opAssign and copy construction. However, if template mixins are preferred to string mixins I suppose that is a good idea for that code and I'll check it out.

I have refactored the dup into its own module, so there is no need for mixin:
https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d

Orange serialization library, supports classes as well:

https://github.com/jacob-carlborg/orange

Reply via email to