TFunction

TFunction

Windows
MacOS
Linux

Inheritance Hierarchy

TFunctionRefBase

TFunction

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/GenericPlatform/GenericPlatformMisc.h

Include

#include "GenericPlatform/GenericPlatformMisc.h"

Syntax

Remarks

TFunction<FuncType>

See the class definition for intended usage.

TFunction<FuncType>

A class which represents a copy of something callable. FuncType represents a function type and so TFunction should be defined as follows:

A function taking a string and float and returning int32. Parameter names are optional. TFunction<int32 (const FString& Name, float Scale)>

Unlike TFunctionRef, this object is intended to be used like a UE4 version of std::function. That is, it takes a copy of whatever is bound to it, meaning you can return it from functions and store them in objects without caring about the lifetime of the original object being bound.

Example:

Something.h TFunction<FString (int32)> GetTransform();

Something.cpp TFunction<FString (int32)> GetTransform(const FString& Prefix) { Squares number and returns it as a string with the specified prefix return [=](int32 Num) { return Prefix + TEXT(": ") + TTypeToString<int32>::ToString(Num * Num); }; }

SomewhereElse.cpp #include "Something.h"

void Func() { TFunction<FString (int32)> Transform = GetTransform(TEXT("Hello"));

FString Result = Transform(5); // "Hello: 25" }

Constructors

Name Description

Public function

TFunction

(
    TYPE_OF_NULLPTR
)

Default constructor.

Public function

TFunction

(
    FunctorType&& InFunc
)

Constructor which binds a TFunction to any function object.

Public function

TFunction

(
    TFunction&&
)

Public function

TFunction

(
    const TFunction& Other
)

Destructors

Name Description

Public function

~TFunction()

Operators

Name Description

Public function Const

 

operator bool()

Tests if the TFunction is callable.

Public function

TFunction &

 

operator=

(
    TFunction&& Other
)

Move assignment operator.

Public function

TFunction &

 

operator=

(
    const TFunction& Other
)

Copy assignment operator.

Typedefs

Name

Description

Super

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss