Boost logo

Boost :

From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2006-01-04 05:22:58

axter wrote:
> "Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
> news:<dpf849$bne$1_at_[hidden]>...
>>axter wrote:
>>>"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
>>>>This is your own 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 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:://
> 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.

right, so you can get slicing. but the poiint I was making is that a
user action that slices, not the library.

> 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.

The pointer-containers don't slica anything on their own.
If you insist on not making your class hierarchy non-copyable, I can't
help you.


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