UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MaxElement.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Templates/IdentityFunctor.h"
7#include "Templates/Invoke.h"
8#include "Templates/Less.h"
9#include "Templates/UnrealTemplate.h" // For MoveTemp
10
11namespace AlgoImpl
12{
13 template <typename RangeType, typename ProjectionType, typename PredicateType>
15 {
16 typename TRangePointerType<RangeType>::Type Result = nullptr;
17
18 for (auto& Elem : Range)
19 {
20 if (!Result || Invoke(Pred, Invoke(Proj, *Result), Invoke(Proj, Elem)))
21 {
22 Result = &Elem;
23 }
24 }
25
26 return Result;
27 }
28}
29
30namespace Algo
31{
39 template <typename RangeType>
40 [[nodiscard]] UE_REWRITE constexpr auto MaxElement(RangeType&& Range)
41 -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), TLess<>()))
42 {
44 }
45
54 template <typename RangeType, typename ComparatorType>
55 [[nodiscard]] UE_REWRITE auto MaxElement(RangeType&& Range, ComparatorType Comp)
57 {
59 }
60
69 template <typename RangeType, typename ProjectionType>
71 -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), TLess<>()))
72 {
74 }
75
85 template <typename RangeType, typename ProjectionType, typename ComparatorType>
91}
#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
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition BinarySearch.h:10
constexpr TRangePointerType< RangeType >::Type MaxElementBy(RangeType &Range, ProjectionType Proj, PredicateType Pred)
Definition MaxElement.h:14
Definition ParallelSort.h:13
UE_REWRITE auto MaxElementBy(RangeType &&Range, ProjectionType Proj) -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), TLess<>()))
Definition MaxElement.h:70
UE_REWRITE constexpr auto MaxElement(RangeType &&Range) -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), TLess<>()))
Definition MaxElement.h:40
decltype(&*DeclVal< RangeType & >().begin()) Type
Definition RangePointerType.h:15
Definition IdentityFunctor.h:11
Definition Less.h:19