Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
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>
26 T* FindLastByPredicate(T* First, SIZE_T Num, PredicateType Pred)
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{
42 /**
43 * Returns a pointer to the last element in the range which is equal to the given value.
44 *
45 * @param Range The range to search.
46 * @param Value The value to search for.
47 *
48 * @return A pointer to the last element found, or nullptr if none was found.
49 */
50 template <typename RangeType, typename ValueType>
51 FORCEINLINE auto FindLast(RangeType&& Range, const ValueType& Value)
52 -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, FIdentityFunctor()))
53 {
55 }
56
57 /**
58 * Returns a pointer to the last element in the range whose projection is equal to the given value.
59 *
60 * @param Range The range to search.
61 * @param Value The value to search for.
62 * @param Proj The projection to apply to the element.
63 *
64 * @return A pointer to the last element found, or nullptr if none was found.
65 */
66 template <typename RangeType, typename ValueType, typename ProjectionType>
67 FORCEINLINE auto FindLastBy(RangeType&& Range, const ValueType& Value, ProjectionType Proj)
68 -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, MoveTemp(Proj)))
69 {
71 }
72
73 /**
74 * Returns a pointer to the last element in the range which matches the predicate.
75 *
76 * @param Range The range to search.
77 * @param Pred The predicate to search for.
78 *
79 * @return A pointer to the last element found, or nullptr if none was found.
80 */
81 template <typename RangeType, typename PredicateType>
82 FORCEINLINE auto FindLastByPredicate(RangeType&& Range, PredicateType Pred)
83 -> decltype(AlgoImpl::FindLastByPredicate(GetData(Range), GetNum(Range), MoveTemp(Pred)))
84 {
86 }
87}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE auto FindLastByPredicate(RangeType &&Range, PredicateType Pred) -> decltype(AlgoImpl::FindLastByPredicate(GetData(Range), GetNum(Range), MoveTemp(Pred)))
Definition FindLast.h:82
FORCEINLINE auto FindLast(RangeType &&Range, const ValueType &Value) -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, FIdentityFunctor()))
Definition FindLast.h:51
FORCEINLINE auto FindLastBy(RangeType &&Range, const ValueType &Value, ProjectionType Proj) -> decltype(AlgoImpl::FindLastBy(GetData(Range), GetNum(Range), Value, MoveTemp(Proj)))
Definition FindLast.h:67
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