Description
Removes the top element from the heap without returning it, then re-heapifies. Use this instead of HeapPop when you need to discard the maximum element and don't need its value, avoiding a copy/move into a local.
Caveats & Gotchas
- • Like HeapPop, calling this on an empty array is undefined and will trigger a bounds check. Guard with Num() > 0.
- • The bool bAllowShrinking overload is deprecated in UE 5.x — use EAllowShrinking::Yes/No.
- • Prefer HeapPopDiscard over HeapPop in tight loops where the top value is not needed, since it skips moving the element into an output variable.
Signature
void HeapPopDiscard(EAllowShrinking AllowShrinking = UE::Core::Private::AllowShrinkingByDefault<AllocatorType>()) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| AllowShrinking | EAllowShrinking | Controls whether the array's allocation can shrink after removal. | UE::Core::Private::AllowShrinkingByDefault<AllocatorType>() |
Return Type
void Example
Trimming a heap to a maximum size C++
// Keep only the 5 smallest scores in a min-heap (using TGreater)
TArray<int32> MinHeap;
MinHeap.Heapify(TGreater<int32>());
for (int32 Score : IncomingScores)
{
MinHeap.HeapPush(Score, TGreater<int32>());
if (MinHeap.Num() > 5)
{
MinHeap.HeapPopDiscard(TGreater<int32>(), EAllowShrinking::No);
}
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?