MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / IsUint

Function IsUint

Bcore/src/main/cpp/base/bit_utils.h:276–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274
275template <size_t kBits, typename T>
276constexpr 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
290template <size_t kBits, typename T>
291constexpr bool IsAbsoluteUint(T value) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected