0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-23 22:13:55 +01:00

ircd::util: Improve bswap template codegen.

This commit is contained in:
Jason Volk 2022-07-01 12:02:55 -07:00
parent 81b6c7b003
commit c60fc0ccdd

View file

@ -138,11 +138,18 @@ ircd::util::bswap(T *const val)
noexcept
{
assert(val != nullptr);
const auto ptr
const auto &src
{
reinterpret_cast<uint8_t *>(val)
reinterpret_cast<const uint8_t *>(val)
};
std::reverse(ptr, ptr + sizeof(T));
T tmp;
const auto &dst
{
reinterpret_cast<uint8_t *>(&tmp)
};
std::reverse_copy(src, src + sizeof(T), dst);
*val = tmp;
return *val;
}