UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Accumulate.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"
8
9// TPlus<T> specifically takes const T& and returns T.
10// TPlus<> (empty angle brackets) is late-binding, taking whatever is passed and returning the correct result type for (A+B)
11template<typename T = void>
12struct TPlus
13{
14 [[nodiscard]] UE_REWRITE T operator()(const T& A, const T& B) { return A + B; }
15};
16template<>
17struct TPlus<void>
18{
19 template<typename U, typename V>
20 [[nodiscard]] UE_REWRITE auto operator()(U&& A, V&& B) -> decltype(A + B) { return A + B; }
21};
22
23
24namespace Algo
25{
35 template <typename T, typename A, typename OpT>
36 [[nodiscard]] T Accumulate(const A& Input, T Init, OpT Op)
37 {
38 T Result = MoveTemp(Init);
39 for (const auto& InputElem : Input)
40 {
41 Result = Invoke(Op, MoveTemp(Result), InputElem);
42 }
43 return Result;
44 }
45
54 template <typename T, typename A>
56 {
58 }
59
70 template <typename T, typename A, typename MapT, typename OpT>
72 {
73 T Result = MoveTemp(Init);
74 for (const auto& InputElem : Input)
75 {
76 Result = Invoke(Op, MoveTemp(Result), Invoke(MapOp, InputElem));
77 }
78 return Result;
79 }
80
90 template <typename T, typename A, typename MapT>
95}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define UE_REWRITE
Definition Platform.h:747
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
void Init()
Definition LockFreeList.h:4
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition ParallelSort.h:13
T TransformAccumulate(const A &Input, MapT MapOp, T Init, OpT Op)
Definition Accumulate.h:71
UE_REWRITE auto operator()(U &&A, V &&B) -> decltype(A+B)
Definition Accumulate.h:20
Definition Accumulate.h:13
UE_REWRITE T operator()(const T &A, const T &B)
Definition Accumulate.h:14