New casts for smart pointers.

[SVN r12743]
This commit is contained in:
Darin Adler
2002-02-06 19:42:04 +00:00
parent f9782387d9
commit 0dd3285d56
4 changed files with 86 additions and 5 deletions
+20
View File
@@ -73,6 +73,15 @@ public:
}
}
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>
weak_ptr & operator=(weak_ptr<Y> const & r) // never throws
{
@@ -170,6 +179,17 @@ 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);
}
// get_pointer() enables boost::mem_fn to recognize weak_ptr
template<class T> inline T * get_pointer(weak_ptr<T> const & p)