Description
Sorts the array in-place and guarantees that equal elements retain their original relative order. Slower than Sort() — use only when stability is required.
Signature
void StableSort(const PREDICATE_CLASS& Predicate) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Predicate | PREDICATE_CLASS | A callable implementing strict weak ordering. Optional — no-argument overload uses operator<. | — |
Return Type
void Caveats & Gotchas
- • Generally slower than Sort() due to merge-sort-based implementation. Only use when order of equal elements matters.
- • Like Sort(), the predicate must implement strict weak ordering — returning true for equal elements is undefined behaviour.
- • If stability is not required, always prefer Sort() for better cache performance on large arrays.
Example
Sort UI items by category while preserving within-category order C++
// Items are already sorted by name; stable-sort by category preserves name order within each category
InventoryItems.StableSort([](const FInventoryItem& A, const FInventoryItem& B)
{
return A.Category < B.Category;
}); See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?