Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-10-10 15:47:42


AMDG

Simonson, Lucanus J <lucanus.j.simonson <at> intel.com> writes:

> Upon reviewing the code it turns out that I use static_cast in the
> implementation of mimic. I must have used reinterpret_cast originally
> and then changed it to static_cast after some code review with Gyuszi.
> static PointConcept& mimic() { return
> static_cast<PointConcept&>(t); }
> I am using autocast on the return value of yield to convert to the base
> type
> T& yield() { return *this; }
> Let's please rewind the conversation.
>
> Using composition instead of inheritance would require reinterpret_cast,
> as I understand it, so perhaps we should decide together if that is
> really a change I should make. Is the suggestion to use composition a
> bad idea? Is it based on unspecified behavior?
>

reinterpret_cast at least guarantees reversibility, static_cast
doesn't even do that.

Compare.

static_cast:

"If the rvalue of type “pointer to cv1 B” points to a B that is
actually a sub-object of an object of type D, the resulting
pointer points to the enclosing object of type D. Otherwise,
the result of the cast is undefined." (5.2.9/8)

reinterpret_cast:

"Except that converting an rvalue of type “pointer to T1” to
the type “pointer to T2” (where T1 and T2 are object types
and where the alignment requirements of T2 are no stricter
than those of T1) and back to its original type yields the
original pointer value, the result of such a pointer
conversion is unspecified." (5.2.10/7)

In Christ,
Steven Watanabe


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