UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FindLast.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Templates/IdentityFunctor.h"
6#include "Templates/Invoke.h"
7#include "Templates/UnrealTemplate.h" // For MoveTemp
8
9namespace AlgoImpl
10{
11 template <typename T, typename ValueType, typename ProjectionType>
12 T* FindLastBy(T* First, SIZE_T Num, const ValueType& Value, ProjectionType Proj)
13 {
14 for (T* Last = First + Num; First != Last;)
15 {
16 if (Invoke(Proj, *--Last) == Value)
17 {
18 return Last;
19 }
20 }
21
22 return nullptr;
23 }
24
25 template <typename T, typename PredicateType>
27 {
28 for (T* Last = First + Num; First != Last;)
29 {
30 if (Invoke(Pred, *--Last))
31 {
32 return Last;
33 }
34 }
35
36 return nullptr;
37 }
38}
39
40namespace Algo
41{
50 template <typename RangeType, typename ValueType>
51 [[nodiscard]] UE_REWRITE auto FindLast(RangeType&& Range, const ValueType& Value)
52 -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, FIdentityFunctor()))
53 {
54 return AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, FIdentityFunctor());
55 }
56
66 template <typename RangeType, typename ValueType, typename ProjectionType>
67 [[nodiscard]] UE_REWRITE auto FindLastBy(RangeType&& Range, const ValueType& Value, ProjectionType Proj)
68 -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, MoveTemp(Proj)))
69 {
70 return AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, MoveTemp(Proj));
71 }
72
81 template <typename RangeType, typename PredicateType>
83 -> decltype(AlgoImpl::FindLastByPredicate(GetData(Range), GetNum(Range), MoveTemp(Pred)))
84 {
86 }
87}
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
#define UE_REWRITE
Definition Platform.h:747
AUTORTFM_INFER UE_FORCEINLINE_HINT constexpr auto Invoke(FuncType &&Func, ArgTypes &&... Args) -> decltype(((FuncType &&) Func)((ArgTypes &&) Args...))
Definition Invoke.h:44
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_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition BinarySearch.h:10
T * FindLastBy(T *First, SIZE_T Num, const ValueType &Value, ProjectionType Proj)
Definition FindLast.h:12
T * FindLastByPredicate(T *First, SIZE_T Num, PredicateType Pred)
Definition FindLast.h:26
Definition ParallelSort.h:13
UE_REWRITE auto FindLast(RangeType &&Range, const ValueType &Value) -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, FIdentityFunctor()))
Definition FindLast.h:51
UE_REWRITE auto FindLastBy(RangeType &&Range, const ValueType &Value, ProjectionType Proj) -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, MoveTemp(Proj)))
Definition FindLast.h:67
UE_REWRITE auto FindLastByPredicate(RangeType &&Range, PredicateType Pred) -> decltype(AlgoImpl::FindLastByPredicate(GetData(Range), GetNum(Range), MoveTemp(Pred)))
Definition FindLast.h:82
Definition IdentityFunctor.h:11