On Wed, Nov 12, 2008 at 2:10 PM, Lawrence Crowl <[EMAIL PROTECTED]> wrote: > > Now would be a good time to mention Google's bit_cast<>.
And here is a simple portable implementation (still implementation
defined really) of that:
#include <cstring>
template<typename to, typename from> to bit_cast(from a)
{
int notthesamesize[sizeof(from) == sizeof(to)?1:-1];
to b;
std::memcpy (&b, &a, sizeof(from));
return b;
}
Thanks,
Andrew Pinski
