bug 382: templated DynamicCast
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 20 Oct 2008 08:40:32 +0200
changeset 3767 b03ea30335a3
parent 3766 9650873fba21
child 3768 4f07ee85f2a1
bug 382: templated DynamicCast
src/core/ptr.cc
src/core/ptr.h
--- a/src/core/ptr.cc	Fri Oct 17 20:07:44 2008 +0200
+++ b/src/core/ptr.cc	Mon Oct 20 08:40:32 2008 +0200
@@ -249,8 +249,8 @@
     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)
--- a/src/core/ptr.h	Fri Oct 17 20:07:44 2008 +0200
+++ b/src/core/ptr.h	Mon Oct 20 08:40:32 2008 +0200
@@ -361,11 +361,18 @@
 
 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.