On Mon, May 24, 2010 at 6:59 PM, John Dlugosz <JDlugosz@tradestation.com> wrote:
>
> The problem is not downcasting, but the fact that T is not rv<T> (the
> dynamic type of T is T, not rv<T>):
>

Reading the referenced article on C99 aliasing rules, perhaps what is needed is a alias_cast template that does it right (e.g. pass it through a union or use proper compiler-specific decorations).


That was my first thought too, but as far as I know all correct uses of a union would mandate a fully copy of the T instance. I think that the containment by pointer that was suggested by Steven Watanabe makes for a nice solution.

If you have a novel solution that uses a union while avoiding assignment to a new T instance I would be very interested.

Regards,
Neil Groves