Flow Visualization 1.0

reverseBytes.h

00001 #ifndef REVERSEBYTES_H
00002 #define REVERSEBYTES_H
00003 
00004 #include <ostream>
00005 #include <iomanip>
00006 #include <algorithm>
00010 template < typename T > T reverseBytes( T const &arg )
00011 {
00012         T nrv( arg );           
00013         // reinterpret_cast ..
00014         unsigned char *p = (unsigned char *)&nrv;
00015         // don't you just love namespaces ...
00016         std::reverse( p, p + sizeof( nrv ) );
00017         // Now for the UB ...
00018         return nrv;
00019 }
00020 #endif
00021