Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MaxElement.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/Less.h"
9#include "Templates/UnrealTemplate.h" // For MoveTemp
10
11namespace AlgoImpl
12{
13 template <typename RangeType, typename ProjectionType, typename PredicateType>
14 typename TRangePointerType<RangeType>::Type MaxElementBy(RangeType& Range, ProjectionType Proj, PredicateType Pred)
15 {
16 typename TRangePointerType<RangeType>::Type Result = nullptr;
17
18 for (auto& Elem : Range)
19 {
21 {
22 Result = &Elem;
23 }
24 }
25
26 return Result;
27 }
28}
29
30namespace Algo
31{
32 /**
33 * Returns a pointer to the maximum element in a range.
34 * If the range contains multiple maximum elements, a pointer to the first one will be returned.
35 *
36 * @param Range The range to find the maximum element in.
37 * @return A pointer to the maximum element, or nullptr if the range was empty.
38 */
39 template <typename RangeType>
41 -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), TLess<>()))
42 {
44 }
45
46 /**
47 * Returns a pointer to the maximum element in a range with a user-defined binary comparator.
48 * If the range contains multiple maximum elements, a pointer to the first one will be returned.
49 *
50 * @param Range The range to find the maximum element in.
51 * @param Comp The comparator to use when comparing two elements.
52 * @return A pointer to the maximum element, or nullptr if the range was empty.
53 */
54 template <typename RangeType, typename ComparatorType>
55 FORCEINLINE auto MaxElement(RangeType& Range, ComparatorType Comp)
56 -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), MoveTemp(Comp)))
57 {
59 }
60
61 /**
62 * Returns a pointer to the maximum element in a range with a user-defined binary comparator.
63 * If the range contains multiple maximum elements, a pointer to the first one will be returned.
64 *
65 * @param Range The range to find the maximum element in.
66 * @param Proj The projection to apply to the element to use for comparison.
67 * @return A pointer to the maximum element, or nullptr if the range was empty.
68 */
69 template <typename RangeType, typename ProjectionType>
71 -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), TLess<>()))
72 {
74 }
75
76 /**
77 * Returns a pointer to the maximum element in a range with a user-defined binary comparator.
78 * If the range contains multiple maximum elements, a pointer to the first one will be returned.
79 *
80 * @param Range The range to find the maximum element in.
81 * @param Proj The projection to apply to the element to use for comparison.
82 * @param Comp The comparator to use when comparing two elements.
83 * @return A pointer to the maximum element, or nullptr if the range was empty.
84 */
85 template <typename RangeType, typename ProjectionType, typename ComparatorType>
86 FORCEINLINE auto MaxElementBy(RangeType& Range, ProjectionType Proj, ComparatorType Comp)
87 -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), MoveTemp(Comp)))
88 {
90 }
91}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE auto MaxElement(RangeType &Range, ComparatorType Comp) -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), MoveTemp(Comp)))
Definition MaxElement.h:55
FORCEINLINE auto MaxElementBy(RangeType &Range, ProjectionType Proj) -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), TLess<>()))
Definition MaxElement.h:70
FORCEINLINE auto MaxElement(RangeType &Range) -> decltype(AlgoImpl::MaxElementBy(Range, FIdentityFunctor(), TLess<>()))
Definition MaxElement.h:40
FORCEINLINE auto MaxElementBy(RangeType &Range, ProjectionType Proj, ComparatorType Comp) -> decltype(AlgoImpl::MaxElementBy(Range, MoveTemp(Proj), MoveTemp(Comp)))
Definition MaxElement.h:86
TRangePointerType< RangeType >::Type MaxElementBy(RangeType &Range, ProjectionType Proj, PredicateType Pred)
Definition MaxElement.h:14