Add missing specializations.

This commit is contained in:
King_DuckZ 2017-06-21 21:05:15 +01:00
parent c92f132007
commit 979b1bf1cb

View file

@ -93,6 +93,28 @@ namespace dhandy {
return static_cast<int64_t>(__builtin_bswap64(static_cast<uint64_t>(parV)));
#else
# error "Unsupported endianness"
#endif
}
template <>
[[gnu::pure]] inline constexpr long long int htobe (long long int parV) {
static_assert(sizeof(long long int) == sizeof(uint64_t), "Size mismatch");
#if __BYTE_ORDER == __BIG_ENDIAN
return parV;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
return static_cast<long long int>(__builtin_bswap64(static_cast<uint64_t>(parV)));
#else
# error "Unsupported endianness"
#endif
}
template <>
[[gnu::pure]] inline constexpr unsigned long long int htobe (unsigned long long int parV) {
static_assert(sizeof(unsigned long long int) == sizeof(uint64_t), "Size mismatch");
#if __BYTE_ORDER == __BIG_ENDIAN
return parV;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
return static_cast<unsigned long long int>(__builtin_bswap64(static_cast<uint64_t>(parV)));
#else
# error "Unsupported endianness"
#endif
}
@ -162,6 +184,28 @@ namespace dhandy {
return parV;
#else
# error "Unsupported endianness"
#endif
}
template <>
[[gnu::pure]] inline constexpr long long int htole (long long int parV) {
static_assert(sizeof(long long int) == sizeof(uint64_t), "Size mismatch");
#if __BYTE_ORDER == __BIG_ENDIAN
return static_cast<long long int>(__builtin_bswap64(static_cast<uint64_t>(parV)));
#elif __BYTE_ORDER == __LITTLE_ENDIAN
return parV;
#else
# error "Unsupported endianness"
#endif
}
template <>
[[gnu::pure]] inline constexpr unsigned long long int htole (unsigned long long int parV) {
static_assert(sizeof(unsigned long long int) == sizeof(uint64_t), "Size mismatch");
#if __BYTE_ORDER == __BIG_ENDIAN
return static_cast<unsigned long long int>(__builtin_bswap64(static_cast<uint64_t>(parV)));
#elif __BYTE_ORDER == __LITTLE_ENDIAN
return parV;
#else
# error "Unsupported endianness"
#endif
}