Boost logo

Boost :

From: Mac Murrett (mmurrett_at_[hidden])
Date: 2002-01-17 10:58:41


On 1/17/02 12:48 AM, "jk_at_[hidden]" <jk_at_[hidden]> wrote:

> 16 Jan 2002 21:27:44 +0300 Mac Murrett wrote:
>> You are both correct on this one, I had not thought of it this way. This
>> would make the implementation:
>>
>> template<class Return_Type, class Argument_Type>
>> inline Return_Type &force_cast(const Argument_Type &rSrc)
>> { return(*reinterpret_cast<const Return_Type *>(&rSrc)); }
>
> If you want mutable Return_Type&, then Argument_Type& should be mutable
> too; if the input argument is const&, then result must be const
> reference too.

Good catch again, I'm asleep at the switch here... How about this:

template<class Return_Type, class Argument_Type>
inline const Return_Type &force_cast(const Argument_Type &rSrc)
    { return(*reinterpret_cast<const Return_Type *>(&rSrc)); }

template<class Return_Type, class Argument_Type>
inline Return_Type &force_cast(Argument_Type &rSrc)
    { return(*reinterpret_cast<Return_Type *>(&rSrc)); }


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