Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Compare.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Templates/EqualTo.h"
7#include "Templates/IdentityFunctor.h"
8#include "Templates/Invoke.h"
9#include "Templates/UnrealTemplate.h"
10
11namespace Algo::Private
12{
13 template <typename InAT, typename InBT, typename ProjectionT, typename PredicateT>
14 constexpr bool Compare(InAT&& InputA, InBT&& InputB, ProjectionT Projection, PredicateT Predicate)
15 {
16 const SIZE_T SizeA = GetNum(InputA);
17 const SIZE_T SizeB = GetNum(InputB);
18
19 if (SizeA != SizeB)
20 {
21 return false;
22 }
23
24 auto* A = GetData(InputA);
25 auto* B = GetData(InputB);
26
27 for (SIZE_T Count = SizeA; Count; --Count)
28 {
29 if (!Invoke(Predicate, Invoke(Projection, *A++), Invoke(Projection, *B++)))
30 {
31 return false;
32 }
33 }
34
35 return true;
36 }
37}
38
39namespace Algo
40{
41 /**
42 * Compares two contiguous containers using operator== to compare pairs of elements.
43 *
44 * @param InputA Container of elements that are used as the first argument to operator==.
45 * @param InputB Container of elements that are used as the second argument to operator==.
46 *
47 * @return Whether the containers are the same size and operator== returned true for every pair of elements.
48 */
49 template <typename InAT, typename InBT>
50 constexpr bool Compare(InAT&& InputA, InBT&& InputB)
51 {
52 return Private::Compare(Forward<InAT>(InputA), Forward<InBT>(InputB), FIdentityFunctor(), TEqualTo<>());
53 }
54
55 /**
56 * Compares two contiguous containers using a predicate to compare pairs of elements.
57 *
58 * @param InputA Container of elements that are used as the first argument to the predicate.
59 * @param InputB Container of elements that are used as the second argument to the predicate.
60 * @param Predicate Condition which returns true for elements which are deemed equal.
61 *
62 * @return Whether the containers are the same size and the predicate returned true for every pair of elements.
63 */
64 template <typename InAT, typename InBT, typename PredicateT>
65 constexpr bool Compare(InAT&& InputA, InBT&& InputB, PredicateT Predicate)
66 {
67 return Private::Compare(Forward<InAT>(InputA), Forward<InBT>(InputB), FIdentityFunctor(), MoveTemp(Predicate));
68 }
69
70 template <typename InAT, typename InBT, typename PredicateT>
71 UE_DEPRECATED(5.0, "CompareByPredicate has been renamed to Compare.")
72 constexpr bool CompareByPredicate(InAT&& InputA, InBT&& InputB, PredicateT Predicate)
73 {
74 return Compare(Forward<InAT>(InputA), Forward<InBT>(InputB), MoveTemp(Predicate));
75 }
76
77 /**
78 * Compares two contiguous containers using operator== to compare pairs of projected elements.
79 *
80 * @param InputA Container of elements that are used as the first argument to operator==.
81 * @param InputB Container of elements that are used as the second argument to operator==.
82 * @param Projection Projection to apply to the elements before comparing them.
83 *
84 * @return Whether the containers are the same size and operator== returned true for every pair of elements.
85 */
86 template <typename InAT, typename InBT, typename ProjectionT>
87 constexpr bool CompareBy(InAT&& InputA, InBT&& InputB, ProjectionT Projection)
88 {
89 return Private::Compare(Forward<InAT>(InputA), Forward<InBT>(InputB), MoveTemp(Projection), TEqualTo<>());
90 }
91
92 /**
93 * Compares two contiguous containers using a predicate to compare pairs of projected elements.
94 *
95 * @param InputA Container of elements that are used as the first argument to the predicate.
96 * @param InputB Container of elements that are used as the second argument to the predicate.
97 * @param Projection Projection to apply to the elements before comparing them.
98 * @param Predicate Condition which returns true for elements which are deemed equal.
99 *
100 * @return Whether the containers are the same size and the predicate returned true for every pair of elements.
101 */
102 template <typename InAT, typename InBT, typename ProjectionT, typename PredicateT>
103 constexpr bool CompareBy(InAT&& InputA, InBT&& InputB, ProjectionT Projection, PredicateT Predicate)
104 {
105 return Private::Compare(Forward<InAT>(InputA), Forward<InBT>(InputB), MoveTemp(Projection), MoveTemp(Predicate));
106 }
107}
#define UE_DEPRECATED(Version, Message)
constexpr bool Compare(InAT &&InputA, InBT &&InputB, ProjectionT Projection, PredicateT Predicate)
Definition Compare.h:14
Definition Heapify.h:12
constexpr bool Compare(InAT &&InputA, InBT &&InputB, PredicateT Predicate)
Definition Compare.h:65
constexpr bool Compare(InAT &&InputA, InBT &&InputB)
Definition Compare.h:50
constexpr bool CompareBy(InAT &&InputA, InBT &&InputB, ProjectionT Projection, PredicateT Predicate)
Definition Compare.h:103
constexpr bool CompareByPredicate(InAT &&InputA, InBT &&InputB, PredicateT Predicate)
Definition Compare.h:72
constexpr bool CompareBy(InAT &&InputA, InBT &&InputB, ProjectionT Projection)
Definition Compare.h:87