fs: Add path class
This commit is contained in:
parent
54372fdff5
commit
2c049ae06d
11 changed files with 2228 additions and 30 deletions
|
@ -19,4 +19,21 @@ inline T WrappingAdd(T lhs, T rhs) {
|
|||
return BitCast<T>(lhs_u + rhs_u);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::is_integral_v<T> && std::is_signed_v<T>)
|
||||
inline bool CanAddWithoutOverflow(T lhs, T rhs) {
|
||||
#ifdef _MSC_VER
|
||||
if (lhs >= 0 && rhs >= 0) {
|
||||
return WrappingAdd(lhs, rhs) >= std::max(lhs, rhs);
|
||||
} else if (lhs < 0 && rhs < 0) {
|
||||
return WrappingAdd(lhs, rhs) <= std::min(lhs, rhs);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
T res;
|
||||
return !__builtin_add_overflow(lhs, rhs, &res);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue