
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. Also consider that + template<class Y> + shared_ptr(detail::shared_count c, Y * p): px(p) // never throws + { + pn.swap(c); + } is now equivalent to the weak_count constructor because shared_count(weak_count) throws. If it yielded an empty shared_count, you wouldn't be able to tell from inside the body whether you need to throw or not (because passing a genuine empty shared_count is legitimate).