Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-11-29 13:49:42


"Peter Dimov" <pdimov_at_[hidden]> writes:

> From: "David Abrahams" <dave_at_[hidden]>
>>
>> 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.

OK, I like this implementation. I'm going to add it to cast.hpp unless
there are objections.

-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk