forked from boostorg/smart_ptr
Removed casts as unsafe.
[SVN r13179]
This commit is contained in:
@ -51,29 +51,6 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Y>
|
|
||||||
weak_ptr(weak_ptr<Y> const & r, detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Y>
|
|
||||||
weak_ptr(weak_ptr<Y> const & r, detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
|
|
||||||
{
|
|
||||||
if (px == 0) // need to allocate new counter -- the cast failed
|
|
||||||
{
|
|
||||||
pn = detail::weak_count();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Y>
|
|
||||||
weak_ptr(weak_ptr<Y> const & r, detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
|
|
||||||
{
|
|
||||||
if (px == 0)
|
|
||||||
{
|
|
||||||
throw std::bad_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Y>
|
template<typename Y>
|
||||||
weak_ptr & operator=(weak_ptr<Y> const & r) // never throws
|
weak_ptr & operator=(weak_ptr<Y> const & r) // never throws
|
||||||
{
|
{
|
||||||
@ -187,27 +164,6 @@ template<class T> shared_ptr<T> make_shared(weak_ptr<T> const & r) // never thro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class U> weak_ptr<T> shared_static_cast(weak_ptr<U> const & r)
|
|
||||||
{
|
|
||||||
return weak_ptr<T>(r, detail::static_cast_tag());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T, class U> weak_ptr<T> shared_dynamic_cast(weak_ptr<U> const & r)
|
|
||||||
{
|
|
||||||
return weak_ptr<T>(r, detail::dynamic_cast_tag());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U> weak_ptr<T> shared_polymorphic_cast(weak_ptr<U> const & r)
|
|
||||||
{
|
|
||||||
return weak_ptr<T>(r, detail::polymorphic_cast_tag());
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename U> weak_ptr<T> shared_polymorphic_downcast(weak_ptr<U> const & r)
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
|
|
||||||
return shared_static_cast<T>(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#ifdef BOOST_MSVC
|
#ifdef BOOST_MSVC
|
||||||
|
@ -244,7 +244,7 @@ int test_main(int, char * [])
|
|||||||
test_is_nonzero(boost::make_shared(wp2));
|
test_is_nonzero(boost::make_shared(wp2));
|
||||||
}
|
}
|
||||||
|
|
||||||
weak_ptr<Y> wp3 = shared_dynamic_cast<Y>(wp2);
|
weak_ptr<Y> wp3 = shared_dynamic_cast<Y>(boost::make_shared(wp2));
|
||||||
|
|
||||||
BOOST_TEST(wp3.use_count() == 1);
|
BOOST_TEST(wp3.use_count() == 1);
|
||||||
BOOST_TEST(wp3.get() != 0);
|
BOOST_TEST(wp3.get() != 0);
|
||||||
|
Reference in New Issue
Block a user