UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
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{
46 template <typename InT, typename OutT, typename PredicateT, typename TransformT>
47 void TransformIf(const InT& Input, OutT&& Output, PredicateT Predicate, TransformT Trans)
48 {
49 for (const auto& Value : Input)
50 {
51 if (Invoke(Predicate, Value))
52 {
53 Output.Add(Invoke(Trans, Value));
54 }
55 }
56 }
57
65 template <typename InT, typename OutT, typename TransformT>
66 void Transform(const InT& Input, OutT&& Output, TransformT Trans)
67 {
68 for (const auto& Value : Input)
69 {
70 Output.Add(Invoke(Trans, Value));
71 }
72 }
73}
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
Definition ParallelSort.h:13
void TransformIf(const InT &Input, OutT &&Output, PredicateT Predicate, TransformT Trans)
Definition Transform.h:47