MCRO
C++23 utilities for Unreal Engine.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Mcro::TypeName Namespace Reference

Data Structures

struct  FType
 Group together type info for identification. Can have an invalid state when no type is specified. More...
 

Functions

template<typename T >
FName TTypeFName ()
 Same as TTypeName converted to FName. This is not cached and a new FName is created every time this is called.
 
template<typename T >
FString TTypeString ()
 Same as TTypeName converted to FString. This is not cached and a new FString is created every time this is called.
 

Variables

template<typename T >
constexpr FType TTypeOf = FType(FType::TTag<T>())
 
template<typename T >
constexpr FStringView TTypeName
 Get a friendly string of an input type without using typeid(T).name().
 
template<typename T >
constexpr std::basic_string_view< TCHAR > TTypeNameStd = GetCompileTimeTypeName<std::decay_t<T>>()
 Same as TTypeName just stored as STL string made during compile time.
 
template<typename T >
constexpr uint64 TTypeHash = GetCompileTimeTypeHash<T>()
 Get a fixed uint64 hash representation of the given type. Have similar caveats as TTypeName
 

Detailed Description

Convert types to string

Function Documentation

◆ TTypeFName()

template<typename T >
FName Mcro::TypeName::TTypeFName ( )

Same as TTypeName converted to FName. This is not cached and a new FName is created every time this is called.

Definition at line 213 of file TypeName.h.

◆ TTypeString()

template<typename T >
FString Mcro::TypeName::TTypeString ( )

Same as TTypeName converted to FString. This is not cached and a new FString is created every time this is called.

Definition at line 223 of file TypeName.h.

Variable Documentation

◆ TTypeHash

template<typename T >
uint64 Mcro::TypeName::TTypeHash = GetCompileTimeTypeHash<T>()
constexpr

Get a fixed uint64 hash representation of the given type. Have similar caveats as TTypeName

Definition at line 206 of file TypeName.h.

◆ TTypeName

template<typename T >
FStringView Mcro::TypeName::TTypeName
constexpr
Initial value:
= FStringView(
GetCompileTimeTypeName<std::decay_t<T>>().data(),
GetCompileTimeTypeName<std::decay_t<T>>().size()
)
size_t size(TArray< T, A > const &r)
Definition Range.h:98
consteval std::basic_string_view< TCHAR > GetCompileTimeTypeName()
Get a string view of the compile time typename.
Definition TypeName.h:57

Get a friendly string of an input type without using typeid(T).name().

Actually this method gives more predictable results across compilers than typeid(T).name() but still not 100% the same. Besides TTypeName can deal with incomplete types as well, whereas typeid(T) cannot (more on this in remarks). While it is more consistent across compilers, it is still not 100% consistent. Take templated types for instance where MSVC compiler will add "class" prefix in front of type arguments where GCC or CLang might not. Because of subtle differences like this, it is strongly discouraged to assume the exact format of the output of TTypeName

Usage:

FStringView myTypeName = TTypeName<FMyType>;
constexpr FStringView TTypeName
Get a friendly string of an input type without using typeid(T).name().
Definition TypeName.h:195

It is useful in templates where a type name should be known in runtime as well. (e.g.: Modular features)

Remarks
Note on incomplete types: incomplete types on MSVC are localized to current scope. which means
class I;
class A
{
FStringView GetName() { return TTypeName<I>; }
// Returns "I"
}
BUT:
class A
{
FStringView GetName() { return TTypeName<class I>; }
// Returns "A::GetName::I"
}
as you can see they are not equal. For sake of simplicity TTypeName only supports incomplete types when they're declared in global scope. Any other case might yield undesired results (e.g.: TTypeName<class I> of incomplete I might not be the same as TTypeName<I> somewhere else with I being fully defined)
Template Parameters
TThe type to be named
Warning
Do not use exact type comparison with serialized data or network communication, as the actual value of the type is different between compilers. Only use this for runtime data. For such scenarios just use Unreal's own UObjects.

Definition at line 195 of file TypeName.h.

◆ TTypeNameStd

template<typename T >
std::basic_string_view<TCHAR> Mcro::TypeName::TTypeNameStd = GetCompileTimeTypeName<std::decay_t<T>>()
constexpr

Same as TTypeName just stored as STL string made during compile time.

Definition at line 202 of file TypeName.h.

◆ TTypeOf

template<typename T >
FType Mcro::TypeName::TTypeOf = FType(FType::TTag<T>())
constexpr

Definition at line 144 of file TypeName.h.