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

    shared_ptr & operator=(T * 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).

Nowhere man

OpenPGP 0xD9D50D8A

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at