11a12 > // 19 Oct 00 Make shared_ptr ctor from auto_ptr explicit. (Robert Vugts) 54a56,57 > #include > #include 118c121,125 < template class base {}; --- > #if defined(BOOST_MSVC6_MEMBER_TEMPLATES) > namespace detail { > template class msvc6_member_templates_base {}; > } > #endif 120c127,131 < template class shared_ptr: public base { --- > template class shared_ptr > #if defined(BOOST_MSVC6_MEMBER_TEMPLATES) > : public detail::msvc6_member_templates_base > #endif > { 138,162c149,155 < /* struct detail_copy { < const shared_ptr& p; < detail_copy(const shared_ptr& p): p(p) {} < }; < < operator const detail_copy() const { return detail_copy(*this); } < < shared_ptr(const detail_copy c): px(c.p.px) { ++*(pn = c.p.pn); } < */ < template < shared_ptr(const base& r): < px(static_cast&>(r).px) < { < ++*(pn = static_cast&>(r).pn); < } < < #if !defined( BOOST_NO_MEMBER_TEMPLATES ) < < // template < // shared_ptr(const shared_ptr& r) : px(r.px) { // never throws < // ++*(pn = r.pn); < // } < < template < shared_ptr(std::auto_ptr& r) { --- > #if !defined(BOOST_NO_AUTO_PTR) > #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) > template explicit shared_ptr(std::auto_ptr& r) > #else > explicit shared_ptr(std::auto_ptr& r) > #endif > { 164,171c157,158 < px = r.release(); // fix: moved here to stop leaky baby if new throws < } < < // template < // shared_ptr& operator=(const shared_ptr& r) { < // share(r.px,r.pn); < // return *this; < // } --- > px = r.release(); // fix: moved here to stop leak if new throws > } 173,174c160,165 < template < shared_ptr& operator=(std::auto_ptr& r) { --- > #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) > template shared_ptr& operator=(std::auto_ptr& r) > #else > shared_ptr& operator=(std::auto_ptr& r) > #endif > { 185,189c176 < #else < shared_ptr(std::auto_ptr& r) { < pn = new long(1); // may throw < px = r.release(); // fix: moved here to stop leak if new throws < } --- > #endif // BOOST_NO_AUTO_PTR 191,199c178,186 < shared_ptr& operator=(std::auto_ptr& r) { < // code choice driven by guarantee of "no effect if new throws" < if (*pn == 1) { delete px; } < else { // allocate new reference counter < long * tmp = new long(1); // may throw < --*pn; // only decrement once danger of new throwing is past < pn = tmp; < } // allocate new reference counter < px = r.release(); // fix: moved here so doesn't leak if new throws --- > #if !defined( BOOST_NO_MEMBER_TEMPLATES ) > template > shared_ptr(const shared_ptr& r) : px(r.px) { // never throws > ++*(pn = r.pn); > } > > template > shared_ptr& operator=(const shared_ptr& r) { > share(r.px,r.pn); 202c189,203 < #endif --- > > #elif defined(BOOST_MSVC6_MEMBER_TEMPLATES) > > template > shared_ptr(const detail::msvc6_member_templates_base& r): > px(static_cast&>(r).px) > { ++*(pn = static_cast&>(r).pn); } > > template > shared_ptr& operator=(const detail::msvc6_member_templates_base& r) { > share(static_cast&>(r).px,static_cast&>(r).pn); > return *this; > } > > #endif // BOOST_NO_MEMBER_TEMPLATES 236c237 < #if defined(BOOST_NO_MEMBER_TEMPLATES) || !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) --- > #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) || !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) 273c274,278 < template class shared_array { --- > template class shared_array > #if defined(BOOST_MSVC6_MEMBER_TEMPLATES) > : public detail::msvc6_member_templates_base > #endif > { 285,288d289 < template < shared_array(const shared_array& r) : px(r.px) // never throws < { ++*(pn = r.pn); } < 292,296c293 < if (pn != r.pn) { < dispose(); < px = r.px; < ++*(pn = r.pn); < } --- > share(r.px,r.pn); 298c295,327 < } // operator= --- > } > > #if !defined( BOOST_NO_MEMBER_TEMPLATES ) > template > shared_array(const shared_array& r) : px(r.px) { // never throws > BOOST_STATIC_ASSERT((is_same::value || is_same::value || is_same::value)); > ++*(pn = r.pn); > } > > template > shared_array& operator=(const shared_array& r) { > BOOST_STATIC_ASSERT((is_same::value || is_same::value || is_same::value)); > share(r.px,r.pn); > return *this; > } > > #elif defined(BOOST_MSVC6_MEMBER_TEMPLATES) > > template > shared_array(const detail::msvc6_member_templates_base& r): > px(static_cast&>(r).px) { > BOOST_STATIC_ASSERT((is_same::value || is_same::value || is_same::value)); > ++*(pn = static_cast&>(r).pn); > } > > template > shared_array& operator=(const detail::msvc6_member_templates_base& r) { > BOOST_STATIC_ASSERT((is_same::value || is_same::value || is_same::value)); > share(static_cast&>(r).px,static_cast&>(r).pn); > return *this; > } > > #endif // BOOST_NO_MEMBER_TEMPLATES 329c358,360 < private: --- > #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) || !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) > private: > #endif 333a365,368 > #if !defined( BOOST_NO_MEMBER_TEMPLATES ) && !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) > template friend class shared_array; > #endif > 335a371,378 > void share(T* rpx, long* rpn) { > if (pn != rpn) { > dispose(); > px = rpx; > ++*(pn = rpn); > } > } > 395d437 <