mirror of
https://github.com/matrix-construct/construct
synced 2024-11-18 07:50:57 +01:00
ircd::util: Fix bswap() to not rely on data()/size() et al.
This commit is contained in:
parent
af0c02cc10
commit
b2503ba1d0
1 changed files with 5 additions and 2 deletions
|
@ -32,7 +32,8 @@ T &
|
||||||
ircd::util::bswap(T *const &val)
|
ircd::util::bswap(T *const &val)
|
||||||
{
|
{
|
||||||
assert(val != nullptr);
|
assert(val != nullptr);
|
||||||
std::reverse(data(*val), data(*val) + size(*val));
|
const auto ptr{reinterpret_cast<uint8_t *>(val)};
|
||||||
|
std::reverse(ptr, ptr + sizeof(T));
|
||||||
return *val;
|
return *val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +43,8 @@ T
|
||||||
ircd::util::bswap(const T &val)
|
ircd::util::bswap(const T &val)
|
||||||
{
|
{
|
||||||
T ret;
|
T ret;
|
||||||
std::reverse_copy(data(val), data(val) + size(val), data(ret));
|
const auto valptr{reinterpret_cast<const uint8_t *>(&val)};
|
||||||
|
const auto retptr{reinterpret_cast<uint8_t *>(&ret)};
|
||||||
|
std::reverse_copy(valptr, valptr + sizeof(T), retptr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue