fix(bit): fix the wrong pass-by-value for non-bit types

This commit is contained in:
DarkSharpness
2024-07-11 00:35:42 +08:00
parent 4e43d84480
commit d4a9987087

View File

@ -18,93 +18,15 @@ constexpr auto operator + (_Lhs lhs, _Rhs rhs) {
return _Lhs { cast(lhs) + cast(rhs) };
}
template <BitType _Lhs, BitType _Rhs>
constexpr auto operator - (_Lhs lhs, _Rhs rhs) {
static_assert(_Lhs::_Bit_Len == _Rhs::_Bit_Len,
"operator -: lhs and rhs should have the same length");
return _Lhs { cast(lhs) - cast(rhs) };
}
template <BitType _Lhs, BitType _Rhs>
constexpr auto operator & (_Lhs lhs, _Rhs rhs) {
static_assert(_Lhs::_Bit_Len == _Rhs::_Bit_Len,
"operator &: lhs and rhs should have the same length");
return _Lhs { cast(lhs) & cast(rhs) };
}
template <BitType _Lhs, BitType _Rhs>
constexpr auto operator | (_Lhs lhs, _Rhs rhs) {
static_assert(_Lhs::_Bit_Len == _Rhs::_Bit_Len,
"operator |: lhs and rhs should have the same length");
return _Lhs { cast(lhs) | cast(rhs) };
}
template <BitType _Lhs, BitType _Rhs>
constexpr auto operator ^ (_Lhs lhs, _Rhs rhs) {
static_assert(_Lhs::_Bit_Len == _Rhs::_Bit_Len,
"operator ^: lhs and rhs should have the same length");
return _Lhs { cast(lhs) ^ cast(rhs) };
}
template <BitType _Lhs, NonBit _Rhs>
constexpr auto operator + (_Lhs lhs, _Rhs rhs) {
constexpr auto operator + (_Lhs lhs, _Rhs &&rhs) {
return _Lhs { cast(lhs) + cast(rhs) };
}
template <BitType _Lhs, NonBit _Rhs>
constexpr auto operator - (_Lhs lhs, _Rhs rhs) {
return _Lhs { cast(lhs) - cast(rhs) };
}
template <BitType _Lhs, NonBit _Rhs>
constexpr auto operator & (_Lhs lhs, _Rhs rhs) {
return _Lhs { cast(lhs) & cast(rhs) };
}
template <BitType _Lhs, NonBit _Rhs>
constexpr auto operator | (_Lhs lhs, _Rhs rhs) {
return _Lhs { cast(lhs) | cast(rhs) };
}
template <BitType _Lhs, NonBit _Rhs>
constexpr auto operator ^ (_Lhs lhs, _Rhs rhs) {
return _Lhs { cast(lhs) ^ cast(rhs) };
}
template <NonBit _Lhs, BitType _Rhs>
constexpr auto operator + (_Lhs lhs, _Rhs rhs) {
constexpr auto operator + (_Lhs &&lhs, _Rhs rhs) {
return _Rhs { cast(lhs) + cast(rhs) };
}
template <NonBit _Lhs, BitType _Rhs>
constexpr auto operator - (_Lhs lhs, _Rhs rhs) {
return _Rhs { cast(lhs) - cast(rhs) };
}
template <NonBit _Lhs, BitType _Rhs>
constexpr auto operator & (_Lhs lhs, _Rhs rhs) {
return _Rhs { cast(lhs) & cast(rhs) };
}
template <NonBit _Lhs, BitType _Rhs>
constexpr auto operator | (_Lhs lhs, _Rhs rhs) {
return _Rhs { cast(lhs) | cast(rhs) };
}
template <NonBit _Lhs, BitType _Rhs>
constexpr auto operator ^ (_Lhs lhs, _Rhs rhs) {
return _Rhs { cast(lhs) ^ cast(rhs) };
}
template <BitType _Tp>
constexpr auto operator ~ (_Tp val) {
return _Tp { ~cast(val) };
}
template <BitType _Tp>
constexpr auto operator ! (_Tp val) {
return _Tp { !cast(val) };
}
} // namespace dark::bits