Boost logo

Boost :

Subject: [boost] Interest in boost.deepcopy
From: Allan Johns (allan.johns_at_[hidden])
Date: 2011-10-24 20:16:43

Just gauging initial interest in a boost.deepcopy library, analogous to
deepcopy in python. Each type would register deepcopy behaviour with the
library (there are similarities to boost.serialize).
Boost.deepcopy would supply out-of-the-box registration for pod types,
pointer types, arrays, stl containers and common boost containers. Example:

template<typename T>
void deepcopy(deepcopycontext& ctxt, const T& obj)

Why not use boost::serialize and serialize into memory then out again I hear
you say? That's a great approach, but only when every object requires the
same deepcopy behaviour (also, it's not too optimal). The problem is, I need
specific behaviour in some types. Specifically, I need copy-on-write
behaviour for a Buffer class that I'm using. For example:

void deepcopy(deepcopycontext& ctxt, const Buf& b)
    Buf b2(b); // doesn't copy the buf data, just holds a shared ptr
internally. Data is only cloned when b/b2 is written to
    ctxt.insert(&b, b2);

I attempted to model this a while ago using boost.serialize, but it turned
out pretty clunky, I started needing a few decorator classes for special
cases, etc.
Apologies for the oversimplified examples above, just wanting to get
interest in the jist of it.

Please let me know if this overlaps with existing boost functionality also
(I'm not aware of anything atm).

Feedback appreciated.

Boost list run by bdawes at, gregod at, cpdaniel at, john at