34 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
"T must be an unsigned integer");
35 static_assert(Bits <=
sizeof(T) * 8,
"Bits must be less than or equal to the number of bits in T");
37 using S =
typename std::make_signed<T>::type;
38 return static_cast<S
>((v & (1ULL << (Bits - 1))) ? (v & ((1ULL << Bits) - 1)) - (1ULL << Bits)
39 : (v & ((1ULL << Bits) - 1)));
constexpr auto unsigned_to_signed(const T v) -> typename std::make_signed< T >::type
Convert an unsigned integer of any maximum number of bits to a signed integer.
Definition conversion.hpp:32