UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Invoke.h File Reference
#include "CoreTypes.h"
#include "AutoRTFM.h"
#include "Traits/MemberFunctionPtrOuter.h"
#include <type_traits>

Go to the source code of this file.

Classes

struct  UE::Core::Private::TInvokeResult_Impl< typename, FuncType, ArgTypes >
 
struct  UE::Core::Private::TInvokeResult_Impl< decltype((void) Invoke(std::declval< FuncType >(), std::declval< ArgTypes >()...)), FuncType, ArgTypes... >
 
struct  TInvokeResult< FuncType, ArgTypes >
 

Namespaces

namespace  UE
 
namespace  UE::Core
 
namespace  UE::Core::Private
 implementation
 

Macros

#define UE_PROJECTION(FuncName)
 
#define UE_PROJECTION_MEMBER(Type, FuncName)
 

Typedefs

template<typename FuncType , typename... ArgTypes>
using TInvokeResult_T = typename TInvokeResult< FuncType, ArgTypes... >::Type
 

Functions

template<typename OuterType , typename TargetType >
constexpr auto UE::Core::Private::DereferenceIfNecessary (TargetType &&Target, const volatile OuterType *TargetPtr) -> decltype((TargetType &&) Target)
 
template<typename OuterType , typename TargetType >
constexpr auto UE::Core::Private::DereferenceIfNecessary (TargetType &&Target,...) -> decltype(*(TargetType &&) Target)
 
template<typename FuncType , typename... ArgTypes>
AUTORTFM_INFER UE_FORCEINLINE_HINT constexpr auto Invoke (FuncType &&Func, ArgTypes &&... Args) -> decltype(((FuncType &&) Func)((ArgTypes &&) Args...))
 
template<typename ReturnType , typename ObjType , typename TargetType >
AUTORTFM_INFER constexpr auto Invoke (ReturnType ObjType::*pdm, TargetType &&Target) -> decltype(UE::Core::Private::DereferenceIfNecessary< ObjType >((TargetType &&) Target, &Target).*pdm)
 
template<typename PtrMemFunType , typename TargetType , typename... ArgTypes, typename ObjType = TMemberFunctionPtrOuter_T<PtrMemFunType>>
AUTORTFM_INFER constexpr auto Invoke (PtrMemFunType PtrMemFun, TargetType &&Target, ArgTypes &&... Args) -> decltype((UE::Core::Private::DereferenceIfNecessary< ObjType >((TargetType &&) Target, &Target).*PtrMemFun)((ArgTypes &&) Args...))
 

Macro Definition Documentation

◆ UE_PROJECTION

#define UE_PROJECTION (   FuncName)
Value:
[](auto&&... Args) -> decltype(auto) \
{ \
return FuncName((decltype(Args)&&)Args...); \
}

Wraps up a named non-member function so that it can easily be passed as a callable. This allows functions with overloads or default arguments to be treated correctly.

Example:

TArray<FMyType> Array = ...;

// Doesn't compile, because you can't take the address of an overloaded function when its type needs to be deduced. Algo::SortBy(Array, &LexToString);

// Works as expected Algo::SortBy(Array, UE_PROJECTION(LexToString));

◆ UE_PROJECTION_MEMBER

#define UE_PROJECTION_MEMBER (   Type,
  FuncName 
)
Value:
[](auto&& Obj, auto&&... Args) -> decltype(auto) \
{ \
return UE::Core::Private::DereferenceIfNecessary<Type>((decltype(Obj)&&)Obj, &Obj).FuncName((decltype(Args)&&)Args...); \
}

Wraps up a named member function so that it can easily be passed as a callable. This allows functions with overloads or default arguments to be treated correctly.

Example:

TArray<UObject*> Array = ...;

// Doesn't compile, because &UObject::GetFullName loses the default argument and passes // FString (UObject::*)(const UObject*) to Algo::SortBy<>(), which is not a valid projection. Algo::SortBy(Array, &UObject::GetFullName);

// Works as expected Algo::SortBy(Array, UE_PROJECTION_MEMBER(UObject, GetFullName));

Typedef Documentation

◆ TInvokeResult_T

template<typename FuncType , typename... ArgTypes>
using TInvokeResult_T = typename TInvokeResult<FuncType, ArgTypes...>::Type

Function Documentation

◆ Invoke() [1/3]

template<typename FuncType , typename... ArgTypes>
AUTORTFM_INFER UE_FORCEINLINE_HINT constexpr auto Invoke ( FuncType &&  Func,
ArgTypes &&...  Args 
) -> decltype(((FuncType&&)Func)((ArgTypes&&)Args...))
constexpr

Invokes a callable with a set of arguments. Allows the following:

  • Calling a functor object given a set of arguments.
  • Calling a function pointer given a set of arguments.
  • Calling a member function given a reference to an object and a set of arguments.
  • Calling a member function given a pointer (including smart pointers) to an object and a set of arguments.
  • Projecting via a data member pointer given a reference to an object.
  • Projecting via a data member pointer given a pointer (including smart pointers) to an object.

See: http://en.cppreference.com/w/cpp/utility/functional/invoke

◆ Invoke() [2/3]

template<typename PtrMemFunType , typename TargetType , typename... ArgTypes, typename ObjType = TMemberFunctionPtrOuter_T<PtrMemFunType>>
AUTORTFM_INFER constexpr auto Invoke ( PtrMemFunType  PtrMemFun,
TargetType &&  Target,
ArgTypes &&...  Args 
) -> decltype((UE::Core::Private::DereferenceIfNecessary<ObjType>((TargetType&&)Target, &Target).*PtrMemFun)((ArgTypes&&)Args...))
constexpr

◆ Invoke() [3/3]

template<typename ReturnType , typename ObjType , typename TargetType >
AUTORTFM_INFER constexpr auto Invoke ( ReturnType ObjType::*  pdm,
TargetType &&  Target 
) -> decltype(UE::Core::Private::DereferenceIfNecessary<ObjType>((TargetType&&)Target, &Target).*pdm)
constexpr