From d4a99870874da08cac3305338a13e8686d61a4f6 Mon Sep 17 00:00:00 2001 From: DarkSharpness <2040703891@qq.com> Date: Thu, 11 Jul 2024 00:35:42 +0800 Subject: [PATCH] fix(bit): fix the wrong pass-by-value for non-bit types --- include/bitop.h | 82 ++----------------------------------------------- 1 file changed, 2 insertions(+), 80 deletions(-) diff --git a/include/bitop.h b/include/bitop.h index 67c5d14..27d5db3 100644 --- a/include/bitop.h +++ b/include/bitop.h @@ -18,93 +18,15 @@ constexpr auto operator + (_Lhs lhs, _Rhs rhs) { return _Lhs { cast(lhs) + cast(rhs) }; } -template -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 -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 -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 -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 -constexpr auto operator + (_Lhs lhs, _Rhs rhs) { +constexpr auto operator + (_Lhs lhs, _Rhs &&rhs) { return _Lhs { cast(lhs) + cast(rhs) }; } -template -constexpr auto operator - (_Lhs lhs, _Rhs rhs) { - return _Lhs { cast(lhs) - cast(rhs) }; -} - -template -constexpr auto operator & (_Lhs lhs, _Rhs rhs) { - return _Lhs { cast(lhs) & cast(rhs) }; -} - -template -constexpr auto operator | (_Lhs lhs, _Rhs rhs) { - return _Lhs { cast(lhs) | cast(rhs) }; -} - -template -constexpr auto operator ^ (_Lhs lhs, _Rhs rhs) { - return _Lhs { cast(lhs) ^ cast(rhs) }; -} - template -constexpr auto operator + (_Lhs lhs, _Rhs rhs) { +constexpr auto operator + (_Lhs &&lhs, _Rhs rhs) { return _Rhs { cast(lhs) + cast(rhs) }; } -template -constexpr auto operator - (_Lhs lhs, _Rhs rhs) { - return _Rhs { cast(lhs) - cast(rhs) }; -} - -template -constexpr auto operator & (_Lhs lhs, _Rhs rhs) { - return _Rhs { cast(lhs) & cast(rhs) }; -} - -template -constexpr auto operator | (_Lhs lhs, _Rhs rhs) { - return _Rhs { cast(lhs) | cast(rhs) }; -} - -template -constexpr auto operator ^ (_Lhs lhs, _Rhs rhs) { - return _Rhs { cast(lhs) ^ cast(rhs) }; -} - -template -constexpr auto operator ~ (_Tp val) { - return _Tp { ~cast(val) }; -} - -template -constexpr auto operator ! (_Tp val) { - return _Tp { !cast(val) }; -} - } // namespace dark::bits