From: "David Abrahams" <[EMAIL PROTECTED]>
> "Peter Dimov" <[EMAIL PROTECTED]> writes:
>
> > From: "David Abrahams" <[EMAIL PROTECTED]>
> >>
> >> Here's what I think might be a correct implementation:
> >>
> >>      template <class T, class U> T implicit_cast(U const& x) { return
x; }
> >>      template <class T, class U> T implicit_cast(U& x) { return x; }
> >
> > The correct implementation IIRC is
> >
> > template<class T> T implicit_cast(typename identity<T>::type x) { return
> > x; }
>
>
> Now I have to put on my inference hat.
>
> ...so the use of identity<> assures that we have a non-deduced
> context, which causes the explicit template parameter to be required?
>
> ...I suppose that T has to be copyable for any of these to work, so
> there's no problem with taking T by-value.

The main reason to prefer this implementation is that it works in contexts
where the conversion is accessible at the point of the implicit_cast call,
but not accessible to the definition of implicit_cast. Here's a test case:

class X
{
};

class Y: private X
{
public:

    void f()
    {
        X * p1 = this;
        X * p2 = implicit_cast<X*>(this);
    }
};

I believe that Darin is the original inventor of this implicit_cast.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to