bug 382: templated DynamicCast

This commit is contained in:
Mathieu Lacage
2008-10-20 08:40:32 +02:00
parent e443a39436
commit 0f8139fc10
2 changed files with 10 additions and 3 deletions

View File

@@ -249,8 +249,8 @@ PtrTest::RunTests (void)
Ptr<NoCount> p4 = CallTestConst (p1);
Ptr<NoCount const> p5 = p4;
//p4 = p5; You cannot make a const pointer be a non-const pointer.
// but if you use const_pointer_cast, you can.
p4 = const_pointer_cast<NoCount> (p5);
// but if you use ConstCast, you can.
p4 = ConstCast<NoCount> (p5);
p5 = p1;
Ptr<NoCount> p;
if (p == 0)

View File

@@ -361,11 +361,18 @@ bool operator >= (const Ptr<T> &lhs, const Ptr<T> &rhs)
template <typename T1, typename T2>
Ptr<T1>
const_pointer_cast (Ptr<T2> const&p)
ConstCast (Ptr<T2> const&p)
{
return Ptr<T1> (const_cast<T1 *> (PeekPointer (p)));
}
template <typename T1, typename T2>
Ptr<T1>
DynamicCast (Ptr<T2> const&p)
{
return Ptr<T1> (dynamic_cast<T1 *> (PeekPointer (p)));
}
/****************************************************
* Member method implementations.