Boost logo

Boost :

From: axter (boost_at_[hidden])
Date: 2006-01-04 08:04:03


"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
news:<dpg7m4$vi6$1_at_[hidden]>...
> 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
> >>>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.
>
> 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.
>

I don't see that making a difference, but could you please post a small
example class that is non-copyable, so that I can test it out.


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