UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AdderRef.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"
7#include <type_traits>
8
39namespace UE::Core::Private
40{
41 template <typename T>
43 {
44 constexpr TAdderVTable(void (*InAddConstRef)(void* ContainerPtr, const T& Val), void (*InAddRValueRef)(void* ContainerPtr, T&& Val))
47 {
48 }
49
50 void (*AddConstRef)(void* ContainerPtr, const T& Val);
51 void (*AddRValueRef)(void* ContainerPtr, T&& Val);
52 };
53
54 template <typename T, typename SizeType>
56 {
57 constexpr TAdderReserverVTable(void (*InAddConstRef)(void* ContainerPtr, const T& Val), void (*InAddRValueRef)(void* ContainerPtr, T&& Val), SizeType (*InNum)(const void* ContainerPtr), void (*InReserve)(void* ContainerPtr, SizeType Size))
59 , Num(InNum)
61 {
62 }
63
64 SizeType (*Num)(const void* ContainerPtr);
65 void (*Reserve)(void* ContainerPtr, SizeType Size);
66 };
67
68 template <typename T, typename ContainerType>
70 {
71 static void AddConstRef(void* ContainerPtr, const T& Val)
72 {
73 ((ContainerType*)ContainerPtr)->Add(Val);
74 }
75
76 static void AddRValueRef(void* ContainerPtr, T&& Val)
77 {
78 ((ContainerType*)ContainerPtr)->Add((T&&)Val);
79 }
80 };
81
82 template <typename SizeType, typename ContainerType>
84 {
85 static SizeType Num(const void* ContainerPtr)
86 {
87 return ((const ContainerType*)ContainerPtr)->Num();
88 }
89
90 static void Reserve(void* ContainerPtr, SizeType Size)
91 {
92 ((ContainerType*)ContainerPtr)->Reserve(Size);
93 }
94 };
95
96 template <typename T, typename Container>
100 );
101
102 template <typename T, typename SizeType, typename Container>
108 );
109}
110
111template <typename T>
113{
114 template <
115 typename ContainerType
116 UE_REQUIRES(!std::is_base_of_v<TAdderRef, ContainerType>)
117 >
119 : VPtr(&UE::Core::Private::GAdderVTableImpl<T, ContainerType>)
121 {
122 }
123
124 UE_NODEBUG void Add(const T& Val) const
125 {
126 this->VPtr->AddConstRef(this->ContainerPtr, Val);
127 }
128
129 UE_NODEBUG void Add(T&& Val) const
130 {
131 this->VPtr->AddRValueRef(this->ContainerPtr, (T&&)Val);
132 }
133
134protected:
140
143};
144
145template <typename T, typename SizeType = int32>
147{
148 template <
149 typename ContainerType
150 UE_REQUIRES(!std::is_base_of_v<TAdderReserverRef, ContainerType>)
151 >
153 : TAdderRef<T>(&UE::Core::Private::GAdderReserverVTableImpl<T, SizeType, ContainerType>, &InContainer)
154 {
155 static_assert(sizeof(InContainer.Num()) <= sizeof(SizeType), "Container has a larger SizeType than the TAdderReserverRef expects");
156 }
157
158 UE_NODEBUG [[nodiscard]] SizeType Num() const
159 {
160 return static_cast<const UE::Core::Private::TAdderReserverVTable<T, SizeType>*>(this->VPtr)->Num(this->ContainerPtr);
161 }
162
163 UE_NODEBUG void Reserve(SizeType Size) const
164 {
165 static_cast<const UE::Core::Private::TAdderReserverVTable<T, SizeType>*>(this->VPtr)->Reserve(this->ContainerPtr, Size);
166 }
167};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define UE_LIFETIMEBOUND
Definition Platform.h:812
#define UE_NODEBUG
Definition Platform.h:817
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_REQUIRES(...)
Definition Requires.h:86
float Val(const FString &Value)
Definition UnrealMath.cpp:3163
uint32 Size
Definition VulkanMemory.cpp:4034
Definition Core.Build.cs:8
Definition OverriddenPropertySet.cpp:45
implementation
Definition PlayInEditorLoadingScope.h:8
Definition AdvancedWidgetsModule.cpp:13
Definition AdderRef.h:113
UE_NODEBUG void Add(const T &Val) const
Definition AdderRef.h:124
UE_NODEBUG void Add(T &&Val) const
Definition AdderRef.h:129
UE_NODEBUG TAdderRef(ContainerType &InContainer UE_LIFETIMEBOUND)
Definition AdderRef.h:118
void * ContainerPtr
Definition AdderRef.h:142
const UE::Core::Private::TAdderVTable< T > * VPtr
Definition AdderRef.h:141
UE_NODEBUG TAdderRef(const UE::Core::Private::TAdderVTable< T > *InVPtr, void *InContainerPtr)
Definition AdderRef.h:135
Definition AdderRef.h:147
UE_NODEBUG TAdderReserverRef(ContainerType &InContainer UE_LIFETIMEBOUND)
Definition AdderRef.h:152
UE_NODEBUG SizeType Num() const
Definition AdderRef.h:158
UE_NODEBUG void Reserve(SizeType Size) const
Definition AdderRef.h:163
static void Reserve(void *ContainerPtr, SizeType Size)
Definition AdderRef.h:90
static SizeType Num(const void *ContainerPtr)
Definition AdderRef.h:85
void(* Reserve)(void *ContainerPtr, SizeType Size)
Definition AdderRef.h:65
constexpr TAdderReserverVTable(void(*InAddConstRef)(void *ContainerPtr, const T &Val), void(*InAddRValueRef)(void *ContainerPtr, T &&Val), SizeType(*InNum)(const void *ContainerPtr), void(*InReserve)(void *ContainerPtr, SizeType Size))
Definition AdderRef.h:57
SizeType(* Num)(const void *ContainerPtr)
Definition AdderRef.h:64
Definition AdderRef.h:70
static void AddRValueRef(void *ContainerPtr, T &&Val)
Definition AdderRef.h:76
static void AddConstRef(void *ContainerPtr, const T &Val)
Definition AdderRef.h:71
Definition AdderRef.h:43
void(* AddRValueRef)(void *ContainerPtr, T &&Val)
Definition AdderRef.h:51
void(* AddConstRef)(void *ContainerPtr, const T &Val)
Definition AdderRef.h:50
constexpr TAdderVTable(void(*InAddConstRef)(void *ContainerPtr, const T &Val), void(*InAddRValueRef)(void *ContainerPtr, T &&Val))
Definition AdderRef.h:44