MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
DelegateFrom.h File Reference
#include "CoreMinimal.h"
#include "Mcro/FunctionTraits.h"
#include "Mcro/Delegates/Traits.h"
#include "Mcro/Tuples.h"

Go to the source code of this file.

Namespaces

namespace  Mcro
 
namespace  Mcro::Delegates
 
namespace  Mcro::Delegates::Detail
 

Typedefs

template<CFunctionLike Function, typename... Captures>
using Mcro::Delegates::TInferredDelegate
 

Functions

template<CFunctionLike Function, typename... Captures>
requires (!TFunction_IsMember<Function>) && (!CFunctorObject<Function>)
TInferredDelegate< Function, Captures... > Mcro::Delegates::From (Function func, const Captures &... captures)
 
template<CFunctorObject Function>
TDelegate< TFunction_Signature< Function > > Mcro::Delegates::From (Function &&func)
 
template<CSharedRef Object, CFunctorObject Function>
TDelegate< TFunction_Signature< Function > > Mcro::Delegates::From (const Object &self, Function &&func)
 
template<CSharedFromThis Object, CFunctorObject Function>
TDelegate< TFunction_Signature< Function > > Mcro::Delegates::From (Object *self, Function &&func)
 
template<CSharedFromThis Object, CFunctorObject Function>
TDelegate< TFunction_Signature< Function > > Mcro::Delegates::From (const Object *self, Function &&func)
 
template<CPlainClass Object, CFunctionLike Function, typename... Captures>
requires TFunction_IsMember<Function> && (!CFunctorObject<Function>)
TInferredDelegate< Function, Captures... > Mcro::Delegates::From (Object *self, Function func, const Captures &... captures)
 
template<CPlainClass Object, CFunctionLike Function, typename... Captures>
requires TFunction_IsMember<Function> && (!CFunctorObject<Function>)
TInferredDelegate< Function, Captures... > Mcro::Delegates::From (const Object *self, Function func, const Captures &... captures)
 
template<CSharedRef Object, CFunctionLike Function, typename... Captures>
requires TFunction_IsMember<Function> && (!CFunctorObject<Function>)
TInferredDelegate< Function, Captures... > Mcro::Delegates::From (const Object &self, Function func, const Captures &... captures)
 
template<typename... Args>
TDelegate< void(Args...)> Mcro::Delegates::From (TMulticastDelegate< void(Args...)> &multicast)
 
template<typename Object , typename... Args>
TDelegate< void(Args...)> Mcro::Delegates::From (Object &&self, TMulticastDelegate< void(Args...)> &multicast)
 
template<CDynamicMulticastDelegate Dynamic, size_t... ArgIndices>
TNative< typename Dynamic::FDelegate > Mcro::Delegates::Detail::FromDynamicMulticastDelegate (Dynamic &multicast, std::index_sequence< ArgIndices... > &&)
 
template<typename Object , CDynamicMulticastDelegate Dynamic, size_t... ArgIndices>
TNative< typename Dynamic::FDelegate > Mcro::Delegates::Detail::FromDynamicMulticastDelegate (Object &&self, Dynamic &multicast, std::index_sequence< ArgIndices... > &&)
 
template<CDynamicMulticastDelegate Dynamic>
TNative< typename Dynamic::FDelegate > Mcro::Delegates::From (Dynamic &multicast)
 
template<typename Object , CDynamicMulticastDelegate Dynamic>
TNative< typename Dynamic::FDelegate > Mcro::Delegates::From (Object &&self, Dynamic &multicast)
 

Detailed Description

Author
David Mórász
Date
2025

Unreal delegates while being great they have the problem that they're pretty verbose to use, as the usage site requires the developer to spell out the delegate types when they're being bound to something. Mcro::Delegate::From overloads not only infer delegate types from input function, but they also infer how the delegate is being used. For example take From(this, &FStuff::MyFunc) can map to several classic delegate usages depending on the type of this:

  • CreateSP if this is TSharedFromThis
  • CreateUObject if this is a UObject
  • CreateRaw in case this is just a plain old C++ object

From can also deal with

  • usages of Lambda functions with same API
  • correct delegate type from combination of given function signature and given captures
    • So From(this, &FStuff::MyFunc, TEXT("my capture") will correctly remove the last argument from the function signature of FStuff::MyFunc when inferring the delegate type.
  • Chain multicast delegates together

Definition in file DelegateFrom.h.