diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index bda28fbfd..764c41c97 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -879,10 +879,10 @@ struct meta_floor_log2 template struct count_bits_impl { - static_assert(std::is_integral::value && std::is_unsigned::value, - "BitsType must be an unsigned integer"); - static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT( + is_integral::value && !NumTraits::IsSigned, + THIS_TYPE_IS_NOT_SUPPORTED); int n = CHAR_BIT * sizeof(BitsType); int shift = n / 2; while (bits > 0 && shift > 0) { @@ -900,6 +900,9 @@ struct count_bits_impl { } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT( + is_integral::value && !NumTraits::IsSigned, + THIS_TYPE_IS_NOT_SUPPORTED); int n = CHAR_BIT * sizeof(BitsType); int shift = n / 2; while (bits > 0 && shift > 0) { @@ -932,45 +935,48 @@ EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { #if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG template -struct count_bits_impl> { +struct count_bits_impl::type> { static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); - static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); static const int kLeadingBitsOffset = (sizeof(unsigned int) - sizeof(BitsType)) * CHAR_BIT; return bits == 0 ? kNumBits : __builtin_clz(static_cast(bits)) - kLeadingBitsOffset; } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); return bits == 0 ? kNumBits : __builtin_ctz(static_cast(bits)); } }; template struct count_bits_impl< - BitsType, std::enable_if_t> { + BitsType, typename enable_if::type> { static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); - static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); static const int kLeadingBitsOffset = (sizeof(unsigned long) - sizeof(BitsType)) * CHAR_BIT; return bits == 0 ? kNumBits : __builtin_clzl(static_cast(bits)) - kLeadingBitsOffset; } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); return bits == 0 ? kNumBits : __builtin_ctzl(static_cast(bits)); } }; template -struct count_bits_impl> { +struct count_bits_impl::type> { static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); - static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); static const int kLeadingBitsOffset = (sizeof(unsigned long long) - sizeof(BitsType)) * CHAR_BIT; return bits == 0 ? kNumBits : __builtin_clzll(static_cast(bits)) - kLeadingBitsOffset; } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); return bits == 0 ? kNumBits : __builtin_ctzll(static_cast(bits)); } }; @@ -978,16 +984,17 @@ struct count_bits_impl -struct count_bits_impl> { +struct count_bits_impl::type> { static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); - static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); unsigned long out; _BitScanReverse(&out, static_cast(bits)); return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); unsigned long out; _BitScanForward(&out, static_cast(bits)); return bits == 0 ? kNumBits : static_cast(out); @@ -998,16 +1005,17 @@ struct count_bits_impl struct count_bits_impl< - BitsType, std::enable_if_t> { + BitsType, typename enable_if::type> { static const int kNumBits = static_cast(sizeof(BitsType) * CHAR_BIT); - static_assert(std::is_integral::value, "BitsType must be a built-in integer"); static EIGEN_DEVICE_FUNC inline int clz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); unsigned long out; _BitScanReverse64(&out, static_cast(bits)); return bits == 0 ? kNumBits : (kNumBits - 1) - static_cast(out); } static EIGEN_DEVICE_FUNC inline int ctz(BitsType bits) { + EIGEN_STATIC_ASSERT(is_integral::value, THIS_TYPE_IS_NOT_SUPPORTED); unsigned long out; _BitScanForward64(&out, static_cast(bits)); return bits == 0 ? kNumBits : static_cast(out);