| 302 | // Generate maximum/minimum values for signed/unsigned n-bit integers |
| 303 | template <typename T> |
| 304 | constexpr T MaxInt(size_t bits) { |
| 305 | DCHECK(std::is_unsigned<T>::value || bits > 0u) << "bits cannot be zero for signed."; |
| 306 | DCHECK_LE(bits, BitSizeOf<T>()); |
| 307 | using unsigned_type = typename std::make_unsigned<T>::type; |
| 308 | return bits == BitSizeOf<T>() |
| 309 | ? std::numeric_limits<T>::max() |
| 310 | : std::is_signed<T>::value |
| 311 | ? ((bits == 1u) ? 0 : static_cast<T>(MaxInt<unsigned_type>(bits - 1))) |
| 312 | : static_cast<T>(UINT64_C(1) << bits) - static_cast<T>(1); |
| 313 | } |
| 314 | |
| 315 | template <typename T> |
| 316 | constexpr T MinInt(size_t bits) { |
nothing calls this directly
no outgoing calls
no test coverage detected