Boost logo

Boost :

From: David Maisonave (dmaisonave_at_[hidden])
Date: 2006-01-06 13:01:01

"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
> David Maisonave wrote:
> > "Sam Partington" <sam.partington_at_[hidden]> wrote in message
> > news:<546fdb840601060205w76ed8be9n2bf73c4323c78c20_at_[hidden]>..
> > .
> >>I don't agree with that. The clone concept is a well established
> >>idiom for polymorphic types. Sure missing out a clone _does_ lead
> >>slicing, but that is understood, and as Thorsten says we can help
> >>check for that with an assert. We can only help the user to get it

> >>write, we can't do it all for them.
> >>
> >
> >
> > The cow_ptr and the copy_ptr can use the same assert code to catch
> > slicing. The assert logic can be placed in the constructor of the
> > cow_ptr and copy_ptr.
> > This would make it easier to catch slicing in the cow_ptr/copw_ptr
> > *than* it would be in the boost pointer containers.
> > That's because in the boost pointer containers you would only catch
> > slicing via assert if and when the object is clone.
> > If the object never gets clone during testing, you would never catch
> > slicing.
> >
> >
> >
> > With cow_ptr/copy_ptr the slicing would be caught when the object
> > gets instantiated. So you have a much higher probability of catching

> > slicing using the cow_ptr clone method, *than* you would using the
> > boost pointer container method.
> I'm not sure I fully understand how the detection mechanism would work
> in your cow_ptr.

Example code:
template<typename T_obj>
        cow_ptr(T_obj* type): m_ref_count(new ref_count(type,
        assert(typeid(*type) == typeid(T_obj));

Since the cow_ptr works by capturing the type on the constructor, it can
easily determine if the right type is being passed in, and if it matches
the pointee type.
That can't be done with the boost pointer containers because they don't
catch the type on the constructor, nor is it part of the required logic
for using a clone function method.

> Nevertheless, as soon as the object is outside
> a cow_ptr might be sliced. That's reason enough not to allow it.

I'm not sure what you're referring to here. Can you post an example?

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