stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r542494 - /incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
Date Tue, 29 May 2007 11:44:13 GMT
Author: faridz
Date: Tue May 29 04:44:13 2007
New Revision: 542494

URL: http://svn.apache.org/viewvc?view=rev&rev=542494
Log:
2007-05-29 Farid Zaripov <Farid_Zaripov@epam.com>

	STDCXX-378
	* dynatype.cpp: Restored dynatype::operator T&(); dynatype::operator T() const
	renamed to dynatype::operator const T&() const.

Modified:
    incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp

Modified: incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp?view=diff&rev=542494&r1=542493&r2=542494
==============================================================================
--- incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp (original)
+++ incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp Tue May 29 04:44:13 2007
@@ -88,13 +88,20 @@
         (this->*p_remove)();
     }
 
-    // retrieve a value of the concrete type from an instance of
+    // retrieve a reference to the concrete type from an instance of
     // dynatype throws std::bad_cast if the types don't match exactly
     template <class T>
-    operator T () const {
+    operator T& () {
         if (map<T>::get ().end () == map<T>::get ().find (this))
             throw std::bad_cast ();
         return map<T>::get () [this];
+    }
+
+    // retrieve a const reference to the concrete type from an instance of
+    // dynatype throws std::bad_cast if the types don't match exactly
+    template <class T>
+    operator const T& () const {
+        return static_cast<T&> (*const_cast<dynatype*> (this));
     }
 
     // assign a value of any type to an instance of dynatype



Mime
View raw message