On Fri, 29 Nov 2002 21:20:14 +0200, "Peter Dimov" <[EMAIL PROTECTED]> wrote:
>From: "David Abrahams" <[EMAIL PROTECTED]> >> 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. Yes, that's the reason for doing conversion directly "on the argument". But I think David was asking why not: template<class T> T implicit_cast(T x) { return x; } The reason for this, I think, is that type deduction is based on the static type of the expression used as argument, so the above would slice the object passed e.g. in: Derived d; Base * p = &d; implicit_cast(*p); // deduction: T = base The identity<> trick avoids this possible oversight (well, you must explicitly specify 'Base' instead of 'Base&' as destination type to make that error! :-). Maybe there are other reasons too, I asked this to you in another post. Are there? Genny. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost