UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IndexOf.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"
8
9namespace AlgoImpl
10{
11 template <typename RangeType, typename ValueType, typename ProjectionType>
12 auto IndexOfBy(const RangeType& Range, const ValueType& Value, ProjectionType Proj)
13 {
14 auto Num = GetNum(Range);
15 auto Data = GetData(Range);
16
17 using SizeType = decltype(Num);
18 for (SizeType Index = 0; Index < Num; ++Index)
19 {
20 if (Invoke(Proj, Data[Index]) == Value)
21 {
22 return Index;
23 }
24 }
25
26 return (SizeType)-1;
27 }
28
29 template <typename RangeType, typename PredicateType>
30 auto IndexOfByPredicate(const RangeType& Range, PredicateType Pred)
31 {
32 auto Num = GetNum(Range);
33 auto Data = GetData(Range);
34
35 using SizeType = decltype(Num);
36 for (SizeType Index = 0; Index < Num; ++Index)
37 {
38 if (Invoke(Pred, Data[Index]))
39 {
40 return Index;
41 }
42 }
43
44 return (SizeType)-1;
45 }
46}
47
48namespace Algo
49{
58 template <typename RangeType, typename ValueType>
59 [[nodiscard]] UE_REWRITE auto IndexOf(const RangeType& Range, const ValueType& Value)
60 {
61 static_assert(TIsContiguousContainer<RangeType>::Value, "Must only be used with contiguous containers");
63 }
64
74 template <typename RangeType, typename ValueType, typename ProjectionType>
75 [[nodiscard]] UE_REWRITE auto IndexOfBy(const RangeType& Range, const ValueType& Value, ProjectionType Proj)
76 {
77 static_assert(TIsContiguousContainer<RangeType>::Value, "Must only be used with contiguous containers");
78 return AlgoImpl::IndexOfBy(Range, Value, MoveTemp(Proj));
79 }
80
89 template <typename RangeType, typename PredicateType>
90 [[nodiscard]] UE_REWRITE auto IndexOfByPredicate(const RangeType& Range, PredicateType Pred)
91 {
92 static_assert(TIsContiguousContainer<RangeType>::Value, "Must only be used with contiguous containers");
94 }
95}
#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
auto IndexOfBy(const RangeType &Range, const ValueType &Value, ProjectionType Proj)
Definition IndexOf.h:12
auto IndexOfByPredicate(const RangeType &Range, PredicateType Pred)
Definition IndexOf.h:30
Definition ParallelSort.h:13
UE_REWRITE auto IndexOfByPredicate(const RangeType &Range, PredicateType Pred)
Definition IndexOf.h:90
UE_REWRITE auto IndexOf(const RangeType &Range, const ValueType &Value)
Definition IndexOf.h:59
UE_REWRITE auto IndexOfBy(const RangeType &Range, const ValueType &Value, ProjectionType Proj)
Definition IndexOf.h:75
U16 Index
Definition radfft.cpp:71
Definition IdentityFunctor.h:11
Definition IsContiguousContainer.h:16