#pragma once #include #include namespace lightningbolt { namespace detail { template constexpr T PunCast(U v) { return *std::bit_cast(&v); } template constexpr T ByteSwap(T v) { if constexpr(sizeof(T) == 2) return static_cast(__builtin_bswap16(PunCast(v))); else if constexpr(sizeof(T) == 4) return static_cast(__builtin_bswap32(PunCast(v))); else if constexpr(sizeof(T) == 8) return static_cast(__builtin_bswap64(PunCast(v))); return v; } } // namespace detail using detail::ByteSwap; } // namespace lightningbolt