MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::TypeName Namespace Reference

Typedefs

using FTypeHash = uint64
 

Functions

template<typename T >
consteval FTypeHash GetCompileTimeTypeHash ()
 
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 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 FTypeHash TTypeHash = GetCompileTimeTypeHash<T>()
 Get a fixed uint64 hash representation of the given type. Have similar caveats as TTypeName
 

Detailed Description

Convert types to string

Typedef Documentation

◆ FTypeHash

using Mcro::TypeName::FTypeHash = uint64

Definition at line 103 of file TypeName.h.

Function Documentation

◆ GetCompileTimeTypeHash()

template<typename T >
FTypeHash Mcro::TypeName::GetCompileTimeTypeHash ( )
consteval

Definition at line 106 of file TypeName.h.

◆ 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 179 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 189 of file TypeName.h.

Variable Documentation

◆ TTypeHash

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

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

Definition at line 172 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:101
consteval std::basic_string_view< TCHAR > GetCompileTimeTypeName()
Get a string view of the compile time typename.
Definition TypeName.h:58

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:161

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 161 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 168 of file TypeName.h.