mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-28 13:19:48 +01:00
Merge accumulator into int128_fallback
This commit is contained in:
@@ -346,8 +346,12 @@ class uint128_fallback {
|
||||
|
||||
public:
|
||||
constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {}
|
||||
explicit operator int() const { return static_cast<int>(lo_); }
|
||||
explicit operator uint64_t() const { return lo_; }
|
||||
|
||||
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
|
||||
constexpr explicit operator T() const {
|
||||
return static_cast<T>(lo_);
|
||||
}
|
||||
|
||||
friend auto operator==(const uint128_fallback& lhs,
|
||||
const uint128_fallback& rhs) -> bool {
|
||||
return lhs.hi_ == rhs.hi_ && lhs.lo_ == rhs.lo_;
|
||||
@@ -361,14 +365,19 @@ class uint128_fallback {
|
||||
FMT_ASSERT(lhs.lo_ >= rhs, "");
|
||||
return {lhs.hi_, lhs.lo_ - rhs};
|
||||
}
|
||||
auto operator>>(int shift) const -> uint128_fallback {
|
||||
FMT_CONSTEXPR auto operator>>(int shift) const -> uint128_fallback {
|
||||
if (shift == 64) return {0, hi_};
|
||||
return {hi_ >> shift, (hi_ << (64 - shift)) | (lo_ >> shift)};
|
||||
}
|
||||
auto operator<<(int shift) const -> uint128_fallback {
|
||||
FMT_CONSTEXPR auto operator<<(int shift) const -> uint128_fallback {
|
||||
if (shift == 64) return {lo_, 0};
|
||||
return {hi_ << shift | (lo_ >> (64 - shift)), (lo_ << shift)};
|
||||
}
|
||||
FMT_CONSTEXPR void operator>>=(int shift) { *this = *this >> shift; }
|
||||
FMT_CONSTEXPR void operator+=(uint64_t n) {
|
||||
lo_ += n;
|
||||
if (lo_ < n) ++hi_;
|
||||
}
|
||||
};
|
||||
|
||||
using uint128_t = conditional_t<FMT_USE_INT128, uint128_opt, uint128_fallback>;
|
||||
|
||||
Reference in New Issue
Block a user