UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Partition.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
6
7namespace Algo
8{
17 template<class T, typename IndexType, typename UnaryPredicate>
18 IndexType Partition(T* Elements, const IndexType Num, UnaryPredicate Predicate)
19 {
20 T* First = Elements;
21 T* Last = Elements + Num;
22
23 while (First != Last)
24 {
25 while (Predicate(*First))
26 {
27 ++First;
28 if (First == Last)
29 {
30 return (IndexType)(First - Elements);
31 }
32 }
33
34 do
35 {
36 --Last;
37 if (First == Last)
38 {
39 return (IndexType)(First - Elements);
40 }
41 } while (!Predicate(*Last));
42
44 ++First;
45 }
46
47 return (IndexType)(First - Elements);
48 }
49
57 template <typename RangeType, typename UnaryPredicateType>
58 UE_REWRITE auto Partition(RangeType&& Range, UnaryPredicateType Predicate) -> decltype(GetNum(Range))
59 {
60 return Partition(GetData(Range), GetNum(Range), MoveTemp(Predicate));
61 }
62} //namespace Algo
#define UE_REWRITE
Definition Platform.h:747
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Num
Definition MetalRHIPrivate.h:234
auto GetNum(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Length())
Definition StringConv.h:808
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
UE_REWRITE constexpr void Exchange(T &A, T &B)
Definition UnrealTemplate.h:627
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition ParallelSort.h:13
IndexType Partition(T *Elements, const IndexType Num, UnaryPredicate Predicate)
Definition Partition.h:18