Boost logo

Boost :

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


"Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
news:<dpmc2d$f75$1_at_[hidden]>...
> David Maisonave wrote:
> > "Thorsten Ottosen" <tottosen_at_[hidden]> wrote in message
>
> >>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,
> > get_alloc_func(type)))
> > {
> > assert(typeid(*type) == typeid(T_obj));
> > }
>
> how can that assertion ever fail when T_obj is deduced?

The only way that cow_ptr and copy_ptr can get slice is if the wrong
type is pass to the constructor.
Example code:

Derivedtype* p = new DerivedDerivedType;

cow_ptr<BaseType> pBase(p); //This will cause an assertion since p type
does not match the pointee

>
> > 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?
>
> *ptr = *ptr2;

Can you please give a more complete example?
Which is the smart pointer, here, and exactly what type of pointers?


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