Boost logo

Boost :

From: Mac Murrett (mmurrett_at_[hidden])
Date: 2002-01-16 13:25:51


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

> Then copying will occur. Wouldn't it be better to return by reference,
> like below?

On 1/16/02 11:55 AM, "bill_kempf" <williamkempf_at_[hidden]> wrote:

> I didn't notice this in your original code. A cast does only that,
> it casts the type. When you use such a cast you should still be
> manipulating the same memory space: you should only be treating it as
> some new type.

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)); }

As a side note, this same way of thinking implies that lexical_cast<> is not
really a cast either, does it not?

Mac Murrett.


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