Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Find.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Algo/Impl/RangePointerType.h"
6#include "Templates/IdentityFunctor.h"
7#include "Templates/Invoke.h"
8#include "Templates/UnrealTemplate.h" // For MoveTemp
9
10namespace AlgoImpl
11{
12 template <typename RangeType, typename ValueType, typename ProjectionType>
13 typename TRangePointerType<typename TRemoveReference<RangeType>::Type>::Type FindBy(RangeType&& Range, const ValueType& Value, ProjectionType Proj)
14 {
15 for (auto&& Elem : Forward<RangeType>(Range))
16 {
17 if (Invoke(Proj, Elem) == Value)
18 {
19 return &Elem;
20 }
21 }
22
23 return nullptr;
24 }
25
26 template <typename RangeType, typename PredicateType>
27 typename TRangePointerType<typename TRemoveReference<RangeType>::Type>::Type FindByPredicate(RangeType&& Range, PredicateType Pred)
28 {
29 for (auto&& Elem : Forward<RangeType>(Range))
30 {
31 if (Invoke(Pred, Elem))
32 {
33 return &Elem;
34 }
35 }
36
37 return nullptr;
38 }
39}
40
41namespace Algo
42{
43 /**
44 * Returns a pointer to the first element in the range which is equal to the given value.
45 *
46 * @param Range The range to search.
47 * @param Value The value to search for.
48 *
49 * @return A pointer to the first element found, or nullptr if none was found.
50 */
51 template <typename RangeType, typename ValueType>
52 FORCEINLINE auto Find(RangeType&& Range, const ValueType& Value)
53 -> decltype(AlgoImpl::FindBy(Forward<RangeType>(Range), Value, FIdentityFunctor()))
54 {
56 }
57
58 /**
59 * Returns a pointer to the first element in the range whose projection is equal to the given value.
60 *
61 * @param Range The range to search.
62 * @param Value The value to search for.
63 * @param Proj The projection to apply to the element.
64 *
65 * @return A pointer to the first element found, or nullptr if none was found.
66 */
67 template <typename RangeType, typename ValueType, typename ProjectionType>
68 FORCEINLINE auto FindBy(RangeType&& Range, const ValueType& Value, ProjectionType Proj)
69 -> decltype(AlgoImpl::FindBy(Forward<RangeType>(Range), Value, MoveTemp(Proj)))
70 {
72 }
73
74 /**
75 * Returns a pointer to the first element in the range which matches the predicate.
76 *
77 * @param Range The range to search.
78 * @param Pred The predicate to search for.
79 *
80 * @return A pointer to the first element found, or nullptr if none was found.
81 */
82 template <typename RangeType, typename PredicateType>
83 FORCEINLINE auto FindByPredicate(RangeType&& Range, PredicateType Pred)
84 -> decltype(AlgoImpl::FindByPredicate(Forward<RangeType>(Range), MoveTemp(Pred)))
85 {
87 }
88}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE auto FindByPredicate(RangeType &&Range, PredicateType Pred) -> decltype(AlgoImpl::FindByPredicate(Forward< RangeType >(Range), MoveTemp(Pred)))
Definition Find.h:83
FORCEINLINE auto FindBy(RangeType &&Range, const ValueType &Value, ProjectionType Proj) -> decltype(AlgoImpl::FindBy(Forward< RangeType >(Range), Value, MoveTemp(Proj)))
Definition Find.h:68
FORCEINLINE auto Find(RangeType &&Range, const ValueType &Value) -> decltype(AlgoImpl::FindBy(Forward< RangeType >(Range), Value, FIdentityFunctor()))
Definition Find.h:52
TRangePointerType< typenameTRemoveReference< RangeType >::Type >::Type FindBy(RangeType &&Range, const ValueType &Value, ProjectionType Proj)
Definition Find.h:13
TRangePointerType< typenameTRemoveReference< RangeType >::Type >::Type FindByPredicate(RangeType &&Range, PredicateType Pred)
Definition Find.h:27