From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-19 05:48:49
From: "David Abrahams" <david.abrahams_at_[hidden]>
> IMO it's not even a question of self-assignment. I would prefer to detect
> calls to "reset" on a pointer that is already managed by another smart
> pointer whenever possible, by asserting.
Exactly my thinking. This simply makes a particular kind of bug a feature:
void f(shared_ptr & a, shared_ptr const & b)
a = b.get(); // bug or feature?
The shared_ptr(p).swap(*this) semantics have a simple precondition:
* p must point to a valid object allocated with "new T" that is not being
owned by another smart pointer or other resource managing object.
and a simple postcondition:
* (*this) is equivalent to shared_ptr(p); in particular, use_count() == 1.
Allowing self-resets introduces a special case in both.
I do know that the motivation for the self-reset is that std::auto_ptr
supports it, but I would strongly suggest that we reconsider propagating the
same mistake into shared_ptr.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk