Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<integral T>
- inline T ByteSwapToBE(T unit) {
- static_assert(sizeof(T) == 2 || sizeof(T) == 4 || sizeof(T) == 8);
- if constexpr(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__){
- if constexpr (sizeof(T) == 2)
- return __builtin_bswap16(unit);
- else if constexpr (sizeof(T) == 4)
- return __builtin_bswap32(unit);
- else if constexpr (sizeof(T) == 8)
- return __builtin_bswap64(unit);
- }
- return unit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement