TArray::CheckInvariants
#include "Containers/Array.h"
Access: public
Specifiers: inline
Description
Asserts (in Debug/Development builds only) that ArrayNum >= 0 and ArrayMax >= ArrayNum. Called internally before every indexed access and most mutation operations.
Caveats & Gotchas
- • The assertion uses checkSlow, which is compiled out in Shipping builds. If corrupted array state only manifests in Shipping, CheckInvariants will not catch it — use Num()/Max() boundary checks in your own logic instead.
- • Because both conditions are combined with bitwise & (not &&), both invariants are always evaluated even if the first fails. This avoids an extra branch but means you may see two distinct assertion failure messages rather than stopping at the first.
Signature
UE_NODEBUG UE_FORCEINLINE_HINT void CheckInvariants() const Return Type
void Example
Called implicitly by RangeCheck C++
TArray<int32> MyArray;
// Every operator[] call internally calls RangeCheck(), which calls CheckInvariants():
MyArray.Add(42);
int32 Val = MyArray[0]; // CheckInvariants() fires here in Debug builds
// You can also call it directly when writing custom TArray subclass code:
MyArray.CheckInvariants(); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?