Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-08-04 07:32:47


Peter Dimov wrote:
> Martin Bonner wrote:
>>> Johan Råde wrote:
>>>
>>>> I still find it hard to believe that the volatile are needed ;-)
>>>
>>> It is not.
>>
>> If volatile is not present, then you can't instantiate the template
>> with T="volatile float" for example. (Similarly you need the "const"
>> so that you can invoke with T="const float".)
>
> template<class T, class S> T binary_cast( S const & s )
> {
> T t;
> memcpy( &t, &s, sizeof(T) );
> return t;
> }

So you were talking about T. Sorry. :-)

Since binary_cast doesn't appear to be safe for use in generic code, it
seems reasonable to assume that a programmer invoking binary_cast<const
float> or binary_cast<volatile float> expects a return type of const float
or volatile float, respectively. But this is impossible. R-values of type
float are never cv-qualified. It doesn't make sense to support such
incorrect signatures to be produced (even though it's trivially possible by
using remove_cv once to remove the error or twice to remove the potential
compiler warning about a cv-qualified float return type.)


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