|
Boost : |
From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-01-13 08:48:31
At 11:46 AM 1/13/2001 +0000, Stephen Silver wrote:
>Beman Dawes wrote:
>
>>At 04:05 PM 1/12/2001 -0500, George A. Heintzelman wrote:
>
>> >template <class T> rational(T n) :
>> > num(boost::implicit_cast<IntType>(n)),
>> > den(IntType(1)) {} // Or whatever you finally decide to use for 1.
>> >
>> >I seem to remember some discussion about exactly this sort of need,
and
>> >had thought that it was in the BCL, but it doesn't seem to be. Perhaps
>> >this is an example which suggests it needs to be added?
>>
>>We removed implicit_cast<> because it had a number of problems. The
>>comment in the header says:
>>
>>// Removed due to uncertain purpose. Use either numeric_cast (see below)
>>// or static_cast according to the need.
>
>This comment makes no sense to me. static_cast can make use of an
>explicit constructor (ISO 5.2.9 / 2), so it can never be used in any
>situation for which implicit_cast is intended. And numeric_cast is
>something quite different.
>
>In any case, neither static_cast nor numeric_cast is suitable in the
>above situation, but implicit_cast is. What were the problems with
>implicit_cast?
Search the archive for "implicit cast" and you will find a bunch of
messages. Read the thread starting about message 889, for example.
IIRC, the best shot at getting it to work correctly was Darin Adler's:
template<typename T> struct mirror_type { typedef T type; };
template<typename T>
inline T implicit_cast( typename mirror_type<T>::type t ) { return t; }
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk