Description
Removes and returns the last element of the array using move semantics. Equivalent to reading Top() and then calling RemoveAt on the last index.
Caveats & Gotchas
- • Calling Pop on an empty array triggers a RangeCheck assertion and crashes in Debug/Development builds. Always verify Num() > 0 or use IsEmpty() before calling.
- • The bool overload Pop(bool bAllowShrinking) is deprecated in UE 5.6 — pass EAllowShrinking::No or EAllowShrinking::Yes instead.
- • Pop moves the element out (MoveTempIfPossible), so the caller owns the returned value. For non-moveable types this falls back to a copy.
Signature
ElementType Pop(EAllowShrinking AllowShrinking = UE::Core::Private::AllowShrinkingByDefault<AllocatorType>()) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| AllowShrinking | EAllowShrinking | Controls whether the backing allocation is shrunk after removal. Defaults to the allocator's preferred policy. | UE::Core::Private::AllowShrinkingByDefault<AllocatorType>() |
Return Type
ElementType Examples
Stack-style usage C++
TArray<FString> Stack;
Stack.Push(TEXT("first"));
Stack.Push(TEXT("second"));
if (!Stack.IsEmpty())
{
FString Top = Stack.Pop(); // returns "second", removes it
} Pop without shrinking in a tight loop C++
TArray<int32> WorkItems = {1, 2, 3, 4};
while (!WorkItems.IsEmpty())
{
int32 Item = WorkItems.Pop(EAllowShrinking::No);
ProcessItem(Item);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?