2626
2727namespace fml {
2828
29+ template <typename T>
30+ struct IsByteSwappable
31+ : public std::
32+ integral_constant<bool , std::is_integral_v<T> || std::is_enum_v<T>> {
33+ };
34+ template <typename T>
35+ constexpr bool IsByteSwappableV = IsByteSwappable<T>::value;
36+
2937// / @brief Flips the endianness of the given value.
3038// / The given value must be an integral type of size 1, 2, 4, or 8.
31- template <typename T, class = std::enable_if_t <std::is_integral_v <T>>>
39+ template <typename T, class = std::enable_if_t <IsByteSwappableV <T>>>
3240constexpr T ByteSwap (T n) {
3341 if constexpr (sizeof (T) == 1 ) {
3442 return n;
@@ -47,7 +55,7 @@ constexpr T ByteSwap(T n) {
4755// / current architecture. This is effectively a cross platform
4856// / ntohl/ntohs (as network byte order is always Big Endian).
4957// / The given value must be an integral type of size 1, 2, 4, or 8.
50- template <typename T, class = std::enable_if_t <std::is_integral_v <T>>>
58+ template <typename T, class = std::enable_if_t <IsByteSwappableV <T>>>
5159constexpr T BigEndianToArch (T n) {
5260#if FML_ARCH_CPU_LITTLE_ENDIAN
5361 return ByteSwap<T>(n);
@@ -59,7 +67,7 @@ constexpr T BigEndianToArch(T n) {
5967// / @brief Convert a known little endian value to match the endianness of the
6068// / current architecture.
6169// / The given value must be an integral type of size 1, 2, 4, or 8.
62- template <typename T, class = std::enable_if_t <std::is_integral_v <T>>>
70+ template <typename T, class = std::enable_if_t <IsByteSwappableV <T>>>
6371constexpr T LittleEndianToArch (T n) {
6472#if !FML_ARCH_CPU_LITTLE_ENDIAN
6573 return ByteSwap<T>(n);
0 commit comments