14#include "CoreMinimal.h"
43 TFunction<void(T*)>
Destruct {[](T* object) {
delete object; }};
46 if constexpr (CCopyConstructible<T>)
return new T(
object);
55 .CopyConstruct = [](T
const& object)
57 if constexpr (CCopyConstructible<T>)
return Ansi::New<T>(
object);
98 , Destruct([facilities](
FAny* self)
100 T*
object =
static_cast<T*
>(self->Storage);
101 facilities.Destruct(
object);
102 self->Storage =
nullptr;
104 , CopyConstruct([facilities](FAny* self, FAny
const& other)
106 const T*
object =
static_cast<const T*
>(other.Storage);
107 self->Storage = facilities.CopyConstruct(*
object);
108 checkf(self->Storage,
TEXT_"Copy constructor failed for %s. Is it deleted?", *TTypeString<T>());
110 CopyTypeInfo(self, &other);
113 ValidTypes.Add(MainType);
115 if constexpr (CHasBases<T>)
117 ForEachExplicitBase<T>([
this] <
typename Base> ()
119 AddAlias(TTypeOf<Base>);
129 template <
typename T>
132 return ValidTypes.Contains(TTypeOf<T>)
133 ?
static_cast<const T*
>(Storage)
137 template <
typename T>
140 return ValidTypes.Contains(TTypeOf<T>)
141 ?
static_cast<T*
>(Storage)
146 template <
typename T,
typename Self>
149 self.AddAlias(TTypeOf<T>);
151 if constexpr (CHasBases<T>)
153 ForEachExplicitBase<T>([&] <
typename Base> ()
155 self.AddAlias(TTypeOf<Base>);
162 template <
typename Self,
typename... T>
165 (self.AddAlias(TTypeOf<T>), ...);
169 FORCEINLINE
bool IsValid()
const {
return static_cast<bool>(Storage); }
174 void AddAlias(
FType const& alias);
175 static void CopyTypeInfo(
FAny* self,
const FAny* other);
178 void* Storage =
nullptr;
181 TFunction<void(FAny* self)> Destruct {};
182 TFunction<void(FAny* self, FAny
const& other)> CopyConstruct {};
184 TSet<FType> ValidTypes {};
#define FWD(...)
Shorten forwarding expression with this macro so one may not need to specify explicit type.
Use leading TEXT_ without parenthesis for Unreal compatible text literals.
#define TEXT_
A convenience alternative to Unreal's own TEXT macro but this one doesn't require parenthesis around ...
void Delete(T *ptr)
Force using the ANSI memory release behavior, instead of the Unreal default.
T * New(Args &&... args)
Force using the ANSI memory allocation behavior, instead of the Unreal default.
TAnyTypeFacilities< T > AnsiAnyFacilities
Type facilities for FAny enforcing standard memory allocations.
This namespace provides templating utilities and introspection into template instantiations.
A simplistic but type-safe and RAII compliant storage for anything. Enclosed data is owned by this ty...
FORCEINLINE FType GetType() const
FORCEINLINE bool IsValid() const
decltype(auto) With(this Self &&self, TTypes< T... > &&)
Specify multiple types the enclosed value can be safely cast to, and are valid to be used with TryGet...
FAny(T *newObject, TAnyTypeFacilities< T > const &facilities={})
decltype(auto) WithAlias(this Self &&self)
Specify one type the enclosed value can be safely cast to, and is valid to be used with TryGet.
FORCEINLINE TSet< FType > const & GetValidTypes() const
Give the opportunity to customize object lifespan operations for FAny by either specializing this tem...
TFunction< void(T *)> Destruct
TFunction< T *(T const &)> CopyConstruct
This template is used to store pack of types in other templates, or to allow parameter pack inference...
Group together type info for identification. Can have an invalid state when no type is specified.