const_pointer_cast added.

[SVN r19147]
This commit is contained in:
Peter Dimov
2003-07-16 11:51:12 +00:00
parent 7c36a640ae
commit 192970b3b8
5 changed files with 106 additions and 0 deletions
+5
View File
@@ -220,6 +220,11 @@ template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U>
return static_cast<T *>(p.get());
}
template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
{
return const_cast<T *>(p.get());
}
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
{
return dynamic_cast<T *>(p.get());
+21
View File
@@ -48,6 +48,7 @@ namespace detail
{
struct static_cast_tag {};
struct const_cast_tag {};
struct dynamic_cast_tag {};
struct polymorphic_cast_tag {};
@@ -68,6 +69,16 @@ template<> struct shared_ptr_traits<void const>
typedef void reference;
};
template<> struct shared_ptr_traits<void volatile>
{
typedef void reference;
};
template<> struct shared_ptr_traits<void const volatile>
{
typedef void reference;
};
#endif
// enable_shared_from_this support
@@ -158,6 +169,11 @@ public:
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
{
}
template<class Y>
shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
{
@@ -351,6 +367,11 @@ template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const
return shared_ptr<T>(r, detail::static_cast_tag());
}
template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
{
return shared_ptr<T>(r, detail::const_cast_tag());
}
template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
{
return shared_ptr<T>(r, detail::dynamic_cast_tag());