Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Count.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
7namespace Algo
8{
9 /**
10 * Counts elements of a range that equal the supplied value
11 *
12 * @param Input Any iterable type
13 * @param InValue Value to compare against
14 */
15 template <typename InT, typename ValueT>
16 FORCEINLINE SIZE_T Count(const InT& Input, const ValueT& InValue)
17 {
18 SIZE_T Result = 0;
19 for (const auto& Value : Input)
20 {
21 if (Value == InValue)
22 {
23 ++Result;
24 }
25 }
26 return Result;
27 }
28
29 /**
30 * Counts elements of a range that match a given predicate
31 *
32 * @param Input Any iterable type
33 * @param Predicate Condition which returns true for elements that should be counted and false for elements that should be skipped
34 */
35 template <typename InT, typename PredicateT>
36 FORCEINLINE SIZE_T CountIf(const InT& Input, PredicateT Predicate)
37 {
38 SIZE_T Result = 0;
39 for (const auto& Value : Input)
40 {
42 {
43 ++Result;
44 }
45 }
46 return Result;
47 }
48
49 /**
50 * Counts elements of a range whose projection equals the supplied value
51 *
52 * @param Input Any iterable type
53 * @param InValue Value to compare against
54 * @param Projection The projection to apply to the element
55 */
56 template <typename InT, typename ValueT, typename ProjectionT>
57 FORCEINLINE SIZE_T CountBy(const InT& Input, const ValueT& InValue, ProjectionT Proj)
58 {
59 SIZE_T Result = 0;
60 for (const auto& Value : Input)
61 {
62 if (Invoke(Proj, Value) == InValue)
63 {
64 ++Result;
65 }
66 }
67 return Result;
68 }
69}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE SIZE_T CountBy(const InT &Input, const ValueT &InValue, ProjectionT Proj)
Definition Count.h:57
FORCEINLINE SIZE_T Count(const InT &Input, const ValueT &InValue)
Definition Count.h:16
FORCEINLINE SIZE_T CountIf(const InT &Input, PredicateT Predicate)
Definition Count.h:36