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 <[EMAIL PROTECTED]>
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