[ox/std] Add ResizedInt to get the same sign int with a different size

This commit is contained in:
Gary Talent 2021-03-09 19:35:02 -06:00
parent f24a0a4aab
commit e583cade27

View File

@ -128,6 +128,24 @@ using Signed = Int<sizeof(T) * 8>;
template<typename T>
using Unsigned = Uint<sizeof(T) * 8>;
// ResizedInt retains the sign while granting a new size
template<typename T, std::size_t bits, bool si = T(-1) < T(0)>
struct ResizedInt {
};
template<typename T, std::size_t bits>
struct ResizedInt<T, bits, true> {
using type = typename SignedType<bits>::type;
};
template<typename T, std::size_t bits>
struct ResizedInt<T, bits, false> {
using type = typename UnsignedType<bits>::type;
};
template<typename T, std::size_t bits>
using ResizedInt_t = typename ResizedInt<T, bits>::type;
}