u128: Add u128::Bit
This commit is contained in:
parent
3e62fea003
commit
5566fab29a
1 changed files with 11 additions and 1 deletions
|
@ -24,7 +24,7 @@ struct u128 {
|
|||
|
||||
u128(u64 lower_, u64 upper_) : lower(lower_), upper(upper_) {}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
/* implicit */ u128(T value) : lower(value), upper(0) {
|
||||
static_assert(std::is_integral_v<T>);
|
||||
static_assert(Common::BitSize<T>() <= Common::BitSize<u64>());
|
||||
|
@ -32,6 +32,16 @@ struct u128 {
|
|||
|
||||
u64 lower = 0;
|
||||
u64 upper = 0;
|
||||
|
||||
template<size_t bit_position>
|
||||
bool Bit() {
|
||||
static_assert(bit_position < 128);
|
||||
if constexpr (bit_position < 64) {
|
||||
return Common::Bit<bit_position>(lower);
|
||||
} else {
|
||||
return Common::Bit<bit_position - 64>(upper);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static_assert(Common::BitSize<u128>() == 128);
|
||||
|
|
Loading…
Reference in a new issue