54template<UE::CIntegral IntType>
58 static_assert(std::is_integral_v<IntType>,
"Only defined for integer types");
59 typedef typename std::make_unsigned_t<IntType> UnsignedType;
61 static constexpr IntType MinValue = std::numeric_limits<IntType>::min();
62 static constexpr IntType MaxValue = std::numeric_limits<IntType>::max();
63 static constexpr IntType NumBits = IntType((
sizeof(IntType) /
sizeof(
char)) * 8);
66 bool bIsValid =
false;
73 template<UE::CIntegral ValueType>
77 if constexpr (std::is_signed_v<ValueType>)
83 bIsValid =
InValue <= UnsignedType(MaxValue);
102 return IsValid() ? Value : DefaultValue;
111 return Get(DefaultValue);
117 if (bIsValid !=
Other.bIsValid)
122 return !bIsValid || Value ==
Other.Value;
128 if (bIsValid !=
Other.bIsValid)
133 return bIsValid && Value !=
Other.Value;
142 return bIsValid &&
Other.bIsValid;
146 template<
typename ValueType>
154 template<
typename ValueType>
162 template<
typename ValueType>
170 template<
typename ValueType>
178 template<
typename ValueType>
186 template<
typename ValueType>
194 template<
typename ValueType>
202 template<
typename ValueType>
214 if constexpr (std::is_signed_v<IntType>)
230 if (!bIsValid || !
Other.bIsValid)
236 return FPlatformMath::AddAndCheckForOverflow<IntType>(Value,
Other.Value, Result)
245 if (!bIsValid || !
Other.bIsValid)
251 return FPlatformMath::SubtractAndCheckForOverflow<IntType>(Value,
Other.Value, Result)
260 if (!bIsValid || !
Other.bIsValid)
266 return FPlatformMath::MultiplyAndCheckForOverflow<IntType>(Value,
Other.Value, Result)
275 if (!bIsValid || !
Other.bIsValid)
283 if (
Other.Value == 0 || (std::is_signed_v<IntType> && Value == MinValue &&
Other.Value == -1))
295 if (!bIsValid || !
Other.bIsValid)
301 if (
Other.Value == 0 || (std::is_signed_v<IntType> && Value == MinValue &&
Other.Value == -1))
313 if (!bIsValid || !
Other.bIsValid)
319 if (
Other.Value < 0 ||
Other.Value >= NumBits)
324 if constexpr (std::is_signed_v<IntType>)
345 return (
static_cast<IntType
>(Value <<
Other.Value) >>
Other.Value) == Value
355 if (!bIsValid || !
Other.bIsValid)
361 if (
Other.Value < 0 ||
Other.Value >= NumBits)
378 if constexpr (std::is_signed_v<IntType>)
382 return (Value < 0) ? -*this : *
this;
392#define UE_GUARDED_SIGNED_INT_IMPL_BINARY_OPERATOR(OP) \
394 TGuardedInt operator OP(IntType InB) const { return *this OP TGuardedInt(InB); } \
395 friend TGuardedInt operator OP(IntType InA, TGuardedInt InB) { return TGuardedInt(InA) OP InB; } \
397 TGuardedInt& operator OP##=(TGuardedInt InB) { return *this = *this OP InB; } \
398 TGuardedInt& operator OP##=(IntType InB) { return *this = *this OP TGuardedInt(InB); } \
409#undef UE_GUARDED_SIGNED_INT_IMPL_BINARY_OPERATOR
413template<
typename SignedType>
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_GUARDED_SIGNED_INT_IMPL_BINARY_OPERATOR(OP)
Definition GuardedInt.h:392
Definition GuardedInt.h:56
TGuardedInt operator+(const TGuardedInt Other) const
Definition GuardedInt.h:227
bool operator!=(const TGuardedInt Other) const
Definition GuardedInt.h:126
bool InvalidOrLessOrEqual(const ValueType Other) const
Definition GuardedInt.h:187
bool ValidAndLessOrEqual(const ValueType Other) const
Definition GuardedInt.h:155
bool InvalidOrGreaterOrEqual(const ValueType Other) const
Definition GuardedInt.h:203
TGuardedInt operator>>(const TGuardedInt Other) const
Definition GuardedInt.h:352
bool ValidAndGreaterOrEqual(const ValueType Other) const
Definition GuardedInt.h:171
TGuardedInt operator/(const TGuardedInt Other) const
Definition GuardedInt.h:272
TGuardedInt(const TGuardedInt &Other)=default
TGuardedInt Abs() const
Definition GuardedInt.h:371
TGuardedInt(ValueType InValue)
Definition GuardedInt.h:74
bool operator==(const TGuardedInt Other) const
Definition GuardedInt.h:115
TGuardedInt operator-() const
Definition GuardedInt.h:212
bool InvalidOrGreaterThan(const ValueType Other) const
Definition GuardedInt.h:195
bool IsValid() const
Definition GuardedInt.h:94
bool ValidAndLessThan(const ValueType Other) const
Definition GuardedInt.h:147
TGuardedInt operator*(const TGuardedInt Other) const
Definition GuardedInt.h:257
TGuardedInt operator<<(const TGuardedInt Other) const
Definition GuardedInt.h:310
bool ComparisonValid(const TGuardedInt Other) const
Definition GuardedInt.h:140
TGuardedInt & operator=(const TGuardedInt &Other)=default
bool InvalidOrLessThan(const ValueType Other) const
Definition GuardedInt.h:179
IntType Get(const IntType DefaultValue) const
Definition GuardedInt.h:100
bool ValidAndGreaterThan(const ValueType Other) const
Definition GuardedInt.h:163
IntType GetChecked(const IntType DefaultValue=0) const
Definition GuardedInt.h:108
TGuardedInt operator%(const TGuardedInt Other) const
Definition GuardedInt.h:292
@ false
Definition radaudio_common.h:23