Boost logo

Boost :

From: Pierre THIERRY (nowhere.man_at_[hidden])
Date: 2006-06-14 19:48:38


Le Mon, 12 Jun 2006 21:24:03 -0400, me22 a écrit :
> You also would never have "sp.reset(p);" if sp used to be a plain
> pointer, so it's not a problem when refitting existing code to use
> smart pointers.

But then it makes refitting code to smart pointers a pain. And if
anything is wrong with the smart pointers, it's a pain again to remove
them.

Maybe in most cases, with smart pointer assignation operator, it would
only be a matter of commenting all calls to free() or the delete
operator and having a typedef for the pointer type and you could easily
use smart pointers or not.

>> But this also renders some uses impossible, like this one:
>>
>> stack<foo*> fooS;
>> while(shared_ptr<foo> = fooS.pop())
>> {
>> ...
>> }
>>
> I'm not sure what that code's trying to do.
>
> Each of these works fine:
>
> stack<foo*> fooS;
> shared_ptr<foo> fptr;
> while ( fptr.reset(fooS.pop()) ) { ... }
>
> stack<foo*> fooS;
> shared_ptr<foo> fptr;
> while ( fptr = shared_ptr<foo>(fooS.pop()) ) { ... }
>
> stack<foo*> fooS;
> shared_ptr<foo> fptr;
> template <typename T>
> shared_ptr<T> make_shared_ptr(T *ptr) { return shared_ptr<foo>(ptr); }
> while ( fptr = make_shared_ptr(fooS.pop()) ) { ... }
>
> stack<foo*> fooS;
> if ( shared_ptr<foo> fptr( fooS.pop() ) ) { ... }

But it's not possible anymore that the pointer be in the scope of the
while() loop. Maybe that's not an issue, though.

Would it be OK if an assignable version of the smart pointers was
implemented as different classes? That is, if a patch added
assignable_shared_ptr and assignable_scoped_ptr?

Quickly,
Nowhere man

-- 
nowhere.man_at_[hidden]
OpenPGP 0xD9D50D8A

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