26 requires std::is_arithmetic_v<T>
27 [[deprecated(
"Use MathUtil::SafelyAddWithCap instead")]]
30 using ForMath = std::conditional_t<std::is_integral_v<T> &&
sizeof(T) <
sizeof(
int), int, T>;
32 const auto a =
static_cast<ForMath
>(base);
33 const auto b =
static_cast<ForMath
>(increment);
34 const auto max =
static_cast<ForMath
>(std::numeric_limits<T>::max());
36 return static_cast<T
>(a + b > max ? max : a + b);
49 requires std::is_arithmetic_v<T>
53 using ForMath = std::conditional_t<std::is_integral_v<T> &&
sizeof(T) <
sizeof(
int), int, T>;
55 const auto a =
static_cast<ForMath
>(base);
56 const auto b =
static_cast<ForMath
>(increment);
57 const auto max = std::min(
static_cast<ForMath
>(cap),
static_cast<ForMath
>(std::numeric_limits<T>::max()));
59 return static_cast<T
>(a + b > max ? max : a + b);
static T SafelyAddWithCap(T base, T increment, T cap=std::numeric_limits< T >::max())
Add a value to another one and cap the result.
Definition st-math.h:50
static T SafelyAdd(T base, T increment)
Template function to add to a value without ever risking overflowing the maximum value that type can ...
Definition st-math.h:28