feat(op): add more bit op

This commit is contained in:
DarkSharpness
2024-07-12 10:31:57 +08:00
parent 4760da41fb
commit 6115549a7e

View File

@ -72,4 +72,37 @@ constexpr auto operator ^ (const _Tp &lhs, const _Up &rhs) {
return Bit <_Len> (cast(lhs) + cast(rhs));
}
template <typename _Tp>
concept int_or_bit = int_type <_Tp> || bit_type <_Tp>;
template <bit_type _Tp, int_or_bit _Up>
constexpr auto operator << (const _Tp &lhs, const _Up &rhs) {
return Bit <_Tp::_Bit_Len> (cast(lhs) << (cast(rhs) & kMaxLength));
}
template <bit_type _Tp, int_or_bit _Up>
constexpr auto operator >> (const _Tp &lhs, const _Up &rhs) {
return Bit <_Tp::_Bit_Len> (cast(lhs) >> (cast(rhs) & kMaxLength));
}
template <bit_type _Tp>
constexpr auto operator ~ (const _Tp &value) {
return Bit <_Tp::_Bit_Len> (~cast(value));
}
template <bit_type _Tp>
constexpr auto operator ! (const _Tp &value) {
return ~value;
}
template <bit_type _Tp>
constexpr auto operator + (const _Tp &value) {
return Bit <_Tp::_Bit_Len> (+cast(value));
}
template <bit_type _Tp>
constexpr auto operator - (const _Tp &value) {
return Bit <_Tp::_Bit_Len> (-cast(value));
}
} // namespace dark