| 274 | |
| 275 | template <size_t kBits, typename T> |
| 276 | constexpr bool IsUint(T value) { |
| 277 | static_assert(kBits > 0, "kBits cannot be zero."); |
| 278 | static_assert(kBits <= BitSizeOf<T>(), "kBits must be <= max."); |
| 279 | static_assert(std::is_integral<T>::value, "Needs an integral type."); |
| 280 | // Corner case for "use all bits." Can't use the limits, as they would overflow, but it is |
| 281 | // trivially true. |
| 282 | // NOTE: To avoid triggering assertion in GetIntLimit(kBits+1) if kBits+1==BitSizeOf<T>(), |
| 283 | // use GetIntLimit(kBits)*2u. The unsigned arithmetic works well for us if it overflows. |
| 284 | using unsigned_type = typename std::make_unsigned<T>::type; |
| 285 | return (0 <= value) && |
| 286 | (kBits == BitSizeOf<T>() || |
| 287 | (static_cast<unsigned_type>(value) <= GetIntLimit<unsigned_type>(kBits) * 2u - 1u)); |
| 288 | } |
| 289 | |
| 290 | template <size_t kBits, typename T> |
| 291 | constexpr bool IsAbsoluteUint(T value) { |
nothing calls this directly
no outgoing calls
no test coverage detected