Boost logo

Boost :

From: Mac Murrett (mmurrett_at_[hidden])
Date: 2002-01-16 11:39:50


On 1/16/02 2:20 AM, "jk_at_[hidden]" <jk_at_[hidden]> wrote:

> 16 Jan 2002 06:52:11 +0300 Mac Murrett ???????:
>> Its purpose is to convert anything to anything, and it looks like this:
>>
>> // force_cast will convert anything to anything.
>>
>> template<class Return_Type, class Argument_Type>
>> inline Return_Type force_cast(const Argument_Type &rSrc)
>> { return(*reinterpret_cast<const Return_Type *>(&rSrc)); }
>
> Then copying will occur. Wouldn't it be better to return by reference,
> like below?
>
> template<class Return_Type, class Argument_Type>
> inline const Return_Type& force_cast(const Argument_Type &rSrc)
> { return(*reinterpret_cast<const Return_Type *>(&rSrc)); }

If a user wants this, (s)he can use force_cast<Type &>. Also, I don't think
that returning a const & by default is fair, as users should have the right
to modify their data :).

Mac Murrett.


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