
On Sat, 2008-04-12 at 19:01 +0300, Peter Dimov wrote:
Daniel Frey:
On Sat, 2008-04-12 at 17:31 +0300, Peter Dimov wrote:
Wouldn't it be easier to make shared_count(weak_count&) to never throw and add
if(!pn) boost::throw_exception( boost::bad_weak_ptr() );
to the non-tagged ctor of the shared_ptr?
No. Consider your proposed
+ template<class Y> + explicit shared_ptr(detail::weak_count const & wc, Y * p): pn(wc) // may throw + { + // it is now safe to copy p, as pn(wc) did not throw + px = p; + }
which would change meaning.
I'm currently happy with a single additional (and mostly internal) ctor, namely template<class Y> shared_ptr(detail::shared_count & c, Y * p) ... which can be used to solve all cases. Please see the updated patch. One thing you can now do is, let enable_shared_from_this_light throw it's own exception type (e.g. bad_shared_from_this) in case of misuse, as the usage of a weak_ptr or weak_count is just an implementation detail. It also allows to remove the whole sp_nothrow_tag stuff - no need for it anymore... Regards, Daniel