31 return std::endian::native == std::endian::little;
45 constexpr i32 sz =
sizeof(a);
49 auto constexpr lambd = []() {
50 if constexpr (sz % 2 == 0) {
57 constexpr i32 steps = lambd();
59 u8 *bytes = (
u8 *) &a;
62 for (
i32 i = 0; i < steps; i++) {
63 xor_swap(bytes[i], bytes[sz - 1 - i]);
std::uint8_t u8
8 bit unsigned integer
std::int32_t i32
32 bit integer
namespace for basic c++ utilities
void endian_swap(T &a)
Swap the endianness of the input value.
T get_endian_swap(T a)
Return a copy of the input value with the endianness swapped.
void xor_swap(T &a, T &b)
swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks....
constexpr bool is_little_endian() noexcept
Check if the CPU is in little endian.