Boost logo

Boost Users :

From: Pierre THIERRY (nowhere.man_at_[hidden])
Date: 2006-01-17 00:44:22


Le Mon, 16 Jan 2006 20:16:14 -0500, me22 a écrit :
>> Is there a problem to have shared_ptr<T>::operator=(T*)?
> As I understand it, it's not allowed so that it's very clear when it's
> done.

OK, but that shouldn't be allowed to be clear when it's done only if
there's a risk using this assignation.

> Once a pointer ends up in a shared_ptr, there's no way to get it out
> of one, so independently creating 2 shared_ptrs that both own the same
> memory location is a recipe for disaster.

Who said it had to be independent? As I see it, the implementation could
be:

    shared_ptr & operator=(T * r)
    {
            reset(r);
            return *this;
    }

> There's always "shared_ptr<Foo> ptr_foo( new Foo );", which is less
> typing than either anyways.

But only possible at the construction. In any other place, you have to
use reset. And the problem is, I have to modify deeply my code to use
shared_ptr, and change it back if I stop using them.

With the operator=(T*), it would need no more than a modified typedef
for the entire code to switch to or from shared_ptr (or from any other
type of pointer that supports this operator).

Simply,
Nowhere man

-- 
nowhere.man_at_[hidden]
OpenPGP 0xD9D50D8A

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net