RealDocs

TArray::VerifyHeap

function Core Since 4.0
#include "Containers/Array.h"
Access: public

Description

Asserts (via check()) that the array satisfies the heap property under the given predicate. Use during development to validate that heap-manipulating code keeps the array in a valid state.

Caveats & Gotchas

  • This is a debug assertion — it calls check(Algo::IsHeap(...)) which compiles out in shipping builds. Do not rely on it for runtime correctness checks in production code.
  • You must pass the same predicate that was used to build the heap. Passing a different predicate may falsely pass or fail the check.
  • There is no overload that uses the default TLess<> comparator — the predicate is always required.

Signature

template <class PREDICATE_CLASS>
void VerifyHeap(const PREDICATE_CLASS& Predicate)

Parameters

Name Type Description Default
Predicate const PREDICATE_CLASS& The same predicate used to build/maintain the heap.

Return Type

void

Example

Validating heap invariant after manual mutations C++
TArray<int32> Heap = {9, 5, 6, 1, 3};
// Assume Heap was built with TLess (max-heap)
Heap.VerifyHeap(TLess<int32>()); // asserts in non-shipping if broken

// After a HeapPush:
Heap.HeapPush(10);
Heap.VerifyHeap(TLess<int32>()); // still valid

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.