
Mathias Gaunard wrote:
On 06/09/2011 00:38, Phil Endecott wrote:
#elif defined(USE_BEMAN)
const char* s (reinterpret_cast<const char*>(&src)); uint32_t target; char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1); *t = *s; *--t = *++s; *--t = *++s; *--t = *++s; return target;
Why isn't that just std::reverse?
Well std::reverse is in-place, and this particular code is not. But yes, std::reverse could be used for some of Beman's functions, and some sort of std::copy with reverse iterators could be used here. There are also places where the code could be more concise if std::swap were used. Fundamentally though, I don't think that casting to bytes is the right way to do this; shifts and bitwise ops seem to produce better code, and involve less worrying casting. Regards, Phil.