From: Jens Maurer (jmaurer_at_[hidden])
Date: 2000-03-10 17:10:19
"Borgerding, Mark A." wrote:
> The concept is a wrapper around an integer type that automatically convert
> to/from the desired byte order.
Please check out <boost/bin_ubin.hpp>, which already has the
equivalent of big_endian<> in a CPU-endianess independent
A little_endian<> class complements this nicely. However,
we should merge it all in one header.
Furthermore, I think that "big_endian<>" and "little_endian<>"
express the semantics a bit better than the current "ubin32".
Aside from syntactical issues (namespace boost etc.), you
should probably use std::reverse from the STL in reverse_bytes()
instead of doing it your own (buggy) way:
> template <class T>
> T reverse_bytes(T d)
> T orig(d);
> const char * pSrc = reinterpret_cast<const char *>(&orig);
> const char * pSrcEnd = pSrc + sizeof(T);
> char * pDest = reinterpret_cast<char *>(&d) + sizeof(T);
> for (;pSrc != pSrcEnd;++pSrc)
> *--pDest = *pSrc;
> return d;
pDest and pSrc will overlap and half of T will be lost.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk