Boost logo

Boost :

From: axter (boost_at_[hidden])
Date: 2006-01-04 01:06:37


"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
news:<dpf849$bne$1_at_[hidden]>...
> axter wrote:
> > "Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
> > news:<dpdofv$434$1_at_[hidden]>...
>
> >>This is your own fault....you should make your class hierarchy
> >>noncopyable by default.
> >
> >
> >
> > So are you saying, that in order to safely use ptr_map, the class
> > hierarchy needs to be noncopyable by default? If so, I would see
> > that as a justification for favoring the use of the cow_ptr smart
> > pointers over using ptr_map, since the cow_ptr does not have such a
> > restriction for it's safe usage.
>
> No, I'm saying that you should make you class hiararchy noncopyable by
> default because it doesn't make sense to copy such types. I believe
> Steven Dewhurst has an item on that in his "Common Knowledge" book.
>
> Your argumentation is weird...in the same manner I could prove your
> cow pointer (or any smart pointer) is worse because it allows slicing:
>
> cow_ptr<T> p1, p2;
> ...
> *p1 = *p2;

Did you test the cow_ptr out, to prove this?
The above code will not cause slicing using the following cow_ptr:
http:://code.axter.com/cow_ptr.h

I recommend you test it, so you can fully understand why I'm recommending it
over the current boost pointer container as the default method for creating
a container of pointers.

If you have an abstract base pointer, the only way to get slicing on this
type of smart pointer is if you pass a derive-derive type via a derive
pointer.

DerivedType * p = new DerivedDerivedType;
cow_ptr<base> p1(p);
cow_ptr<base> p2(p1);//This would produce slicing
Of course the above logic would not be in keeping with clone logic in which
a clone pointer is suppose to have sole ownership of a pointer from
conception to deletion. The clone pointer will only slice if you pass it the
wrong type on the constructor.

Similar type of slicing can occur with the current boost pointer container.
If a derived-derived type does not implement a clone method, then it will
get sliced when cloning.

Neither the cow_ptr nor the copy_ptr requires that the pointee have a clone
function, or any other additional clone methods from the user. So in this
respect, I consider the cow_ptr and copy_ptr easier to use, and safer.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk