Commit d0646aa4 authored by Tiago Peixoto's avatar Tiago Peixoto

graph_io_binary.hh: figure out endianess at compile-time

parent e81cdd98
Pipeline #689 passed with stage
in 71 minutes and 50 seconds
......@@ -33,16 +33,19 @@ const uint8_t _version = 1;
// deal with endianness
inline bool is_bigendian()
inline constexpr bool is_bigendian()
{
// from: http://esr.ibiblio.org/?p=5095
return (*(uint16_t *)"\0\xff" < 0x100);
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return false;
#else
return true;
#endif
};
template <bool BE, typename T>
void byte_swap(T& p)
{
if (BE == is_bigendian())
if constexpr (BE == is_bigendian())
return;
char& r = reinterpret_cast<char&>(p);
std::reverse(&r, &r + sizeof(T));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment