[C++-sig] How about class_<...>.enable_copy() ?

David Abrahams dave at boost-consulting.com
Tue Oct 30 00:41:57 CET 2007


on Tue Oct 16 2007, Hans Meine <hans_meine-AT-gmx.net> wrote:

> Hi again!
>
> Anyone cares to comment on my older posting?
>
> On Montag 23 Juli 2007, Hans Meine wrote:
>> On Montag 23 Juli 2007, Hans Meine wrote:
>> > foo = Foo(other) # copy constructor as in C++ (1)
>> > foo = copy.copy(other) # pythonic copying (2)
>> > foo = copy.deepcopy(other) # deepcopying (3)
>> >
>> > (1) is easy to do by exporting the copy constructor
>> >
>> > (2) could be implemented by setting __copy__ to the above copy
>> > constructor, but one would assume __dict__ to be (non-deep)copied, too.
>> >
>> > (3) definitely needs its own implementation, which needs to call deepcopy
>> > recursively.
>> >
>> > I would still believe that an .enable_copy() would be very handy.  It
>> > could possibly be controlled by an enum arg which of the above methods
>> > should be exported.
>
> Here is the updated, perfectly working code for (2) and (3), which I propose 
> to be included in BPL.  Also, some things appear hackish to me -- I would be 
> glad to get feedback on how to do this in a more "standard" way:

Is there a reason to have a special interface for this?  Suppose we
just do it unconditionally unless the person wrapping passes
noncopyable to class_<...> ?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list