[EMAIL PROTECTED] wrote:
Author: faridz
Date: Fri May 25 06:13:16 2007
New Revision: 541635

URL: http://svn.apache.org/viewvc?view=rev&rev=541635
Log:
2007-05-25 Farid Zaripov <[EMAIL PROTECTED]>

        STDCXX-378
        * dynatype.cpp: Removed dynatype::operator T&() to resolve
        ambiguity between user defined conversions on MSVC.

Hmm. This isn't quite the same thing as the original code, even
though it doesn't change the behavior of the example program
itself. The change makes it impossible to retrieve a reference
(or pointer) to the object stored in the dynatype object. For
example, this won't work:

    dynatype d = 1;
    int *pi = &(int&)d;
    *pd = 2;
    assert (*pd == 2);

The dynatype program is an example of a dynamic type, a type
which can hold and allow users to manipulate values of any
arbitrary type, so we need to consider the impact of changes
to the dynatype template on user code as if the class were
a general purpose library component. It would be unfortunate
to remove useful functionality just to work around bugs in
a single broken compiler.

I appreciate your effort to get the example to compile with
MSVC but if we can't come up with a portable workaround maybe
we need to acknowledge that the compiler is simply too broken
to compile the full example and move on.

Btw., I tried to get the test case you submitted to Microsoft
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=266262
to work and changing class test like this did it:

    struct test {
        template <class T> operator T& ();
        template <class T> operator const T& () const;
    };

Does it work in the full example?

Martin


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=541635&r1=541634&r2=541635
==============================================================================
--- incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp (original)
+++ incubator/stdcxx/trunk/examples/tutorial/dynatype.cpp Fri May 25 06:13:16 
2007
@@ -88,20 +88,13 @@
         (this->*p_remove)();
     }
- // retrieve a reference to the concrete type from an instance of
+    // retrieve a value of the concrete type from an instance of
     // dynatype throws std::bad_cast if the types don't match exactly
     template <class T>
-    operator T& () {
+    operator T () const {
         if (map<T>::get ().end () == map<T>::get ().find (this))
             throw std::bad_cast ();
         return map<T>::get () [this];
-    }
-
-    // retrieve a value of 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 {
-        return static_cast<T&> (*const_cast<dynatype*>(this));
     }
// assign a value of any type to an instance of dynatype



Reply via email to