diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2023-11-03 01:59:28 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2023-11-03 02:28:41 +0300 |
commit | d366e8a8ae0c46aaaabd5cde2bd35fbf8adad525 (patch) | |
tree | ed7b47f9f267985138edae3e17814582854b9514 /library/cpp | |
parent | 1ff41fbc8d84eb71ae278c62500546cedab8dce2 (diff) | |
download | ydb-d366e8a8ae0c46aaaabd5cde2bd35fbf8adad525.tar.gz |
YT-20376: Removed some of the std overloads
First commit
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/int128/int128.h | 64 | ||||
-rw-r--r-- | library/cpp/int128/ut/i128_type_traits_ut.cpp | 6 | ||||
-rw-r--r-- | library/cpp/yt/small_containers/compact_vector-inl.h | 14 |
3 files changed, 42 insertions, 42 deletions
diff --git a/library/cpp/int128/int128.h b/library/cpp/int128/int128.h index f1121fc0c6..41f143e295 100644 --- a/library/cpp/int128/int128.h +++ b/library/cpp/int128/int128.h @@ -307,6 +307,23 @@ private: template <bool IsSigned2> friend constexpr ui64 GetLow(TInteger128<IsSigned2> value) noexcept; + friend constexpr bool signbit(TInteger128 arg) noexcept { + if constexpr (IsSigned) { + return GetHigh(arg) & 0x8000000000000000; + } else { + Y_UNUSED(arg); + return false; + } + } + + friend constexpr TInteger128 abs(TInteger128 arg) noexcept { + if constexpr (IsSigned) { + return signbit(arg) ? (-arg) : arg; + } else { + return arg; + } + } + friend IOutputStream& operator<<(IOutputStream& out, const TInteger128& other); }; // class TInteger128 @@ -459,23 +476,6 @@ namespace std { return 0; } }; - - constexpr bool signbit(const ui128 arg) noexcept { - Y_UNUSED(arg); - return false; - } - - constexpr bool signbit(const i128 arg) noexcept { - return GetHigh(arg) & 0x8000000000000000; - } - - constexpr ui128 abs(const ui128 arg) noexcept { - return arg; - } - - constexpr i128 abs(const i128 arg) noexcept { - return signbit(arg) ? (-arg) : arg; - } } constexpr bool operator==(const ui128 lhs, const ui128 rhs) noexcept { @@ -507,8 +507,8 @@ constexpr bool operator<(const i128 lhs, const i128 rhs) noexcept { return false; } - const bool lhsIsNegative = std::signbit(lhs); - const bool rhsIsNegative = std::signbit(rhs); + const bool lhsIsNegative = signbit(lhs); + const bool rhsIsNegative = signbit(rhs); if (lhsIsNegative && !rhsIsNegative) { return true; @@ -921,12 +921,12 @@ constexpr ui128 operator/(const ui128 lhs, const ui128 rhs) noexcept { } constexpr i128 operator/(const i128 lhs, const i128 rhs) noexcept { - i128 a = std::abs(lhs); - i128 b = std::abs(rhs); + i128 a = abs(lhs); + i128 b = abs(rhs); ui128 quotient{}; NPrivateInt128::DivMod128(a, b, "ient, nullptr); - if (std::signbit(lhs) ^ std::signbit(rhs)) { + if (signbit(lhs) ^ signbit(rhs)) { quotient = -quotient; } return quotient; @@ -939,11 +939,11 @@ constexpr ui128 operator%(const ui128 lhs, const ui128 rhs) noexcept { } constexpr i128 operator%(const i128 lhs, const i128 rhs) noexcept { - i128 a = std::abs(lhs); - i128 b = std::abs(rhs); + i128 a = abs(lhs); + i128 b = abs(rhs); ui128 remainder{}; NPrivateInt128::DivMod128(a, b, nullptr, &remainder); - if (std::signbit(lhs)) { + if (signbit(lhs)) { remainder = -remainder; } return remainder; @@ -1075,7 +1075,7 @@ namespace NPrivateInt128 { // X/0 = +/- inf, X%0 = X if (rhs == 0) { // UB, let's return: `X / 0 = +inf`, and `X % 0 = X` - result.Quotient = std::signbit(lhs) ? std::numeric_limits<i128>::min() : std::numeric_limits<i128>::max(); + result.Quotient = signbit(lhs) ? std::numeric_limits<i128>::min() : std::numeric_limits<i128>::max(); result.Remainder = lhs; } @@ -1098,7 +1098,7 @@ namespace NPrivateInt128 { } // abs(X)<abs(Y), X/Y = 0, X%Y = X - else if (std::abs(lhs) < std::abs(rhs)) { + else if (abs(lhs) < abs(rhs)) { result.Quotient = 0; result.Remainder = lhs; } @@ -1113,12 +1113,12 @@ namespace NPrivateInt128 { result.Remainder = 0; } - else if (std::abs(lhs) > std::abs(rhs)) { - const bool quotientMustBeNegative = std::signbit(lhs) ^ std::signbit(rhs); - const bool remainderMustBeNegative = std::signbit(lhs); + else if (abs(lhs) > abs(rhs)) { + const bool quotientMustBeNegative = signbit(lhs) ^ signbit(rhs); + const bool remainderMustBeNegative = signbit(lhs); - lhs = std::abs(lhs); - rhs = std::abs(rhs); + lhs = abs(lhs); + rhs = abs(rhs); // result is division of two ui64 if (GetHigh(lhs) == 0 && GetHigh(rhs) == 0) { diff --git a/library/cpp/int128/ut/i128_type_traits_ut.cpp b/library/cpp/int128/ut/i128_type_traits_ut.cpp index 4ed87bf229..9206f02c7a 100644 --- a/library/cpp/int128/ut/i128_type_traits_ut.cpp +++ b/library/cpp/int128/ut/i128_type_traits_ut.cpp @@ -34,20 +34,20 @@ Y_UNIT_TEST_SUITE(I128TypeTraitsSuite) { Y_UNIT_TEST(AbsFromPositive) { const i128 n = 1; - const i128 m = std::abs(n); + const i128 m = abs(n); UNIT_ASSERT(m == n); } Y_UNIT_TEST(AbsFromNegative) { const i128 n = -1; - const i128 m = std::abs(n); + const i128 m = abs(n); const i128 expected = 1; UNIT_ASSERT(m == expected); } Y_UNIT_TEST(AbsFromZero) { const i128 n = 0; - const i128 m = std::abs(n); + const i128 m = abs(n); UNIT_ASSERT(m == n); } diff --git a/library/cpp/yt/small_containers/compact_vector-inl.h b/library/cpp/yt/small_containers/compact_vector-inl.h index ba1223102d..3bb9576d3e 100644 --- a/library/cpp/yt/small_containers/compact_vector-inl.h +++ b/library/cpp/yt/small_containers/compact_vector-inl.h @@ -992,20 +992,20 @@ bool operator<(const TCompactVector<T, LhsN>& lhs, const TCompactVector<T, RhsN> return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } -///////////////////////////////////////////////////////////////////////////// - -} // namespace NYT - -namespace std { - //////////////////////////////////////////////////////////////////////////////// template <class T, size_t N> -void swap(NYT::TCompactVector<T, N>& lhs, NYT::TCompactVector<T, N>& rhs) +void swap(TCompactVector<T, N>& lhs, TCompactVector<T, N>& rhs) // NOLINT { lhs.swap(rhs); } +///////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + +namespace std { + //////////////////////////////////////////////////////////////////////////////// template <class T, size_t N> |