
4 Aug
2006
4 Aug
'06
10:06 a.m.
And here is an implementation of binary_cast, based on Gennaro Prota's code. template<class T, class S> T binary_cast(const S& s) { BOOST_STATIC_ASSERT(sizeof(S) == sizeof(T)); T t; std::copy( reinterpret_cast<const volatile char*>(&s), reinterpret_cast<const volatile char*>(&s) + sizeof(S), reinterpret_cast<volatile char*>(&t) ); return t; } I still find it hard to believe that the volatile are needed ;-) But my experience with different compilers is quite limited. --Johan Råde