mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-07 19:41:38 +12:00
Add explicit return-type overload for getBits
Allows the return-type to be specified, allowing a concise final cast after extracting the bit-type. Addresses the remaining `C4244` warnings regarding `getBits`.
This commit is contained in:
parent
37b75f0928
commit
119c908aa7
3 changed files with 36 additions and 29 deletions
|
@ -113,9 +113,16 @@ namespace Helpers {
|
|||
}
|
||||
|
||||
/// Extract bits from an integer-type
|
||||
template <usize offset, usize bits, typename T>
|
||||
static constexpr T getBits(T value) {
|
||||
return (value >> offset) & ones<T, bits>();
|
||||
template <usize offset, usize bits, typename ReturnT, typename ValueT>
|
||||
static constexpr ReturnT getBits(ValueT value) {
|
||||
static_assert((offset + bits) <= (CHAR_BIT * sizeof(ValueT)), "Invalid bit range");
|
||||
static_assert(bits > 0, "Invalid bit size");
|
||||
return ReturnT(ValueT(value >> offset) & ones<ValueT, bits>());
|
||||
}
|
||||
|
||||
template <usize offset, usize bits, typename ValueT>
|
||||
static constexpr ValueT getBits(ValueT value) {
|
||||
return getBits<offset, bits, ValueT, ValueT>(value);
|
||||
}
|
||||
|
||||
#ifdef HELPERS_APPLE_CLANG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue