Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Transform.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/Invoke.h"
7
8/*
9 * Inspired by std::transform.
10 *
11 * Simple example:
12 * TArray<FString> Out;
13 * TArray<int32> Inputs { 1, 2, 3, 4, 5, 6 };
14 * Algo::Transform(
15 * Inputs,
16 * Out,
17 * [](int32 Input) { return LexToString(Input); }
18 * );
19 * // Out1 == [ "1", "2", "3", "4", "5", "6" ]
20 *
21 * You can also use Transform to output to multiple targets that have an Add function, by using :
22 *
23 * TArray<FString> Out1;
24 * TArray<int32> Out2;
25 *
26 * TArray<int32> Inputs = { 1, 2, 3, 4, 5, 6 };
27 * Algo::Transform(
28 * Inputs,
29 * TiedTupleAdd(Out1, Out2),
30 * [](int32 Input) { return ForwardAsTuple(LexToString(Input), Input * Input); }
31 * );
32 *
33 * // Out1 == [ "1", "2", "3", "4", "5", "6" ]
34 * // Out2 == [ 1, 4, 9, 16, 25, 36 ]
35 */
36namespace Algo
37{
38 /**
39 * Conditionally applies a transform to a range and stores the results into a container
40 *
41 * @param Input Any iterable type
42 * @param Output Container to hold the output
43 * @param Predicate Condition which returns true for elements that should be transformed and false for elements that should be skipped
44 * @param Trans Transformation operation
45 */
46 template <typename InT, typename OutT, typename PredicateT, typename TransformT>
47 FORCEINLINE void TransformIf(const InT& Input, OutT&& Output, PredicateT Predicate, TransformT Trans)
48 {
49 for (const auto& Value : Input)
50 {
52 {
54 }
55 }
56 }
57
58 /**
59 * Applies a transform to a range and stores the results into a container
60 *
61 * @param Input Any iterable type
62 * @param Output Container to hold the output
63 * @param Trans Transformation operation
64 */
65 template <typename InT, typename OutT, typename TransformT>
66 FORCEINLINE void Transform(const InT& Input, OutT&& Output, TransformT Trans)
67 {
68 for (const auto& Value : Input)
69 {
71 }
72 }
73}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE void TransformIf(const InT &Input, OutT &&Output, PredicateT Predicate, TransformT Trans)
Definition Transform.h:47
FORCEINLINE void Transform(const InT &Input, OutT &&Output, TransformT Trans)
Definition Transform.h:66